PropertySet.java revision 998747bfaaa3c6b28bbfaf0e282e6c0ccbf46bc0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008 Sun Microsystems, Inc.
* Portions Copyright 2015 ForgeRock AS
*/
/**
* A set of properties. Instances of this class can be used as the
* core of a managed object implementation.
*/
public final class PropertySet {
/**
* Internal property implementation.
*
* @param <T>
* The type of the property.
*/
private static final class MyProperty<T> implements Property<T> {
// The active set of values.
private final SortedSet<T> activeValues;
// The definition associated with this property.
private final PropertyDefinition<T> d;
// The default set of values (read-only).
private final SortedSet<T> defaultValues;
// The pending set of values.
private final SortedSet<T> pendingValues;
/**
* Create a property with the provided sets of pre-validated
* default and active values.
*
* @param pd
* The property definition.
* @param defaultValues
* The set of default values for the property.
* @param activeValues
* The set of active values for the property.
*/
Collection<T> activeValues) {
this.d = pd;
this.defaultValues = Collections
// Initially the pending values is the same as the active
// values.
}
/**
* Makes the pending values active.
*/
public void commit() {
}
/**
* {@inheritDoc}
*/
public SortedSet<T> getActiveValues() {
}
/**
* {@inheritDoc}
*/
public SortedSet<T> getDefaultValues() {
return defaultValues;
}
/**
* {@inheritDoc}
*/
public SortedSet<T> getEffectiveValues() {
values = getDefaultValues();
}
return values;
}
/**
* {@inheritDoc}
*/
public SortedSet<T> getPendingValues() {
}
/**
* {@inheritDoc}
*/
public PropertyDefinition<T> getPropertyDefinition() {
return d;
}
/**
* {@inheritDoc}
*/
public boolean isEmpty() {
return pendingValues.isEmpty();
}
/**
* {@inheritDoc}
*/
public boolean isModified() {
}
/**
* Replace all pending values of this property with the provided
* values.
*
* @param c
* The new set of pending property values.
*/
public void setPendingValues(Collection<T> c) {
pendingValues.addAll(c);
}
/**
* {@inheritDoc}
*/
return getEffectiveValues().toString();
}
/**
* {@inheritDoc}
*/
public boolean wasEmpty() {
return activeValues.isEmpty();
}
}
// The properties.
/**
* Creates a new empty property set.
*/
public PropertySet() {
}
/**
* Creates a property with the provided sets of pre-validated
* default and active values.
*
* @param <T>
* The type of the property.
* @param pd
* The property definition.
* @param defaultValues
* The set of default values for the property.
* @param activeValues
* The set of active values for the property.
*/
}
/**
* Get the property associated with the specified property
* definition.
*
* @param <T>
* The underlying type of the property.
* @param d
* The Property definition.
* @return Returns the property associated with the specified
* property definition.
* @throws IllegalArgumentException
* If this property provider does not recognise the
* requested property definition.
*/
@SuppressWarnings("unchecked")
throws IllegalArgumentException {
if (!properties.containsKey(d)) {
}
}
/**
* {@inheritDoc}
*/
}
}
/**
* Makes all pending values active.
*/
void commit()
{
{
p.commit();
}
}
/**
* Set a new pending values for the specified property.
* <p>
* See the class description for more information regarding pending values.
*
* @param <T>
* The type of the property to be modified.
* @param d
* The property to be modified.
* @param values
* A non-<code>null</code> set of new pending values for the property
* (an empty set indicates that the property should be reset to its
* default behavior). The set will not be referenced by this managed
* object.
* @throws PropertyException
* If a new pending value is deemed to be invalid according to the
* property definition, or if an attempt was made to add multiple
* pending values to a single-valued property, or if an attempt was
* made to remove a mandatory property.
* @throws IllegalArgumentException
* If the specified property definition is not associated with this
* managed object.
*/
{
}
// But only if there are no default values.
}
}
// Validate each value.
for (T e : values) {
if (e == null) {
throw new NullPointerException();
}
d.validateValue(e);
}
// Update the property.
}
}