| | |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS |
| | | */ |
| | | |
| | | package org.opends.server.admin.client.spi; |
| | | |
| | | |
| | | |
| | | import static org.opends.server.admin.PropertyException.*; |
| | | |
| | | import java.util.ArrayList; |
| | |
| | | import org.opends.server.admin.Configuration; |
| | | import org.opends.server.admin.ConfigurationClient; |
| | | import org.opends.server.admin.Constraint; |
| | | import org.opends.server.admin.PropertyException; |
| | | import org.opends.server.admin.DefaultBehaviorProviderVisitor; |
| | | import org.opends.server.admin.DefinedDefaultBehaviorProvider; |
| | | import org.opends.server.admin.DefinitionDecodingException; |
| | | import org.opends.server.admin.DefinitionDecodingException.Reason; |
| | | import org.opends.server.admin.InstantiableRelationDefinition; |
| | | import org.opends.server.admin.ManagedObjectNotFoundException; |
| | | import org.opends.server.admin.ManagedObjectPath; |
| | | import org.opends.server.admin.OptionalRelationDefinition; |
| | | import org.opends.server.admin.PropertyDefinition; |
| | | import org.opends.server.admin.PropertyException; |
| | | import org.opends.server.admin.PropertyNotFoundException; |
| | | import org.opends.server.admin.PropertyOption; |
| | | import org.opends.server.admin.RelationDefinition; |
| | | import org.opends.server.admin.RelativeInheritedDefaultBehaviorProvider; |
| | | import org.opends.server.admin.SetRelationDefinition; |
| | | import org.opends.server.admin.UndefinedDefaultBehaviorProvider; |
| | | import org.opends.server.admin.DefinitionDecodingException.Reason; |
| | | import org.opends.server.admin.client.AuthorizationException; |
| | | import org.opends.server.admin.client.ClientConstraintHandler; |
| | | import org.opends.server.admin.client.CommunicationException; |
| | |
| | | import org.opends.server.admin.client.OperationRejectedException.OperationType; |
| | | import org.opends.server.admin.std.client.RootCfgClient; |
| | | |
| | | |
| | | |
| | | /** |
| | | * An abstract management connection context driver which should form |
| | | * the basis of driver implementations. |
| | |
| | | /** The next property whose default values were required. */ |
| | | private PropertyDefinition<T> nextProperty; |
| | | |
| | | |
| | | |
| | | /** Private constructor. */ |
| | | private DefaultValueFinder(ManagedObjectPath<?, ?> p, boolean isCreate) { |
| | | this.firstPath = p; |
| | | this.isCreate = isCreate; |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Collection<T> visitAbsoluteInherited( |
| | | AbsoluteInheritedDefaultBehaviorProvider<T> d, Void p) { |
| | | try { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Collection<T> visitAlias(AliasDefaultBehaviorProvider<T> d, Void p) { |
| | | return Collections.emptySet(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Collection<T> visitDefined(DefinedDefaultBehaviorProvider<T> d, |
| | | Void p) { |
| | | Collection<String> stringValues = d.getDefaultValues(); |
| | | List<T> values = new ArrayList<T>(stringValues.size()); |
| | | List<T> values = new ArrayList<>(stringValues.size()); |
| | | |
| | | for (String stringValue : stringValues) { |
| | | try { |
| | |
| | | return values; |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Collection<T> visitRelativeInherited( |
| | | RelativeInheritedDefaultBehaviorProvider<T> d, Void p) { |
| | | try { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Collection<T> visitUndefined(UndefinedDefaultBehaviorProvider<T> d, |
| | | Void p) { |
| | | return Collections.emptySet(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** Find the default values for the next path/property. */ |
| | | private Collection<T> find(ManagedObjectPath<?, ?> p, |
| | | PropertyDefinition<T> pd) throws PropertyException { |
| | |
| | | return values; |
| | | } |
| | | |
| | | |
| | | |
| | | /** Get an inherited property value. */ |
| | | @SuppressWarnings("unchecked") |
| | | private Collection<T> getInheritedProperty(ManagedObjectPath target, |
| | |
| | | if (isCreate && firstPath.equals(target)) { |
| | | // Recursively retrieve this property's default values. |
| | | Collection<T> tmp = find(target, pd2); |
| | | Collection<T> values = new ArrayList<T>(tmp.size()); |
| | | Collection<T> values = new ArrayList<>(tmp.size()); |
| | | for (T value : tmp) { |
| | | pd1.validateValue(value); |
| | | values.add(value); |
| | |
| | | // inherits its defaults from the newly created managed object. |
| | | return getPropertyValues(target, pd2); |
| | | } |
| | | } catch (PropertyException e) { |
| | | // Wrap any errors due to recursion. |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | | } catch (DefinitionDecodingException e) { |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | | } catch (PropertyNotFoundException e) { |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | | } catch (AuthorizationException e) { |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | | } catch (ManagedObjectNotFoundException e) { |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | | } catch (CommunicationException e) { |
| | | } catch (PropertyException | DefinitionDecodingException | PropertyNotFoundException |
| | | | AuthorizationException | ManagedObjectNotFoundException | CommunicationException e) { |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | | } |
| | | } |
| | | }; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new abstract management context. |
| | | */ |
| | | /** Creates a new abstract management context. */ |
| | | protected Driver() { |
| | | // No implementation required. |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Closes any context associated with this management context |
| | | * driver. |
| | | */ |
| | | /** Closes any context associated with this management context driver. */ |
| | | public void close() { |
| | | // do nothing by default |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Deletes the named instantiable child managed object from the |
| | | * named parent managed object. |
| | |
| | | return doDeleteManagedObject(child); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Deletes the optional child managed object from the named parent |
| | | * managed object. |
| | |
| | | return doDeleteManagedObject(child); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Deletes the named instantiable child managed object from the |
| | | * named parent managed object. |
| | |
| | | return doDeleteManagedObject(child); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the named managed object. The path is guaranteed to be |
| | | * non-empty, so implementations do not need to worry about handling |
| | |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, |
| | | AuthorizationException, CommunicationException; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the effective values of a property in the named managed |
| | | * object. |
| | |
| | | AuthorizationException, ManagedObjectNotFoundException, |
| | | CommunicationException, PropertyException; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the root configuration managed object associated with this |
| | | * management context driver. |
| | |
| | | public abstract |
| | | ManagedObject<RootCfgClient> getRootConfigurationManagedObject(); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Lists the child managed objects of the named parent managed |
| | | * object which are a sub-type of the specified managed object |
| | |
| | | throws IllegalArgumentException, ManagedObjectNotFoundException, |
| | | AuthorizationException, CommunicationException; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Lists the child managed objects of the named parent managed |
| | | * object which are a sub-type of the specified managed object |
| | |
| | | throws IllegalArgumentException, ManagedObjectNotFoundException, |
| | | AuthorizationException, CommunicationException; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Determines whether or not the named managed object exists. |
| | | * <p> |
| | |
| | | throws ManagedObjectNotFoundException, AuthorizationException, |
| | | CommunicationException; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Deletes the named managed object. |
| | | * <p> |
| | |
| | | ManagedObjectPath<C, S> path) throws OperationRejectedException, |
| | | AuthorizationException, CommunicationException; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the default values for the specified property. |
| | | * |
| | |
| | | protected final <PD> Collection<PD> findDefaultValues( |
| | | ManagedObjectPath<?, ?> p, PropertyDefinition<PD> pd, boolean isCreate) |
| | | throws PropertyException { |
| | | DefaultValueFinder<PD> v = new DefaultValueFinder<PD>(p, isCreate); |
| | | DefaultValueFinder<PD> v = new DefaultValueFinder<>(p, isCreate); |
| | | return v.find(p, pd); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the management context associated with this driver. |
| | | * |
| | |
| | | */ |
| | | protected abstract ManagementContext getManagementContext(); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Validate that a relation definition belongs to the managed object |
| | | * referenced by the provided path. |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Remove a managed object, first ensuring that the parent exists, |
| | | * then ensuring that the child exists, before ensuring that any |
| | |
| | | // The targeted managed object is guaranteed to exist, so enforce |
| | | // any constraints. |
| | | AbstractManagedObjectDefinition<?, ?> d = path.getManagedObjectDefinition(); |
| | | List<LocalizableMessage> messages = new LinkedList<LocalizableMessage>(); |
| | | List<LocalizableMessage> messages = new LinkedList<>(); |
| | | boolean isAcceptable = true; |
| | | |
| | | for (Constraint constraint : d.getAllConstraints()) { |
| | |
| | | deleteManagedObject(path); |
| | | return true; |
| | | } |
| | | |
| | | } |