| | |
| | | import org.opends.server.admin.RelationDefinition; |
| | | import org.opends.server.admin.RelativeInheritedDefaultBehaviorProvider; |
| | | import org.opends.server.admin.UndefinedDefaultBehaviorProvider; |
| | | import org.opends.server.admin.UnknownPropertyDefinitionException; |
| | | import org.opends.server.admin.DefinitionDecodingException.Reason; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.config.ConfigurationRepository; |
| | |
| | | * @param <T> |
| | | * The type of the property. |
| | | */ |
| | | private class DefaultValueFinder<T> implements DefaultBehaviorProviderVisitor<T, Collection<T>, Void> { |
| | | private final class DefaultValueFinder<T> implements DefaultBehaviorProviderVisitor<T, Collection<T>, Void> { |
| | | |
| | | // Any exception that occurred whilst retrieving inherited default |
| | | // values. |
| | |
| | | } |
| | | |
| | | // Find the default values for the next path/property. |
| | | private Collection<T> find(ManagedObjectPath<?, ?> path, PropertyDefinition<T> propertyDef) |
| | | throws DefaultBehaviorException { |
| | | private Collection<T> find(ManagedObjectPath<?, ?> path, PropertyDefinition<T> propertyDef) { |
| | | nextPath = path; |
| | | nextProperty = propertyDef; |
| | | |
| | |
| | | |
| | | // Get an inherited property value. |
| | | @SuppressWarnings("unchecked") |
| | | private Collection<T> getInheritedProperty(ManagedObjectPath<?,?> target, |
| | | AbstractManagedObjectDefinition<?, ?> definition, String propertyName) |
| | | throws DefaultBehaviorException { |
| | | private Collection<T> getInheritedProperty(ManagedObjectPath<?, ?> target, |
| | | AbstractManagedObjectDefinition<?, ?> definition, String propertyName) { |
| | | // First check that the requested type of managed object |
| | | // corresponds to the path. |
| | | AbstractManagedObjectDefinition<?, ?> supr = target.getManagedObjectDefinition(); |
| | |
| | | * A definition resolver that determines the managed object definition from |
| | | * the object classes of a ConfigEntry. |
| | | */ |
| | | private class MyDefinitionResolver implements DefinitionResolver { |
| | | private final class MyDefinitionResolver implements DefinitionResolver { |
| | | |
| | | // The config entry. |
| | | private final Entry entry; |
| | |
| | | /** |
| | | * Decodes the provided property LDAP value. |
| | | * |
| | | * @param <PD> |
| | | * @param <P> |
| | | * The type of the property. |
| | | * @param propertyDef |
| | | * The property definition. |
| | |
| | | * If the property value could not be decoded because it was |
| | | * invalid. |
| | | */ |
| | | public static <PD> PD decode(PropertyDefinition<PD> propertyDef, String value) |
| | | throws IllegalPropertyValueStringException { |
| | | public static <P> P decode(PropertyDefinition<P> propertyDef, String value) { |
| | | return propertyDef.castValue(propertyDef.accept(new ValueDecoder(), value)); |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <T> Object visitUnknown(PropertyDefinition<T> d, String p) throws UnknownPropertyDefinitionException { |
| | | public <T> Object visitUnknown(PropertyDefinition<T> d, String p) { |
| | | // By default the property definition's decoder will do. |
| | | return d.decodeValue(p); |
| | | } |
| | |
| | | */ |
| | | private volatile ServerManagedObject<RootCfg> root; |
| | | |
| | | /** Repository of configuration entries */ |
| | | /** Repository of configuration entries. */ |
| | | private final ConfigurationRepository configRepository; |
| | | |
| | | /** |
| | |
| | | * @param <S> |
| | | * The type of server managed object configuration that the path |
| | | * definition refers to. |
| | | * @param <PD> |
| | | * @param <P> |
| | | * The type of the property to be retrieved. |
| | | * @param path |
| | | * The path of the managed object containing the property. |
| | |
| | | * If the named managed object could not be found or if it could |
| | | * not be decoded. |
| | | */ |
| | | public <C extends ConfigurationClient, S extends Configuration, PD> PD getPropertyValue( |
| | | ManagedObjectPath<C, S> path, PropertyDefinition<PD> pd) throws IllegalArgumentException, ConfigException, |
| | | PropertyException { |
| | | SortedSet<PD> values = getPropertyValues(path, pd); |
| | | public <C extends ConfigurationClient, S extends Configuration, P> P getPropertyValue( |
| | | ManagedObjectPath<C, S> path, PropertyDefinition<P> pd) throws ConfigException { |
| | | SortedSet<P> values = getPropertyValues(path, pd); |
| | | if (values.isEmpty()) { |
| | | return null; |
| | | } else { |
| | |
| | | * @param <S> |
| | | * The type of server managed object configuration that the path |
| | | * definition refers to. |
| | | * @param <PD> |
| | | * @param <P> |
| | | * The type of the property to be retrieved. |
| | | * @param path |
| | | * The path of the managed object containing the property. |
| | |
| | | * not be decoded. |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public <C extends ConfigurationClient, S extends Configuration, PD> SortedSet<PD> getPropertyValues( |
| | | ManagedObjectPath<C, S> path, PropertyDefinition<PD> propertyDef) throws IllegalArgumentException, ConfigException, |
| | | PropertyException { |
| | | public <C extends ConfigurationClient, S extends Configuration, P> SortedSet<P> getPropertyValues( |
| | | ManagedObjectPath<C, S> path, PropertyDefinition<P> propertyDef) throws ConfigException { |
| | | // Check that the requested property is from the definition |
| | | // associated with the path. |
| | | AbstractManagedObjectDefinition<C, S> definition = path.getManagedObjectDefinition(); |
| | |
| | | // Make sure we use the correct property definition, the |
| | | // provided one might have been overridden in the resolved |
| | | // definition. |
| | | propertyDef = (PropertyDefinition<PD>) managedObjDef.getPropertyDefinition(propertyDef.getName()); |
| | | propertyDef = (PropertyDefinition<P>) managedObjDef.getPropertyDefinition(propertyDef.getName()); |
| | | |
| | | List<String> attributeValues = getAttributeValues(managedObjDef, propertyDef, configEntry); |
| | | return decodeProperty(path.asSubType(managedObjDef), propertyDef, attributeValues, null); |
| | |
| | | * @return the root configuration server managed object |
| | | */ |
| | | public ServerManagedObject<RootCfg> getRootConfigurationManagedObject() { |
| | | // Use lazy initialisation because it needs a reference to this server context. |
| | | // Use lazy initialisation because it needs a reference to this server |
| | | // context. |
| | | ServerManagedObject<RootCfg> rootObject = root; |
| | | if (rootObject == null) { |
| | | synchronized(this) { |
| | | synchronized (this) { |
| | | rootObject = root; |
| | | if (rootObject == null) { |
| | | root = rootObject = new ServerManagedObject<RootCfg>(ManagedObjectPath.emptyPath(), |
| | | RootCfgDefn.getInstance(), Collections.<PropertyDefinition<?>, SortedSet<?>> emptyMap(), |
| | | null, this); |
| | | root = rootObject = |
| | | new ServerManagedObject<RootCfg>(ManagedObjectPath.emptyPath(), |
| | | RootCfgDefn.getInstance(), Collections.<PropertyDefinition<?>, |
| | | SortedSet<?>> emptyMap(), null, this); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | /** Decode a property using the provided attribute values. */ |
| | | private <T> SortedSet<T> decodeProperty(ManagedObjectPath<?, ?> path, PropertyDefinition<T> propertyDef, |
| | | List<String> attributeValues, Entry newConfigEntry) throws PropertyException { |
| | | List<String> attributeValues, Entry newConfigEntry) { |
| | | PropertyException exception = null; |
| | | SortedSet<T> pvalues = new TreeSet<T>(propertyDef); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** Gets the attribute values associated with a property from a ConfigEntry */ |
| | | /** Gets the attribute values associated with a property from a ConfigEntry. */ |
| | | private List<String> getAttributeValues(ManagedObjectDefinition<?, ?> d, PropertyDefinition<?> pd, |
| | | Entry configEntry) { |
| | | // TODO: we create a default attribute type if it is undefined. |
| | |
| | | |
| | | // Get the default values for the specified property. |
| | | private <T> Collection<T> getDefaultValues(ManagedObjectPath<?, ?> p, PropertyDefinition<T> pd, |
| | | Entry newConfigEntry) throws DefaultBehaviorException { |
| | | Entry newConfigEntry) { |
| | | DefaultValueFinder<T> v = new DefaultValueFinder<T>(newConfigEntry); |
| | | return v.find(p, pd); |
| | | } |
| | |
| | | } |
| | | |
| | | // Validate that a relation definition belongs to the path. |
| | | private void validateRelationDefinition(ManagedObjectPath<?, ?> path, RelationDefinition<?, ?> rd) |
| | | throws IllegalArgumentException { |
| | | private void validateRelationDefinition(ManagedObjectPath<?, ?> path, RelationDefinition<?, ?> rd) { |
| | | AbstractManagedObjectDefinition<?, ?> d = path.getManagedObjectDefinition(); |
| | | RelationDefinition<?, ?> tmp = d.getRelationDefinition(rd.getName()); |
| | | if (tmp != rd) { |