Checkpoint commit for OPENDJ-1235 : Migrate configuration framework
* Fix all checkstyle errors.
* Migrate missing package-info.java files for some packages
113 files modified
6 files added
| | |
| | | /** |
| | | * ACI property definition. |
| | | */ |
| | | public class ACIPropertyDefinition extends PropertyDefinition<Aci> { |
| | | public final class ACIPropertyDefinition extends PropertyDefinition<Aci> { |
| | | |
| | | /** |
| | | * An interface for incrementally constructing ACI property definitions. |
| | | */ |
| | | public static final class Builder extends AbstractBuilder<Aci, ACIPropertyDefinition> { |
| | | |
| | | /** |
| | | * An interface for incrementally constructing ACI property |
| | | * definitions. |
| | | */ |
| | | public static class Builder extends |
| | | AbstractBuilder<Aci, ACIPropertyDefinition> { |
| | | // Private constructor |
| | | private Builder(AbstractManagedObjectDefinition<?, ?> d, String propertyName) { |
| | | super(d, propertyName); |
| | | } |
| | | |
| | | // Private constructor |
| | | private Builder( |
| | | AbstractManagedObjectDefinition<?, ?> d, String propertyName) { |
| | | super(d, propertyName); |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected ACIPropertyDefinition buildInstance(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Aci> defaultBehavior) { |
| | | return new ACIPropertyDefinition(d, propertyName, options, adminAction, defaultBehavior); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Create a ACI property definition builder. |
| | | * |
| | | * @param d |
| | | * The managed object definition associated with this property |
| | | * definition. |
| | | * @param propertyName |
| | | * The property name. |
| | | * @return Returns the new ACI property definition builder. |
| | | */ |
| | | public static Builder createBuilder(AbstractManagedObjectDefinition<?, ?> d, String propertyName) { |
| | | return new Builder(d, propertyName); |
| | | } |
| | | |
| | | // Private constructor. |
| | | private ACIPropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Aci> defaultBehavior) { |
| | | super(d, Aci.class, propertyName, options, adminAction, defaultBehavior); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected ACIPropertyDefinition buildInstance( |
| | | AbstractManagedObjectDefinition<?, ?> d, |
| | | String propertyName, EnumSet<PropertyOption> options, |
| | | AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Aci> defaultBehavior) { |
| | | return new ACIPropertyDefinition(d, propertyName, options, |
| | | adminAction, defaultBehavior); |
| | | public void validateValue(Aci value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Aci decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | /** |
| | | * Create a ACI property definition builder. |
| | | * |
| | | * @param d |
| | | * The managed object definition associated with this |
| | | * property definition. |
| | | * @param propertyName |
| | | * The property name. |
| | | * @return Returns the new ACI property definition builder. |
| | | */ |
| | | public static Builder createBuilder( |
| | | AbstractManagedObjectDefinition<?, ?> d, String propertyName) { |
| | | return new Builder(d, propertyName); |
| | | } |
| | | |
| | | |
| | | // Private constructor. |
| | | private ACIPropertyDefinition( |
| | | AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, |
| | | AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Aci> defaultBehavior) { |
| | | super(d, Aci.class, propertyName, options, adminAction, |
| | | defaultBehavior); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Aci value) |
| | | throws IllegalPropertyValueException { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Aci decodeValue(String value) |
| | | throws IllegalPropertyValueStringException { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | | return Aci.decode(ByteString.valueOf(value), DN.rootDN()); |
| | | } catch (AciException e) { |
| | | // TODO: it would be nice to throw the cause. |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | try { |
| | | return Aci.decode(ByteString.valueOf(value), DN.rootDN()); |
| | | } catch (AciException e) { |
| | | // TODO: it would be nice to throw the cause. |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <R, P> R accept(PropertyDefinitionVisitor<R, P> v, P p) { |
| | | return v.visitACI(this, p); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <R, P> R accept(PropertyDefinitionVisitor<R, P> v, P p) { |
| | | return v.visitACI(this, p); |
| | | } |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <R, P> R accept(PropertyValueVisitor<R, P> v, Aci value, P p) { |
| | | return v.visitACI(this, value, p); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <R, P> R accept(PropertyValueVisitor<R, P> v, Aci value, P p) { |
| | | return v.visitACI(this, value, p); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public int compare(Aci o1, Aci o2) { |
| | | return o1.toString().compareTo(o2.toString()); |
| | | } |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public int compare(Aci o1, Aci o2) { |
| | | return o1.toString().compareTo(o2.toString()); |
| | | } |
| | | } |
| | |
| | | * |
| | | * Copyright 2007-2010 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | import java.util.ArrayList; |
| | |
| | | * <code>null</code> parent, unless the definition is being used |
| | | * for testing). |
| | | */ |
| | | protected AbstractManagedObjectDefinition(String name, AbstractManagedObjectDefinition<? super C, ? super S> parent) { |
| | | protected AbstractManagedObjectDefinition(String name, |
| | | AbstractManagedObjectDefinition<? super C, ? super S> parent) { |
| | | this.name = name; |
| | | this.parent = parent; |
| | | this.constraints = new LinkedList<Constraint>(); |
| | |
| | | * definition. |
| | | */ |
| | | public final Collection<AbstractManagedObjectDefinition<? extends C, ? extends S>> getAllChildren() { |
| | | List<AbstractManagedObjectDefinition<? extends C, ? extends S>> list = new ArrayList<AbstractManagedObjectDefinition<? extends C, ? extends S>>( |
| | | children.values()); |
| | | List<AbstractManagedObjectDefinition<? extends C, ? extends S>> list = |
| | | new ArrayList<AbstractManagedObjectDefinition<? extends C, ? extends S>>(children.values()); |
| | | |
| | | for (AbstractManagedObjectDefinition<? extends C, ? extends S> child : children.values()) { |
| | | list.addAll(child.getAllChildren()); |
| | |
| | | // This method does not used a cached set of relations because |
| | | // relations may be updated after child definitions have been |
| | | // defined. |
| | | List<RelationDefinition<? super C, ? super S>> rdlist = new LinkedList<RelationDefinition<? super C, ? super S>>(); |
| | | List<RelationDefinition<? super C, ? super S>> rdlist = |
| | | new LinkedList<RelationDefinition<? super C, ? super S>>(); |
| | | |
| | | if (parent != null) { |
| | | rdlist.addAll(parent.getAllReverseRelationDefinitions()); |
| | |
| | | * empty or if the requested subordinate managed object |
| | | * definition was not found. |
| | | */ |
| | | public final AbstractManagedObjectDefinition<? extends C, ? extends S> getChild(String name) |
| | | throws IllegalArgumentException { |
| | | public final AbstractManagedObjectDefinition<? extends C, ? extends S> getChild(String name) { |
| | | if ((name == null) || (name.length() == 0)) { |
| | | throw new IllegalArgumentException("null or empty managed object name"); |
| | | } |
| | |
| | | * @throws UnsupportedOperationException |
| | | * If this managed object definition is the {@link TopCfgDefn}. |
| | | */ |
| | | public final LocalizableMessage getDescription() throws UnsupportedOperationException { |
| | | public final LocalizableMessage getDescription() { |
| | | return getDescription(Locale.getDefault()); |
| | | } |
| | | |
| | |
| | | * @throws UnsupportedOperationException |
| | | * If this managed object definition is the {@link TopCfgDefn}. |
| | | */ |
| | | public final LocalizableMessage getDescription(Locale locale) throws UnsupportedOperationException { |
| | | public final LocalizableMessage getDescription(Locale locale) { |
| | | try { |
| | | return ManagedObjectDefinitionI18NResource.getInstance().getMessage(this, "description", locale); |
| | | } catch (MissingResourceException e) { |
| | |
| | | * If the specified property name was null or empty or if the |
| | | * requested property definition was not found. |
| | | */ |
| | | public final PropertyDefinition<?> getPropertyDefinition(String name) throws IllegalArgumentException { |
| | | public final PropertyDefinition<?> getPropertyDefinition(String name) { |
| | | if ((name == null) || (name.length() == 0)) { |
| | | throw new IllegalArgumentException("null or empty property name"); |
| | | } |
| | |
| | | * If the specified relation name was null or empty or if the |
| | | * requested relation definition was not found. |
| | | */ |
| | | public final RelationDefinition<?, ?> getRelationDefinition(String name) throws IllegalArgumentException { |
| | | public final RelationDefinition<?, ?> getRelationDefinition(String name) { |
| | | if ((name == null) || (name.length() == 0)) { |
| | | throw new IllegalArgumentException("null or empty relation name"); |
| | | } |
| | |
| | | * or if the requested aggregation property definition was not |
| | | * found. |
| | | */ |
| | | public final AggregationPropertyDefinition<?, ?> getAggregationPropertyDefinition(String name) |
| | | throws IllegalArgumentException { |
| | | public final AggregationPropertyDefinition<?, ?> getAggregationPropertyDefinition(String name) { |
| | | if ((name == null) || (name.length() == 0)) { |
| | | throw new IllegalArgumentException("null or empty aggregation property name"); |
| | | } |
| | |
| | | * @throws UnsupportedOperationException |
| | | * If this managed object definition is the {@link TopCfgDefn}. |
| | | */ |
| | | public final LocalizableMessage getSynopsis() throws UnsupportedOperationException { |
| | | public final LocalizableMessage getSynopsis() { |
| | | return getSynopsis(Locale.getDefault()); |
| | | } |
| | | |
| | |
| | | * @throws UnsupportedOperationException |
| | | * If this managed object definition is the {@link TopCfgDefn}. |
| | | */ |
| | | public final LocalizableMessage getSynopsis(Locale locale) throws UnsupportedOperationException { |
| | | public final LocalizableMessage getSynopsis(Locale locale) { |
| | | return ManagedObjectDefinitionI18NResource.getInstance().getMessage(this, "synopsis", locale); |
| | | } |
| | | |
| | |
| | | * @throws UnsupportedOperationException |
| | | * If this managed object definition is the {@link TopCfgDefn}. |
| | | */ |
| | | public final LocalizableMessage getUserFriendlyName() throws UnsupportedOperationException { |
| | | public final LocalizableMessage getUserFriendlyName() { |
| | | return getUserFriendlyName(Locale.getDefault()); |
| | | } |
| | | |
| | |
| | | * @throws UnsupportedOperationException |
| | | * If this managed object definition is the {@link TopCfgDefn}. |
| | | */ |
| | | public final LocalizableMessage getUserFriendlyName(Locale locale) throws UnsupportedOperationException { |
| | | public final LocalizableMessage getUserFriendlyName(Locale locale) { |
| | | return LocalizableMessage.raw(ManagedObjectDefinitionI18NResource.getInstance().getMessage(this, |
| | | "user-friendly-name", locale)); |
| | | "user-friendly-name", locale)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws UnsupportedOperationException |
| | | * If this managed object definition is the {@link TopCfgDefn}. |
| | | */ |
| | | public final LocalizableMessage getUserFriendlyPluralName() throws UnsupportedOperationException { |
| | | public final LocalizableMessage getUserFriendlyPluralName() { |
| | | return getUserFriendlyPluralName(Locale.getDefault()); |
| | | } |
| | | |
| | |
| | | * @throws UnsupportedOperationException |
| | | * If this managed object definition is the {@link TopCfgDefn}. |
| | | */ |
| | | public final LocalizableMessage getUserFriendlyPluralName(Locale locale) throws UnsupportedOperationException { |
| | | return ManagedObjectDefinitionI18NResource.getInstance().getMessage(this, |
| | | "user-friendly-plural-name", locale); |
| | | public final LocalizableMessage getUserFriendlyPluralName(Locale locale) { |
| | | return ManagedObjectDefinitionI18NResource.getInstance() |
| | | .getMessage(this, "user-friendly-plural-name", locale); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | // Register a relation definition in the referenced managed object |
| | | // definition's reverse lookup table. |
| | | private <CC extends ConfigurationClient, SS extends Configuration> void registerReverseRelationDefinition( |
| | | RelationDefinition<CC, SS> rd) { |
| | | private <C1 extends ConfigurationClient, S1 extends Configuration> void registerReverseRelationDefinition( |
| | | RelationDefinition<C1, S1> rd) { |
| | | rd.getChildDefinition().reverseRelationDefinitions.add(rd); |
| | | } |
| | | |
| | |
| | | // Recursively descend definition hierarchy to find the best match |
| | | // definition. |
| | | private AbstractManagedObjectDefinition<? extends C, ? extends S> resolveManagedObjectDefinitionAux( |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d, DefinitionResolver r) { |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d, DefinitionResolver r) { |
| | | if (!r.matches(d)) { |
| | | return null; |
| | | } |
| | | |
| | | for (AbstractManagedObjectDefinition<? extends C, ? extends S> child : d.getChildren()) { |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> rd = resolveManagedObjectDefinitionAux(child, r); |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> rd = |
| | | resolveManagedObjectDefinitionAux(child, r); |
| | | if (rd != null) { |
| | | return rd; |
| | | } |
| | |
| | | * aggregation property definition refers to. |
| | | */ |
| | | public final class AggregationPropertyDefinition<C extends ConfigurationClient, S extends Configuration> extends |
| | | PropertyDefinition<String> { |
| | | PropertyDefinition<String> { |
| | | |
| | | /** |
| | | * An interface for incrementally constructing aggregation property |
| | |
| | | * The type of server managed object configuration that this |
| | | * aggregation property definition refers to. |
| | | */ |
| | | public static class Builder<C extends ConfigurationClient, S extends Configuration> extends |
| | | AbstractBuilder<String, AggregationPropertyDefinition<C, S>> { |
| | | public static final class Builder<C extends ConfigurationClient, S extends Configuration> extends |
| | | AbstractBuilder<String, AggregationPropertyDefinition<C, S>> { |
| | | |
| | | // The string representation of the managed object path specifying |
| | | // the parent of the aggregated managed objects. |
| | |
| | | */ |
| | | @Override |
| | | protected AggregationPropertyDefinition<C, S> buildInstance(AbstractManagedObjectDefinition<?, ?> d, |
| | | String propertyName, EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<String> defaultBehavior) { |
| | | String propertyName, EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<String> defaultBehavior) { |
| | | // Make sure that the parent path has been defined. |
| | | if (parentPathString == null) { |
| | | throw new IllegalStateException("Parent path undefined"); |
| | |
| | | } |
| | | |
| | | return new AggregationPropertyDefinition<C, S>(d, propertyName, options, adminAction, defaultBehavior, |
| | | parentPathString, rdName, targetNeedsEnablingCondition, targetIsEnabledCondition); |
| | | parentPathString, rdName, targetNeedsEnablingCondition, targetIsEnabledCondition); |
| | | } |
| | | |
| | | } |
| | |
| | | /** |
| | | * A change listener which prevents the named component from being disabled. |
| | | */ |
| | | private class ReferentialIntegrityChangeListener implements ServerManagedObjectChangeListener<S> { |
| | | private final class ReferentialIntegrityChangeListener implements ServerManagedObjectChangeListener<S> { |
| | | |
| | | // The error message which should be returned if an attempt is |
| | | // made to disable the referenced component. |
| | |
| | | // This should not happen - the previous call-back should have |
| | | // trapped this. |
| | | throw new IllegalStateException("Attempting to disable a referenced " |
| | | + relationDefinition.getChildDefinition().getUserFriendlyName()); |
| | | + relationDefinition.getChildDefinition().getUserFriendlyName()); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean isConfigurationChangeAcceptable(ServerManagedObject<? extends S> mo, |
| | | List<LocalizableMessage> unacceptableReasons) { |
| | | List<LocalizableMessage> unacceptableReasons) { |
| | | // Always prevent the referenced component from being |
| | | // disabled. |
| | | try { |
| | |
| | | } catch (ConfigException e) { |
| | | // The condition could not be evaluated. |
| | | debugLogger.trace("Unable to perform post add", e); |
| | | LocalizableMessage message = ERR_REFINT_UNABLE_TO_EVALUATE_TARGET_CONDITION.get(mo |
| | | .getManagedObjectDefinition().getUserFriendlyName(), String.valueOf(mo.getDN()), |
| | | getExceptionMessage(e)); |
| | | LocalizedLogger logger = LocalizedLogger |
| | | .getLocalizedLogger(ERR_REFINT_UNABLE_TO_EVALUATE_TARGET_CONDITION.resourceName()); |
| | | LocalizableMessage message = |
| | | ERR_REFINT_UNABLE_TO_EVALUATE_TARGET_CONDITION.get(mo.getManagedObjectDefinition() |
| | | .getUserFriendlyName(), String.valueOf(mo.getDN()), getExceptionMessage(e)); |
| | | LocalizedLogger logger = |
| | | LocalizedLogger.getLocalizedLogger(ERR_REFINT_UNABLE_TO_EVALUATE_TARGET_CONDITION.resourceName()); |
| | | logger.error(message); |
| | | unacceptableReasons.add(message); |
| | | return false; |
| | |
| | | /** |
| | | * A delete listener which prevents the named component from being deleted. |
| | | */ |
| | | private class ReferentialIntegrityDeleteListener implements ConfigurationDeleteListener<S> { |
| | | private final class ReferentialIntegrityDeleteListener implements ConfigurationDeleteListener<S> { |
| | | |
| | | // The DN of the referenced configuration entry. |
| | | private final DN dn; |
| | |
| | | // isConfigurationDeleteAcceptable() call-back should have |
| | | // trapped this. |
| | | throw new IllegalStateException("Attempting to delete a referenced " |
| | | + relationDefinition.getChildDefinition().getUserFriendlyName()); |
| | | + relationDefinition.getChildDefinition().getUserFriendlyName()); |
| | | } else { |
| | | return new ConfigChangeResult(ResultCode.SUCCESS, false); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public boolean isUsable(ServerManagedObject<?> managedObject, Collection<LocalizableMessage> unacceptableReasons) |
| | | throws ConfigException { |
| | | public boolean isUsable(ServerManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ConfigException { |
| | | SortedSet<String> names = managedObject.getPropertyValues(AggregationPropertyDefinition.this); |
| | | ServerManagementContext context = managedObject.getServerContext(); |
| | | LocalizableMessage thisUFN = managedObject.getManagedObjectDefinition().getUserFriendlyName(); |
| | |
| | | String thatDN = path.toDN().toString(); |
| | | |
| | | if (!context.managedObjectExists(path)) { |
| | | LocalizableMessage msg = ERR_SERVER_REFINT_DANGLING_REFERENCE.get(name, getName(), thisUFN, thisDN, thatUFN, |
| | | thatDN); |
| | | LocalizableMessage msg = |
| | | ERR_SERVER_REFINT_DANGLING_REFERENCE.get(name, getName(), thisUFN, thisDN, thatUFN, thatDN); |
| | | unacceptableReasons.add(msg); |
| | | isUsable = false; |
| | | } else if (needsEnabling) { |
| | |
| | | // required. |
| | | ServerManagedObject<? extends S> ref = context.getManagedObject(path); |
| | | if (!targetIsEnabledCondition.evaluate(ref)) { |
| | | LocalizableMessage msg = ERR_SERVER_REFINT_TARGET_DISABLED.get(name, getName(), thisUFN, thisDN, thatUFN, |
| | | thatDN); |
| | | LocalizableMessage msg = |
| | | ERR_SERVER_REFINT_TARGET_DISABLED.get(name, getName(), thisUFN, thisDN, thatUFN, thatDN); |
| | | unacceptableReasons.add(msg); |
| | | isUsable = false; |
| | | } |
| | |
| | | String thatDN = dn.toString(); |
| | | |
| | | // Register the delete listener. |
| | | LocalizableMessage msg = ERR_SERVER_REFINT_CANNOT_DELETE.get(thatUFN, thatDN, getName(), thisUFN, thisDN); |
| | | LocalizableMessage msg = |
| | | ERR_SERVER_REFINT_CANNOT_DELETE.get(thatUFN, thatDN, getName(), thisUFN, thisDN); |
| | | ReferentialIntegrityDeleteListener dl = new ReferentialIntegrityDeleteListener(dn, msg); |
| | | parent.registerDeleteListener(getRelationDefinition(), dl); |
| | | dlist.add(dl); |
| | |
| | | */ |
| | | @Override |
| | | public boolean isAddAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | // If all of this managed object's "enabled" properties are true |
| | | // then any referenced managed objects must also be enabled. |
| | | boolean needsEnabling = targetNeedsEnablingCondition.evaluate(context, managedObject); |
| | |
| | | try { |
| | | ref = context.getManagedObject(path); |
| | | } catch (DefinitionDecodingException e) { |
| | | LocalizableMessage msg = ERR_CLIENT_REFINT_TARGET_INVALID.get(ufn, name, getName(), |
| | | e.getMessageObject()); |
| | | LocalizableMessage msg = |
| | | ERR_CLIENT_REFINT_TARGET_INVALID.get(ufn, name, getName(), e.getMessageObject()); |
| | | unacceptableReasons.add(msg); |
| | | isAcceptable = false; |
| | | continue; |
| | | } catch (ManagedObjectDecodingException e) { |
| | | LocalizableMessage msg = ERR_CLIENT_REFINT_TARGET_INVALID.get(ufn, name, getName(), |
| | | e.getMessageObject()); |
| | | LocalizableMessage msg = |
| | | ERR_CLIENT_REFINT_TARGET_INVALID.get(ufn, name, getName(), e.getMessageObject()); |
| | | unacceptableReasons.add(msg); |
| | | isAcceptable = false; |
| | | continue; |
| | |
| | | */ |
| | | @Override |
| | | public boolean isModifyAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | // The same constraint applies as for adds. |
| | | return isAddAcceptable(context, managedObject, unacceptableReasons); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public boolean isDeleteAcceptable(ManagementContext context, ManagedObjectPath<?, ?> path, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | // Any references to the deleted managed object should cause a |
| | | // constraint violation. |
| | | boolean isAcceptable = true; |
| | | for (ManagedObject<?> mo : findReferences(context, getManagedObjectDefinition(), path.getName())) { |
| | | String name = mo.getManagedObjectPath().getName(); |
| | | if (name == null) { |
| | | LocalizableMessage msg = ERR_CLIENT_REFINT_CANNOT_DELETE_WITHOUT_NAME.get(getName(), mo |
| | | .getManagedObjectDefinition().getUserFriendlyName(), getManagedObjectDefinition() |
| | | .getUserFriendlyName()); |
| | | LocalizableMessage msg = |
| | | ERR_CLIENT_REFINT_CANNOT_DELETE_WITHOUT_NAME.get(getName(), mo.getManagedObjectDefinition() |
| | | .getUserFriendlyName(), getManagedObjectDefinition().getUserFriendlyName()); |
| | | unacceptableReasons.add(msg); |
| | | } else { |
| | | LocalizableMessage msg = ERR_CLIENT_REFINT_CANNOT_DELETE_WITH_NAME.get(getName(), mo |
| | | .getManagedObjectDefinition().getUserFriendlyName(), name, getManagedObjectDefinition() |
| | | .getUserFriendlyName()); |
| | | LocalizableMessage msg = |
| | | ERR_CLIENT_REFINT_CANNOT_DELETE_WITH_NAME.get(getName(), mo.getManagedObjectDefinition() |
| | | .getUserFriendlyName(), name, getManagedObjectDefinition().getUserFriendlyName()); |
| | | unacceptableReasons.add(msg); |
| | | } |
| | | isAcceptable = false; |
| | |
| | | */ |
| | | @Override |
| | | public boolean isModifyAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | // If the modified managed object is disabled and there are some |
| | | // active references then refuse the change. |
| | | if (targetIsEnabledCondition.evaluate(context, managedObject)) { |
| | |
| | | // active references. |
| | | boolean isAcceptable = true; |
| | | for (ManagedObject<?> mo : findReferences(context, getManagedObjectDefinition(), managedObject |
| | | .getManagedObjectPath().getName())) { |
| | | .getManagedObjectPath().getName())) { |
| | | if (targetNeedsEnablingCondition.evaluate(context, mo)) { |
| | | String name = mo.getManagedObjectPath().getName(); |
| | | if (name == null) { |
| | | LocalizableMessage msg = ERR_CLIENT_REFINT_CANNOT_DISABLE_WITHOUT_NAME.get(managedObject |
| | | LocalizableMessage msg = |
| | | ERR_CLIENT_REFINT_CANNOT_DISABLE_WITHOUT_NAME.get(managedObject |
| | | .getManagedObjectDefinition().getUserFriendlyName(), getName(), mo |
| | | .getManagedObjectDefinition().getUserFriendlyName()); |
| | | unacceptableReasons.add(msg); |
| | | } else { |
| | | LocalizableMessage msg = ERR_CLIENT_REFINT_CANNOT_DISABLE_WITH_NAME.get(managedObject |
| | | .getManagedObjectDefinition().getUserFriendlyName(), getName(), mo |
| | | .getManagedObjectDefinition().getUserFriendlyName(), name); |
| | | LocalizableMessage msg = |
| | | ERR_CLIENT_REFINT_CANNOT_DISABLE_WITH_NAME.get( |
| | | managedObject.getManagedObjectDefinition().getUserFriendlyName(), getName(), |
| | | mo.getManagedObjectDefinition().getUserFriendlyName(), name); |
| | | unacceptableReasons.add(msg); |
| | | } |
| | | isAcceptable = false; |
| | |
| | | |
| | | // Find all managed objects which reference the named managed |
| | | // object using this property. |
| | | private <CC extends ConfigurationClient> List<ManagedObject<? extends CC>> findReferences( |
| | | ManagementContext context, AbstractManagedObjectDefinition<CC, ?> mod, String name) |
| | | private <C1 extends ConfigurationClient> List<ManagedObject<? extends C1>> findReferences( |
| | | ManagementContext context, AbstractManagedObjectDefinition<C1, ?> mod, String name) |
| | | throws ErrorResultException { |
| | | List<ManagedObject<? extends CC>> instances = findInstances(context, mod); |
| | | List<ManagedObject<? extends C1>> instances = findInstances(context, mod); |
| | | |
| | | Iterator<ManagedObject<? extends CC>> i = instances.iterator(); |
| | | Iterator<ManagedObject<? extends C1>> i = instances.iterator(); |
| | | while (i.hasNext()) { |
| | | ManagedObject<? extends CC> mo = i.next(); |
| | | ManagedObject<? extends C1> mo = i.next(); |
| | | boolean hasReference = false; |
| | | |
| | | for (String value : mo.getPropertyValues(AggregationPropertyDefinition.this)) { |
| | |
| | | |
| | | // Find all instances of a specific type of managed object. |
| | | @SuppressWarnings("unchecked") |
| | | private <CC extends ConfigurationClient> List<ManagedObject<? extends CC>> findInstances( |
| | | ManagementContext context, AbstractManagedObjectDefinition<CC, ?> mod) throws ErrorResultException { |
| | | List<ManagedObject<? extends CC>> instances = new LinkedList<ManagedObject<? extends CC>>(); |
| | | private <C1 extends ConfigurationClient> List<ManagedObject<? extends C1>> findInstances( |
| | | ManagementContext context, AbstractManagedObjectDefinition<C1, ?> mod) throws ErrorResultException { |
| | | List<ManagedObject<? extends C1>> instances = new LinkedList<ManagedObject<? extends C1>>(); |
| | | |
| | | if (mod == RootCfgDefn.getInstance()) { |
| | | instances.add((ManagedObject<? extends CC>) context.getRootConfigurationManagedObject()); |
| | | instances.add((ManagedObject<? extends C1>) context.getRootConfigurationManagedObject()); |
| | | } else { |
| | | for (RelationDefinition<? super CC, ?> rd : mod.getAllReverseRelationDefinitions()) { |
| | | for (RelationDefinition<? super C1, ?> rd : mod.getAllReverseRelationDefinitions()) { |
| | | for (ManagedObject<?> parent : findInstances(context, rd.getParentDefinition())) { |
| | | try { |
| | | if (rd instanceof SingletonRelationDefinition) { |
| | | SingletonRelationDefinition<? super CC, ?> srd = (SingletonRelationDefinition<? super CC, ?>) rd; |
| | | SingletonRelationDefinition<? super C1, ?> srd = |
| | | (SingletonRelationDefinition<? super C1, ?>) rd; |
| | | ManagedObject<?> mo = parent.getChild(srd); |
| | | if (mo.getManagedObjectDefinition().isChildOf(mod)) { |
| | | instances.add((ManagedObject<? extends CC>) mo); |
| | | instances.add((ManagedObject<? extends C1>) mo); |
| | | } |
| | | } else if (rd instanceof OptionalRelationDefinition) { |
| | | OptionalRelationDefinition<? super CC, ?> ord = (OptionalRelationDefinition<? super CC, ?>) rd; |
| | | OptionalRelationDefinition<? super C1, ?> ord = |
| | | (OptionalRelationDefinition<? super C1, ?>) rd; |
| | | ManagedObject<?> mo = parent.getChild(ord); |
| | | if (mo.getManagedObjectDefinition().isChildOf(mod)) { |
| | | instances.add((ManagedObject<? extends CC>) mo); |
| | | instances.add((ManagedObject<? extends C1>) mo); |
| | | } |
| | | } else if (rd instanceof InstantiableRelationDefinition) { |
| | | InstantiableRelationDefinition<? super CC, ?> ird = (InstantiableRelationDefinition<? super CC, ?>) rd; |
| | | InstantiableRelationDefinition<? super C1, ?> ird = |
| | | (InstantiableRelationDefinition<? super C1, ?>) rd; |
| | | |
| | | for (String name : parent.listChildren(ird)) { |
| | | ManagedObject<?> mo = parent.getChild(ird, name); |
| | | if (mo.getManagedObjectDefinition().isChildOf(mod)) { |
| | | instances.add((ManagedObject<? extends CC>) mo); |
| | | instances.add((ManagedObject<? extends C1>) mo); |
| | | } |
| | | } |
| | | } |
| | |
| | | * @return Returns the new aggregation property definition builder. |
| | | */ |
| | | public static <C extends ConfigurationClient, S extends Configuration> Builder<C, S> createBuilder( |
| | | AbstractManagedObjectDefinition<?, ?> d, String propertyName) { |
| | | AbstractManagedObjectDefinition<?, ?> d, String propertyName) { |
| | | return new Builder<C, S>(d, propertyName); |
| | | } |
| | | |
| | |
| | | |
| | | // The active server-side referential integrity change listeners |
| | | // associated with this property. |
| | | private final Map<DN, List<ReferentialIntegrityChangeListener>> changeListeners = new HashMap<DN, List<ReferentialIntegrityChangeListener>>(); |
| | | private final Map<DN, List<ReferentialIntegrityChangeListener>> changeListeners = |
| | | new HashMap<DN, List<ReferentialIntegrityChangeListener>>(); |
| | | |
| | | // The active server-side referential integrity delete listeners |
| | | // associated with this property. |
| | | private final Map<DN, List<ReferentialIntegrityDeleteListener>> deleteListeners = new HashMap<DN, List<ReferentialIntegrityDeleteListener>>(); |
| | | private final Map<DN, List<ReferentialIntegrityDeleteListener>> deleteListeners = |
| | | new HashMap<DN, List<ReferentialIntegrityDeleteListener>>(); |
| | | |
| | | // The name of the managed object which is the parent of the |
| | | // aggregated managed objects. |
| | |
| | | |
| | | // Private constructor. |
| | | private AggregationPropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<String> defaultBehavior, String parentPathString, String rdName, |
| | | Condition targetNeedsEnablingCondition, Condition targetIsEnabledCondition) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<String> defaultBehavior, String parentPathString, String rdName, |
| | | Condition targetNeedsEnablingCondition, Condition targetIsEnabledCondition) { |
| | | super(d, String.class, propertyName, options, adminAction, defaultBehavior); |
| | | |
| | | this.parentPathString = parentPathString; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String decodeValue(String value) throws IllegalPropertyValueStringException { |
| | | public String decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String normalizeValue(String value) throws IllegalPropertyValueException { |
| | | public String normalizeValue(String value) { |
| | | try { |
| | | Reference<C, S> reference = Reference.parseName(parentPath, relationDefinition, value); |
| | | return reference.getNormalizedName(); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(String value) throws IllegalPropertyValueException { |
| | | public void validateValue(String value) { |
| | | try { |
| | | Reference.parseName(parentPath, relationDefinition, value); |
| | | } catch (IllegalArgumentException e) { |
| | |
| | | * An interface for incrementally constructing attribute type property |
| | | * definitions. |
| | | */ |
| | | public static class Builder extends AbstractBuilder<AttributeType, AttributeTypePropertyDefinition> { |
| | | public static final class Builder extends AbstractBuilder<AttributeType, AttributeTypePropertyDefinition> { |
| | | |
| | | // Private constructor |
| | | private Builder(AbstractManagedObjectDefinition<?, ?> d, String propertyName) { |
| | |
| | | */ |
| | | @Override |
| | | protected AttributeTypePropertyDefinition buildInstance(AbstractManagedObjectDefinition<?, ?> d, |
| | | String propertyName, EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<AttributeType> defaultBehavior) { |
| | | String propertyName, EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<AttributeType> defaultBehavior) { |
| | | return new AttributeTypePropertyDefinition(d, propertyName, options, adminAction, defaultBehavior); |
| | | } |
| | | } |
| | |
| | | |
| | | // Private constructor. |
| | | private AttributeTypePropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<AttributeType> defaultBehavior) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<AttributeType> defaultBehavior) { |
| | | super(d, AttributeType.class, propertyName, options, adminAction, defaultBehavior); |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public AttributeType decodeValue(String value) throws IllegalPropertyValueStringException { |
| | | public AttributeType decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | String name = value.trim().toLowerCase(); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String encodeValue(AttributeType value) throws IllegalPropertyValueException { |
| | | public String encodeValue(AttributeType value) { |
| | | return value.getNameOrOID(); |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(AttributeType value) throws IllegalPropertyValueException { |
| | | public void validateValue(AttributeType value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No implementation required. |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | import org.forgerock.util.Reject; |
| | |
| | | /** |
| | | * Boolean property definition. |
| | | */ |
| | | public final class BooleanPropertyDefinition extends |
| | | PropertyDefinition<Boolean> { |
| | | public final class BooleanPropertyDefinition extends PropertyDefinition<Boolean> { |
| | | |
| | | /** |
| | | * Mapping used for parsing boolean values. This mapping is more flexible than |
| | | * the standard boolean string parser and supports common true/false synonyms |
| | | * used in configuration. |
| | | */ |
| | | private static final Map<String, Boolean> VALUE_MAP; |
| | | static { |
| | | VALUE_MAP = new HashMap<String, Boolean>(); |
| | | /** |
| | | * Mapping used for parsing boolean values. This mapping is more flexible |
| | | * than the standard boolean string parser and supports common true/false |
| | | * synonyms used in configuration. |
| | | */ |
| | | private static final Map<String, Boolean> VALUE_MAP; |
| | | static { |
| | | VALUE_MAP = new HashMap<String, Boolean>(); |
| | | |
| | | // We could have more possibilities but decided against in issue 1960. |
| | | VALUE_MAP.put("false", Boolean.FALSE); |
| | | VALUE_MAP.put("true", Boolean.TRUE); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * An interface for incrementally constructing boolean property definitions. |
| | | */ |
| | | public static class Builder extends |
| | | AbstractBuilder<Boolean, BooleanPropertyDefinition> { |
| | | |
| | | // Private constructor |
| | | private Builder( |
| | | AbstractManagedObjectDefinition<?, ?> d, String propertyName) { |
| | | super(d, propertyName); |
| | | // We could have more possibilities but decided against in issue 1960. |
| | | VALUE_MAP.put("false", Boolean.FALSE); |
| | | VALUE_MAP.put("true", Boolean.TRUE); |
| | | } |
| | | |
| | | /** |
| | | * An interface for incrementally constructing boolean property definitions. |
| | | */ |
| | | public static final class Builder extends AbstractBuilder<Boolean, BooleanPropertyDefinition> { |
| | | |
| | | // Private constructor |
| | | private Builder(AbstractManagedObjectDefinition<?, ?> d, String propertyName) { |
| | | super(d, propertyName); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected BooleanPropertyDefinition buildInstance(AbstractManagedObjectDefinition<?, ?> d, |
| | | String propertyName, EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Boolean> defaultBehavior) { |
| | | return new BooleanPropertyDefinition(d, propertyName, options, adminAction, defaultBehavior); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * Create a boolean property definition builder. |
| | | * |
| | | * @param d |
| | | * The managed object definition associated with this property |
| | | * definition. |
| | | * @param propertyName |
| | | * The property name. |
| | | * @return Returns the new boolean property definition builder. |
| | | */ |
| | | public static Builder createBuilder(AbstractManagedObjectDefinition<?, ?> d, String propertyName) { |
| | | return new Builder(d, propertyName); |
| | | } |
| | | |
| | | // Private constructor. |
| | | private BooleanPropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Boolean> defaultBehavior) { |
| | | super(d, Boolean.class, propertyName, options, adminAction, defaultBehavior); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected BooleanPropertyDefinition buildInstance( |
| | | AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, |
| | | AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Boolean> defaultBehavior) { |
| | | return new BooleanPropertyDefinition(d, propertyName, options, |
| | | adminAction, defaultBehavior); |
| | | public void validateValue(Boolean value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | | } |
| | | |
| | | } |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Boolean decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | String nvalue = value.trim().toLowerCase(); |
| | | Boolean b = VALUE_MAP.get(nvalue); |
| | | |
| | | |
| | | /** |
| | | * Create a boolean property definition builder. |
| | | * |
| | | * @param d |
| | | * The managed object definition associated with this |
| | | * property definition. |
| | | * @param propertyName |
| | | * The property name. |
| | | * @return Returns the new boolean property definition builder. |
| | | */ |
| | | public static Builder createBuilder( |
| | | AbstractManagedObjectDefinition<?, ?> d, String propertyName) { |
| | | return new Builder(d, propertyName); |
| | | } |
| | | |
| | | |
| | | |
| | | // Private constructor. |
| | | private BooleanPropertyDefinition( |
| | | AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, |
| | | AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Boolean> defaultBehavior) { |
| | | super(d, Boolean.class, propertyName, options, adminAction, |
| | | defaultBehavior); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Boolean value) |
| | | throws IllegalPropertyValueException { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Boolean decodeValue(String value) |
| | | throws IllegalPropertyValueStringException { |
| | | Reject.ifNull(value); |
| | | |
| | | String nvalue = value.trim().toLowerCase(); |
| | | Boolean b = VALUE_MAP.get(nvalue); |
| | | |
| | | if (b == null) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } else { |
| | | return b; |
| | | if (b == null) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } else { |
| | | return b; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <R, P> R accept(PropertyDefinitionVisitor<R, P> v, P p) { |
| | | return v.visitBoolean(this, p); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <R, P> R accept(PropertyValueVisitor<R, P> v, Boolean value, P p) { |
| | | return v.visitBoolean(this, value, p); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <R, P> R accept(PropertyDefinitionVisitor<R, P> v, P p) { |
| | | return v.visitBoolean(this, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <R, P> R accept(PropertyValueVisitor<R, P> v, Boolean value, P p) { |
| | | return v.visitBoolean(this, value, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public int compare(Boolean o1, Boolean o2) { |
| | | return o1.compareTo(o2); |
| | | } |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public int compare(Boolean o1, Boolean o2) { |
| | | return o1.compareTo(o2); |
| | | } |
| | | } |
| | |
| | | */ |
| | | public final class ClassLoaderProvider { |
| | | |
| | | private static final LocalizedLogger adminLogger = LocalizedLogger.getLocalizedLogger(AdminMessages.resourceName()); |
| | | private static final LocalizedLogger adminLogger = LocalizedLogger.getLocalizedLogger(AdminMessages |
| | | .resourceName()); |
| | | private static final Logger debugLogger = LoggerFactory.getLogger(ClassLoaderProvider.class); |
| | | |
| | | /** |
| | |
| | | * @throws SecurityException |
| | | * If a required system property value cannot be accessed. |
| | | */ |
| | | public void addJarFile(File jarFile) throws SecurityException, MalformedURLException { |
| | | public void addJarFile(File jarFile) throws MalformedURLException { |
| | | addURL(jarFile.toURI().toURL()); |
| | | } |
| | | |
| | |
| | | |
| | | // The attribute names for build information is name, version and revision |
| | | // number |
| | | private static final String[] BUILD_INFORMATION_ATTRIBUTE_NAMES = new String[] { |
| | | Attributes.Name.EXTENSION_NAME.toString(), Attributes.Name.IMPLEMENTATION_VERSION.toString(), |
| | | private static final String[] BUILD_INFORMATION_ATTRIBUTE_NAMES = |
| | | new String[] { Attributes.Name.EXTENSION_NAME.toString(), Attributes.Name.IMPLEMENTATION_VERSION.toString(), |
| | | REVISION_NUMBER }; |
| | | |
| | | /** |
| | |
| | | * If one of the extension names was not a single relative path |
| | | * name element or was an absolute path. |
| | | */ |
| | | public synchronized void addExtension(String... extensions) throws InitializationException, IllegalStateException, |
| | | IllegalArgumentException { |
| | | public synchronized void addExtension(String... extensions) throws InitializationException { |
| | | Reject.ifNull(extensions); |
| | | |
| | | if (loader == null) { |
| | |
| | | * @throws IllegalStateException |
| | | * If this class loader provider is already disabled. |
| | | */ |
| | | public synchronized void disable() throws IllegalStateException { |
| | | public synchronized void disable() { |
| | | if (loader == null) { |
| | | throw new IllegalStateException("Class loader provider already disabled."); |
| | | } |
| | |
| | | * @throws IllegalStateException |
| | | * If this class loader provider is already enabled. |
| | | */ |
| | | public synchronized void enable() throws InitializationException, IllegalStateException { |
| | | public synchronized void enable() throws InitializationException { |
| | | enable(RootCfgDefn.class.getClassLoader()); |
| | | } |
| | | |
| | |
| | | * @throws IllegalStateException |
| | | * If this class loader provider is already enabled. |
| | | */ |
| | | public synchronized void enable(ClassLoader parent) throws InitializationException, IllegalStateException { |
| | | public synchronized void enable(ClassLoader parent) throws InitializationException { |
| | | if (loader != null) { |
| | | throw new IllegalStateException("Class loader provider already enabled."); |
| | | } |
| | |
| | | loader.addJarFile(extension); |
| | | } catch (Exception e) { |
| | | debugLogger.trace("Unable to register the jar file with the class loader", e); |
| | | LocalizableMessage message = ERR_ADMIN_CANNOT_OPEN_JAR_FILE.get(extension.getName(), |
| | | extension.getParent(), stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | LocalizableMessage message = |
| | | ERR_ADMIN_CANNOT_OPEN_JAR_FILE.get(extension.getName(), extension.getParent(), |
| | | stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | throw new InitializationException(message); |
| | | } |
| | | jarFiles.add(extension); |
| | |
| | | * <code>null</code> if there is no information available. |
| | | */ |
| | | public String printExtensionInformation() { |
| | | File extensionsPath = new File(new StringBuilder(DirectoryServer.getServerRoot()).append(File.separator) |
| | | .append(LIB_DIR).append(File.separator).append(EXTENSIONS_DIR).toString()); |
| | | File extensionsPath = |
| | | new File(new StringBuilder(DirectoryServer.getServerRoot()).append(File.separator).append(LIB_DIR) |
| | | .append(File.separator).append(EXTENSIONS_DIR).toString()); |
| | | |
| | | if (!extensionsPath.exists() || !extensionsPath.isDirectory()) { |
| | | // no extensions' directory |
| | |
| | | if (!extensionsPath.isDirectory()) { |
| | | // The extensions directory is not a directory. This is more |
| | | // critical. |
| | | LocalizableMessage message = ERR_ADMIN_EXTENSIONS_DIR_NOT_DIRECTORY.get(String.valueOf(extensionsPath)); |
| | | LocalizableMessage message = |
| | | ERR_ADMIN_EXTENSIONS_DIR_NOT_DIRECTORY.get(String.valueOf(extensionsPath)); |
| | | throw new InitializationException(message); |
| | | } |
| | | |
| | |
| | | throw e; |
| | | } catch (Exception e) { |
| | | debugLogger.trace("Unable to initialize all extensions", e); |
| | | LocalizableMessage message = ERR_ADMIN_EXTENSIONS_CANNOT_LIST_FILES.get(String.valueOf(extensionsPath), |
| | | LocalizableMessage message = |
| | | ERR_ADMIN_EXTENSIONS_CANNOT_LIST_FILES.get(String.valueOf(extensionsPath), |
| | | stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | throw new InitializationException(message, e); |
| | | } |
| | |
| | | loadDefinitionClasses(is); |
| | | } catch (InitializationException e) { |
| | | debugLogger.trace("Unable to initialize core components", e); |
| | | LocalizableMessage message = ERR_CLASS_LOADER_CANNOT_LOAD_CORE.get(CORE_MANIFEST, |
| | | LocalizableMessage message = |
| | | ERR_CLASS_LOADER_CANNOT_LOAD_CORE.get(CORE_MANIFEST, |
| | | stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | throw new InitializationException(message); |
| | | } |
| | |
| | | is = jarFile.getInputStream(entry); |
| | | } catch (Exception e) { |
| | | debugLogger.trace("Unable to get input stream from jar", e); |
| | | LocalizableMessage message = ERR_ADMIN_CANNOT_READ_EXTENSION_MANIFEST.get(EXTENSION_MANIFEST, |
| | | jarFile.getName(), stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | LocalizableMessage message = |
| | | ERR_ADMIN_CANNOT_READ_EXTENSION_MANIFEST.get(EXTENSION_MANIFEST, jarFile.getName(), |
| | | stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | throw new InitializationException(message); |
| | | } |
| | | |
| | |
| | | loadDefinitionClasses(is); |
| | | } catch (InitializationException e) { |
| | | debugLogger.trace("Unable to load classes from input stream", e); |
| | | LocalizableMessage message = ERR_CLASS_LOADER_CANNOT_LOAD_EXTENSION.get(jarFile.getName(), |
| | | EXTENSION_MANIFEST, stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | LocalizableMessage message = |
| | | ERR_CLASS_LOADER_CANNOT_LOAD_EXTENSION.get(jarFile.getName(), EXTENSION_MANIFEST, |
| | | stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | throw new InitializationException(message); |
| | | } |
| | | try { |
| | | // Log build information of extensions in the error log |
| | | String[] information = getBuildInformation(jarFile); |
| | | LocalizableMessage message = NOTE_LOG_EXTENSION_INFORMATION.get(jarFile.getName(), information[1], |
| | | information[2]); |
| | | LocalizableMessage message = |
| | | NOTE_LOG_EXTENSION_INFORMATION.get(jarFile.getName(), information[1], information[2]); |
| | | LocalizedLogger.getLocalizedLogger(message.resourceName()).error(message); |
| | | } catch (Exception e) { |
| | | // Do not log information for that extension |
| | |
| | | */ |
| | | private void loadDefinitionClasses(InputStream is) throws InitializationException { |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
| | | List<AbstractManagedObjectDefinition<?, ?>> definitions = new LinkedList<AbstractManagedObjectDefinition<?, ?>>(); |
| | | List<AbstractManagedObjectDefinition<?, ?>> definitions = |
| | | new LinkedList<AbstractManagedObjectDefinition<?, ?>>(); |
| | | while (true) { |
| | | String className; |
| | | try { |
| | | className = reader.readLine(); |
| | | } catch (IOException e) { |
| | | LocalizableMessage msg = ERR_CLASS_LOADER_CANNOT_READ_MANIFEST_FILE.get(String.valueOf(e.getMessage())); |
| | | LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_READ_MANIFEST_FILE.get(String.valueOf(e.getMessage())); |
| | | throw new InitializationException(msg, e); |
| | | } |
| | | |
| | |
| | | try { |
| | | theClass = Class.forName(className, true, loader); |
| | | } catch (Exception e) { |
| | | LocalizableMessage msg = ERR_CLASS_LOADER_CANNOT_LOAD_CLASS.get(className, |
| | | String.valueOf(e.getMessage())); |
| | | LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_LOAD_CLASS.get(className, String.valueOf(e.getMessage())); |
| | | throw new InitializationException(msg, e); |
| | | } |
| | | if (AbstractManagedObjectDefinition.class.isAssignableFrom(theClass)) { |
| | |
| | | try { |
| | | method = theClass.getMethod("getInstance"); |
| | | } catch (Exception e) { |
| | | LocalizableMessage msg = ERR_CLASS_LOADER_CANNOT_FIND_GET_INSTANCE_METHOD.get(className, |
| | | LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_FIND_GET_INSTANCE_METHOD.get(className, |
| | | String.valueOf(e.getMessage())); |
| | | throw new InitializationException(msg, e); |
| | | } |
| | |
| | | try { |
| | | d = (AbstractManagedObjectDefinition<?, ?>) method.invoke(null); |
| | | } catch (Exception e) { |
| | | LocalizableMessage msg = ERR_CLASS_LOADER_CANNOT_INVOKE_GET_INSTANCE_METHOD.get(className, |
| | | LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_INVOKE_GET_INSTANCE_METHOD.get(className, |
| | | String.valueOf(e.getMessage())); |
| | | throw new InitializationException(msg, e); |
| | | } |
| | |
| | | try { |
| | | d.initialize(); |
| | | } catch (Exception e) { |
| | | LocalizableMessage msg = ERR_CLASS_LOADER_CANNOT_INITIALIZE_DEFN.get(d.getName(), d.getClass() |
| | | .getName(), String.valueOf(e.getMessage())); |
| | | LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_INITIALIZE_DEFN.get(d.getName(), d.getClass().getName(), |
| | | String.valueOf(e.getMessage())); |
| | | throw new InitializationException(msg, e); |
| | | } |
| | | } |
| | |
| | | } catch (Exception e) { |
| | | debugLogger.trace("Unable to load jar file: " + jar, e); |
| | | |
| | | LocalizableMessage message = ERR_ADMIN_CANNOT_OPEN_JAR_FILE.get(jar.getName(), jar.getParent(), |
| | | LocalizableMessage message = |
| | | ERR_ADMIN_CANNOT_OPEN_JAR_FILE.get(jar.getName(), jar.getParent(), |
| | | stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | throw new InitializationException(message); |
| | | } |
| | |
| | | /** |
| | | * An interface for incrementally constructing class property definitions. |
| | | */ |
| | | public static class Builder extends AbstractBuilder<String, ClassPropertyDefinition> { |
| | | public static final class Builder extends AbstractBuilder<String, ClassPropertyDefinition> { |
| | | |
| | | // List of interfaces which property values must implement. |
| | | private List<String> instanceOfInterfaces; |
| | |
| | | */ |
| | | @Override |
| | | protected ClassPropertyDefinition buildInstance(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<String> defaultBehavior) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<String> defaultBehavior) { |
| | | return new ClassPropertyDefinition(d, propertyName, options, adminAction, defaultBehavior, |
| | | instanceOfInterfaces); |
| | | instanceOfInterfaces); |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | // Load a named class. |
| | | private static Class<?> loadClass(String className, boolean initialize) |
| | | throws ClassNotFoundException, LinkageError { |
| | | return Class.forName(className, initialize, ClassLoaderProvider.getInstance() |
| | | .getClassLoader()); |
| | | private static Class<?> loadClass(String className, boolean initialize) throws ClassNotFoundException { |
| | | return Class.forName(className, initialize, ClassLoaderProvider.getInstance().getClassLoader()); |
| | | } |
| | | |
| | | // List of interfaces which property values must implement. |
| | |
| | | |
| | | // Private constructor. |
| | | private ClassPropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<String> defaultBehavior, List<String> instanceOfInterfaces) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<String> defaultBehavior, List<String> instanceOfInterfaces) { |
| | | super(d, String.class, propertyName, options, adminAction, defaultBehavior); |
| | | |
| | | this.instanceOfInterfaces = Collections.unmodifiableList(new LinkedList<String>(instanceOfInterfaces)); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String decodeValue(String value) throws IllegalPropertyValueStringException { |
| | | public String decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | |
| | | * If the referenced class does not implement the requested |
| | | * type. |
| | | */ |
| | | public <T> Class<? extends T> loadClass(String className, Class<T> instanceOf) |
| | | throws IllegalPropertyValueException, ClassCastException { |
| | | public <T> Class<? extends T> loadClass(String className, Class<T> instanceOf) { |
| | | Reject.ifNull(className, instanceOf); |
| | | |
| | | // Make sure that the named class is valid. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String normalizeValue(String value) throws IllegalPropertyValueException { |
| | | public String normalizeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | return value.trim(); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(String value) throws IllegalPropertyValueException { |
| | | public void validateValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // Always make sure the name is a valid class name. |
| | |
| | | /* |
| | | * Do some basic checks to make sure the string representation is valid. |
| | | */ |
| | | private void validateClassName(String className) throws IllegalPropertyValueException { |
| | | private void validateClassName(String className) { |
| | | String nvalue = className.trim(); |
| | | if (!nvalue.matches(CLASS_RE)) { |
| | | throw new IllegalPropertyValueException(this, className); |
| | | } |
| | | } |
| | | |
| | | |
| | | /* |
| | | * Make sure that named class implements the interfaces named by this |
| | | * definition. |
| | | */ |
| | | private Class<?> validateClassInterfaces(String className, boolean initialize) |
| | | throws IllegalPropertyValueException { |
| | | private Class<?> validateClassInterfaces(String className, boolean initialize) { |
| | | Class<?> theClass = loadClassForValidation(className, className, initialize); |
| | | for (String i : instanceOfInterfaces) { |
| | | Class<?> instanceOfClass = loadClassForValidation(className, i, initialize); |
| | |
| | | return theClass; |
| | | } |
| | | |
| | | private Class<?> loadClassForValidation(String componentClassName, String classToBeLoaded, |
| | | boolean initialize) { |
| | | private Class<?> loadClassForValidation(String componentClassName, String classToBeLoaded, boolean initialize) { |
| | | try { |
| | | return loadClass(classToBeLoaded.trim(), initialize); |
| | | } catch (ClassNotFoundException e) { |
| | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | |
| | | /** |
| | | * A common base interface for all server managed object |
| | | * configurations. |
| | | * A common base interface for all server managed object configurations. |
| | | */ |
| | | public interface Configuration { |
| | | |
| | | /** |
| | | * Gets the DN of the LDAP entry associated with this configuration. |
| | | * |
| | | * @return Returns the DN of the LDAP entry associated with this |
| | | * configuration. |
| | | */ |
| | | DN dn(); |
| | | /** |
| | | * Gets the DN of the LDAP entry associated with this configuration. |
| | | * |
| | | * @return Returns the DN of the LDAP entry associated with this |
| | | * configuration. |
| | | */ |
| | | DN dn(); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the configuration class associated with this configuration. |
| | | * |
| | | * @return Returns the configuration class associated with this |
| | | * configuration. |
| | | */ |
| | | Class<? extends Configuration> configurationClass(); |
| | | /** |
| | | * Gets the configuration class associated with this configuration. |
| | | * |
| | | * @return Returns the configuration class associated with this |
| | | * configuration. |
| | | */ |
| | | Class<? extends Configuration> configurationClass(); |
| | | } |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | void commit() throws ManagedObjectAlreadyExistsException, MissingMandatoryPropertiesException, |
| | | ConcurrentModificationException, OperationRejectedException, ErrorResultException; |
| | | ConcurrentModificationException, OperationRejectedException, ErrorResultException; |
| | | |
| | | } |
| | |
| | | /** |
| | | * An interface for incrementally constructing DN property definitions. |
| | | */ |
| | | public static class Builder extends AbstractBuilder<DN, DNPropertyDefinition> { |
| | | public static final class Builder extends AbstractBuilder<DN, DNPropertyDefinition> { |
| | | |
| | | // Optional base DN which all valid values must be immediately |
| | | // subordinate to. |
| | |
| | | * If the provided string is not a valid DN string |
| | | * representation. |
| | | */ |
| | | public void setBaseDN(String baseDN) throws IllegalArgumentException { |
| | | public void setBaseDN(String baseDN) { |
| | | if (baseDN == null) { |
| | | setBaseDN((DN) null); |
| | | } else { |
| | |
| | | */ |
| | | @Override |
| | | protected DNPropertyDefinition buildInstance(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<DN> defaultBehavior) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<DN> defaultBehavior) { |
| | | return new DNPropertyDefinition(d, propertyName, options, adminAction, defaultBehavior, baseDN); |
| | | } |
| | | } |
| | |
| | | |
| | | // Private constructor. |
| | | private DNPropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<DN> defaultBehavior, DN baseDN) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<DN> defaultBehavior, DN baseDN) { |
| | | super(d, DN.class, propertyName, options, adminAction, defaultBehavior); |
| | | this.baseDN = baseDN; |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(DN value) throws IllegalPropertyValueException { |
| | | public void validateValue(DN value) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (baseDN != null) { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public DN decodeValue(String value) throws IllegalPropertyValueStringException { |
| | | public DN decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | |
| | | */ |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | /** |
| | | * An interface for determining the default behavior of a property. A |
| | | * property exhibits default behavior when it has no values defined. |
| | | * There are four different types of default behavior: |
| | | * An interface for determining the default behavior of a property. A property |
| | | * exhibits default behavior when it has no values defined. There are four |
| | | * different types of default behavior: |
| | | * <ol> |
| | | * <li>there is no default behavior - e.g. leaving a "description" |
| | | * unset has no side-effects. This default behavior is represented |
| | | * using the {@link UndefinedDefaultBehaviorProvider} implementation |
| | | * <li>the property defaults to one or more real values of the |
| | | * property. This default behavior is represented using the |
| | | * <li>there is no default behavior - e.g. leaving a "description" unset has no |
| | | * side-effects. This default behavior is represented using the |
| | | * {@link UndefinedDefaultBehaviorProvider} implementation |
| | | * <li>the property defaults to one or more real values of the property. This |
| | | * default behavior is represented using the |
| | | * {@link DefinedDefaultBehaviorProvider} implementation |
| | | * <li>the property defaults to some special behavior that cannot be |
| | | * represented using real property values. This default behavior is |
| | | * represented using the {@link AliasDefaultBehaviorProvider} |
| | | * implementation |
| | | * <li>the property inherits its values from property held in another |
| | | * managed object (e.g. the parent managed object). This default |
| | | * behavior is represented using the |
| | | * {@link AbsoluteInheritedDefaultBehaviorProvider} and |
| | | * <li>the property defaults to some special behavior that cannot be represented |
| | | * using real property values. This default behavior is represented using the |
| | | * {@link AliasDefaultBehaviorProvider} implementation |
| | | * <li>the property inherits its values from property held in another managed |
| | | * object (e.g. the parent managed object). This default behavior is represented |
| | | * using the {@link AbsoluteInheritedDefaultBehaviorProvider} and |
| | | * {@link RelativeInheritedDefaultBehaviorProvider} implementations. |
| | | * </ol> |
| | | * An application can perform actions based on the type of the default |
| | | * behavior by implementing the {@link DefaultBehaviorProviderVisitor} |
| | | * interface. |
| | | * An application can perform actions based on the type of the default behavior |
| | | * by implementing the {@link DefaultBehaviorProviderVisitor} interface. |
| | | * |
| | | * @param <T> |
| | | * The type of values represented by this provider. |
| | | * The type of values represented by this provider. |
| | | */ |
| | | public abstract class DefaultBehaviorProvider<T> { |
| | | |
| | | /** |
| | | * Creates a new default behavior provider. |
| | | */ |
| | | protected DefaultBehaviorProvider() { |
| | | // No implementation required. |
| | | } |
| | | /** |
| | | * Creates a new default behavior provider. |
| | | */ |
| | | protected DefaultBehaviorProvider() { |
| | | // No implementation required. |
| | | } |
| | | |
| | | /** |
| | | * Apply a visitor to this default behavior provider. |
| | | * |
| | | * @param <R> |
| | | * The return type of the visitor's methods. |
| | | * @param <P> |
| | | * The type of the additional parameters to the visitor's |
| | | * methods. |
| | | * @param v |
| | | * The default behavior visitor. |
| | | * @param p |
| | | * Optional additional visitor parameter. |
| | | * @return Returns a result as specified by the visitor. |
| | | */ |
| | | public abstract <R, P> R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p); |
| | | |
| | | |
| | | /** |
| | | * Apply a visitor to this default behavior provider. |
| | | * |
| | | * @param <R> |
| | | * The return type of the visitor's methods. |
| | | * @param <P> |
| | | * The type of the additional parameters to the visitor's |
| | | * methods. |
| | | * @param v |
| | | * The default behavior visitor. |
| | | * @param p |
| | | * Optional additional visitor parameter. |
| | | * @return Returns a result as specified by the visitor. |
| | | */ |
| | | public abstract <R, P> |
| | | R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Performs any run-time initialization required by this default |
| | | * behavior provider. This may include resolving managed object |
| | | * paths and property names. |
| | | * <p> |
| | | * The default implementation is to do nothing. |
| | | * |
| | | * @throws Exception |
| | | * If this default behavior provider could not be |
| | | * initialized. |
| | | */ |
| | | protected void initialize() throws Exception { |
| | | // Default implementation is to do nothing. |
| | | } |
| | | /** |
| | | * Performs any run-time initialization required by this default behavior |
| | | * provider. This may include resolving managed object paths and property |
| | | * names. |
| | | * <p> |
| | | * The default implementation is to do nothing. |
| | | * |
| | | * @throws Exception |
| | | * If this default behavior provider could not be initialized. |
| | | */ |
| | | protected void initialize() throws Exception { |
| | | // Default implementation is to do nothing. |
| | | } |
| | | |
| | | } |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A visitor of default behavior providers, in the style of the visitor design |
| | | * pattern. Classes implementing this interface can query default behavior |
| | | * providers in a type-safe manner when the kind of default behavior provider |
| | | * is unknown at compile time. When a visitor is passed to a default behavior |
| | | * providers in a type-safe manner when the kind of default behavior provider is |
| | | * unknown at compile time. When a visitor is passed to a default behavior |
| | | * provider's accept method, the corresponding visit method most applicable to |
| | | * that default behavior provider is invoked. |
| | | * |
| | | * @param <T> |
| | | * The type of values represented by the default value provider. |
| | | * The type of values represented by the default value provider. |
| | | * @param <R> |
| | | * The return type of this visitor's methods. Use |
| | | * {@link java.lang.Void} for visitors that do not need to return |
| | | * results. |
| | | * The return type of this visitor's methods. Use |
| | | * {@link java.lang.Void} for visitors that do not need to return |
| | | * results. |
| | | * @param <P> |
| | | * The type of the additional parameter to this visitor's methods. Use |
| | | * {@link java.lang.Void} for visitors that do not need an additional |
| | | * parameter. |
| | | * The type of the additional parameter to this visitor's methods. |
| | | * Use {@link java.lang.Void} for visitors that do not need an |
| | | * additional parameter. |
| | | */ |
| | | public interface DefaultBehaviorProviderVisitor<T, R, P> { |
| | | |
| | | /** |
| | | * Visit an absolute inherited default behavior provider. |
| | | * |
| | | * @param d |
| | | * The absolute inherited default behavior provider to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | R visitAbsoluteInherited(AbsoluteInheritedDefaultBehaviorProvider<T> d, P p); |
| | | /** |
| | | * Visit an absolute inherited default behavior provider. |
| | | * |
| | | * @param d |
| | | * The absolute inherited default behavior provider to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | R visitAbsoluteInherited(AbsoluteInheritedDefaultBehaviorProvider<T> d, P p); |
| | | |
| | | /** |
| | | * Visit an alias default behavior provider. |
| | | * |
| | | * @param d |
| | | * The alias default behavior provider to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | R visitAlias(AliasDefaultBehaviorProvider<T> d, P p); |
| | | |
| | | /** |
| | | * Visit an defined default behavior provider. |
| | | * |
| | | * @param d |
| | | * The defined default behavior provider to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | R visitDefined(DefinedDefaultBehaviorProvider<T> d, P p); |
| | | |
| | | /** |
| | | * Visit an alias default behavior provider. |
| | | * |
| | | * @param d |
| | | * The alias default behavior provider to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | R visitAlias(AliasDefaultBehaviorProvider<T> d, P p); |
| | | /** |
| | | * Visit a relative inherited default behavior provider. |
| | | * |
| | | * @param d |
| | | * The relative inherited default behavior provider to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | R visitRelativeInherited(RelativeInheritedDefaultBehaviorProvider<T> d, P p); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit an defined default behavior provider. |
| | | * |
| | | * @param d |
| | | * The defined default behavior provider to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | R visitDefined(DefinedDefaultBehaviorProvider<T> d, P p); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit a relative inherited default behavior provider. |
| | | * |
| | | * @param d |
| | | * The relative inherited default behavior provider to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | R visitRelativeInherited(RelativeInheritedDefaultBehaviorProvider<T> d, P p); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit an undefined default behavior provider. |
| | | * |
| | | * @param d |
| | | * The undefined default behavior provider to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | R visitUndefined(UndefinedDefaultBehaviorProvider<T> d, P p); |
| | | /** |
| | | * Visit an undefined default behavior provider. |
| | | * |
| | | * @param d |
| | | * The undefined default behavior provider to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | R visitUndefined(UndefinedDefaultBehaviorProvider<T> d, P p); |
| | | |
| | | } |
| | |
| | | */ |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | import java.util.SortedSet; |
| | | import java.util.TreeSet; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A default managed object which should be created when a parent |
| | | * managed object is created. Default managed objects are associated |
| | | * with a {@link RelationDefinition}. |
| | | * A default managed object which should be created when a parent managed object |
| | | * is created. Default managed objects are associated with a |
| | | * {@link RelationDefinition}. |
| | | * |
| | | * @param <C> |
| | | * The type of client default managed object configuration. |
| | | * The type of client default managed object configuration. |
| | | * @param <S> |
| | | * The type of server default managed object configuration. |
| | | * The type of server default managed object configuration. |
| | | */ |
| | | public final class DefaultManagedObject |
| | | <C extends ConfigurationClient, S extends Configuration> |
| | | implements PropertyProvider { |
| | | public final class DefaultManagedObject<C extends ConfigurationClient, S extends Configuration> implements |
| | | PropertyProvider { |
| | | |
| | | /** |
| | | * An interface for incrementally constructing default managed |
| | | * objects. |
| | | * |
| | | * @param <C> |
| | | * The type of client default managed object configuration. |
| | | * @param <S> |
| | | * The type of server default managed object configuration. |
| | | */ |
| | | public static final class Builder |
| | | <C extends ConfigurationClient, S extends Configuration> { |
| | | /** |
| | | * An interface for incrementally constructing default managed objects. |
| | | * |
| | | * @param <C> |
| | | * The type of client default managed object configuration. |
| | | * @param <S> |
| | | * The type of server default managed object configuration. |
| | | */ |
| | | public static final class Builder<C extends ConfigurationClient, S extends Configuration> { |
| | | |
| | | // The default managed object's definition. |
| | | private final ManagedObjectDefinition<C, S> definition; |
| | | |
| | | // The string encoded default managed object's properties. |
| | | private final Map<String, List<String>> propertyStringValues = new HashMap<String, List<String>>(); |
| | | |
| | | /** |
| | | * Creates a new default managed object builder. |
| | | * |
| | | * @param definition |
| | | * The default managed object's definition. |
| | | */ |
| | | public Builder(ManagedObjectDefinition<C, S> definition) { |
| | | this.definition = definition; |
| | | } |
| | | |
| | | /** |
| | | * Construct a default managed object based on the properties of this |
| | | * builder. |
| | | * |
| | | * @return Returns the new default managed object. |
| | | */ |
| | | public DefaultManagedObject<C, S> getInstance() { |
| | | return new DefaultManagedObject<C, S>(definition, propertyStringValues); |
| | | } |
| | | |
| | | /** |
| | | * Defines a property's values for the default managed object. |
| | | * |
| | | * @param name |
| | | * The name of the property. |
| | | * @param values |
| | | * One or more property values in the string representation. |
| | | */ |
| | | public void setPropertyValues(String name, String... values) { |
| | | if (values == null || values.length == 0) { |
| | | throw new IllegalArgumentException("null or empty values specified for property " + name); |
| | | } |
| | | |
| | | propertyStringValues.put(name, Arrays.asList(values)); |
| | | } |
| | | } |
| | | |
| | | // The default managed object's definition. |
| | | private final ManagedObjectDefinition<C, S> definition; |
| | | |
| | | // The string encoded default managed object's properties. |
| | | private final Map<String, List<String>> propertyStringValues = |
| | | new HashMap<String, List<String>>(); |
| | | private final Map<String, List<String>> propertyStringValues; |
| | | |
| | | |
| | | // Private constructor. |
| | | private DefaultManagedObject(ManagedObjectDefinition<C, S> definition, |
| | | Map<String, List<String>> propertyStringValues) { |
| | | this.definition = definition; |
| | | this.propertyStringValues = propertyStringValues; |
| | | } |
| | | |
| | | /** |
| | | * Creates a new default managed object builder. |
| | | * Gets the managed object definition associated with this default managed |
| | | * object. |
| | | * |
| | | * @param definition |
| | | * The default managed object's definition. |
| | | * @return Returns the managed object definition associated with this |
| | | * default managed object. |
| | | */ |
| | | public Builder(ManagedObjectDefinition<C, S> definition) { |
| | | this.definition = definition; |
| | | public ManagedObjectDefinition<C, S> getManagedObjectDefinition() { |
| | | return definition; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Construct a default managed object based on the properties of |
| | | * this builder. |
| | | * Gets a mutable copy of the set of property values for the specified |
| | | * property. |
| | | * |
| | | * @return Returns the new default managed object. |
| | | * @param <T> |
| | | * The type of the property to be retrieved. |
| | | * @param pd |
| | | * The property to be retrieved. |
| | | * @return Returns a newly allocated set containing a copy of the property's |
| | | * values. An empty set indicates that the property has no values |
| | | * defined and any default behavior is applicable. |
| | | * @throws IllegalArgumentException |
| | | * If the property definition is not associated with this |
| | | * managed object's definition. |
| | | */ |
| | | public DefaultManagedObject<C, S> getInstance() { |
| | | return new DefaultManagedObject<C, S>(definition, propertyStringValues); |
| | | public <T> SortedSet<T> getPropertyValues(PropertyDefinition<T> pd) { |
| | | // Validate the property definition. |
| | | definition.getPropertyDefinition(pd.getName()); |
| | | |
| | | // Do a defensive copy. |
| | | SortedSet<T> values = new TreeSet<T>(pd); |
| | | List<String> stringValues = propertyStringValues.get(pd.getName()); |
| | | if (stringValues != null) { |
| | | for (String stringValue : stringValues) { |
| | | values.add(pd.decodeValue(stringValue)); |
| | | } |
| | | } |
| | | return values; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Defines a property's values for the default managed object. |
| | | * Performs run-time initialization of properties. |
| | | * |
| | | * @param name |
| | | * The name of the property. |
| | | * @param values |
| | | * One or more property values in the string |
| | | * representation. |
| | | * @throws Exception |
| | | * If this default managed object could not be initialized. |
| | | */ |
| | | public void setPropertyValues(String name, String... values) { |
| | | if (values == null || values.length == 0) { |
| | | throw new IllegalArgumentException( |
| | | "null or empty values specified for property " + name); |
| | | } |
| | | void initialize() throws Exception { |
| | | // FIXME: it would be nice if we could decode all property values |
| | | // at this point. However this is not possible on the server side |
| | | // since some properties will be determined to be invalid since |
| | | // the schema is not loaded. |
| | | |
| | | propertyStringValues.put(name, Arrays.asList(values)); |
| | | // Validate provided property names. |
| | | for (String name : propertyStringValues.keySet()) { |
| | | definition.getPropertyDefinition(name); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // The default managed object's definition. |
| | | private final ManagedObjectDefinition<C, S> definition; |
| | | |
| | | // The string encoded default managed object's properties. |
| | | private final Map<String, List<String>> propertyStringValues; |
| | | |
| | | |
| | | |
| | | // Private constructor. |
| | | private DefaultManagedObject(ManagedObjectDefinition<C, S> definition, |
| | | Map<String, List<String>> propertyStringValues) { |
| | | this.definition = definition; |
| | | this.propertyStringValues = propertyStringValues; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the managed object definition associated with this default |
| | | * managed object. |
| | | * |
| | | * @return Returns the managed object definition associated with |
| | | * this default managed object. |
| | | */ |
| | | public ManagedObjectDefinition<C, S> getManagedObjectDefinition() { |
| | | return definition; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets a mutable copy of the set of property values for the |
| | | * specified property. |
| | | * |
| | | * @param <T> |
| | | * The type of the property to be retrieved. |
| | | * @param pd |
| | | * The property to be retrieved. |
| | | * @return Returns a newly allocated set containing a copy of the |
| | | * property's values. An empty set indicates that the |
| | | * property has no values defined and any default behavior |
| | | * is applicable. |
| | | * @throws IllegalArgumentException |
| | | * If the property definition is not associated with this |
| | | * managed object's definition. |
| | | */ |
| | | public <T> SortedSet<T> getPropertyValues(PropertyDefinition<T> pd) |
| | | throws IllegalArgumentException { |
| | | // Validate the property definition. |
| | | definition.getPropertyDefinition(pd.getName()); |
| | | |
| | | // Do a defensive copy. |
| | | SortedSet<T> values = new TreeSet<T>(pd); |
| | | List<String> stringValues = propertyStringValues.get(pd.getName()); |
| | | if (stringValues != null) { |
| | | for (String stringValue : stringValues) { |
| | | values.add(pd.decodeValue(stringValue)); |
| | | } |
| | | } |
| | | return values; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Performs run-time initialization of properties. |
| | | * |
| | | * @throws Exception |
| | | * If this default managed object could not be |
| | | * initialized. |
| | | */ |
| | | void initialize() throws Exception { |
| | | // FIXME: it would be nice if we could decode all property values |
| | | // at this point. However this is not possible on the server side |
| | | // since some properties will be determined to be invalid since |
| | | // the schema is not loaded. |
| | | |
| | | // Validate provided property names. |
| | | for (String name : propertyStringValues.keySet()) { |
| | | definition.getPropertyDefinition(name); |
| | | } |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collection; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A default behavior provider which represents a well-defined set of default |
| | | * values. It should be used by properties which have default value(s) which are |
| | | * valid value(s) according to the constraints of the property's definition. |
| | | * |
| | | * @param <T> |
| | | * The type of values represented by this provider. |
| | | * The type of values represented by this provider. |
| | | */ |
| | | public final class DefinedDefaultBehaviorProvider<T> extends |
| | | DefaultBehaviorProvider<T> { |
| | | public final class DefinedDefaultBehaviorProvider<T> extends DefaultBehaviorProvider<T> { |
| | | |
| | | // The collection of default values. |
| | | private final Collection<String> values; |
| | | // The collection of default values. |
| | | private final Collection<String> values; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a new defined default behavior provider associated with the |
| | | * specified list of values. |
| | | * |
| | | * @param values |
| | | * The list of values (must be non-<code>null</code> and not |
| | | * empty) in their string representation. |
| | | * @throws IllegalArgumentException |
| | | * If the list of values was <code>null</code> or empty. |
| | | */ |
| | | public DefinedDefaultBehaviorProvider(String... values) |
| | | throws IllegalArgumentException { |
| | | if (values == null || values.length == 0) { |
| | | throw new IllegalArgumentException( |
| | | "Null or empty list of default values"); |
| | | /** |
| | | * Create a new defined default behavior provider associated with the |
| | | * specified list of values. |
| | | * |
| | | * @param values |
| | | * The list of values (must be non-<code>null</code> and not |
| | | * empty) in their string representation. |
| | | * @throws IllegalArgumentException |
| | | * If the list of values was <code>null</code> or empty. |
| | | */ |
| | | public DefinedDefaultBehaviorProvider(String... values) { |
| | | if (values == null || values.length == 0) { |
| | | throw new IllegalArgumentException("Null or empty list of default values"); |
| | | } |
| | | this.values = Arrays.asList(values); |
| | | } |
| | | this.values = Arrays.asList(values); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <R, P> R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p) { |
| | | return v.visitDefined(this, p); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <R, P> R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p) { |
| | | return v.visitDefined(this, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get a copy of the default values. |
| | | * |
| | | * @return Returns a newly allocated collection containing a copy of the |
| | | * default values. |
| | | */ |
| | | public Collection<String> getDefaultValues() { |
| | | return new ArrayList<String>(values); |
| | | } |
| | | /** |
| | | * Get a copy of the default values. |
| | | * |
| | | * @return Returns a newly allocated collection containing a copy of the |
| | | * default values. |
| | | */ |
| | | public Collection<String> getDefaultValues() { |
| | | return new ArrayList<String>(values); |
| | | } |
| | | |
| | | } |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | |
| | | /** |
| | | * The requested managed object was found but its type could not be |
| | | * determined. |
| | | * The requested managed object was found but its type could not be determined. |
| | | */ |
| | | public class DefinitionDecodingException extends DecodingException { |
| | | |
| | | /** |
| | | * An enumeration defining the reasons why the definition could not |
| | | * be resolved. |
| | | */ |
| | | public static enum Reason { |
| | | /** |
| | | * The managed object could be found but its type resolved to an |
| | | * abstract managed object definition. |
| | | * An enumeration defining the reasons why the definition could not be |
| | | * resolved. |
| | | */ |
| | | ABSTRACT_TYPE_INFORMATION(), |
| | | public static enum Reason { |
| | | /** |
| | | * The managed object could be found but its type resolved to an |
| | | * abstract managed object definition. |
| | | */ |
| | | ABSTRACT_TYPE_INFORMATION(), |
| | | |
| | | /** |
| | | * The managed object could be found but did not contain any type |
| | | * information (eg missing object classes in LDAP). |
| | | */ |
| | | NO_TYPE_INFORMATION(), |
| | | /** |
| | | * The managed object could be found but did not contain any type |
| | | * information (eg missing object classes in LDAP). |
| | | */ |
| | | NO_TYPE_INFORMATION(), |
| | | |
| | | /** |
| | | * The managed object could be found but did not contain the |
| | | * expected type information (eg incorrect object classes in |
| | | * LDAP). |
| | | */ |
| | | WRONG_TYPE_INFORMATION(); |
| | | /** |
| | | * The managed object could be found but did not contain the expected |
| | | * type information (eg incorrect object classes in LDAP). |
| | | */ |
| | | WRONG_TYPE_INFORMATION(); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * Version ID required by serializable classes. |
| | | */ |
| | | private static final long serialVersionUID = 3459033551415663416L; |
| | | |
| | | |
| | | |
| | | // Create the message. |
| | | private static LocalizableMessage createLocalizableMessage(AbstractManagedObjectDefinition<?, ?> d, |
| | | Reason reason) { |
| | | LocalizableMessage ufn = d.getUserFriendlyName(); |
| | | switch (reason) { |
| | | case NO_TYPE_INFORMATION: |
| | | return ERR_DECODING_EXCEPTION_NO_TYPE_INFO.get(ufn); |
| | | case WRONG_TYPE_INFORMATION: |
| | | return ERR_DECODING_EXCEPTION_WRONG_TYPE_INFO.get(ufn); |
| | | default: |
| | | return ERR_DECODING_EXCEPTION_ABSTRACT_TYPE_INFO.get(ufn); |
| | | } |
| | | } |
| | | |
| | | // The expected type of managed object. |
| | | private final AbstractManagedObjectDefinition<?, ?> d; |
| | | /** |
| | | * Version ID required by serializable classes. |
| | | */ |
| | | private static final long serialVersionUID = 3459033551415663416L; |
| | | |
| | | // The reason why the definition could not be determined. |
| | | private final Reason reason; |
| | | // Create the message. |
| | | private static LocalizableMessage createLocalizableMessage(AbstractManagedObjectDefinition<?, ?> d, Reason reason) { |
| | | LocalizableMessage ufn = d.getUserFriendlyName(); |
| | | switch (reason) { |
| | | case NO_TYPE_INFORMATION: |
| | | return ERR_DECODING_EXCEPTION_NO_TYPE_INFO.get(ufn); |
| | | case WRONG_TYPE_INFORMATION: |
| | | return ERR_DECODING_EXCEPTION_WRONG_TYPE_INFO.get(ufn); |
| | | default: |
| | | return ERR_DECODING_EXCEPTION_ABSTRACT_TYPE_INFO.get(ufn); |
| | | } |
| | | } |
| | | |
| | | // The expected type of managed object. |
| | | private final AbstractManagedObjectDefinition<?, ?> d; |
| | | |
| | | // The reason why the definition could not be determined. |
| | | private final Reason reason; |
| | | |
| | | /** |
| | | * Create a new definition decoding exception. |
| | | * |
| | | * @param d |
| | | * The expected type of managed object. |
| | | * @param reason |
| | | * The reason why the definition could not be determined. |
| | | */ |
| | | public DefinitionDecodingException(AbstractManagedObjectDefinition<?, ?> d, |
| | | Reason reason) { |
| | | super(createLocalizableMessage(d, reason)); |
| | | this.d = d; |
| | | this.reason = reason; |
| | | } |
| | | /** |
| | | * Create a new definition decoding exception. |
| | | * |
| | | * @param d |
| | | * The expected type of managed object. |
| | | * @param reason |
| | | * The reason why the definition could not be determined. |
| | | */ |
| | | public DefinitionDecodingException(AbstractManagedObjectDefinition<?, ?> d, Reason reason) { |
| | | super(createLocalizableMessage(d, reason)); |
| | | this.d = d; |
| | | this.reason = reason; |
| | | } |
| | | |
| | | /** |
| | | * Gets the expected managed object definition. |
| | | * |
| | | * @return Returns the expected managed object definition. |
| | | */ |
| | | public AbstractManagedObjectDefinition<?, ?> getManagedObjectDefinition() { |
| | | return d; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Gets the expected managed object definition. |
| | | * |
| | | * @return Returns the expected managed object definition. |
| | | */ |
| | | public AbstractManagedObjectDefinition<?, ?> getManagedObjectDefinition() { |
| | | return d; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the reason why the definition could not be determined. |
| | | * |
| | | * @return Returns the reason why the definition could not be |
| | | * determined. |
| | | */ |
| | | public Reason getReason() { |
| | | return reason; |
| | | } |
| | | /** |
| | | * Gets the reason why the definition could not be determined. |
| | | * |
| | | * @return Returns the reason why the definition could not be determined. |
| | | */ |
| | | public Reason getReason() { |
| | | return reason; |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This interface is used to determine the "best match" managed object |
| | | * definition in a definition hierarchy. |
| | | * <p> |
| | | * Managed object definitions, like Java classes, are arranged in an |
| | | * inheritance hierarchy. When managed objects are decoded (e.g. from |
| | | * LDAP entries), the driver implementation is provided with an |
| | | * "expected managed object definition". However, the actual decoded |
| | | * managed object is often an instance of a sub-type of this |
| | | * definition. For example, when decoding a connection handler managed |
| | | * object, the actual type can never be a connection handler because |
| | | * it is an abstract managed object type. Instead, the decoded managed |
| | | * object must be a "concrete" sub-type: an LDAP connection handler or |
| | | * JMX connection handler. |
| | | * Managed object definitions, like Java classes, are arranged in an inheritance |
| | | * hierarchy. When managed objects are decoded (e.g. from LDAP entries), the |
| | | * driver implementation is provided with an |
| | | * "expected managed object definition". However, the actual decoded managed |
| | | * object is often an instance of a sub-type of this definition. For example, |
| | | * when decoding a connection handler managed object, the actual type can never |
| | | * be a connection handler because it is an abstract managed object type. |
| | | * Instead, the decoded managed object must be a "concrete" sub-type: an LDAP |
| | | * connection handler or JMX connection handler. |
| | | * <p> |
| | | * This resolution process is coordinated by the |
| | | * <code>resolveManagedObjectDefinition</code> method in managed |
| | | * object definitions, where it is passed a |
| | | * <code>DefinitionResolver</code> implementation. The |
| | | * <code>resolveManagedObjectDefinition</code> method takes care of |
| | | * recursively descending through the definition hierarchy and invokes |
| | | * the {@link #matches(AbstractManagedObjectDefinition)} method |
| | | * against each potential sub-type. It is the job of the resolver to |
| | | * indicate whether the provided managed object definition is a |
| | | * candidate definition. For example, the LDAP driver provides a |
| | | * definition resolver which uses the decoded LDAP entry's object |
| | | * classes to determine the final appropriate managed object |
| | | * <code>resolveManagedObjectDefinition</code> method in managed object |
| | | * definitions, where it is passed a <code>DefinitionResolver</code> |
| | | * implementation. The <code>resolveManagedObjectDefinition</code> method takes |
| | | * care of recursively descending through the definition hierarchy and invokes |
| | | * the {@link #matches(AbstractManagedObjectDefinition)} method against each |
| | | * potential sub-type. It is the job of the resolver to indicate whether the |
| | | * provided managed object definition is a candidate definition. For example, |
| | | * the LDAP driver provides a definition resolver which uses the decoded LDAP |
| | | * entry's object classes to determine the final appropriate managed object |
| | | * definition. |
| | | */ |
| | | public interface DefinitionResolver { |
| | | |
| | | /** |
| | | * Determines whether or not the provided managed object definition matches |
| | | * this resolver's criteria. |
| | | * |
| | | * @param d |
| | | * The managed object definition. |
| | | * @return Returns <code>true</code> if the the provided managed object |
| | | * definition matches this resolver's criteria. |
| | | */ |
| | | boolean matches(AbstractManagedObjectDefinition<?, ?> d); |
| | | /** |
| | | * Determines whether or not the provided managed object definition matches |
| | | * this resolver's criteria. |
| | | * |
| | | * @param d |
| | | * The managed object definition. |
| | | * @return Returns <code>true</code> if the the provided managed object |
| | | * definition matches this resolver's criteria. |
| | | */ |
| | | boolean matches(AbstractManagedObjectDefinition<?, ?> d); |
| | | } |
| | |
| | | * An interface for incrementally constructing duration property |
| | | * definitions. |
| | | */ |
| | | public static class Builder extends AbstractBuilder<Long, DurationPropertyDefinition> { |
| | | public static final class Builder extends AbstractBuilder<Long, DurationPropertyDefinition> { |
| | | |
| | | // The base unit for this property definition. |
| | | private DurationUnit baseUnit = DurationUnit.SECONDS; |
| | |
| | | * duration unit, or if the base unit is bigger than the |
| | | * maximum unit. |
| | | */ |
| | | public final void setBaseUnit(String unit) throws IllegalArgumentException { |
| | | public final void setBaseUnit(String unit) { |
| | | Reject.ifNull(unit); |
| | | |
| | | setBaseUnit(DurationUnit.getUnit(unit)); |
| | |
| | | * If the provided base unit is bigger than the maximum |
| | | * unit. |
| | | */ |
| | | public final void setBaseUnit(DurationUnit unit) throws IllegalArgumentException { |
| | | public final void setBaseUnit(DurationUnit unit) { |
| | | Reject.ifNull(unit); |
| | | |
| | | // Make sure that the base unit is not bigger than the maximum |
| | |
| | | * duration unit, or if the maximum unit is smaller than the |
| | | * base unit. |
| | | */ |
| | | public final void setMaximumUnit(String unit) throws IllegalArgumentException { |
| | | public final void setMaximumUnit(String unit) { |
| | | if (unit == null) { |
| | | setMaximumUnit((DurationUnit) null); |
| | | } else { |
| | |
| | | * If the provided maximum unit is smaller than the base |
| | | * unit. |
| | | */ |
| | | public final void setMaximumUnit(DurationUnit unit) throws IllegalArgumentException { |
| | | public final void setMaximumUnit(DurationUnit unit) { |
| | | if (unit != null) { |
| | | // Make sure that the maximum unit is not smaller than the |
| | | // base unit. |
| | |
| | | * If a negative lower limit was specified, or the lower |
| | | * limit is greater than the upper limit. |
| | | */ |
| | | public final void setLowerLimit(long lowerLimit) throws IllegalArgumentException { |
| | | public final void setLowerLimit(long lowerLimit) { |
| | | if (lowerLimit < 0) { |
| | | throw new IllegalArgumentException("Negative lower limit"); |
| | | } |
| | |
| | | * lower limit was specified, or the lower limit is greater |
| | | * than the upper limit. |
| | | */ |
| | | public final void setLowerLimit(String lowerLimit) throws IllegalArgumentException { |
| | | public final void setLowerLimit(String lowerLimit) { |
| | | setLowerLimit(DurationUnit.parseValue(lowerLimit, baseUnit)); |
| | | } |
| | | |
| | |
| | | * limit is greater than the upper limit or unlimited |
| | | * durations are permitted. |
| | | */ |
| | | public final void setUpperLimit(Long upperLimit) throws IllegalArgumentException { |
| | | public final void setUpperLimit(Long upperLimit) { |
| | | if (upperLimit != null) { |
| | | if (upperLimit < 0) { |
| | | throw new IllegalArgumentException("Negative upper limit"); |
| | |
| | | * If the upper limit could not be parsed, or if the lower |
| | | * limit is greater than the upper limit. |
| | | */ |
| | | public final void setUpperLimit(String upperLimit) throws IllegalArgumentException { |
| | | public final void setUpperLimit(String upperLimit) { |
| | | if (upperLimit == null) { |
| | | setUpperLimit((Long) null); |
| | | } else { |
| | |
| | | * If unlimited values are to be permitted but there is an |
| | | * upper limit specified. |
| | | */ |
| | | public final void setAllowUnlimited(boolean allowUnlimited) throws IllegalArgumentException { |
| | | public final void setAllowUnlimited(boolean allowUnlimited) { |
| | | if (allowUnlimited && upperLimit != null) { |
| | | throw new IllegalArgumentException("Upper limit specified when unlimited durations are permitted"); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | protected DurationPropertyDefinition buildInstance(AbstractManagedObjectDefinition<?, ?> d, |
| | | String propertyName, EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Long> defaultBehavior) { |
| | | String propertyName, EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Long> defaultBehavior) { |
| | | return new DurationPropertyDefinition(d, propertyName, options, adminAction, defaultBehavior, baseUnit, |
| | | maximumUnit, lowerLimit, upperLimit, allowUnlimited); |
| | | maximumUnit, lowerLimit, upperLimit, allowUnlimited); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | // Private constructor. |
| | | private DurationPropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Long> defaultBehavior, DurationUnit baseUnit, DurationUnit maximumUnit, |
| | | Long lowerLimit, Long upperLimit, boolean allowUnlimited) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Long> defaultBehavior, DurationUnit baseUnit, DurationUnit maximumUnit, |
| | | Long lowerLimit, Long upperLimit, boolean allowUnlimited) { |
| | | super(d, Long.class, propertyName, options, adminAction, defaultBehavior); |
| | | this.baseUnit = baseUnit; |
| | | this.maximumUnit = maximumUnit; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Long value) throws IllegalPropertyValueException { |
| | | public void validateValue(Long value) { |
| | | Reject.ifNull(value); |
| | | |
| | | long nvalue = baseUnit.toMilliSeconds(value); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String encodeValue(Long value) throws IllegalPropertyValueException { |
| | | public String encodeValue(Long value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // Make sure that we correctly encode negative values as |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Long decodeValue(String value) throws IllegalPropertyValueStringException { |
| | | public Long decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // First check for the special "unlimited" value when necessary. |
| | |
| | | */ |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This enumeration defines various duration units. |
| | | */ |
| | | public enum DurationUnit { |
| | | |
| | | /** |
| | | * A day unit. |
| | | */ |
| | | DAYS((long) 24 * 60 * 60 * 1000, "d", "days"), |
| | | /** |
| | | * A day unit. |
| | | */ |
| | | DAYS((long) 24 * 60 * 60 * 1000, "d", "days"), |
| | | |
| | | /** |
| | | * An hour unit. |
| | | */ |
| | | HOURS((long) 60 * 60 * 1000, "h", "hours"), |
| | | /** |
| | | * An hour unit. |
| | | */ |
| | | HOURS((long) 60 * 60 * 1000, "h", "hours"), |
| | | |
| | | /** |
| | | * A millisecond unit. |
| | | */ |
| | | MILLI_SECONDS(1L, "ms", "milliseconds"), |
| | | /** |
| | | * A millisecond unit. |
| | | */ |
| | | MILLI_SECONDS(1L, "ms", "milliseconds"), |
| | | |
| | | /** |
| | | * A minute unit. |
| | | */ |
| | | MINUTES((long) 60 * 1000, "m", "minutes"), |
| | | /** |
| | | * A minute unit. |
| | | */ |
| | | MINUTES((long) 60 * 1000, "m", "minutes"), |
| | | |
| | | /** |
| | | * A second unit. |
| | | */ |
| | | SECONDS(1000L, "s", "seconds"), |
| | | /** |
| | | * A second unit. |
| | | */ |
| | | SECONDS(1000L, "s", "seconds"), |
| | | |
| | | /** |
| | | * A week unit. |
| | | */ |
| | | WEEKS((long) 7 * 24 * 60 * 60 * 1000, "w", "weeks"); |
| | | /** |
| | | * A week unit. |
| | | */ |
| | | WEEKS((long) 7 * 24 * 60 * 60 * 1000, "w", "weeks"); |
| | | |
| | | // A lookup table for resolving a unit from its name. |
| | | private static final Map<String, DurationUnit> nameToUnit; |
| | | static { |
| | | nameToUnit = new HashMap<String, DurationUnit>(); |
| | | // A lookup table for resolving a unit from its name. |
| | | private static final Map<String, DurationUnit> NAME_TO_UNIT; |
| | | static { |
| | | NAME_TO_UNIT = new HashMap<String, DurationUnit>(); |
| | | |
| | | for (DurationUnit unit : DurationUnit.values()) { |
| | | nameToUnit.put(unit.shortName, unit); |
| | | nameToUnit.put(unit.longName, unit); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the unit corresponding to the provided unit name. |
| | | * |
| | | * @param s |
| | | * The name of the unit. Can be the abbreviated or long |
| | | * name and can contain white space and mixed case |
| | | * characters. |
| | | * @return Returns the unit corresponding to the provided unit name. |
| | | * @throws IllegalArgumentException |
| | | * If the provided name did not correspond to a known |
| | | * duration unit. |
| | | */ |
| | | public static DurationUnit getUnit(String s) throws IllegalArgumentException { |
| | | DurationUnit unit = nameToUnit.get(s.trim().toLowerCase()); |
| | | if (unit == null) { |
| | | throw new IllegalArgumentException("Illegal duration unit \"" + s + "\""); |
| | | } |
| | | return unit; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parse the provided duration string and return its equivalent |
| | | * duration in milliseconds. The duration string must specify the |
| | | * unit e.g. "10s". This method will parse duration string |
| | | * representations produced from the {@link #toString(long)} method. |
| | | * Therefore, a duration can comprise of multiple duration |
| | | * specifiers, for example <code>1d15m25s</code>. |
| | | * |
| | | * @param s |
| | | * The duration string to be parsed. |
| | | * @return Returns the parsed duration in milliseconds. |
| | | * @throws NumberFormatException |
| | | * If the provided duration string could not be parsed. |
| | | * @see #toString(long) |
| | | */ |
| | | public static long parseValue(String s) throws NumberFormatException { |
| | | return parseValue(s, null); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parse the provided duration string and return its equivalent |
| | | * duration in milliseconds. This method will parse duration string |
| | | * representations produced from the {@link #toString(long)} method. |
| | | * Therefore, a duration can comprise of multiple duration |
| | | * specifiers, for example <code>1d15m25s</code>. |
| | | * |
| | | * @param s |
| | | * The duration string to be parsed. |
| | | * @param defaultUnit |
| | | * The default unit to use if there is no unit specified in |
| | | * the duration string, or <code>null</code> if the |
| | | * string must always contain a unit. |
| | | * @return Returns the parsed duration in milliseconds. |
| | | * @throws NumberFormatException |
| | | * If the provided duration string could not be parsed. |
| | | * @see #toString(long) |
| | | */ |
| | | public static long parseValue(String s, DurationUnit defaultUnit) |
| | | throws NumberFormatException { |
| | | String ns = s.trim(); |
| | | if (ns.length() == 0) { |
| | | throw new NumberFormatException("Empty duration value \"" + s + "\""); |
| | | for (DurationUnit unit : DurationUnit.values()) { |
| | | NAME_TO_UNIT.put(unit.shortName, unit); |
| | | NAME_TO_UNIT.put(unit.longName, unit); |
| | | } |
| | | } |
| | | |
| | | Pattern p1 = Pattern.compile("^\\s*((\\d+)\\s*w)?" + "\\s*((\\d+)\\s*d)?" |
| | | + "\\s*((\\d+)\\s*h)?" + "\\s*((\\d+)\\s*m)?" + "\\s*((\\d+)\\s*s)?" |
| | | + "\\s*((\\d+)\\s*ms)?\\s*$", Pattern.CASE_INSENSITIVE); |
| | | Matcher m1 = p1.matcher(ns); |
| | | if (m1.matches()) { |
| | | // Value must be of the form produced by toString(long). |
| | | String weeks = m1.group(2); |
| | | String days = m1.group(4); |
| | | String hours = m1.group(6); |
| | | String minutes = m1.group(8); |
| | | String seconds = m1.group(10); |
| | | String ms = m1.group(12); |
| | | /** |
| | | * Get the unit corresponding to the provided unit name. |
| | | * |
| | | * @param s |
| | | * The name of the unit. Can be the abbreviated or long name and |
| | | * can contain white space and mixed case characters. |
| | | * @return Returns the unit corresponding to the provided unit name. |
| | | * @throws IllegalArgumentException |
| | | * If the provided name did not correspond to a known duration |
| | | * unit. |
| | | */ |
| | | public static DurationUnit getUnit(String s) { |
| | | DurationUnit unit = NAME_TO_UNIT.get(s.trim().toLowerCase()); |
| | | if (unit == null) { |
| | | throw new IllegalArgumentException("Illegal duration unit \"" + s + "\""); |
| | | } |
| | | return unit; |
| | | } |
| | | |
| | | long duration = 0; |
| | | /** |
| | | * Parse the provided duration string and return its equivalent duration in |
| | | * milliseconds. The duration string must specify the unit e.g. "10s". This |
| | | * method will parse duration string representations produced from the |
| | | * {@link #toString(long)} method. Therefore, a duration can comprise of |
| | | * multiple duration specifiers, for example <code>1d15m25s</code>. |
| | | * |
| | | * @param s |
| | | * The duration string to be parsed. |
| | | * @return Returns the parsed duration in milliseconds. |
| | | * @throws NumberFormatException |
| | | * If the provided duration string could not be parsed. |
| | | * @see #toString(long) |
| | | */ |
| | | public static long parseValue(String s) { |
| | | return parseValue(s, null); |
| | | } |
| | | |
| | | try { |
| | | if (weeks != null) { |
| | | duration += Long.valueOf(weeks) * WEEKS.getDuration(); |
| | | /** |
| | | * Parse the provided duration string and return its equivalent duration in |
| | | * milliseconds. This method will parse duration string representations |
| | | * produced from the {@link #toString(long)} method. Therefore, a duration |
| | | * can comprise of multiple duration specifiers, for example |
| | | * <code>1d15m25s</code>. |
| | | * |
| | | * @param s |
| | | * The duration string to be parsed. |
| | | * @param defaultUnit |
| | | * The default unit to use if there is no unit specified in the |
| | | * duration string, or <code>null</code> if the string must |
| | | * always contain a unit. |
| | | * @return Returns the parsed duration in milliseconds. |
| | | * @throws NumberFormatException |
| | | * If the provided duration string could not be parsed. |
| | | * @see #toString(long) |
| | | */ |
| | | public static long parseValue(String s, DurationUnit defaultUnit) { |
| | | String ns = s.trim(); |
| | | if (ns.length() == 0) { |
| | | throw new NumberFormatException("Empty duration value \"" + s + "\""); |
| | | } |
| | | |
| | | if (days != null) { |
| | | duration += Long.valueOf(days) * DAYS.getDuration(); |
| | | } |
| | | Pattern p1 = |
| | | Pattern.compile("^\\s*((\\d+)\\s*w)?" + "\\s*((\\d+)\\s*d)?" + "\\s*((\\d+)\\s*h)?" |
| | | + "\\s*((\\d+)\\s*m)?" + "\\s*((\\d+)\\s*s)?" + "\\s*((\\d+)\\s*ms)?\\s*$", Pattern.CASE_INSENSITIVE); |
| | | Matcher m1 = p1.matcher(ns); |
| | | if (m1.matches()) { |
| | | // Value must be of the form produced by toString(long). |
| | | String weeks = m1.group(2); |
| | | String days = m1.group(4); |
| | | String hours = m1.group(6); |
| | | String minutes = m1.group(8); |
| | | String seconds = m1.group(10); |
| | | String ms = m1.group(12); |
| | | |
| | | if (hours != null) { |
| | | duration += Long.valueOf(hours) * HOURS.getDuration(); |
| | | } |
| | | long duration = 0; |
| | | |
| | | if (minutes != null) { |
| | | duration += Long.valueOf(minutes) * MINUTES.getDuration(); |
| | | } |
| | | try { |
| | | if (weeks != null) { |
| | | duration += Long.valueOf(weeks) * WEEKS.getDuration(); |
| | | } |
| | | |
| | | if (seconds != null) { |
| | | duration += Long.valueOf(seconds) * SECONDS.getDuration(); |
| | | } |
| | | if (days != null) { |
| | | duration += Long.valueOf(days) * DAYS.getDuration(); |
| | | } |
| | | |
| | | if (ms != null) { |
| | | duration += Long.valueOf(ms) * MILLI_SECONDS.getDuration(); |
| | | } |
| | | } catch (NumberFormatException e) { |
| | | throw new NumberFormatException("Invalid duration value \"" + s + "\""); |
| | | } |
| | | if (hours != null) { |
| | | duration += Long.valueOf(hours) * HOURS.getDuration(); |
| | | } |
| | | |
| | | return duration; |
| | | } else { |
| | | // Value must be a floating point number followed by a unit. |
| | | Pattern p2 = Pattern.compile("^\\s*(\\d+(\\.\\d+)?)\\s*(\\w+)?\\s*$"); |
| | | Matcher m2 = p2.matcher(ns); |
| | | if (minutes != null) { |
| | | duration += Long.valueOf(minutes) * MINUTES.getDuration(); |
| | | } |
| | | |
| | | if (!m2.matches()) { |
| | | throw new NumberFormatException("Invalid duration value \"" + s + "\""); |
| | | } |
| | | if (seconds != null) { |
| | | duration += Long.valueOf(seconds) * SECONDS.getDuration(); |
| | | } |
| | | |
| | | // Group 1 is the float. |
| | | double d; |
| | | try { |
| | | d = Double.valueOf(m2.group(1)); |
| | | } catch (NumberFormatException e) { |
| | | throw new NumberFormatException("Invalid duration value \"" + s + "\""); |
| | | } |
| | | if (ms != null) { |
| | | duration += Long.valueOf(ms) * MILLI_SECONDS.getDuration(); |
| | | } |
| | | } catch (NumberFormatException e) { |
| | | throw new NumberFormatException("Invalid duration value \"" + s + "\""); |
| | | } |
| | | |
| | | // Group 3 is the unit. |
| | | String unitString = m2.group(3); |
| | | DurationUnit unit; |
| | | if (unitString == null) { |
| | | if (defaultUnit == null) { |
| | | throw new NumberFormatException("Invalid duration value \"" + s |
| | | + "\""); |
| | | return duration; |
| | | } else { |
| | | unit = defaultUnit; |
| | | // Value must be a floating point number followed by a unit. |
| | | Pattern p2 = Pattern.compile("^\\s*(\\d+(\\.\\d+)?)\\s*(\\w+)?\\s*$"); |
| | | Matcher m2 = p2.matcher(ns); |
| | | |
| | | if (!m2.matches()) { |
| | | throw new NumberFormatException("Invalid duration value \"" + s + "\""); |
| | | } |
| | | |
| | | // Group 1 is the float. |
| | | double d; |
| | | try { |
| | | d = Double.valueOf(m2.group(1)); |
| | | } catch (NumberFormatException e) { |
| | | throw new NumberFormatException("Invalid duration value \"" + s + "\""); |
| | | } |
| | | |
| | | // Group 3 is the unit. |
| | | String unitString = m2.group(3); |
| | | DurationUnit unit; |
| | | if (unitString == null) { |
| | | if (defaultUnit == null) { |
| | | throw new NumberFormatException("Invalid duration value \"" + s + "\""); |
| | | } else { |
| | | unit = defaultUnit; |
| | | } |
| | | } else { |
| | | try { |
| | | unit = getUnit(unitString); |
| | | } catch (IllegalArgumentException e) { |
| | | throw new NumberFormatException("Invalid duration value \"" + s + "\""); |
| | | } |
| | | } |
| | | |
| | | return unit.toMilliSeconds(d); |
| | | } |
| | | } else { |
| | | try { |
| | | unit = getUnit(unitString); |
| | | } catch (IllegalArgumentException e) { |
| | | throw new NumberFormatException("Invalid duration value \"" + s |
| | | + "\""); |
| | | } |
| | | |
| | | /** |
| | | * Returns a string representation of the provided duration. The string |
| | | * representation can be parsed using the {@link #parseValue(String)} |
| | | * method. The string representation is comprised of one or more of the |
| | | * number of weeks, days, hours, minutes, seconds, and milliseconds. Here |
| | | * are some examples: |
| | | * |
| | | * <pre> |
| | | * toString(0) // 0 ms |
| | | * toString(999) // 999 ms |
| | | * toString(1000) // 1 s |
| | | * toString(1500) // 1 s 500 ms |
| | | * toString(3650000) // 1 h 50 s |
| | | * toString(3700000) // 1 h 1 m 40 s |
| | | * </pre> |
| | | * |
| | | * @param duration |
| | | * The duration in milliseconds. |
| | | * @return Returns a string representation of the provided duration. |
| | | * @throws IllegalArgumentException |
| | | * If the provided duration is negative. |
| | | * @see #parseValue(String) |
| | | * @see #parseValue(String, DurationUnit) |
| | | */ |
| | | public static String toString(long duration) { |
| | | if (duration < 0) { |
| | | throw new IllegalArgumentException("Negative duration " + duration); |
| | | } |
| | | } |
| | | |
| | | return unit.toMilliSeconds(d); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Returns a string representation of the provided duration. The |
| | | * string representation can be parsed using the |
| | | * {@link #parseValue(String)} method. The string representation is |
| | | * comprised of one or more of the number of weeks, days, hours, |
| | | * minutes, seconds, and milliseconds. Here are some examples: |
| | | * |
| | | * <pre> |
| | | * toString(0) // 0 ms |
| | | * toString(999) // 999 ms |
| | | * toString(1000) // 1 s |
| | | * toString(1500) // 1 s 500 ms |
| | | * toString(3650000) // 1 h 50 s |
| | | * toString(3700000) // 1 h 1 m 40 s |
| | | * </pre> |
| | | * |
| | | * @param duration |
| | | * The duration in milliseconds. |
| | | * @return Returns a string representation of the provided duration. |
| | | * @throws IllegalArgumentException |
| | | * If the provided duration is negative. |
| | | * @see #parseValue(String) |
| | | * @see #parseValue(String, DurationUnit) |
| | | */ |
| | | public static String toString(long duration) throws IllegalArgumentException { |
| | | if (duration < 0) { |
| | | throw new IllegalArgumentException("Negative duration " + duration); |
| | | } |
| | | |
| | | if (duration == 0) { |
| | | return "0 ms"; |
| | | } |
| | | |
| | | DurationUnit[] units = new DurationUnit[] { WEEKS, DAYS, HOURS, MINUTES, |
| | | SECONDS, MILLI_SECONDS }; |
| | | long remainder = duration; |
| | | StringBuilder builder = new StringBuilder(); |
| | | boolean isFirst = true; |
| | | for (DurationUnit unit : units) { |
| | | long count = remainder / unit.getDuration(); |
| | | if (count > 0) { |
| | | if (!isFirst) { |
| | | builder.append(' '); |
| | | if (duration == 0) { |
| | | return "0 ms"; |
| | | } |
| | | builder.append(count); |
| | | builder.append(' '); |
| | | builder.append(unit.getShortName()); |
| | | remainder = remainder - (count * unit.getDuration()); |
| | | isFirst = false; |
| | | } |
| | | |
| | | DurationUnit[] units = new DurationUnit[] { WEEKS, DAYS, HOURS, MINUTES, SECONDS, MILLI_SECONDS }; |
| | | long remainder = duration; |
| | | StringBuilder builder = new StringBuilder(); |
| | | boolean isFirst = true; |
| | | for (DurationUnit unit : units) { |
| | | long count = remainder / unit.getDuration(); |
| | | if (count > 0) { |
| | | if (!isFirst) { |
| | | builder.append(' '); |
| | | } |
| | | builder.append(count); |
| | | builder.append(' '); |
| | | builder.append(unit.getShortName()); |
| | | remainder = remainder - (count * unit.getDuration()); |
| | | isFirst = false; |
| | | } |
| | | } |
| | | return builder.toString(); |
| | | } |
| | | return builder.toString(); |
| | | } |
| | | |
| | | // The long name of the unit. |
| | | private final String longName; |
| | | // The long name of the unit. |
| | | private final String longName; |
| | | |
| | | // The abbreviation of the unit. |
| | | private final String shortName; |
| | | // The abbreviation of the unit. |
| | | private final String shortName; |
| | | |
| | | // The size of the unit in milliseconds. |
| | | private final long sz; |
| | | // The size of the unit in milliseconds. |
| | | private final long sz; |
| | | |
| | | // Private constructor. |
| | | private DurationUnit(long sz, String shortName, String longName) { |
| | | this.sz = sz; |
| | | this.shortName = shortName; |
| | | this.longName = longName; |
| | | } |
| | | |
| | | /** |
| | | * Converts the specified duration in milliseconds to this unit. |
| | | * |
| | | * @param duration |
| | | * The duration in milliseconds. |
| | | * @return Returns milliseconds in this unit. |
| | | */ |
| | | public double fromMilliSeconds(long duration) { |
| | | return ((double) duration / sz); |
| | | } |
| | | |
| | | // Private constructor. |
| | | private DurationUnit(long sz, String shortName, String longName) { |
| | | this.sz = sz; |
| | | this.shortName = shortName; |
| | | this.longName = longName; |
| | | } |
| | | /** |
| | | * Get the number of milliseconds that this unit represents. |
| | | * |
| | | * @return Returns the number of milliseconds that this unit represents. |
| | | */ |
| | | public long getDuration() { |
| | | return sz; |
| | | } |
| | | |
| | | /** |
| | | * Get the long name of this unit. |
| | | * |
| | | * @return Returns the long name of this unit. |
| | | */ |
| | | public String getLongName() { |
| | | return longName; |
| | | } |
| | | |
| | | /** |
| | | * Get the abbreviated name of this unit. |
| | | * |
| | | * @return Returns the abbreviated name of this unit. |
| | | */ |
| | | public String getShortName() { |
| | | return shortName; |
| | | } |
| | | |
| | | /** |
| | | * Converts the specified duration in milliseconds to this unit. |
| | | * |
| | | * @param duration |
| | | * The duration in milliseconds. |
| | | * @return Returns milliseconds in this unit. |
| | | */ |
| | | public double fromMilliSeconds(long duration) { |
| | | return ((double) duration / sz); |
| | | } |
| | | /** |
| | | * Converts the specified duration in this unit to milliseconds. |
| | | * |
| | | * @param duration |
| | | * The duration as a quantity of this unit. |
| | | * @return Returns the number of milliseconds that the duration represents. |
| | | */ |
| | | public long toMilliSeconds(double duration) { |
| | | return (long) (sz * duration); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the number of milliseconds that this unit represents. |
| | | * |
| | | * @return Returns the number of milliseconds that this unit |
| | | * represents. |
| | | */ |
| | | public long getDuration() { |
| | | return sz; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the long name of this unit. |
| | | * |
| | | * @return Returns the long name of this unit. |
| | | */ |
| | | public String getLongName() { |
| | | return longName; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the abbreviated name of this unit. |
| | | * |
| | | * @return Returns the abbreviated name of this unit. |
| | | */ |
| | | public String getShortName() { |
| | | return shortName; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Converts the specified duration in this unit to milliseconds. |
| | | * |
| | | * @param duration |
| | | * The duration as a quantity of this unit. |
| | | * @return Returns the number of milliseconds that the duration |
| | | * represents. |
| | | */ |
| | | public long toMilliSeconds(double duration) { |
| | | return (long) (sz * duration); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | * <p> |
| | | * This implementation returns the abbreviated name of this duration |
| | | * unit. |
| | | */ |
| | | @Override |
| | | public String toString() { |
| | | return shortName; |
| | | } |
| | | /** |
| | | * {@inheritDoc} |
| | | * <p> |
| | | * This implementation returns the abbreviated name of this duration unit. |
| | | */ |
| | | @Override |
| | | public String toString() { |
| | | return shortName; |
| | | } |
| | | } |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | import org.forgerock.util.Reject; |
| | |
| | | * The enumeration that should be used for values of this |
| | | * property definition. |
| | | */ |
| | | public static class Builder<E extends Enum<E>> extends AbstractBuilder<E, EnumPropertyDefinition<E>> { |
| | | public final static class Builder<E extends Enum<E>> extends AbstractBuilder<E, EnumPropertyDefinition<E>> { |
| | | |
| | | // The enumeration class. |
| | | private Class<E> enumClass; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected EnumPropertyDefinition<E> buildInstance(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<E> defaultBehavior) { |
| | | protected EnumPropertyDefinition<E> buildInstance(AbstractManagedObjectDefinition<?, ?> d, |
| | | String propertyName, EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<E> defaultBehavior) { |
| | | // Make sure that the enumeration class has been defined. |
| | | if (enumClass == null) { |
| | | throw new IllegalStateException("Enumeration class undefined"); |
| | |
| | | * @return Returns the new enumeration property definition builder. |
| | | */ |
| | | public static <E extends Enum<E>> Builder<E> createBuilder(AbstractManagedObjectDefinition<?, ?> d, |
| | | String propertyName) { |
| | | String propertyName) { |
| | | return new Builder<E>(d, propertyName); |
| | | } |
| | | |
| | |
| | | |
| | | // Private constructor. |
| | | private EnumPropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<E> defaultBehavior, Class<E> enumClass) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, DefaultBehaviorProvider<E> defaultBehavior, |
| | | Class<E> enumClass) { |
| | | super(d, enumClass, propertyName, options, adminAction, defaultBehavior); |
| | | this.enumClass = enumClass; |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public E decodeValue(String value) throws IllegalPropertyValueStringException { |
| | | public E decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | String nvalue = value.trim().toLowerCase(); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String normalizeValue(E value) throws IllegalPropertyValueException { |
| | | public String normalizeValue(E value) { |
| | | Reject.ifNull(value); |
| | | |
| | | return value.toString().trim().toLowerCase(); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(E value) throws IllegalPropertyValueException { |
| | | public void validateValue(E value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | |
| | | /** |
| | | * The client-side constraint handler. |
| | | */ |
| | | private class ClientHandler extends ClientConstraintHandler { |
| | | private final class ClientHandler extends ClientConstraintHandler { |
| | | |
| | | // Private constructor. |
| | | private ClientHandler() { |
| | |
| | | */ |
| | | @Override |
| | | public boolean isAddAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | if (!condition.evaluate(context, managedObject)) { |
| | | unacceptableReasons.add(getSynopsis()); |
| | | return false; |
| | |
| | | */ |
| | | @Override |
| | | public boolean isModifyAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | if (!condition.evaluate(context, managedObject)) { |
| | | unacceptableReasons.add(getSynopsis()); |
| | | return false; |
| | |
| | | /** |
| | | * The server-side constraint handler. |
| | | */ |
| | | private class ServerHandler extends ServerConstraintHandler { |
| | | private final class ServerHandler extends ServerConstraintHandler { |
| | | |
| | | // Private constructor. |
| | | private ServerHandler() { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public boolean isUsable(ServerManagedObject<?> managedObject, Collection<LocalizableMessage> unacceptableReasons) |
| | | throws ConfigException { |
| | | public boolean isUsable(ServerManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ConfigException { |
| | | if (!condition.evaluate(managedObject)) { |
| | | unacceptableReasons.add(getSynopsis()); |
| | | return false; |
| | |
| | | * An interface for incrementally constructing IP address mask property |
| | | * definitions. |
| | | */ |
| | | public static class Builder extends AbstractBuilder<AddressMask, IPAddressMaskPropertyDefinition> { |
| | | public static final class Builder extends AbstractBuilder<AddressMask, IPAddressMaskPropertyDefinition> { |
| | | |
| | | // Private constructor |
| | | private Builder(AbstractManagedObjectDefinition<?, ?> d, String propertyName) { |
| | |
| | | */ |
| | | @Override |
| | | protected IPAddressMaskPropertyDefinition buildInstance(AbstractManagedObjectDefinition<?, ?> d, |
| | | String propertyName, EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<AddressMask> defaultBehavior) { |
| | | String propertyName, EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<AddressMask> defaultBehavior) { |
| | | return new IPAddressMaskPropertyDefinition(d, propertyName, options, adminAction, defaultBehavior); |
| | | } |
| | | |
| | |
| | | |
| | | // Private constructor. |
| | | private IPAddressMaskPropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<AddressMask> defaultBehavior) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<AddressMask> defaultBehavior) { |
| | | super(d, AddressMask.class, propertyName, options, adminAction, defaultBehavior); |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(AddressMask value) throws IllegalPropertyValueException { |
| | | public void validateValue(AddressMask value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public AddressMask decodeValue(String value) throws IllegalPropertyValueStringException { |
| | | public AddressMask decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | |
| | | * An interface for incrementally constructing IP address property |
| | | * definitions. |
| | | */ |
| | | public static class Builder extends AbstractBuilder<InetAddress, IPAddressPropertyDefinition> { |
| | | public static final class Builder extends AbstractBuilder<InetAddress, IPAddressPropertyDefinition> { |
| | | |
| | | // Private constructor |
| | | private Builder(AbstractManagedObjectDefinition<?, ?> d, String propertyName) { |
| | |
| | | */ |
| | | @Override |
| | | protected IPAddressPropertyDefinition buildInstance(AbstractManagedObjectDefinition<?, ?> d, |
| | | String propertyName, EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<InetAddress> defaultBehavior) { |
| | | String propertyName, EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<InetAddress> defaultBehavior) { |
| | | return new IPAddressPropertyDefinition(d, propertyName, options, adminAction, defaultBehavior); |
| | | } |
| | | |
| | |
| | | |
| | | // Private constructor. |
| | | private IPAddressPropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<InetAddress> defaultBehavior) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<InetAddress> defaultBehavior) { |
| | | super(d, InetAddress.class, propertyName, options, adminAction, defaultBehavior); |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(InetAddress value) throws IllegalPropertyValueException { |
| | | public void validateValue(InetAddress value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public InetAddress decodeValue(String value) throws IllegalPropertyValueStringException { |
| | | public InetAddress decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String encodeValue(InetAddress value) throws IllegalPropertyValueException { |
| | | public String encodeValue(InetAddress value) { |
| | | // We should return the host name if it is available, or the IP |
| | | // address if not. |
| | | |
| | |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | |
| | | * definition refers to. |
| | | */ |
| | | public final class InstantiableRelationDefinition<C extends ConfigurationClient, S extends Configuration> extends |
| | | RelationDefinition<C, S> { |
| | | RelationDefinition<C, S> { |
| | | |
| | | /** |
| | | * An interface for incrementally constructing instantiable relation |
| | |
| | | * relation definition refers to. |
| | | */ |
| | | public static final class Builder<C extends ConfigurationClient, S extends Configuration> extends |
| | | AbstractBuilder<C, S, InstantiableRelationDefinition<C, S>> { |
| | | AbstractBuilder<C, S, InstantiableRelationDefinition<C, S>> { |
| | | |
| | | // The optional naming property definition. |
| | | private PropertyDefinition<?> namingPropertyDefinition = null; |
| | |
| | | |
| | | // The optional default managed objects associated with this |
| | | // instantiable relation definition. |
| | | private final Map<String, DefaultManagedObject<? extends C, ? extends S>> defaultManagedObjects = new HashMap<String, DefaultManagedObject<? extends C, ? extends S>>(); |
| | | private final Map<String, DefaultManagedObject<? extends C, ? extends S>> defaultManagedObjects = |
| | | new HashMap<String, DefaultManagedObject<? extends C, ? extends S>>(); |
| | | |
| | | /** |
| | | * Creates a new builder which can be used to incrementally build an |
| | |
| | | * The child managed object definition. |
| | | */ |
| | | public Builder(AbstractManagedObjectDefinition<?, ?> pd, String name, String pluralName, |
| | | AbstractManagedObjectDefinition<C, S> cd) { |
| | | AbstractManagedObjectDefinition<C, S> cd) { |
| | | super(pd, name, cd); |
| | | this.pluralName = pluralName; |
| | | } |
| | |
| | | * The default managed object. |
| | | */ |
| | | public void setDefaultManagedObject(String name, |
| | | DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { |
| | | DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { |
| | | this.defaultManagedObjects.put(name, defaultManagedObject); |
| | | } |
| | | |
| | |
| | | @Override |
| | | protected InstantiableRelationDefinition<C, S> buildInstance(Common<C, S> common) { |
| | | return new InstantiableRelationDefinition<C, S>(common, pluralName, namingPropertyDefinition, |
| | | defaultManagedObjects); |
| | | defaultManagedObjects); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | // Private constructor. |
| | | private InstantiableRelationDefinition(Common<C, S> common, String pluralName, |
| | | PropertyDefinition<?> namingPropertyDefinition, |
| | | Map<String, DefaultManagedObject<? extends C, ? extends S>> defaultManagedObjects) { |
| | | PropertyDefinition<?> namingPropertyDefinition, |
| | | Map<String, DefaultManagedObject<? extends C, ? extends S>> defaultManagedObjects) { |
| | | super(common); |
| | | this.pluralName = pluralName; |
| | | this.namingPropertyDefinition = namingPropertyDefinition; |
| | |
| | | * If there is no default managed object associated with the |
| | | * provided name. |
| | | */ |
| | | public DefaultManagedObject<? extends C, ? extends S> getDefaultManagedObject(String name) |
| | | throws IllegalArgumentException { |
| | | public DefaultManagedObject<? extends C, ? extends S> getDefaultManagedObject(String name) { |
| | | if (!defaultManagedObjects.containsKey(name)) { |
| | | throw new IllegalArgumentException("unrecognized default managed object \"" + name + "\""); |
| | | } |
| | |
| | | /** |
| | | * An interface for incrementally constructing integer property definitions. |
| | | */ |
| | | public static class Builder extends AbstractBuilder<Integer, IntegerPropertyDefinition> { |
| | | public static final class Builder extends AbstractBuilder<Integer, IntegerPropertyDefinition> { |
| | | |
| | | // The lower limit of the property value. |
| | | private int lowerLimit = 0; |
| | |
| | | * If a negative lower limit was specified or the lower |
| | | * limit is greater than the upper limit. |
| | | */ |
| | | public final void setLowerLimit(int lowerLimit) throws IllegalArgumentException { |
| | | public final void setLowerLimit(int lowerLimit) { |
| | | if (lowerLimit < 0) { |
| | | throw new IllegalArgumentException("Negative lower limit"); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected IntegerPropertyDefinition buildInstance(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Integer> defaultBehavior) { |
| | | protected IntegerPropertyDefinition buildInstance(AbstractManagedObjectDefinition<?, ?> d, |
| | | String propertyName, EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Integer> defaultBehavior) { |
| | | return new IntegerPropertyDefinition(d, propertyName, options, adminAction, defaultBehavior, lowerLimit, |
| | | upperLimit, allowUnlimited); |
| | | upperLimit, allowUnlimited); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | // Private constructor. |
| | | private IntegerPropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Integer> defaultBehavior, int lowerLimit, Integer upperLimit, boolean allowUnlimited) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Integer> defaultBehavior, int lowerLimit, Integer upperLimit, boolean allowUnlimited) { |
| | | super(d, Integer.class, propertyName, options, adminAction, defaultBehavior); |
| | | this.lowerLimit = lowerLimit; |
| | | this.upperLimit = upperLimit; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Integer value) throws IllegalPropertyValueException { |
| | | public void validateValue(Integer value) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (!allowUnlimited && value < lowerLimit) { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String encodeValue(Integer value) throws IllegalPropertyValueException { |
| | | public String encodeValue(Integer value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // Make sure that we correctly encode negative values as "unlimited". |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Integer decodeValue(String value) throws IllegalPropertyValueStringException { |
| | | public Integer decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (allowUnlimited) { |
| | |
| | | * If the LDAP profile properties file associated with the |
| | | * provided managed object definition could not be loaded. |
| | | */ |
| | | public String getAttributeName(AbstractManagedObjectDefinition<?, ?> d, PropertyDefinition<?> pd) |
| | | throws MissingResourceException { |
| | | public String getAttributeName(AbstractManagedObjectDefinition<?, ?> d, PropertyDefinition<?> pd) { |
| | | for (Wrapper profile : profiles) { |
| | | String attributeName = profile.getAttributeName(d, pd); |
| | | if (attributeName != null) { |
| | |
| | | * If the LDAP profile properties file associated with the |
| | | * provided managed object definition could not be loaded. |
| | | */ |
| | | public String getRelationChildRDNType(InstantiableRelationDefinition<?, ?> r) throws MissingResourceException { |
| | | public String getRelationChildRDNType(InstantiableRelationDefinition<?, ?> r) { |
| | | if (r.getNamingPropertyDefinition() != null) { |
| | | // Use the attribute associated with the naming property. |
| | | return getAttributeName(r.getChildDefinition(), r.getNamingPropertyDefinition()); |
| | |
| | | * If the LDAP profile properties file associated with the |
| | | * provided managed object definition could not be loaded. |
| | | */ |
| | | public String getRelationChildRDNType(SetRelationDefinition<?, ?> r) throws MissingResourceException { |
| | | public String getRelationChildRDNType(SetRelationDefinition<?, ?> r) { |
| | | for (Wrapper profile : profiles) { |
| | | String rdnType = profile.getRelationChildRDNType(r); |
| | | if (rdnType != null) { |
| | |
| | | * If the LDAP profile properties file associated with the |
| | | * provided managed object definition could not be loaded. |
| | | */ |
| | | public String getObjectClass(AbstractManagedObjectDefinition<?, ?> d) throws MissingResourceException { |
| | | public String getObjectClass(AbstractManagedObjectDefinition<?, ?> d) { |
| | | if (d.isTop()) { |
| | | return "top"; |
| | | } |
| | |
| | | * If the LDAP profile properties file associated with the |
| | | * provided managed object definition could not be loaded. |
| | | */ |
| | | public List<String> getObjectClasses(AbstractManagedObjectDefinition<?, ?> d) throws MissingResourceException { |
| | | public List<String> getObjectClasses(AbstractManagedObjectDefinition<?, ?> d) { |
| | | LinkedList<String> objectClasses = new LinkedList<String>(); |
| | | Set<String> s = new HashSet<String>(); |
| | | |
| | |
| | | * If the LDAP profile properties file associated with the |
| | | * provided managed object definition could not be loaded. |
| | | */ |
| | | public String getRelationRDNSequence(RelationDefinition<?, ?> r) throws MissingResourceException { |
| | | public String getRelationRDNSequence(RelationDefinition<?, ?> r) { |
| | | for (Wrapper profile : profiles) { |
| | | String rdnSequence = profile.getRelationRDNSequence(r); |
| | | if (rdnSequence != null) { |
| | |
| | | * @throws NoSuchElementException |
| | | * If there are no LDAP profile wrappers. |
| | | */ |
| | | public void popWrapper() throws NoSuchElementException { |
| | | public void popWrapper() { |
| | | profiles.removeFirst(); |
| | | } |
| | | |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | import org.opends.server.admin.client.ManagedObject; |
| | | import org.opends.server.admin.server.ServerManagedObject; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Defines the structure of a managed object which can be |
| | | * instantiated. |
| | | * Defines the structure of a managed object which can be instantiated. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that this |
| | | * definition represents. |
| | | * The type of client managed object configuration that this |
| | | * definition represents. |
| | | * @param <S> |
| | | * The type of server managed object configuration that this |
| | | * definition represents. |
| | | * The type of server managed object configuration that this |
| | | * definition represents. |
| | | */ |
| | | public abstract class ManagedObjectDefinition |
| | | <C extends ConfigurationClient, S extends Configuration> |
| | | extends AbstractManagedObjectDefinition<C, S> { |
| | | public abstract class ManagedObjectDefinition<C extends ConfigurationClient, S extends Configuration> extends |
| | | AbstractManagedObjectDefinition<C, S> { |
| | | |
| | | /** |
| | | * Create a new managed object definition. |
| | | * |
| | | * @param name |
| | | * The name of the definition. |
| | | * @param parent |
| | | * The parent definition, or <code>null</code> if there |
| | | * is no parent. |
| | | */ |
| | | protected ManagedObjectDefinition(String name, |
| | | AbstractManagedObjectDefinition<? super C, ? super S> parent) { |
| | | super(name, parent); |
| | | } |
| | | /** |
| | | * Create a new managed object definition. |
| | | * |
| | | * @param name |
| | | * The name of the definition. |
| | | * @param parent |
| | | * The parent definition, or <code>null</code> if there is no |
| | | * parent. |
| | | */ |
| | | protected ManagedObjectDefinition(String name, AbstractManagedObjectDefinition<? super C, ? super S> parent) { |
| | | super(name, parent); |
| | | } |
| | | |
| | | /** |
| | | * Creates a client configuration view of the provided managed object. |
| | | * Modifications made to the underlying managed object will be reflected in |
| | | * the client configuration view and vice versa. |
| | | * |
| | | * @param managedObject |
| | | * The managed object. |
| | | * @return Returns a client configuration view of the provided managed |
| | | * object. |
| | | */ |
| | | public abstract C createClientConfiguration(ManagedObject<? extends C> managedObject); |
| | | |
| | | /** |
| | | * Creates a server configuration view of the provided server managed |
| | | * object. |
| | | * |
| | | * @param managedObject |
| | | * The server managed object. |
| | | * @return Returns a server configuration view of the provided server |
| | | * managed object. |
| | | */ |
| | | public abstract S createServerConfiguration(ServerManagedObject<? extends S> managedObject); |
| | | |
| | | /** |
| | | * Creates a client configuration view of the provided managed |
| | | * object. Modifications made to the underlying managed object will |
| | | * be reflected in the client configuration view and vice versa. |
| | | * |
| | | * @param managedObject |
| | | * The managed object. |
| | | * @return Returns a client configuration view of the provided |
| | | * managed object. |
| | | */ |
| | | public abstract C createClientConfiguration( |
| | | ManagedObject<? extends C> managedObject); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a server configuration view of the provided server |
| | | * managed object. |
| | | * |
| | | * @param managedObject |
| | | * The server managed object. |
| | | * @return Returns a server configuration view of the provided |
| | | * server managed object. |
| | | */ |
| | | public abstract S createServerConfiguration( |
| | | ServerManagedObject<? extends S> managedObject); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the server configuration class instance associated with this |
| | | * managed object definition. |
| | | * |
| | | * @return Returns the server configuration class instance |
| | | * associated with this managed object definition. |
| | | */ |
| | | public abstract Class<S> getServerConfigurationClass(); |
| | | /** |
| | | * Gets the server configuration class instance associated with this managed |
| | | * object definition. |
| | | * |
| | | * @return Returns the server configuration class instance associated with |
| | | * this managed object definition. |
| | | */ |
| | | public abstract Class<S> getServerConfigurationClass(); |
| | | } |
| | |
| | | |
| | | // Application-wide set of instances. |
| | | private static final Map<String, ManagedObjectDefinitionI18NResource> INSTANCES = |
| | | new HashMap<String, ManagedObjectDefinitionI18NResource>(); |
| | | new HashMap<String, ManagedObjectDefinitionI18NResource>(); |
| | | |
| | | /** |
| | | * Gets the internationalized resource instance which can be used to |
| | |
| | | * If the provided managed object definition was the |
| | | * {@link TopCfgDefn}. |
| | | */ |
| | | public LocalizableMessage getMessage(AbstractManagedObjectDefinition<?, ?> d, String key) |
| | | throws MissingResourceException, UnsupportedOperationException { |
| | | public LocalizableMessage getMessage(AbstractManagedObjectDefinition<?, ?> d, String key) { |
| | | return getMessage(d, key, Locale.getDefault(), (String[]) null); |
| | | } |
| | | |
| | |
| | | * If the provided managed object definition was the |
| | | * {@link TopCfgDefn}. |
| | | */ |
| | | public LocalizableMessage getMessage(AbstractManagedObjectDefinition<?, ?> d, String key, Locale locale) |
| | | throws MissingResourceException, UnsupportedOperationException { |
| | | public LocalizableMessage getMessage(AbstractManagedObjectDefinition<?, ?> d, String key, Locale locale) { |
| | | return getMessage(d, key, locale, (String[]) null); |
| | | } |
| | | |
| | |
| | | * {@link TopCfgDefn}. |
| | | */ |
| | | public LocalizableMessage getMessage(AbstractManagedObjectDefinition<?, ?> d, String key, Locale locale, |
| | | String... args) throws MissingResourceException, UnsupportedOperationException { |
| | | String... args) { |
| | | ResourceBundle resource = getResourceBundle(d, locale); |
| | | |
| | | // TODO: use message framework directly |
| | |
| | | * If the provided managed object definition was the |
| | | * {@link TopCfgDefn}. |
| | | */ |
| | | public LocalizableMessage getMessage(AbstractManagedObjectDefinition<?, ?> d, String key, String... args) |
| | | throws MissingResourceException, UnsupportedOperationException { |
| | | public LocalizableMessage getMessage(AbstractManagedObjectDefinition<?, ?> d, String key, String... args) { |
| | | return getMessage(d, key, Locale.getDefault(), args); |
| | | } |
| | | |
| | |
| | | * The resource bundle to be used. |
| | | */ |
| | | synchronized void setResourceBundle(AbstractManagedObjectDefinition<?, ?> d, Locale locale, |
| | | ResourceBundle resoureBundle) { |
| | | ResourceBundle resoureBundle) { |
| | | // First get the locale-resource mapping, creating it if |
| | | // necessary. |
| | | Map<Locale, ResourceBundle> map = resources.get(d); |
| | |
| | | |
| | | // Retrieve the resource bundle associated with a managed object and |
| | | // locale, lazily loading it if necessary. |
| | | private synchronized ResourceBundle getResourceBundle(AbstractManagedObjectDefinition<?, ?> d, Locale locale) |
| | | throws MissingResourceException, UnsupportedOperationException { |
| | | private synchronized ResourceBundle getResourceBundle(AbstractManagedObjectDefinition<?, ?> d, Locale locale) { |
| | | if (d.isTop()) { |
| | | throw new UnsupportedOperationException("I18n resources are not available for the " |
| | | + "Top configuration definition"); |
| | | + "Top configuration definition"); |
| | | } |
| | | |
| | | // First get the locale-resource mapping, creating it if |
| | |
| | | ResourceBundle resourceBundle = map.get(locale); |
| | | if (resourceBundle == null) { |
| | | String baseName = prefix + "." + d.getClass().getName(); |
| | | resourceBundle = ResourceBundle.getBundle(baseName, locale, ClassLoaderProvider.getInstance() |
| | | .getClassLoader()); |
| | | resourceBundle = |
| | | ResourceBundle.getBundle(baseName, locale, ClassLoaderProvider.getInstance().getClassLoader()); |
| | | map.put(locale, resourceBundle); |
| | | } |
| | | |
| | |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | import java.io.BufferedInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | |
| | | import java.util.MissingResourceException; |
| | | import java.util.Properties; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A class for retrieving non-internationalized resource properties |
| | | * associated with a managed object definition. |
| | | * A class for retrieving non-internationalized resource properties associated |
| | | * with a managed object definition. |
| | | * <p> |
| | | * Resource properties are not available for the {@link TopCfgDefn}. |
| | | */ |
| | | public final class ManagedObjectDefinitionResource { |
| | | |
| | | // Mapping from definition to property tables. |
| | | private final Map<AbstractManagedObjectDefinition<?, ?>, |
| | | Properties> properties; |
| | | // Mapping from definition to property tables. |
| | | private final Map<AbstractManagedObjectDefinition<?, ?>, Properties> properties; |
| | | |
| | | // The resource name prefix. |
| | | private final String prefix; |
| | | // The resource name prefix. |
| | | private final String prefix; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new resource instance for the named profile. |
| | | * |
| | | * @param profile |
| | | * The name of the profile. |
| | | * @return Returns the resource instance for the named profile. |
| | | */ |
| | | public static ManagedObjectDefinitionResource createForProfile( |
| | | String profile) { |
| | | return new ManagedObjectDefinitionResource("admin.profiles." |
| | | + profile); |
| | | } |
| | | |
| | | |
| | | |
| | | // Private constructor. |
| | | private ManagedObjectDefinitionResource(String prefix) { |
| | | this.properties = |
| | | new HashMap<AbstractManagedObjectDefinition<?, ?>, Properties>(); |
| | | this.prefix = prefix; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the resource value associated with the specified key. |
| | | * |
| | | * @param d |
| | | * The managed object definition. |
| | | * @param key |
| | | * The resource key. |
| | | * @return Returns the resource value associated with the specified |
| | | * key. |
| | | * @throws MissingResourceException |
| | | * If the key was not found. |
| | | * @throws UnsupportedOperationException |
| | | * If the provided managed object definition was the |
| | | * {@link TopCfgDefn}. |
| | | */ |
| | | public String getString(AbstractManagedObjectDefinition<?, ?> d, String key) |
| | | throws MissingResourceException, UnsupportedOperationException { |
| | | if (d.isTop()) { |
| | | throw new UnsupportedOperationException( |
| | | "Profile resources are not available for the " |
| | | + "Top configuration definition"); |
| | | /** |
| | | * Creates a new resource instance for the named profile. |
| | | * |
| | | * @param profile |
| | | * The name of the profile. |
| | | * @return Returns the resource instance for the named profile. |
| | | */ |
| | | public static ManagedObjectDefinitionResource createForProfile(String profile) { |
| | | return new ManagedObjectDefinitionResource("admin.profiles." + profile); |
| | | } |
| | | |
| | | Properties p = getProperties(d); |
| | | String result = p.getProperty(key); |
| | | |
| | | if (result == null) { |
| | | String baseName = prefix + "." + d.getClass().getName(); |
| | | String path = baseName.replace('.', '/') + ".properties"; |
| | | |
| | | throw new MissingResourceException("Can't find resource " |
| | | + path + ", key " + key, baseName, key); |
| | | // Private constructor. |
| | | private ManagedObjectDefinitionResource(String prefix) { |
| | | this.properties = new HashMap<AbstractManagedObjectDefinition<?, ?>, Properties>(); |
| | | this.prefix = prefix; |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | /** |
| | | * Get the resource value associated with the specified key. |
| | | * |
| | | * @param d |
| | | * The managed object definition. |
| | | * @param key |
| | | * The resource key. |
| | | * @return Returns the resource value associated with the specified key. |
| | | * @throws MissingResourceException |
| | | * If the key was not found. |
| | | * @throws UnsupportedOperationException |
| | | * If the provided managed object definition was the |
| | | * {@link TopCfgDefn}. |
| | | */ |
| | | public String getString(AbstractManagedObjectDefinition<?, ?> d, String key) { |
| | | if (d.isTop()) { |
| | | throw new UnsupportedOperationException("Profile resources are not available for the " |
| | | + "Top configuration definition"); |
| | | } |
| | | |
| | | Properties p = getProperties(d); |
| | | String result = p.getProperty(key); |
| | | |
| | | if (result == null) { |
| | | String baseName = prefix + "." + d.getClass().getName(); |
| | | String path = baseName.replace('.', '/') + ".properties"; |
| | | |
| | | // Retrieve the properties table associated with a managed object, |
| | | // lazily loading it if necessary. |
| | | private synchronized Properties getProperties( |
| | | AbstractManagedObjectDefinition<?, ?> d) |
| | | throws MissingResourceException { |
| | | Properties p = properties.get(d); |
| | | throw new MissingResourceException("Can't find resource " + path + ", key " + key, baseName, key); |
| | | } |
| | | |
| | | if (p == null) { |
| | | // Load the resource file. |
| | | String baseName = prefix + "." + d.getClass().getName(); |
| | | String path = baseName.replace('.', '/') + ".properties"; |
| | | InputStream stream = ClassLoaderProvider.getInstance() |
| | | .getClassLoader().getResourceAsStream(path); |
| | | |
| | | if (stream == null) { |
| | | throw new MissingResourceException("Can't find resource " |
| | | + path, baseName, ""); |
| | | } |
| | | |
| | | p = new Properties(); |
| | | try { |
| | | p.load(new BufferedInputStream(stream)); |
| | | } catch (IOException e) { |
| | | throw new MissingResourceException("Can't load resource " |
| | | + path + " due to IO exception: " + e.getMessage(), |
| | | baseName, ""); |
| | | } |
| | | |
| | | // Cache the resource. |
| | | properties.put(d, p); |
| | | return result; |
| | | } |
| | | |
| | | return p; |
| | | } |
| | | // Retrieve the properties table associated with a managed object, |
| | | // lazily loading it if necessary. |
| | | private synchronized Properties getProperties(AbstractManagedObjectDefinition<?, ?> d) { |
| | | Properties p = properties.get(d); |
| | | |
| | | if (p == null) { |
| | | // Load the resource file. |
| | | String baseName = prefix + "." + d.getClass().getName(); |
| | | String path = baseName.replace('.', '/') + ".properties"; |
| | | InputStream stream = ClassLoaderProvider.getInstance().getClassLoader().getResourceAsStream(path); |
| | | |
| | | if (stream == null) { |
| | | throw new MissingResourceException("Can't find resource " + path, baseName, ""); |
| | | } |
| | | |
| | | p = new Properties(); |
| | | try { |
| | | p.load(new BufferedInputStream(stream)); |
| | | } catch (IOException e) { |
| | | throw new MissingResourceException("Can't load resource " + path + " due to IO exception: " |
| | | + e.getMessage(), baseName, ""); |
| | | } |
| | | |
| | | // Cache the resource. |
| | | properties.put(d, p); |
| | | } |
| | | |
| | | return p; |
| | | } |
| | | } |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This enumeration contains various options that can be associated |
| | | * with managed object definitions. |
| | | * This enumeration contains various options that can be associated with managed |
| | | * object definitions. |
| | | */ |
| | | public enum ManagedObjectOption { |
| | | /** |
| | | * Use this option to identify managed object types which should be |
| | | * considered as advanced and should not be exposed by default in |
| | | * client applications. |
| | | */ |
| | | ADVANCED, |
| | | /** |
| | | * Use this option to identify managed object types which should be |
| | | * considered as advanced and should not be exposed by default in client |
| | | * applications. |
| | | */ |
| | | ADVANCED, |
| | | |
| | | /** |
| | | * Use this option to identify managed object types which must not |
| | | * be directly exposed in client applications. |
| | | */ |
| | | HIDDEN; |
| | | /** |
| | | * Use this option to identify managed object types which must not be |
| | | * directly exposed in client applications. |
| | | */ |
| | | HIDDEN; |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | InstantiableRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d, |
| | | String name) { |
| | | InstantiableRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d, |
| | | String name) { |
| | | // Add the RDN sequence representing the relation. |
| | | appendManagedObjectPathElement(r); |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | SetRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | SetRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | // Add the RDN sequence representing the relation. |
| | | appendManagedObjectPathElement(r); |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | OptionalRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | OptionalRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | // Add the RDN sequence representing the relation. |
| | | appendManagedObjectPathElement(r); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | SingletonRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | SingletonRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | // Add the RDN sequence representing the relation. |
| | | appendManagedObjectPathElement(r); |
| | | } |
| | |
| | | * A path element representing an instantiable managed object. |
| | | */ |
| | | private static final class InstantiableElement<C extends ConfigurationClient, S extends Configuration> extends |
| | | Element<C, S> { |
| | | Element<C, S> { |
| | | |
| | | // Factory method. |
| | | private static final <C extends ConfigurationClient, S extends Configuration> InstantiableElement<C, S> create( |
| | | InstantiableRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d, |
| | | String name) { |
| | | InstantiableRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d, |
| | | String name) { |
| | | return new InstantiableElement<C, S>(r, d, name); |
| | | } |
| | | |
| | |
| | | |
| | | // Private constructor. |
| | | private InstantiableElement(InstantiableRelationDefinition<? super C, ? super S> r, |
| | | AbstractManagedObjectDefinition<C, S> d, String name) { |
| | | AbstractManagedObjectDefinition<C, S> d, String name) { |
| | | super(d); |
| | | this.r = r; |
| | | this.name = name; |
| | |
| | | * A path element representing an optional managed object. |
| | | */ |
| | | private static final class OptionalElement<C extends ConfigurationClient, S extends Configuration> extends |
| | | Element<C, S> { |
| | | Element<C, S> { |
| | | |
| | | // Factory method. |
| | | private static final <C extends ConfigurationClient, S extends Configuration> OptionalElement<C, S> create( |
| | | OptionalRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | OptionalRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | return new OptionalElement<C, S>(r, d); |
| | | } |
| | | |
| | |
| | | |
| | | // Private constructor. |
| | | private OptionalElement(OptionalRelationDefinition<? super C, ? super S> r, |
| | | AbstractManagedObjectDefinition<C, S> d) { |
| | | AbstractManagedObjectDefinition<C, S> d) { |
| | | super(d); |
| | | this.r = r; |
| | | } |
| | |
| | | /** |
| | | * A path element representing an set managed object. |
| | | */ |
| | | private static final class SetElement<C extends ConfigurationClient, S extends Configuration> extends Element<C, S> { |
| | | private static final class SetElement<C extends ConfigurationClient, S extends Configuration> extends |
| | | Element<C, S> { |
| | | |
| | | // Factory method. |
| | | private static final <C extends ConfigurationClient, S extends Configuration> SetElement<C, S> create( |
| | | SetRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | SetRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | return new SetElement<C, S>(r, d); |
| | | } |
| | | |
| | |
| | | * A path element representing a singleton managed object. |
| | | */ |
| | | private static final class SingletonElement<C extends ConfigurationClient, S extends Configuration> extends |
| | | Element<C, S> { |
| | | Element<C, S> { |
| | | |
| | | // Factory method. |
| | | private static final <C extends ConfigurationClient, S extends Configuration> SingletonElement<C, S> create( |
| | | SingletonRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | SingletonRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | return new SingletonElement<C, S>(r, d); |
| | | } |
| | | |
| | |
| | | |
| | | // Private constructor. |
| | | private SingletonElement(SingletonRelationDefinition<? super C, ? super S> r, |
| | | AbstractManagedObjectDefinition<C, S> d) { |
| | | AbstractManagedObjectDefinition<C, S> d) { |
| | | super(d); |
| | | this.r = r; |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public <M extends ConfigurationClient, N extends Configuration> void appendManagedObjectPathElement( |
| | | InstantiableRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d, |
| | | String name) { |
| | | InstantiableRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d, |
| | | String name) { |
| | | serializeElement(r, d); |
| | | |
| | | // Be careful to escape any forward slashes in the name. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public <M extends ConfigurationClient, N extends Configuration> void appendManagedObjectPathElement( |
| | | OptionalRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) { |
| | | OptionalRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) { |
| | | serializeElement(r, d); |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public <M extends ConfigurationClient, N extends Configuration> void appendManagedObjectPathElement( |
| | | SingletonRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) { |
| | | SingletonRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) { |
| | | serializeElement(r, d); |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public <M extends ConfigurationClient, N extends Configuration> void appendManagedObjectPathElement( |
| | | SetRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) { |
| | | SetRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) { |
| | | serializeElement(r, d); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // Single instance of a root path. |
| | | private static final ManagedObjectPath<RootCfgClient, RootCfg> EMPTY_PATH = new ManagedObjectPath<RootCfgClient, RootCfg>( |
| | | new LinkedList<Element<?, ?>>(), null, RootCfgDefn.getInstance()); |
| | | private static final ManagedObjectPath<RootCfgClient, RootCfg> EMPTY_PATH = |
| | | new ManagedObjectPath<RootCfgClient, RootCfg>(new LinkedList<Element<?, ?>>(), null, |
| | | RootCfgDefn.getInstance()); |
| | | |
| | | // A regular expression used to parse path elements. |
| | | private static final Pattern PE_REGEXP = Pattern.compile("^\\s*relation=\\s*([^+]+)\\s*" |
| | | + "(\\+\\s*type=\\s*([^+]+)\\s*)?" + "(\\+\\s*name=\\s*([^+]+)\\s*)?$"); |
| | | + "(\\+\\s*type=\\s*([^+]+)\\s*)?" + "(\\+\\s*name=\\s*([^+]+)\\s*)?$"); |
| | | |
| | | /** |
| | | * Creates a new managed object path representing the configuration root. |
| | |
| | | * @throws IllegalArgumentException |
| | | * If the string could not be parsed. |
| | | */ |
| | | public static ManagedObjectPath<?, ?> valueOf(String s) throws IllegalArgumentException { |
| | | public static ManagedObjectPath<?, ?> valueOf(String s) { |
| | | String ns = s.trim(); |
| | | |
| | | // Check for root special case. |
| | |
| | | if (c == '/') { |
| | | if (end == (ns.length() - 1)) { |
| | | throw new IllegalArgumentException("Invalid path \"" + ns |
| | | + "\": must not end with a trailing \"/\""); |
| | | + "\": must not end with a trailing \"/\""); |
| | | } |
| | | |
| | | if (ns.charAt(end + 1) == '/') { |
| | |
| | | r = definition.getRelationDefinition(relation); |
| | | } catch (IllegalArgumentException e) { |
| | | throw new IllegalArgumentException("Invalid path element \"" + es + "\" in path \"" + ns |
| | | + "\": unknown relation \"" + relation + "\""); |
| | | + "\": unknown relation \"" + relation + "\""); |
| | | } |
| | | |
| | | // Append the next element. |
| | |
| | | // Factory method required in order to allow generic wild-card |
| | | // construction of new paths. |
| | | private static <C extends ConfigurationClient, S extends Configuration> ManagedObjectPath<C, S> create( |
| | | LinkedList<Element<?, ?>> elements, Element<C, S> lastElement) { |
| | | LinkedList<Element<?, ?>> elements, Element<C, S> lastElement) { |
| | | return new ManagedObjectPath<C, S>(elements, lastElement.getRelationDefinition(), |
| | | lastElement.getManagedObjectDefinition()); |
| | | lastElement.getManagedObjectDefinition()); |
| | | } |
| | | |
| | | // Decode an element. |
| | | // @Checkstyle:ignore |
| | | private static <C extends ConfigurationClient, S extends Configuration> Element<? extends C, ? extends S> createElement( |
| | | RelationDefinition<C, S> r, String path, String element, String type, String name) { |
| | | RelationDefinition<C, S> r, String path, String element, String type, String name) { |
| | | // First determine the managed object definition. |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d = null; |
| | | |
| | | if (type != null) { |
| | | for (AbstractManagedObjectDefinition<? extends C, ? extends S> child : r.getChildDefinition() |
| | | .getAllChildren()) { |
| | | .getAllChildren()) { |
| | | if (child.getName().equals(type)) { |
| | | d = child; |
| | | break; |
| | |
| | | |
| | | if (d == null) { |
| | | throw new IllegalArgumentException("Invalid path element \"" + element + "\" in path \"" + path |
| | | + "\": unknown sub-type \"" + type + "\""); |
| | | + "\": unknown sub-type \"" + type + "\""); |
| | | } |
| | | } else { |
| | | d = r.getChildDefinition(); |
| | |
| | | |
| | | if (name == null) { |
| | | throw new IllegalArgumentException("Invalid path element \"" + element + "\" in path \"" + path |
| | | + "\": no instance name for instantiable relation"); |
| | | + "\": no instance name for instantiable relation"); |
| | | } |
| | | |
| | | return InstantiableElement.create(ir, d, name); |
| | |
| | | |
| | | if (name != null) { |
| | | throw new IllegalArgumentException("Invalid path element \"" + element + "\" in path \"" + path |
| | | + "\": instance name specified for set relation"); |
| | | + "\": instance name specified for set relation"); |
| | | } |
| | | |
| | | return SetElement.create(ir, d); |
| | |
| | | |
| | | if (name != null) { |
| | | throw new IllegalArgumentException("Invalid path element \"" + element + "\" in path \"" + path |
| | | + "\": instance name specified for optional relation"); |
| | | + "\": instance name specified for optional relation"); |
| | | } |
| | | |
| | | return OptionalElement.create(or, d); |
| | |
| | | |
| | | if (name != null) { |
| | | throw new IllegalArgumentException("Invalid path element \"" + element + "\" in path \"" + path |
| | | + "\": instance name specified for singleton relation"); |
| | | + "\": instance name specified for singleton relation"); |
| | | } |
| | | |
| | | return SingletonElement.create(sr, d); |
| | | } else { |
| | | throw new IllegalArgumentException("Invalid path element \"" + element + "\" in path \"" + path |
| | | + "\": unsupported relation type"); |
| | | + "\": unsupported relation type"); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | // Private constructor. |
| | | private ManagedObjectPath(LinkedList<Element<?, ?>> elements, RelationDefinition<? super C, ? super S> r, |
| | | AbstractManagedObjectDefinition<C, S> d) { |
| | | AbstractManagedObjectDefinition<C, S> d) { |
| | | this.elements = Collections.unmodifiableList(elements); |
| | | this.r = r; |
| | | this.d = d; |
| | |
| | | * path except that the final path element is associated with the specified |
| | | * managed object definition. |
| | | * |
| | | * @param <CC> |
| | | * @param <C1> |
| | | * The type of client managed object configuration that this path |
| | | * will reference. |
| | | * @param <SS> |
| | | * @param <S1> |
| | | * The type of server managed object configuration that this path |
| | | * will reference. |
| | | * @param nd |
| | |
| | | * this path except that the final path element is associated with |
| | | * the specified managed object definition. |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public <CC extends C, SS extends S> ManagedObjectPath<CC, SS> asSubType(AbstractManagedObjectDefinition<CC, SS> nd) { |
| | | // @Checkstyle:ignore |
| | | public <C1 extends C, S1 extends S> ManagedObjectPath<C1, S1> asSubType(AbstractManagedObjectDefinition<C1, S1> nd) { |
| | | if (r instanceof InstantiableRelationDefinition) { |
| | | InstantiableRelationDefinition<? super C, ? super S> ir = (InstantiableRelationDefinition<? super C, ? super S>) r; |
| | | InstantiableRelationDefinition<? super C, ? super S> ir = |
| | | (InstantiableRelationDefinition<? super C, ? super S>) r; |
| | | if (elements.size() == 0) { |
| | | return parent().child(ir, nd, "null"); |
| | | } else { |
| | |
| | | SetRelationDefinition<? super C, ? super S> sr = (SetRelationDefinition<? super C, ? super S>) r; |
| | | return parent().child(sr, nd); |
| | | } else if (r instanceof OptionalRelationDefinition) { |
| | | OptionalRelationDefinition<? super C, ? super S> or = (OptionalRelationDefinition<? super C, ? super S>) r; |
| | | OptionalRelationDefinition<? super C, ? super S> or = |
| | | (OptionalRelationDefinition<? super C, ? super S>) r; |
| | | return parent().child(or, nd); |
| | | } else { |
| | | SingletonRelationDefinition<? super C, ? super S> sr = (SingletonRelationDefinition<? super C, ? super S>) r; |
| | | SingletonRelationDefinition<? super C, ? super S> sr = |
| | | (SingletonRelationDefinition<? super C, ? super S>) r; |
| | | return parent().child(sr, nd); |
| | | } |
| | | } |
| | |
| | | * If the provided name is empty or blank. |
| | | */ |
| | | public <M extends ConfigurationClient, N extends Configuration> ManagedObjectPath<M, N> child( |
| | | InstantiableRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d, String name) |
| | | throws IllegalArgumentException { |
| | | InstantiableRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d, String name) { |
| | | if (name.trim().length() == 0) { |
| | | throw new IllegalArgumentException("Empty or blank managed object names are not allowed"); |
| | | } |
| | |
| | | * If the provided name is empty or blank. |
| | | */ |
| | | public <M extends ConfigurationClient, N extends Configuration> ManagedObjectPath<M, N> child( |
| | | InstantiableRelationDefinition<M, N> r, String name) throws IllegalArgumentException { |
| | | InstantiableRelationDefinition<M, N> r, String name) { |
| | | return child(r, r.getChildDefinition(), name); |
| | | } |
| | | |
| | |
| | | * parent path. |
| | | */ |
| | | public <M extends ConfigurationClient, N extends Configuration> ManagedObjectPath<M, N> child( |
| | | OptionalRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) { |
| | | OptionalRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) { |
| | | LinkedList<Element<?, ?>> celements = new LinkedList<Element<?, ?>>(elements); |
| | | celements.add(new OptionalElement<M, N>(r, d)); |
| | | return new ManagedObjectPath<M, N>(celements, r, d); |
| | |
| | | * parent path. |
| | | */ |
| | | public <M extends ConfigurationClient, N extends Configuration> ManagedObjectPath<M, N> child( |
| | | OptionalRelationDefinition<M, N> r) { |
| | | OptionalRelationDefinition<M, N> r) { |
| | | return child(r, r.getChildDefinition()); |
| | | } |
| | | |
| | |
| | | * parent path. |
| | | */ |
| | | public <M extends ConfigurationClient, N extends Configuration> ManagedObjectPath<M, N> child( |
| | | SingletonRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) { |
| | | SingletonRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) { |
| | | LinkedList<Element<?, ?>> celements = new LinkedList<Element<?, ?>>(elements); |
| | | celements.add(new SingletonElement<M, N>(r, d)); |
| | | return new ManagedObjectPath<M, N>(celements, r, d); |
| | |
| | | * parent path. |
| | | */ |
| | | public <M extends ConfigurationClient, N extends Configuration> ManagedObjectPath<M, N> child( |
| | | SingletonRelationDefinition<M, N> r) { |
| | | SingletonRelationDefinition<M, N> r) { |
| | | return child(r, r.getChildDefinition()); |
| | | } |
| | | |
| | |
| | | * If the provided name is empty or blank. |
| | | */ |
| | | public <M extends ConfigurationClient, N extends Configuration> ManagedObjectPath<M, N> child( |
| | | SetRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) |
| | | throws IllegalArgumentException { |
| | | SetRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) { |
| | | LinkedList<Element<?, ?>> celements = new LinkedList<Element<?, ?>>(elements); |
| | | celements.add(new SetElement<M, N>(r, d)); |
| | | return new ManagedObjectPath<M, N>(celements, r, d); |
| | |
| | | * child definition. |
| | | */ |
| | | public <M extends ConfigurationClient, N extends Configuration> ManagedObjectPath<? extends M, ? extends N> child( |
| | | SetRelationDefinition<M, N> r, String name) throws IllegalArgumentException { |
| | | SetRelationDefinition<M, N> r, String name) { |
| | | AbstractManagedObjectDefinition<M, N> d = r.getChildDefinition(); |
| | | return child(r, d.getChild(name)); |
| | | } |
| | |
| | | * If the provided name is empty or blank. |
| | | */ |
| | | public <M extends ConfigurationClient, N extends Configuration> ManagedObjectPath<M, N> child( |
| | | SetRelationDefinition<M, N> r) throws IllegalArgumentException { |
| | | SetRelationDefinition<M, N> r) { |
| | | return child(r, r.getChildDefinition()); |
| | | } |
| | | |
| | |
| | | * If this path does not have a parent (i.e. it is the empty |
| | | * path). |
| | | */ |
| | | public ManagedObjectPath<?, ?> parent() throws IllegalArgumentException { |
| | | public ManagedObjectPath<?, ?> parent() { |
| | | return parent(1); |
| | | } |
| | | |
| | |
| | | * If the offset is less than 0, or greater than the number of |
| | | * path elements in this path. |
| | | */ |
| | | public ManagedObjectPath<?, ?> parent(int offset) throws IllegalArgumentException { |
| | | public ManagedObjectPath<?, ?> parent(int offset) { |
| | | if (offset < 0) { |
| | | throw new IllegalArgumentException("Negative offset"); |
| | | } |
| | |
| | | return emptyPath(); |
| | | } |
| | | |
| | | LinkedList<Element<?, ?>> celements = new LinkedList<Element<?, ?>>(elements.subList(0, elements.size() |
| | | - offset)); |
| | | LinkedList<Element<?, ?>> celements = |
| | | new LinkedList<Element<?, ?>>(elements.subList(0, elements.size() - offset)); |
| | | return create(celements, celements.getLast()); |
| | | } |
| | | |
| | |
| | | * If this managed object path is empty or if its final path |
| | | * element does not comprise of an instantiable relation. |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public ManagedObjectPath<C, S> rename(String newName) throws IllegalStateException { |
| | | public ManagedObjectPath<C, S> rename(String newName) { |
| | | if (elements.size() == 0) { |
| | | throw new IllegalStateException("Cannot rename an empty path"); |
| | | } |
| | | |
| | | if (r instanceof InstantiableRelationDefinition) { |
| | | InstantiableRelationDefinition<? super C, ? super S> ir = (InstantiableRelationDefinition<? super C, ? super S>) r; |
| | | InstantiableRelationDefinition<? super C, ? super S> ir = |
| | | (InstantiableRelationDefinition<? super C, ? super S>) r; |
| | | return parent().child(ir, d, newName); |
| | | } else { |
| | | throw new IllegalStateException("Not an instantiable relation"); |
| | |
| | | */ |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A strategy for serializing managed object paths. |
| | | * <p> |
| | | * This interface provides a generic means for serializing managed |
| | | * object paths into application specific forms. For example, a JNDI |
| | | * client would use this interface to construct <code>LdapName</code> |
| | | * objects from a path. Similarly, on the server side, a serialization |
| | | * strategy is used to construct <code>DN</code> instances from a |
| | | * path. |
| | | * This interface provides a generic means for serializing managed object paths |
| | | * into application specific forms. For example, a JNDI client would use this |
| | | * interface to construct <code>LdapName</code> objects from a path. Similarly, |
| | | * on the server side, a serialization strategy is used to construct |
| | | * <code>DN</code> instances from a path. |
| | | * <p> |
| | | * During serialization the serializer is invoked for each element in |
| | | * the managed object path in big-endian order, starting from the root |
| | | * and proceeding down to the leaf element. |
| | | * During serialization the serializer is invoked for each element in the |
| | | * managed object path in big-endian order, starting from the root and |
| | | * proceeding down to the leaf element. |
| | | */ |
| | | public interface ManagedObjectPathSerializer { |
| | | |
| | | /** |
| | | * Append a managed object path element identified by an |
| | | * instantiable relation and an instance name. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that |
| | | * this path element references. |
| | | * @param <S> |
| | | * The type of server managed object configuration that |
| | | * this path element references. |
| | | * @param r |
| | | * The instantiable relation. |
| | | * @param d |
| | | * The managed object definition. |
| | | * @param name |
| | | * The instance name. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> |
| | | void appendManagedObjectPathElement( |
| | | InstantiableRelationDefinition<? super C, ? super S> r, |
| | | AbstractManagedObjectDefinition<C, S> d, String name); |
| | | /** |
| | | * Append a managed object path element identified by an instantiable |
| | | * relation and an instance name. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that this path |
| | | * element references. |
| | | * @param <S> |
| | | * The type of server managed object configuration that this path |
| | | * element references. |
| | | * @param r |
| | | * The instantiable relation. |
| | | * @param d |
| | | * The managed object definition. |
| | | * @param name |
| | | * The instance name. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | InstantiableRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d, String name); |
| | | |
| | | /** |
| | | * Append a managed object path element identified by an optional relation. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that this path |
| | | * element references. |
| | | * @param <S> |
| | | * The type of server managed object configuration that this path |
| | | * element references. |
| | | * @param r |
| | | * The optional relation. |
| | | * @param d |
| | | * The managed object definition. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | OptionalRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d); |
| | | |
| | | /** |
| | | * Append a managed object path element identified by a singleton relation. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that this path |
| | | * element references. |
| | | * @param <S> |
| | | * The type of server managed object configuration that this path |
| | | * element references. |
| | | * @param r |
| | | * The singleton relation. |
| | | * @param d |
| | | * The managed object definition. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | SingletonRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d); |
| | | |
| | | /** |
| | | * Append a managed object path element identified by an optional |
| | | * relation. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that |
| | | * this path element references. |
| | | * @param <S> |
| | | * The type of server managed object configuration that |
| | | * this path element references. |
| | | * @param r |
| | | * The optional relation. |
| | | * @param d |
| | | * The managed object definition. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> |
| | | void appendManagedObjectPathElement( |
| | | OptionalRelationDefinition<? super C, ? super S> r, |
| | | AbstractManagedObjectDefinition<C, S> d); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Append a managed object path element identified by a singleton |
| | | * relation. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that |
| | | * this path element references. |
| | | * @param <S> |
| | | * The type of server managed object configuration that |
| | | * this path element references. |
| | | * @param r |
| | | * The singleton relation. |
| | | * @param d |
| | | * The managed object definition. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> |
| | | void appendManagedObjectPathElement( |
| | | SingletonRelationDefinition<? super C, ? super S> r, |
| | | AbstractManagedObjectDefinition<C, S> d); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Append a managed object path element identified by a |
| | | * set relation. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that |
| | | * this path element references. |
| | | * @param <S> |
| | | * The type of server managed object configuration that |
| | | * this path element references. |
| | | * @param r |
| | | * The set relation. |
| | | * @param d |
| | | * The managed object definition. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> |
| | | void appendManagedObjectPathElement( |
| | | SetRelationDefinition<? super C, ? super S> r, |
| | | AbstractManagedObjectDefinition<C, S> d); |
| | | /** |
| | | * Append a managed object path element identified by a set relation. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that this path |
| | | * element references. |
| | | * @param <S> |
| | | * The type of server managed object configuration that this path |
| | | * element references. |
| | | * @param r |
| | | * The set relation. |
| | | * @param d |
| | | * The managed object definition. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | SetRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d); |
| | | |
| | | } |
| | |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A managed object composite relationship definition which represents |
| | | * a composition of an optional single managed object (i.e. the |
| | | * referenced managed object may or may not be present). |
| | | * A managed object composite relationship definition which represents a |
| | | * composition of an optional single managed object (i.e. the referenced managed |
| | | * object may or may not be present). |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that this |
| | | * relation definition refers to. |
| | | * The type of client managed object configuration that this relation |
| | | * definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that this |
| | | * relation definition refers to. |
| | | * The type of server managed object configuration that this relation |
| | | * definition refers to. |
| | | */ |
| | | public final class OptionalRelationDefinition |
| | | <C extends ConfigurationClient, S extends Configuration> |
| | | extends RelationDefinition<C, S> { |
| | | public final class OptionalRelationDefinition<C extends ConfigurationClient, S extends Configuration> extends |
| | | RelationDefinition<C, S> { |
| | | |
| | | /** |
| | | * An interface for incrementally constructing optional relation |
| | | * definitions. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that |
| | | * this relation definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that |
| | | * this relation definition refers to. |
| | | */ |
| | | public static final class Builder |
| | | <C extends ConfigurationClient, S extends Configuration> |
| | | extends AbstractBuilder<C, S, OptionalRelationDefinition<C, S>> { |
| | | /** |
| | | * An interface for incrementally constructing optional relation |
| | | * definitions. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that this |
| | | * relation definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that this |
| | | * relation definition refers to. |
| | | */ |
| | | public static final class Builder<C extends ConfigurationClient, S extends Configuration> extends |
| | | AbstractBuilder<C, S, OptionalRelationDefinition<C, S>> { |
| | | |
| | | // The optional default managed object associated with this |
| | | // optional relation. |
| | | private DefaultManagedObject<? extends C, ? extends S> defaultManagedObject = null; |
| | | |
| | | /** |
| | | * Creates a new builder which can be used to incrementally build an |
| | | * optional relation definition. |
| | | * |
| | | * @param pd |
| | | * The parent managed object definition. |
| | | * @param name |
| | | * The name of the relation. |
| | | * @param cd |
| | | * The child managed object definition. |
| | | */ |
| | | // @Checkstyle:ignore |
| | | public Builder(AbstractManagedObjectDefinition<?, ?> pd, String name, AbstractManagedObjectDefinition<C, S> cd) { |
| | | super(pd, name, cd); |
| | | } |
| | | |
| | | /** |
| | | * Sets the optional default managed object associated with this |
| | | * optional relation definition. |
| | | * |
| | | * @param defaultManagedObject |
| | | * The default managed object or <code>null</code> if there |
| | | * is no default managed object defined for this relation |
| | | * definition. |
| | | */ |
| | | public void setDefaultManagedObject(DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { |
| | | this.defaultManagedObject = defaultManagedObject; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected OptionalRelationDefinition<C, S> buildInstance(Common<C, S> common) { |
| | | return new OptionalRelationDefinition<C, S>(common, defaultManagedObject); |
| | | } |
| | | |
| | | } |
| | | |
| | | // The optional default managed object associated with this |
| | | // optional relation. |
| | | private DefaultManagedObject<? extends C, ? extends S> |
| | | defaultManagedObject = null; |
| | | private final DefaultManagedObject<? extends C, ? extends S> defaultManagedObject; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new builder which can be used to incrementally build |
| | | * an optional relation definition. |
| | | * |
| | | * @param pd |
| | | * The parent managed object definition. |
| | | * @param name |
| | | * The name of the relation. |
| | | * @param cd |
| | | * The child managed object definition. |
| | | */ |
| | | public Builder(AbstractManagedObjectDefinition<?, ?> pd, String name, |
| | | AbstractManagedObjectDefinition<C, S> cd) { |
| | | super(pd, name, cd); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Sets the optional default managed object associated with this |
| | | * optional relation definition. |
| | | * |
| | | * @param defaultManagedObject |
| | | * The default managed object or <code>null</code> if |
| | | * there is no default managed object defined for this |
| | | * relation definition. |
| | | */ |
| | | public void setDefaultManagedObject( |
| | | // Private constructor. |
| | | private OptionalRelationDefinition(Common<C, S> common, |
| | | DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { |
| | | this.defaultManagedObject = defaultManagedObject; |
| | | super(common); |
| | | this.defaultManagedObject = defaultManagedObject; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected OptionalRelationDefinition<C, S> buildInstance( |
| | | Common<C, S> common) { |
| | | return new OptionalRelationDefinition<C, S>(common, defaultManagedObject); |
| | | public <R, P> R accept(RelationDefinitionVisitor<R, P> v, P p) { |
| | | return v.visitOptional(this, p); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | // The optional default managed object associated with this |
| | | // optional relation. |
| | | private final DefaultManagedObject<? extends C, ? extends S> |
| | | defaultManagedObject; |
| | | |
| | | |
| | | |
| | | // Private constructor. |
| | | private OptionalRelationDefinition(Common<C, S> common, |
| | | DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { |
| | | super(common); |
| | | this.defaultManagedObject = defaultManagedObject; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <R, P> R accept(RelationDefinitionVisitor<R, P> v, P p) { |
| | | return v.visitOptional(this, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the optional default managed object associated with this |
| | | * optional relation definition. |
| | | * |
| | | * @return Returns the default managed object or <code>null</code> |
| | | * if there is no default managed object defined for this |
| | | * relation definition. |
| | | */ |
| | | public DefaultManagedObject<? extends C, ? extends S> |
| | | getDefaultManagedObject() { |
| | | return defaultManagedObject; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void toString(StringBuilder builder) { |
| | | builder.append("name="); |
| | | builder.append(getName()); |
| | | builder.append(" type=optional parent="); |
| | | builder.append(getParentDefinition().getName()); |
| | | builder.append(" child="); |
| | | builder.append(getChildDefinition().getName()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected void initialize() throws Exception { |
| | | if (defaultManagedObject != null) { |
| | | defaultManagedObject.initialize(); |
| | | /** |
| | | * Gets the optional default managed object associated with this optional |
| | | * relation definition. |
| | | * |
| | | * @return Returns the default managed object or <code>null</code> if there |
| | | * is no default managed object defined for this relation |
| | | * definition. |
| | | */ |
| | | public DefaultManagedObject<? extends C, ? extends S> getDefaultManagedObject() { |
| | | return defaultManagedObject; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void toString(StringBuilder builder) { |
| | | builder.append("name="); |
| | | builder.append(getName()); |
| | | builder.append(" type=optional parent="); |
| | | builder.append(getParentDefinition().getName()); |
| | | builder.append(" child="); |
| | | builder.append(getChildDefinition().getName()); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected void initialize() throws Exception { |
| | | if (defaultManagedObject != null) { |
| | | defaultManagedObject.initialize(); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | * @return The new property definition. |
| | | */ |
| | | protected abstract D buildInstance(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<T> defaultBehavior); |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<T> defaultBehavior); |
| | | } |
| | | |
| | | // The administrator action. |
| | |
| | | * The default behavior provider. |
| | | */ |
| | | protected PropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, Class<T> theClass, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, DefaultBehaviorProvider<T> defaultBehavior) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, DefaultBehaviorProvider<T> defaultBehavior) { |
| | | Reject.ifNull(d, theClass, propertyName, options, adminAction, defaultBehavior); |
| | | |
| | | this.definition = d; |
| | |
| | | * @throws ClassCastException |
| | | * If the provided property value did not have the correct type. |
| | | */ |
| | | public final T castValue(Object object) throws ClassCastException { |
| | | public final T castValue(Object object) { |
| | | return theClass.cast(object); |
| | | } |
| | | |
| | |
| | | * @throws IllegalPropertyValueStringException |
| | | * If the property value string is invalid. |
| | | */ |
| | | public abstract T decodeValue(String value) throws IllegalPropertyValueStringException; |
| | | public abstract T decodeValue(String value); |
| | | |
| | | /** |
| | | * Encode the provided property value into its string representation. |
| | |
| | | * @throws IllegalPropertyValueException |
| | | * If the property value is invalid. |
| | | */ |
| | | public String encodeValue(T value) throws IllegalPropertyValueException { |
| | | public String encodeValue(T value) { |
| | | Reject.ifNull(value); |
| | | |
| | | return value.toString(); |
| | |
| | | * @throws IllegalPropertyValueException |
| | | * If the property value is invalid. |
| | | */ |
| | | public String normalizeValue(T value) throws IllegalPropertyValueException { |
| | | public String normalizeValue(T value) { |
| | | Reject.ifNull(value); |
| | | |
| | | return encodeValue(value); |
| | |
| | | * @throws IllegalPropertyValueException |
| | | * If the property value is invalid. |
| | | */ |
| | | public abstract void validateValue(T value) throws IllegalPropertyValueException; |
| | | public abstract void validateValue(T value); |
| | | |
| | | /** |
| | | * Performs any run-time initialization required by this property |
| | |
| | | /** |
| | | * Underlying implementation. |
| | | */ |
| | | private class MyPropertyDefinitionVisitor extends PropertyDefinitionVisitor<LocalizableMessage, Void> { |
| | | private final class MyPropertyDefinitionVisitor extends PropertyDefinitionVisitor<LocalizableMessage, Void> { |
| | | |
| | | // Flag indicating whether detailed syntax information will be |
| | | // generated. |
| | |
| | | */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> LocalizableMessage visitAggregation( |
| | | AggregationPropertyDefinition<C, S> d, Void p) { |
| | | AggregationPropertyDefinition<C, S> d, Void p) { |
| | | return LocalizableMessage.raw("NAME"); |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <T> LocalizableMessage visitUnknown(PropertyDefinition<T> d, Void p) |
| | | throws UnknownPropertyDefinitionException { |
| | | public <T> LocalizableMessage visitUnknown(PropertyDefinition<T> d, Void p) { |
| | | return LocalizableMessage.raw("?"); |
| | | } |
| | | } |
| | |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A visitor of property definitions, in the style of the visitor |
| | | * design pattern. Classes implementing this interface can query |
| | | * property definitions in a type-safe manner when the kind of |
| | | * property definition is unknown at compile time. When a visitor is |
| | | * passed to a property definition's accept method, the corresponding |
| | | * visit method most applicable to that property definition is |
| | | * invoked. |
| | | * A visitor of property definitions, in the style of the visitor design |
| | | * pattern. Classes implementing this interface can query property definitions |
| | | * in a type-safe manner when the kind of property definition is unknown at |
| | | * compile time. When a visitor is passed to a property definition's accept |
| | | * method, the corresponding visit method most applicable to that property |
| | | * definition is invoked. |
| | | * <p> |
| | | * Each <code>visitXXX</code> method is provided with a default |
| | | * implementation which calls |
| | | * {@link #visitUnknown(PropertyDefinition, Object)}. Sub-classes can |
| | | * override any or all of the methods to provide their own |
| | | * type-specific behavior. |
| | | * Each <code>visitXXX</code> method is provided with a default implementation |
| | | * which calls {@link #visitUnknown(PropertyDefinition, Object)}. Sub-classes |
| | | * can override any or all of the methods to provide their own type-specific |
| | | * behavior. |
| | | * |
| | | * @param <R> |
| | | * The return type of this visitor's methods. Use |
| | | * {@link java.lang.Void} for visitors that do not need to |
| | | * return results. |
| | | * The return type of this visitor's methods. Use |
| | | * {@link java.lang.Void} for visitors that do not need to return |
| | | * results. |
| | | * @param <P> |
| | | * The type of the additional parameter to this visitor's |
| | | * methods. Use {@link java.lang.Void} for visitors that do |
| | | * not need an additional parameter. |
| | | * The type of the additional parameter to this visitor's methods. |
| | | * Use {@link java.lang.Void} for visitors that do not need an |
| | | * additional parameter. |
| | | */ |
| | | public abstract class PropertyDefinitionVisitor<R, P> { |
| | | |
| | | /** |
| | | * Default constructor. |
| | | */ |
| | | protected PropertyDefinitionVisitor() { |
| | | // No implementation required. |
| | | } |
| | | /** |
| | | * Default constructor. |
| | | */ |
| | | protected PropertyDefinitionVisitor() { |
| | | // No implementation required. |
| | | } |
| | | |
| | | /** |
| | | * Visit a dseecompat Global ACI property definition. |
| | | * |
| | | * @param pd |
| | | * The Global ACI property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitACI(ACIPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit an aggregation property definition. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that this |
| | | * aggregation property definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that this |
| | | * aggregation property definition refers to. |
| | | * @param pd |
| | | * The aggregation property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public <C extends ConfigurationClient, S extends Configuration> R visitAggregation( |
| | | AggregationPropertyDefinition<C, S> pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a dseecompat Global ACI property definition. |
| | | * |
| | | * @param pd |
| | | * The Global ACI property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitACI(ACIPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | /** |
| | | * Visit an attribute type property definition. |
| | | * |
| | | * @param pd |
| | | * The attribute type property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitAttributeType(AttributeTypePropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a boolean property definition. |
| | | * |
| | | * @param pd |
| | | * The boolean property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitBoolean(BooleanPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a class property definition. |
| | | * |
| | | * @param pd |
| | | * The class property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitClass(ClassPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit an aggregation property definition. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that |
| | | * this aggregation property definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that |
| | | * this aggregation property definition refers to. |
| | | * @param pd |
| | | * The aggregation property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public <C extends ConfigurationClient, S extends Configuration> |
| | | R visitAggregation(AggregationPropertyDefinition<C, S> pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | /** |
| | | * Visit a DN property definition. |
| | | * |
| | | * @param pd |
| | | * The DN property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitDN(DNPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a duration property definition. |
| | | * |
| | | * @param pd |
| | | * The duration property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitDuration(DurationPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit an enumeration property definition. |
| | | * |
| | | * @param <E> |
| | | * The enumeration that should be used for values of the property |
| | | * definition. |
| | | * @param pd |
| | | * The enumeration property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public <E extends Enum<E>> R visitEnum(EnumPropertyDefinition<E> pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit an attribute type property definition. |
| | | * |
| | | * @param pd |
| | | * The attribute type property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitAttributeType(AttributeTypePropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | /** |
| | | * Visit an integer property definition. |
| | | * |
| | | * @param pd |
| | | * The integer property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitInteger(IntegerPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a IP address property definition. |
| | | * |
| | | * @param pd |
| | | * The IP address property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitIPAddress(IPAddressPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a IP address mask property definition. |
| | | * |
| | | * @param pd |
| | | * The IP address mask property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitIPAddressMask(IPAddressMaskPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a boolean property definition. |
| | | * |
| | | * @param pd |
| | | * The boolean property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitBoolean(BooleanPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | /** |
| | | * Visit a size property definition. |
| | | * |
| | | * @param pd |
| | | * The size property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitSize(SizePropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a string property definition. |
| | | * |
| | | * @param pd |
| | | * The string property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitString(StringPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Visit a class property definition. |
| | | * |
| | | * @param pd |
| | | * The class property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitClass(ClassPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit a DN property definition. |
| | | * |
| | | * @param pd |
| | | * The DN property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitDN(DNPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit a duration property definition. |
| | | * |
| | | * @param pd |
| | | * The duration property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitDuration(DurationPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit an enumeration property definition. |
| | | * |
| | | * @param <E> |
| | | * The enumeration that should be used for values of the |
| | | * property definition. |
| | | * @param pd |
| | | * The enumeration property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public <E extends Enum<E>> R visitEnum(EnumPropertyDefinition<E> pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit an integer property definition. |
| | | * |
| | | * @param pd |
| | | * The integer property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitInteger(IntegerPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit a IP address property definition. |
| | | * |
| | | * @param pd |
| | | * The IP address property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitIPAddress(IPAddressPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit a IP address mask property definition. |
| | | * |
| | | * @param pd |
| | | * The IP address mask property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitIPAddressMask(IPAddressMaskPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Visit a size property definition. |
| | | * |
| | | * @param pd |
| | | * The size property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitSize(SizePropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit a string property definition. |
| | | * |
| | | * @param pd |
| | | * The string property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitString(StringPropertyDefinition pd, P p) { |
| | | return visitUnknown(pd, p); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit an unknown type of property definition. Implementations of |
| | | * this method can provide default behavior for unknown property |
| | | * definition types. |
| | | * <p> |
| | | * The default implementation of this method throws an |
| | | * {@link UnknownPropertyDefinitionException}. Sub-classes can |
| | | * override this method with their own default behavior. |
| | | * |
| | | * @param <T> |
| | | * The type of the underlying property. |
| | | * @param pd |
| | | * The property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | * @throws UnknownPropertyDefinitionException |
| | | * Visitor implementations may optionally throw this |
| | | * exception. |
| | | */ |
| | | public <T> R visitUnknown(PropertyDefinition<T> pd, P p) |
| | | throws UnknownPropertyDefinitionException { |
| | | throw new UnknownPropertyDefinitionException(pd, p); |
| | | } |
| | | /** |
| | | * Visit an unknown type of property definition. Implementations of this |
| | | * method can provide default behavior for unknown property definition |
| | | * types. |
| | | * <p> |
| | | * The default implementation of this method throws an |
| | | * {@link UnknownPropertyDefinitionException}. Sub-classes can override this |
| | | * method with their own default behavior. |
| | | * |
| | | * @param <T> |
| | | * The type of the underlying property. |
| | | * @param pd |
| | | * The property definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | * @throws UnknownPropertyDefinitionException |
| | | * Visitor implementations may optionally throw this exception. |
| | | */ |
| | | public <T> R visitUnknown(PropertyDefinition<T> pd, P p) { |
| | | throw new UnknownPropertyDefinitionException(pd, p); |
| | | } |
| | | |
| | | } |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This enumeration contains various options that can be associated |
| | | * with property definitions. |
| | | * This enumeration contains various options that can be associated with |
| | | * property definitions. |
| | | */ |
| | | public enum PropertyOption { |
| | | /** |
| | | * Use this option to identify properties which should be considered |
| | | * as advanced and should not be exposed by default in client |
| | | * applications. |
| | | */ |
| | | ADVANCED, |
| | | /** |
| | | * Use this option to identify properties which should be considered as |
| | | * advanced and should not be exposed by default in client applications. |
| | | */ |
| | | ADVANCED, |
| | | |
| | | /** |
| | | * Use this option to identify properties which must not be directly |
| | | * exposed in client applications. |
| | | */ |
| | | HIDDEN, |
| | | /** |
| | | * Use this option to identify properties which must not be directly exposed |
| | | * in client applications. |
| | | */ |
| | | HIDDEN, |
| | | |
| | | /** |
| | | * Use this option to identify properties which must have a value. |
| | | */ |
| | | MANDATORY, |
| | | /** |
| | | * Use this option to identify properties which must have a value. |
| | | */ |
| | | MANDATORY, |
| | | |
| | | /** |
| | | * Use this option to identify properties which are multi-valued. |
| | | */ |
| | | MULTI_VALUED, |
| | | /** |
| | | * Use this option to identify properties which are multi-valued. |
| | | */ |
| | | MULTI_VALUED, |
| | | |
| | | /** |
| | | * Use this option to identify properties which can be initialized |
| | | * once only and are read-only thereafter. |
| | | */ |
| | | READ_ONLY, |
| | | /** |
| | | * Use this option to identify properties which can be initialized once only |
| | | * and are read-only thereafter. |
| | | */ |
| | | READ_ONLY, |
| | | |
| | | /** |
| | | * Use this option to identify properties which are for monitoring |
| | | * purposes only and are generated automatically by the server.. |
| | | */ |
| | | MONITORING; |
| | | /** |
| | | * Use this option to identify properties which are for monitoring purposes |
| | | * only and are generated automatically by the server.. |
| | | */ |
| | | MONITORING; |
| | | } |
| | |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | |
| | | |
| | | |
| | | /** |
| | | * An interface which can be used to initialize the contents of a managed |
| | | * object. |
| | | */ |
| | | public interface PropertyProvider { |
| | | |
| | | /** |
| | | * A property provider which always returns empty property values, indicating |
| | | * default behavior. |
| | | */ |
| | | public static final PropertyProvider DEFAULT_PROVIDER = |
| | | new PropertyProvider() { |
| | | /** |
| | | * A property provider which always returns empty property values, |
| | | * indicating default behavior. |
| | | */ |
| | | public static final PropertyProvider DEFAULT_PROVIDER = new PropertyProvider() { |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <T> Collection<T> getPropertyValues(PropertyDefinition<T> d) { |
| | | return Collections.<T> emptySet(); |
| | | } |
| | | |
| | | }; |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | * Get the property values associated with the specified property |
| | | * definition. |
| | | * <p> |
| | | * Implementations are not required to validate the values that they |
| | | * provide. Specifically: |
| | | * <ul> |
| | | * <li>they do not need to guarantee that the provided values are valid |
| | | * according to the property's syntax |
| | | * <li>they do not need to provide values for mandatory properties |
| | | * <li>they do not need to ensure that single-valued properties do contain |
| | | * at most one value. |
| | | * </ul> |
| | | * The returned set of values is allowed to contain duplicates. |
| | | * |
| | | * @param <T> |
| | | * The underlying type of the property. |
| | | * @param d |
| | | * The Property definition. |
| | | * @return Returns a newly allocated set containing a copy of the property's |
| | | * values. An empty set indicates that the property has no values |
| | | * defined and any default behavior is applicable. |
| | | * @throws IllegalArgumentException |
| | | * If this property provider does not recognise the requested |
| | | * property definition. |
| | | */ |
| | | public <T> Collection<T> getPropertyValues(PropertyDefinition<T> d) |
| | | throws IllegalArgumentException { |
| | | return Collections.<T> emptySet(); |
| | | } |
| | | |
| | | }; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the property values associated with the specified property definition. |
| | | * <p> |
| | | * Implementations are not required to validate the values that they provide. |
| | | * Specifically: |
| | | * <ul> |
| | | * <li>they do not need to guarantee that the provided values are valid |
| | | * according to the property's syntax |
| | | * <li>they do not need to provide values for mandatory properties |
| | | * <li>they do not need to ensure that single-valued properties do contain at |
| | | * most one value. |
| | | * </ul> |
| | | * The returned set of values is allowed to contain duplicates. |
| | | * |
| | | * @param <T> |
| | | * The underlying type of the property. |
| | | * @param d |
| | | * The Property definition. |
| | | * @return Returns a newly allocated set containing a copy of the property's |
| | | * values. An empty set indicates that the property has no values |
| | | * defined and any default behavior is applicable. |
| | | * @throws IllegalArgumentException |
| | | * If this property provider does not recognise the requested |
| | | * property definition. |
| | | */ |
| | | <T> Collection<T> getPropertyValues(PropertyDefinition<T> d) |
| | | throws IllegalArgumentException; |
| | | <T> Collection<T> getPropertyValues(PropertyDefinition<T> d); |
| | | } |
| | |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | import java.net.InetAddress; |
| | | |
| | | import org.forgerock.opendj.ldap.DN; |
| | |
| | | import org.opends.server.authorization.dseecompat.Aci; |
| | | import org.opends.server.types.AddressMask; |
| | | |
| | | |
| | | /** |
| | | * A visitor of property values, in the style of the visitor design |
| | | * pattern. Classes implementing this interface can query a property a |
| | | * value and its associated property definition in a type-safe manner |
| | | * when the kind of property value is unknown at compile time. When a |
| | | * visitor is passed to a property definition's accept method, the |
| | | * corresponding visit method most applicable to that property |
| | | * definition is invoked. |
| | | * A visitor of property values, in the style of the visitor design pattern. |
| | | * Classes implementing this interface can query a property a value and its |
| | | * associated property definition in a type-safe manner when the kind of |
| | | * property value is unknown at compile time. When a visitor is passed to a |
| | | * property definition's accept method, the corresponding visit method most |
| | | * applicable to that property definition is invoked. |
| | | * <p> |
| | | * Each <code>visitXXX</code> method is provided with a default |
| | | * implementation which calls |
| | | * {@link #visitUnknown(PropertyDefinition, Object, Object)}. |
| | | * Sub-classes can override any or all of the methods to provide their |
| | | * own type-specific behavior. |
| | | * Each <code>visitXXX</code> method is provided with a default implementation |
| | | * which calls {@link #visitUnknown(PropertyDefinition, Object, Object)}. |
| | | * Sub-classes can override any or all of the methods to provide their own |
| | | * type-specific behavior. |
| | | * |
| | | * @param <R> |
| | | * The return type of this visitor's methods. Use |
| | | * {@link java.lang.Void} for visitors that do not need to |
| | | * return results. |
| | | * The return type of this visitor's methods. Use |
| | | * {@link java.lang.Void} for visitors that do not need to return |
| | | * results. |
| | | * @param <P> |
| | | * The type of the additional parameter to this visitor's |
| | | * methods. Use {@link java.lang.Void} for visitors that do |
| | | * not need an additional parameter. |
| | | * The type of the additional parameter to this visitor's methods. |
| | | * Use {@link java.lang.Void} for visitors that do not need an |
| | | * additional parameter. |
| | | */ |
| | | public abstract class PropertyValueVisitor<R, P> { |
| | | |
| | | /** |
| | | * Default constructor. |
| | | */ |
| | | protected PropertyValueVisitor() { |
| | | // No implementation required. |
| | | } |
| | | /** |
| | | * Default constructor. |
| | | */ |
| | | protected PropertyValueVisitor() { |
| | | // No implementation required. |
| | | } |
| | | |
| | | /** |
| | | * Visit a dseecompat ACI. |
| | | * |
| | | * @param pd |
| | | * The dseecompat ACI property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitACI(ACIPropertyDefinition pd, Aci v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit an aggregation property value. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that this |
| | | * aggregation property definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that this |
| | | * aggregation property definition refers to. |
| | | * @param pd |
| | | * The aggregation property definition to visit. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public <C extends ConfigurationClient, S extends Configuration> R visitAggregation( |
| | | AggregationPropertyDefinition<C, S> pd, String v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a dseecompat ACI. |
| | | * |
| | | * @param pd |
| | | * The dseecompat ACI property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitACI(ACIPropertyDefinition pd, Aci v, |
| | | P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | /** |
| | | * Visit an attribute type. |
| | | * |
| | | * @param pd |
| | | * The attribute type property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitAttributeType(AttributeTypePropertyDefinition pd, AttributeType v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a boolean. |
| | | * |
| | | * @param pd |
| | | * The boolean property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitBoolean(BooleanPropertyDefinition pd, Boolean v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a class. |
| | | * |
| | | * @param pd |
| | | * The class property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitClass(ClassPropertyDefinition pd, String v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit an aggregation property value. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that |
| | | * this aggregation property definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that |
| | | * this aggregation property definition refers to. |
| | | * @param pd |
| | | * The aggregation property definition to visit. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public <C extends ConfigurationClient, S extends Configuration> |
| | | R visitAggregation( |
| | | AggregationPropertyDefinition<C, S> pd, String v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | /** |
| | | * Visit a DN. |
| | | * |
| | | * @param pd |
| | | * The DN property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitDN(DNPropertyDefinition pd, DN v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a duration. |
| | | * |
| | | * @param pd |
| | | * The duration property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitDuration(DurationPropertyDefinition pd, Long v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit an enumeration. |
| | | * |
| | | * @param <E> |
| | | * The enumeration that should be used for values of the property |
| | | * definition. |
| | | * @param pd |
| | | * The enumeration property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public <E extends Enum<E>> R visitEnum(EnumPropertyDefinition<E> pd, E v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit an attribute type. |
| | | * |
| | | * @param pd |
| | | * The attribute type property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitAttributeType(AttributeTypePropertyDefinition pd, |
| | | AttributeType v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | /** |
| | | * Visit an integer. |
| | | * |
| | | * @param pd |
| | | * The integer property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitInteger(IntegerPropertyDefinition pd, Integer v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a IP address. |
| | | * |
| | | * @param pd |
| | | * The IP address property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitIPAddress(IPAddressPropertyDefinition pd, InetAddress v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a IP address mask. |
| | | * |
| | | * @param pd |
| | | * The IP address mask property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitIPAddressMask(IPAddressMaskPropertyDefinition pd, AddressMask v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a boolean. |
| | | * |
| | | * @param pd |
| | | * The boolean property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitBoolean(BooleanPropertyDefinition pd, Boolean v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | /** |
| | | * Visit a size. |
| | | * |
| | | * @param pd |
| | | * The size property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitSize(SizePropertyDefinition pd, Long v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | /** |
| | | * Visit a string. |
| | | * |
| | | * @param pd |
| | | * The string property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitString(StringPropertyDefinition pd, String v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Visit a class. |
| | | * |
| | | * @param pd |
| | | * The class property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitClass(ClassPropertyDefinition pd, String v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit a DN. |
| | | * |
| | | * @param pd |
| | | * The DN property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitDN(DNPropertyDefinition pd, DN v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit a duration. |
| | | * |
| | | * @param pd |
| | | * The duration property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitDuration(DurationPropertyDefinition pd, Long v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit an enumeration. |
| | | * |
| | | * @param <E> |
| | | * The enumeration that should be used for values of the |
| | | * property definition. |
| | | * @param pd |
| | | * The enumeration property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public <E extends Enum<E>> |
| | | R visitEnum(EnumPropertyDefinition<E> pd, E v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit an integer. |
| | | * |
| | | * @param pd |
| | | * The integer property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitInteger(IntegerPropertyDefinition pd, Integer v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit a IP address. |
| | | * |
| | | * @param pd |
| | | * The IP address property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitIPAddress(IPAddressPropertyDefinition pd, InetAddress v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit a IP address mask. |
| | | * |
| | | * @param pd |
| | | * The IP address mask property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitIPAddressMask(IPAddressMaskPropertyDefinition pd, AddressMask v, |
| | | P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Visit a size. |
| | | * |
| | | * @param pd |
| | | * The size property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitSize(SizePropertyDefinition pd, Long v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit a string. |
| | | * |
| | | * @param pd |
| | | * The string property definition. |
| | | * @param v |
| | | * The property value to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | public R visitString(StringPropertyDefinition pd, String v, P p) { |
| | | return visitUnknown(pd, v, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit an unknown type of property value. Implementations of this |
| | | * method can provide default behavior for unknown types of |
| | | * property. |
| | | * <p> |
| | | * The default implementation of this method throws an |
| | | * {@link UnknownPropertyDefinitionException}. Sub-classes can |
| | | * override this method with their own default behavior. |
| | | * |
| | | * @param <T> |
| | | * The type of property value to visit. |
| | | * @param pd |
| | | * The property definition. |
| | | * @param v |
| | | * The property value. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | * @throws UnknownPropertyDefinitionException |
| | | * Visitor implementations may optionally throw this |
| | | * exception. |
| | | */ |
| | | public <T> R visitUnknown(PropertyDefinition<T> pd, T v, P p) |
| | | throws UnknownPropertyDefinitionException { |
| | | throw new UnknownPropertyDefinitionException(pd, p); |
| | | } |
| | | /** |
| | | * Visit an unknown type of property value. Implementations of this method |
| | | * can provide default behavior for unknown types of property. |
| | | * <p> |
| | | * The default implementation of this method throws an |
| | | * {@link UnknownPropertyDefinitionException}. Sub-classes can override this |
| | | * method with their own default behavior. |
| | | * |
| | | * @param <T> |
| | | * The type of property value to visit. |
| | | * @param pd |
| | | * The property definition. |
| | | * @param v |
| | | * The property value. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | * @throws UnknownPropertyDefinitionException |
| | | * Visitor implementations may optionally throw this exception. |
| | | */ |
| | | public <T> R visitUnknown(PropertyDefinition<T> pd, T v, P p) { |
| | | throw new UnknownPropertyDefinitionException(pd, p); |
| | | } |
| | | |
| | | } |
| | |
| | | * relation. |
| | | */ |
| | | public static <C extends ConfigurationClient, S extends Configuration> Reference<C, S> parseDN( |
| | | ManagedObjectPath<?, ?> path, InstantiableRelationDefinition<C, S> relationDef, String dnAsString) |
| | | throws IllegalArgumentException { |
| | | ManagedObjectPath<?, ?> path, InstantiableRelationDefinition<C, S> relationDef, String dnAsString) { |
| | | AbstractManagedObjectDefinition<?, ?> definition = path.getManagedObjectDefinition(); |
| | | RelationDefinition<?, ?> tmp = definition.getRelationDefinition(relationDef.getName()); |
| | | if (tmp != relationDef) { |
| | | // TODO : i18n ? |
| | | throw new IllegalArgumentException("The relation \"" + relationDef.getName() |
| | | + "\" is not associated with the definition \"" + definition.getName() + "\""); |
| | | + "\" is not associated with the definition \"" + definition.getName() + "\""); |
| | | } |
| | | |
| | | DN dn = DN.valueOf(dnAsString); |
| | |
| | | * definition, or if the provided name is empty. |
| | | */ |
| | | public static <C extends ConfigurationClient, S extends Configuration> Reference<C, S> parseName( |
| | | ManagedObjectPath<?, ?> p, InstantiableRelationDefinition<C, S> rd, String s) |
| | | throws IllegalArgumentException { |
| | | ManagedObjectPath<?, ?> p, InstantiableRelationDefinition<C, S> rd, String s) { |
| | | // Sanity checks. |
| | | AbstractManagedObjectDefinition<?, ?> d = p.getManagedObjectDefinition(); |
| | | RelationDefinition<?, ?> tmp = d.getRelationDefinition(rd.getName()); |
| | | if (tmp != rd) { |
| | | throw new IllegalArgumentException("The relation \"" + rd.getName() |
| | | + "\" is not associated with the definition \"" + d.getName() + "\""); |
| | | + "\" is not associated with the definition \"" + d.getName() + "\""); |
| | | } |
| | | |
| | | if (s.trim().length() == 0) { |
| | |
| | | private final InstantiableRelationDefinition<C, S> relation; |
| | | |
| | | // Private constructor. |
| | | private Reference(ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> relation, String name) |
| | | throws IllegalArgumentException { |
| | | private Reference(ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> relation, String name) { |
| | | this.relation = relation; |
| | | this.name = name; |
| | | this.path = parent.child(relation, name); |
| | |
| | | * @param <D> |
| | | * The type of relation definition constructed by this builder. |
| | | */ |
| | | protected abstract static class AbstractBuilder<C extends ConfigurationClient, S extends Configuration, D extends RelationDefinition<C, S>> { |
| | | protected abstract static class AbstractBuilder<C extends ConfigurationClient, S extends Configuration, |
| | | D extends RelationDefinition<C, S>> { |
| | | |
| | | // Common fields. |
| | | private final Common<C, S> common; |
| | |
| | | * The child managed object definition. |
| | | */ |
| | | protected AbstractBuilder(AbstractManagedObjectDefinition<?, ?> pd, String name, |
| | | AbstractManagedObjectDefinition<C, S> cd) { |
| | | AbstractManagedObjectDefinition<C, S> cd) { |
| | | this.common = new Common<C, S>(pd, name, cd); |
| | | } |
| | | |
| | |
| | | private final AbstractManagedObjectDefinition<?, ?> pd; |
| | | |
| | | // Private constructor. |
| | | private Common(AbstractManagedObjectDefinition<?, ?> pd, String name, AbstractManagedObjectDefinition<C, S> cd) { |
| | | private Common(AbstractManagedObjectDefinition<?, ?> pd, String name, |
| | | AbstractManagedObjectDefinition<C, S> cd) { |
| | | this.name = name; |
| | | this.pd = pd; |
| | | this.cd = cd; |
| | |
| | | public final LocalizableMessage getDescription(Locale locale) { |
| | | try { |
| | | String property = "relation." + common.name + ".description"; |
| | | return ManagedObjectDefinitionI18NResource.getInstance() |
| | | .getMessage(getParentDefinition(), property, locale); |
| | | return ManagedObjectDefinitionI18NResource.getInstance().getMessage(getParentDefinition(), property, |
| | | locale); |
| | | } catch (MissingResourceException e) { |
| | | return null; |
| | | } |
| | |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A visitor of relation definitions, in the style of the visitor |
| | | * design pattern. Classes implementing this interface can query |
| | | * relation definitions in a type-safe manner when the kind of |
| | | * relation definition is unknown at compile time. When a visitor is |
| | | * passed to a relation definition's accept method, the corresponding |
| | | * visit method most applicable to that relation definition is |
| | | * invoked. |
| | | * A visitor of relation definitions, in the style of the visitor design |
| | | * pattern. Classes implementing this interface can query relation definitions |
| | | * in a type-safe manner when the kind of relation definition is unknown at |
| | | * compile time. When a visitor is passed to a relation definition's accept |
| | | * method, the corresponding visit method most applicable to that relation |
| | | * definition is invoked. |
| | | * |
| | | * @param <R> |
| | | * The return type of this visitor's methods. Use |
| | | * {@link java.lang.Void} for visitors that do not need to |
| | | * return results. |
| | | * The return type of this visitor's methods. Use |
| | | * {@link java.lang.Void} for visitors that do not need to return |
| | | * results. |
| | | * @param <P> |
| | | * The type of the additional parameter to this visitor's |
| | | * methods. Use {@link java.lang.Void} for visitors that do |
| | | * not need an additional parameter. |
| | | * The type of the additional parameter to this visitor's methods. |
| | | * Use {@link java.lang.Void} for visitors that do not need an |
| | | * additional parameter. |
| | | */ |
| | | public interface RelationDefinitionVisitor<R, P> { |
| | | |
| | | /** |
| | | * Visit an instantiable relation definition. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param rd |
| | | * The instantiable relation definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> R visitInstantiable( |
| | | InstantiableRelationDefinition<C, S> rd, P p); |
| | | /** |
| | | * Visit an instantiable relation definition. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param rd |
| | | * The instantiable relation definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> R visitInstantiable( |
| | | InstantiableRelationDefinition<C, S> rd, P p); |
| | | |
| | | /** |
| | | * Visit a set relation definition. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param rd |
| | | * The set relation definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> R visitSet(SetRelationDefinition<C, S> rd, P p); |
| | | |
| | | /** |
| | | * Visit an optional relation definition. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param rd |
| | | * The optional relation definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> R visitOptional(OptionalRelationDefinition<C, S> rd, P p); |
| | | |
| | | /** |
| | | * Visit a set relation definition. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param rd |
| | | * The set relation definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> R visitSet( |
| | | SetRelationDefinition<C, S> rd, P p); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit an optional relation definition. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param rd |
| | | * The optional relation definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> R visitOptional( |
| | | OptionalRelationDefinition<C, S> rd, P p); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Visit a singleton relation definition. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param rd |
| | | * The singleton relation definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> R visitSingleton( |
| | | SingletonRelationDefinition<C, S> rd, P p); |
| | | /** |
| | | * Visit a singleton relation definition. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that the |
| | | * relation definition refers to. |
| | | * @param rd |
| | | * The singleton relation definition to visit. |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> R visitSingleton(SingletonRelationDefinition<C, S> rd, |
| | | P p); |
| | | |
| | | } |
| | |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This enumeration contains various options that can be associated |
| | | * with relation definitions. |
| | | * This enumeration contains various options that can be associated with |
| | | * relation definitions. |
| | | */ |
| | | public enum RelationOption { |
| | | /** |
| | | * Use this option to identify relations which should be considered |
| | | * as advanced and should not be exposed by default in client |
| | | * applications. |
| | | */ |
| | | ADVANCED, |
| | | /** |
| | | * Use this option to identify relations which should be considered as |
| | | * advanced and should not be exposed by default in client applications. |
| | | */ |
| | | ADVANCED, |
| | | |
| | | /** |
| | | * Use this option to identify relations which must not be directly |
| | | * exposed in client applications. |
| | | */ |
| | | HIDDEN; |
| | | /** |
| | | * Use this option to identify relations which must not be directly exposed |
| | | * in client applications. |
| | | */ |
| | | HIDDEN; |
| | | } |
| | |
| | | */ |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A default behavior provider which retrieves default values from a |
| | | * parent managed object. It should be used by properties which |
| | | * inherit their default value(s) from properties held in an other |
| | | * managed object. |
| | | * A default behavior provider which retrieves default values from a parent |
| | | * managed object. It should be used by properties which inherit their default |
| | | * value(s) from properties held in an other managed object. |
| | | * |
| | | * @param <T> |
| | | * The type of values represented by this provider. |
| | | * The type of values represented by this provider. |
| | | */ |
| | | public final class RelativeInheritedDefaultBehaviorProvider<T> extends |
| | | DefaultBehaviorProvider<T> { |
| | | public final class RelativeInheritedDefaultBehaviorProvider<T> extends DefaultBehaviorProvider<T> { |
| | | |
| | | // The type of managed object expected at the relative offset. |
| | | private final AbstractManagedObjectDefinition<?, ?> d; |
| | | // The type of managed object expected at the relative offset. |
| | | private final AbstractManagedObjectDefinition<?, ?> d; |
| | | |
| | | // The relative offset (where 1 = parent, 2 = grandparent) of the |
| | | // managed object containing the property. |
| | | private final int offset; |
| | | // The relative offset (where 1 = parent, 2 = grandparent) of the |
| | | // managed object containing the property. |
| | | private final int offset; |
| | | |
| | | // The name of the property containing the inherited default values. |
| | | private final String propertyName; |
| | | // The name of the property containing the inherited default values. |
| | | private final String propertyName; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a relative inherited default behavior provider associated |
| | | * with a parent managed object. |
| | | * |
| | | * @param d |
| | | * The type of parent managed object expected at the |
| | | * relative location. |
| | | * @param propertyName |
| | | * The name of the property containing the inherited |
| | | * default values. |
| | | * @param offset |
| | | * The relative location of the parent managed object |
| | | * (where 0 is the managed object itself, 1 is the parent, |
| | | * and 2 is the grand-parent). |
| | | * @throws IllegalArgumentException |
| | | * If the offset is less than 0. |
| | | */ |
| | | public RelativeInheritedDefaultBehaviorProvider( |
| | | AbstractManagedObjectDefinition<?, ?> d, String propertyName, int offset) |
| | | throws IllegalArgumentException { |
| | | // We do not decode the property name now because the property |
| | | // might not have been constructed at this point (e.g. when the |
| | | // offset is 0). |
| | | if (offset < 0) { |
| | | throw new IllegalArgumentException("Negative offset"); |
| | | /** |
| | | * Create a relative inherited default behavior provider associated with a |
| | | * parent managed object. |
| | | * |
| | | * @param d |
| | | * The type of parent managed object expected at the relative |
| | | * location. |
| | | * @param propertyName |
| | | * The name of the property containing the inherited default |
| | | * values. |
| | | * @param offset |
| | | * The relative location of the parent managed object (where 0 is |
| | | * the managed object itself, 1 is the parent, and 2 is the |
| | | * grand-parent). |
| | | * @throws IllegalArgumentException |
| | | * If the offset is less than 0. |
| | | */ |
| | | public RelativeInheritedDefaultBehaviorProvider(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | int offset) { |
| | | // We do not decode the property name now because the property |
| | | // might not have been constructed at this point (e.g. when the |
| | | // offset is 0). |
| | | if (offset < 0) { |
| | | throw new IllegalArgumentException("Negative offset"); |
| | | } |
| | | this.d = d; |
| | | this.propertyName = propertyName; |
| | | this.offset = offset; |
| | | } |
| | | this.d = d; |
| | | this.propertyName = propertyName; |
| | | this.offset = offset; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <R, P> R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p) { |
| | | return v.visitRelativeInherited(this, p); |
| | | } |
| | | |
| | | /** |
| | | * Get the definition of the parent managed object containing the inherited |
| | | * default values. |
| | | * |
| | | * @return Returns the definition of the parent managed object containing |
| | | * the inherited default values. |
| | | */ |
| | | public AbstractManagedObjectDefinition<?, ?> getManagedObjectDefinition() { |
| | | return d; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <R, P> R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p) { |
| | | return v.visitRelativeInherited(this, p); |
| | | } |
| | | /** |
| | | * Get the absolute path of the managed object containing the property which |
| | | * has the default values. |
| | | * |
| | | * @param path |
| | | * The path of the current managed object from which the relative |
| | | * path should be determined. |
| | | * @return Returns the absolute path of the managed object containing the |
| | | * property which has the default values. |
| | | */ |
| | | public ManagedObjectPath<?, ?> getManagedObjectPath(ManagedObjectPath<?, ?> path) { |
| | | return path.parent(offset); |
| | | } |
| | | |
| | | /** |
| | | * Gets the name of the property containing the inherited default values. |
| | | * |
| | | * @return Returns the name of the property containing the inherited default |
| | | * values. |
| | | */ |
| | | public String getPropertyName() { |
| | | return propertyName; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Get the definition of the parent managed object containing the |
| | | * inherited default values. |
| | | * |
| | | * @return Returns the definition of the parent managed object |
| | | * containing the inherited default values. |
| | | */ |
| | | public AbstractManagedObjectDefinition<?, ?> getManagedObjectDefinition() { |
| | | return d; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the absolute path of the managed object containing the |
| | | * property which has the default values. |
| | | * |
| | | * @param path |
| | | * The path of the current managed object from which the |
| | | * relative path should be determined. |
| | | * @return Returns the absolute path of the managed object |
| | | * containing the property which has the default values. |
| | | */ |
| | | public ManagedObjectPath<?, ?> getManagedObjectPath( |
| | | ManagedObjectPath<?, ?> path) { |
| | | return path.parent(offset); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the name of the property containing the inherited default |
| | | * values. |
| | | * |
| | | * @return Returns the name of the property containing the inherited |
| | | * default values. |
| | | */ |
| | | public String getPropertyName() { |
| | | return propertyName; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the relative location of the parent managed object. |
| | | * |
| | | * @return Returns the relative location of the parent managed |
| | | * object (where 0 is the managed object itself, 1 is the |
| | | * parent, and 2 is the grand-parent). |
| | | */ |
| | | public int getRelativeOffset() { |
| | | return offset; |
| | | } |
| | | /** |
| | | * Get the relative location of the parent managed object. |
| | | * |
| | | * @return Returns the relative location of the parent managed object (where |
| | | * 0 is the managed object itself, 1 is the parent, and 2 is the |
| | | * grand-parent). |
| | | */ |
| | | public int getRelativeOffset() { |
| | | return offset; |
| | | } |
| | | } |
| | |
| | | * definition refers to. |
| | | */ |
| | | public final class SetRelationDefinition<C extends ConfigurationClient, S extends Configuration> extends |
| | | RelationDefinition<C, S> { |
| | | RelationDefinition<C, S> { |
| | | |
| | | /** |
| | | * An interface for incrementally constructing set relation definitions. |
| | |
| | | * relation definition refers to. |
| | | */ |
| | | public static final class Builder<C extends ConfigurationClient, S extends Configuration> extends |
| | | AbstractBuilder<C, S, SetRelationDefinition<C, S>> { |
| | | AbstractBuilder<C, S, SetRelationDefinition<C, S>> { |
| | | |
| | | // The plural name of the relation. |
| | | private final String pluralName; |
| | | |
| | | // The optional default managed objects associated with this |
| | | // set relation definition. |
| | | private final Map<String, DefaultManagedObject<? extends C, ? extends S>> defaultManagedObjects = new HashMap<String, DefaultManagedObject<? extends C, ? extends S>>(); |
| | | private final Map<String, DefaultManagedObject<? extends C, ? extends S>> defaultManagedObjects = |
| | | new HashMap<String, DefaultManagedObject<? extends C, ? extends S>>(); |
| | | |
| | | /** |
| | | * Creates a new builder which can be used to incrementally build a set |
| | |
| | | * The child managed object definition. |
| | | */ |
| | | public Builder(AbstractManagedObjectDefinition<?, ?> pd, String name, String pluralName, |
| | | AbstractManagedObjectDefinition<C, S> cd) { |
| | | AbstractManagedObjectDefinition<C, S> cd) { |
| | | super(pd, name, cd); |
| | | this.pluralName = pluralName; |
| | | } |
| | |
| | | */ |
| | | public void setDefaultManagedObject(DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { |
| | | this.defaultManagedObjects.put(defaultManagedObject.getManagedObjectDefinition().getName(), |
| | | defaultManagedObject); |
| | | defaultManagedObject); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | // Private constructor. |
| | | private SetRelationDefinition(Common<C, S> common, String pluralName, |
| | | Map<String, DefaultManagedObject<? extends C, ? extends S>> defaultManagedObjects) { |
| | | Map<String, DefaultManagedObject<? extends C, ? extends S>> defaultManagedObjects) { |
| | | super(common); |
| | | this.pluralName = pluralName; |
| | | this.defaultManagedObjects = defaultManagedObjects; |
| | |
| | | * If there is no default managed object associated with the |
| | | * provided name. |
| | | */ |
| | | public DefaultManagedObject<? extends C, ? extends S> getDefaultManagedObject(String name) |
| | | throws IllegalArgumentException { |
| | | public DefaultManagedObject<? extends C, ? extends S> getDefaultManagedObject(String name) { |
| | | if (!defaultManagedObjects.containsKey(name)) { |
| | | throw new IllegalArgumentException("unrecognized default managed object \"" + name + "\""); |
| | | } |
| | |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A managed object composite relationship definition which represents |
| | | * a composition of a single managed object (i.e. the managed object |
| | | * must be present). |
| | | * A managed object composite relationship definition which represents a |
| | | * composition of a single managed object (i.e. the managed object must be |
| | | * present). |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that this |
| | | * relation definition refers to. |
| | | * The type of client managed object configuration that this relation |
| | | * definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that this |
| | | * relation definition refers to. |
| | | * The type of server managed object configuration that this relation |
| | | * definition refers to. |
| | | */ |
| | | public final class SingletonRelationDefinition |
| | | <C extends ConfigurationClient, S extends Configuration> |
| | | extends RelationDefinition<C, S> { |
| | | public final class SingletonRelationDefinition<C extends ConfigurationClient, S extends Configuration> extends |
| | | RelationDefinition<C, S> { |
| | | |
| | | /** |
| | | * An interface for incrementally constructing singleton relation |
| | | * definitions. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that |
| | | * this relation definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that |
| | | * this relation definition refers to. |
| | | */ |
| | | public static final class Builder |
| | | <C extends ConfigurationClient, S extends Configuration> |
| | | extends AbstractBuilder<C, S, SingletonRelationDefinition<C, S>> { |
| | | /** |
| | | * An interface for incrementally constructing singleton relation |
| | | * definitions. |
| | | * |
| | | * @param <C> |
| | | * The type of client managed object configuration that this |
| | | * relation definition refers to. |
| | | * @param <S> |
| | | * The type of server managed object configuration that this |
| | | * relation definition refers to. |
| | | */ |
| | | public static final class Builder<C extends ConfigurationClient, S extends Configuration> extends |
| | | AbstractBuilder<C, S, SingletonRelationDefinition<C, S>> { |
| | | |
| | | // The optional default managed object associated with this |
| | | // singleton relation. |
| | | private DefaultManagedObject<? extends C, ? extends S> defaultManagedObject = null; |
| | | |
| | | /** |
| | | * Creates a new builder which can be used to incrementally build an |
| | | * singleton relation definition. |
| | | * |
| | | * @param pd |
| | | * The parent managed object definition. |
| | | * @param name |
| | | * The name of the relation. |
| | | * @param cd |
| | | * The child managed object definition. |
| | | */ |
| | | // @Checkstyle:ignore |
| | | public Builder(AbstractManagedObjectDefinition<?, ?> pd, String name, AbstractManagedObjectDefinition<C, S> cd) { |
| | | super(pd, name, cd); |
| | | } |
| | | |
| | | /** |
| | | * Sets the optional default managed object associated with this |
| | | * singleton relation definition. |
| | | * |
| | | * @param defaultManagedObject |
| | | * The default managed object or <code>null</code> if there |
| | | * is no default managed object defined for this relation |
| | | * definition. |
| | | */ |
| | | public void setDefaultManagedObject(DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { |
| | | this.defaultManagedObject = defaultManagedObject; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected SingletonRelationDefinition<C, S> buildInstance(Common<C, S> common) { |
| | | return new SingletonRelationDefinition<C, S>(common, defaultManagedObject); |
| | | } |
| | | |
| | | } |
| | | |
| | | // The optional default managed object associated with this |
| | | // singleton relation. |
| | | private DefaultManagedObject<? extends C, ? extends S> |
| | | defaultManagedObject = null; |
| | | private final DefaultManagedObject<? extends C, ? extends S> defaultManagedObject; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new builder which can be used to incrementally build |
| | | * an singleton relation definition. |
| | | * |
| | | * @param pd |
| | | * The parent managed object definition. |
| | | * @param name |
| | | * The name of the relation. |
| | | * @param cd |
| | | * The child managed object definition. |
| | | */ |
| | | public Builder(AbstractManagedObjectDefinition<?, ?> pd, String name, |
| | | AbstractManagedObjectDefinition<C, S> cd) { |
| | | super(pd, name, cd); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Sets the optional default managed object associated with this |
| | | * singleton relation definition. |
| | | * |
| | | * @param defaultManagedObject |
| | | * The default managed object or <code>null</code> if |
| | | * there is no default managed object defined for this |
| | | * relation definition. |
| | | */ |
| | | public void setDefaultManagedObject( |
| | | // Private constructor. |
| | | private SingletonRelationDefinition(Common<C, S> common, |
| | | DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { |
| | | this.defaultManagedObject = defaultManagedObject; |
| | | super(common); |
| | | this.defaultManagedObject = defaultManagedObject; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected SingletonRelationDefinition<C, S> buildInstance( |
| | | Common<C, S> common) { |
| | | return new SingletonRelationDefinition<C, S>(common, |
| | | defaultManagedObject); |
| | | public <R, P> R accept(RelationDefinitionVisitor<R, P> v, P p) { |
| | | return v.visitSingleton(this, p); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | // The optional default managed object associated with this |
| | | // singleton relation. |
| | | private final DefaultManagedObject<? extends C, ? extends S> |
| | | defaultManagedObject; |
| | | |
| | | |
| | | |
| | | // Private constructor. |
| | | private SingletonRelationDefinition(Common<C, S> common, |
| | | DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { |
| | | super(common); |
| | | this.defaultManagedObject = defaultManagedObject; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <R, P> R accept(RelationDefinitionVisitor<R, P> v, P p) { |
| | | return v.visitSingleton(this, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the optional default managed object associated with this |
| | | * singleton relation definition. |
| | | * |
| | | * @return Returns the default managed object or <code>null</code> |
| | | * if there is no default managed object defined for this |
| | | * relation definition. |
| | | */ |
| | | public DefaultManagedObject<? extends C, ? extends S> |
| | | getDefaultManagedObject() { |
| | | return defaultManagedObject; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void toString(StringBuilder builder) { |
| | | builder.append("name="); |
| | | builder.append(getName()); |
| | | builder.append(" type=singleton parent="); |
| | | builder.append(getParentDefinition().getName()); |
| | | builder.append(" child="); |
| | | builder.append(getChildDefinition().getName()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected void initialize() throws Exception { |
| | | if (defaultManagedObject != null) { |
| | | defaultManagedObject.initialize(); |
| | | /** |
| | | * Gets the optional default managed object associated with this singleton |
| | | * relation definition. |
| | | * |
| | | * @return Returns the default managed object or <code>null</code> if there |
| | | * is no default managed object defined for this relation |
| | | * definition. |
| | | */ |
| | | public DefaultManagedObject<? extends C, ? extends S> getDefaultManagedObject() { |
| | | return defaultManagedObject; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void toString(StringBuilder builder) { |
| | | builder.append("name="); |
| | | builder.append(getName()); |
| | | builder.append(" type=singleton parent="); |
| | | builder.append(getParentDefinition().getName()); |
| | | builder.append(" child="); |
| | | builder.append(getChildDefinition().getName()); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected void initialize() throws Exception { |
| | | if (defaultManagedObject != null) { |
| | | defaultManagedObject.initialize(); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | import org.forgerock.util.Reject; |
| | |
| | | * An interface for incrementally constructing memory size property |
| | | * definitions. |
| | | */ |
| | | public static class Builder extends AbstractBuilder<Long, SizePropertyDefinition> { |
| | | public static final class Builder extends AbstractBuilder<Long, SizePropertyDefinition> { |
| | | |
| | | // The lower limit of the property value in bytes. |
| | | private long lowerLimit = 0L; |
| | |
| | | * If a negative lower limit was specified, or if the lower |
| | | * limit is greater than the upper limit. |
| | | */ |
| | | public final void setLowerLimit(long lowerLimit) throws IllegalArgumentException { |
| | | public final void setLowerLimit(long lowerLimit) { |
| | | if (lowerLimit < 0) { |
| | | throw new IllegalArgumentException("Negative lower limit"); |
| | | } |
| | |
| | | * lower limit was specified, or the lower limit is greater |
| | | * than the upper limit. |
| | | */ |
| | | public final void setLowerLimit(String lowerLimit) throws IllegalArgumentException { |
| | | public final void setLowerLimit(String lowerLimit) { |
| | | setLowerLimit(SizeUnit.parseValue(lowerLimit, SizeUnit.BYTES)); |
| | | } |
| | | |
| | |
| | | * @throws IllegalArgumentException |
| | | * If the lower limit is greater than the upper limit. |
| | | */ |
| | | public final void setUpperLimit(Long upperLimit) throws IllegalArgumentException { |
| | | public final void setUpperLimit(Long upperLimit) { |
| | | if (upperLimit != null) { |
| | | if (upperLimit < 0) { |
| | | throw new IllegalArgumentException("Negative upper limit"); |
| | |
| | | * If the upper limit could not be parsed, or if the lower |
| | | * limit is greater than the upper limit. |
| | | */ |
| | | public final void setUpperLimit(String upperLimit) throws IllegalArgumentException { |
| | | public final void setUpperLimit(String upperLimit) { |
| | | if (upperLimit == null) { |
| | | setUpperLimit((Long) null); |
| | | } else { |
| | |
| | | */ |
| | | @Override |
| | | protected SizePropertyDefinition buildInstance(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Long> defaultBehavior) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Long> defaultBehavior) { |
| | | return new SizePropertyDefinition(d, propertyName, options, adminAction, defaultBehavior, lowerLimit, |
| | | upperLimit, allowUnlimited); |
| | | upperLimit, allowUnlimited); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | // Private constructor. |
| | | private SizePropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Long> defaultBehavior, Long lowerLimit, Long upperLimit, boolean allowUnlimited) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<Long> defaultBehavior, Long lowerLimit, Long upperLimit, boolean allowUnlimited) { |
| | | super(d, Long.class, propertyName, options, adminAction, defaultBehavior); |
| | | this.lowerLimit = lowerLimit; |
| | | this.upperLimit = upperLimit; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Long value) throws IllegalPropertyValueException { |
| | | public void validateValue(Long value) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (!allowUnlimited && value < lowerLimit) { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String encodeValue(Long value) throws IllegalPropertyValueException { |
| | | public String encodeValue(Long value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // Make sure that we correctly encode negative values as "unlimited". |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Long decodeValue(String value) throws IllegalPropertyValueStringException { |
| | | public Long decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // First check for the special "unlimited" value when necessary. |
| | |
| | | */ |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This enumeration defines various memory size units. |
| | | */ |
| | | public enum SizeUnit { |
| | | |
| | | /** |
| | | * A byte unit. |
| | | */ |
| | | BYTES(1L, "b", "bytes"), |
| | | /** |
| | | * A byte unit. |
| | | */ |
| | | BYTES(1L, "b", "bytes"), |
| | | |
| | | /** |
| | | * A gibi-byte unit. |
| | | */ |
| | | GIBI_BYTES((long) 1024 * 1024 * 1024, "gib", "gibibytes"), |
| | | /** |
| | | * A gibi-byte unit. |
| | | */ |
| | | GIBI_BYTES((long) 1024 * 1024 * 1024, "gib", "gibibytes"), |
| | | |
| | | /** |
| | | * A giga-byte unit. |
| | | */ |
| | | GIGA_BYTES((long) 1000 * 1000 * 1000, "gb", "gigabytes"), |
| | | /** |
| | | * A giga-byte unit. |
| | | */ |
| | | GIGA_BYTES((long) 1000 * 1000 * 1000, "gb", "gigabytes"), |
| | | |
| | | /** |
| | | * A kibi-byte unit. |
| | | */ |
| | | KIBI_BYTES(1024L, "kib", "kibibytes"), |
| | | /** |
| | | * A kibi-byte unit. |
| | | */ |
| | | KIBI_BYTES(1024L, "kib", "kibibytes"), |
| | | |
| | | /** |
| | | * A kilo-byte unit. |
| | | */ |
| | | KILO_BYTES(1000L, "kb", "kilobytes"), |
| | | /** |
| | | * A kilo-byte unit. |
| | | */ |
| | | KILO_BYTES(1000L, "kb", "kilobytes"), |
| | | |
| | | /** |
| | | * A mebi-byte unit. |
| | | */ |
| | | MEBI_BYTES((long) 1024 * 1024, "mib", "mebibytes"), |
| | | /** |
| | | * A mebi-byte unit. |
| | | */ |
| | | MEBI_BYTES((long) 1024 * 1024, "mib", "mebibytes"), |
| | | |
| | | /** |
| | | * A mega-byte unit. |
| | | */ |
| | | MEGA_BYTES((long) 1000 * 1000, "mb", "megabytes"), |
| | | /** |
| | | * A mega-byte unit. |
| | | */ |
| | | MEGA_BYTES((long) 1000 * 1000, "mb", "megabytes"), |
| | | |
| | | /** |
| | | * A tebi-byte unit. |
| | | */ |
| | | TEBI_BYTES((long) 1024 * 1024 * 1024 * 1024, "tib", "tebibytes"), |
| | | /** |
| | | * A tebi-byte unit. |
| | | */ |
| | | TEBI_BYTES((long) 1024 * 1024 * 1024 * 1024, "tib", "tebibytes"), |
| | | |
| | | /** |
| | | * A tera-byte unit. |
| | | */ |
| | | TERA_BYTES((long) 1000 * 1000 * 1000 * 1000, "tb", "terabytes"); |
| | | /** |
| | | * A tera-byte unit. |
| | | */ |
| | | TERA_BYTES((long) 1000 * 1000 * 1000 * 1000, "tb", "terabytes"); |
| | | |
| | | // A lookup table for resolving a unit from its name. |
| | | private static final Map<String, SizeUnit> nameToUnit; |
| | | static { |
| | | nameToUnit = new HashMap<String, SizeUnit>(); |
| | | // A lookup table for resolving a unit from its name. |
| | | private static final Map<String, SizeUnit> NAME_TO_UNIT; |
| | | static { |
| | | NAME_TO_UNIT = new HashMap<String, SizeUnit>(); |
| | | |
| | | for (SizeUnit unit : SizeUnit.values()) { |
| | | nameToUnit.put(unit.shortName, unit); |
| | | nameToUnit.put(unit.longName, unit); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the best-fit unit for the specified number of bytes. The |
| | | * returned unit will be able to represent the number of bytes using |
| | | * a decimal number comprising of an integer part which is greater |
| | | * than zero. Bigger units are chosen in preference to smaller units |
| | | * and binary units are only returned if they are an exact fit. If |
| | | * the number of bytes is zero then the {@link #BYTES} unit is |
| | | * always returned. For example: |
| | | * |
| | | * <pre> |
| | | * getBestFitUnit(0) // BYTES |
| | | * getBestFitUnit(999) // BYTES |
| | | * getBestFitUnit(1000) // KILO_BYTES |
| | | * getBestFitUnit(1024) // KIBI_BYTES |
| | | * getBestFitUnit(1025) // KILO_BYTES |
| | | * getBestFitUnit(999999) // KILO_BYTES |
| | | * getBestFitUnit(1000000) // MEGA_BYTES |
| | | * </pre> |
| | | * |
| | | * @param bytes |
| | | * The number of bytes. |
| | | * @return Returns the best fit unit. |
| | | * @throws IllegalArgumentException |
| | | * If <code>bytes</code> is negative. |
| | | * @see #getBestFitUnitExact(long) |
| | | */ |
| | | public static SizeUnit getBestFitUnit(long bytes) |
| | | throws IllegalArgumentException { |
| | | if (bytes < 0) { |
| | | throw new IllegalArgumentException("negative number of bytes: " + bytes); |
| | | } else if (bytes == 0) { |
| | | // Always use bytes for zero values. |
| | | return BYTES; |
| | | } else { |
| | | // Determine best fit: prefer non-binary units unless binary |
| | | // fits exactly. |
| | | SizeUnit[] nonBinary = new SizeUnit[] { TERA_BYTES, GIGA_BYTES, |
| | | MEGA_BYTES, KILO_BYTES }; |
| | | SizeUnit[] binary = new SizeUnit[] { TEBI_BYTES, GIBI_BYTES, MEBI_BYTES, |
| | | KIBI_BYTES }; |
| | | |
| | | for (int i = 0; i < nonBinary.length; i++) { |
| | | if ((bytes % binary[i].getSize()) == 0) { |
| | | return binary[i]; |
| | | } else if ((bytes / nonBinary[i].getSize()) > 0) { |
| | | return nonBinary[i]; |
| | | for (SizeUnit unit : SizeUnit.values()) { |
| | | NAME_TO_UNIT.put(unit.shortName, unit); |
| | | NAME_TO_UNIT.put(unit.longName, unit); |
| | | } |
| | | } |
| | | |
| | | return BYTES; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Gets the best-fit unit for the specified number of bytes. The returned |
| | | * unit will be able to represent the number of bytes using a decimal number |
| | | * comprising of an integer part which is greater than zero. Bigger units |
| | | * are chosen in preference to smaller units and binary units are only |
| | | * returned if they are an exact fit. If the number of bytes is zero then |
| | | * the {@link #BYTES} unit is always returned. For example: |
| | | * |
| | | * <pre> |
| | | * getBestFitUnit(0) // BYTES |
| | | * getBestFitUnit(999) // BYTES |
| | | * getBestFitUnit(1000) // KILO_BYTES |
| | | * getBestFitUnit(1024) // KIBI_BYTES |
| | | * getBestFitUnit(1025) // KILO_BYTES |
| | | * getBestFitUnit(999999) // KILO_BYTES |
| | | * getBestFitUnit(1000000) // MEGA_BYTES |
| | | * </pre> |
| | | * |
| | | * @param bytes |
| | | * The number of bytes. |
| | | * @return Returns the best fit unit. |
| | | * @throws IllegalArgumentException |
| | | * If <code>bytes</code> is negative. |
| | | * @see #getBestFitUnitExact(long) |
| | | */ |
| | | public static SizeUnit getBestFitUnit(long bytes) { |
| | | if (bytes < 0) { |
| | | throw new IllegalArgumentException("negative number of bytes: " + bytes); |
| | | } else if (bytes == 0) { |
| | | // Always use bytes for zero values. |
| | | return BYTES; |
| | | } else { |
| | | // Determine best fit: prefer non-binary units unless binary |
| | | // fits exactly. |
| | | SizeUnit[] nonBinary = new SizeUnit[] { TERA_BYTES, GIGA_BYTES, MEGA_BYTES, KILO_BYTES }; |
| | | SizeUnit[] binary = new SizeUnit[] { TEBI_BYTES, GIBI_BYTES, MEBI_BYTES, KIBI_BYTES }; |
| | | |
| | | for (int i = 0; i < nonBinary.length; i++) { |
| | | if ((bytes % binary[i].getSize()) == 0) { |
| | | return binary[i]; |
| | | } else if ((bytes / nonBinary[i].getSize()) > 0) { |
| | | return nonBinary[i]; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Gets the best-fit unit for the specified number of bytes which |
| | | * can represent the provided value using an integral value. Bigger |
| | | * units are chosen in preference to smaller units. If the number of |
| | | * bytes is zero then the {@link #BYTES} unit is always returned. |
| | | * For example: |
| | | * |
| | | * <pre> |
| | | * getBestFitUnitExact(0) // BYTES |
| | | * getBestFitUnitExact(999) // BYTES |
| | | * getBestFitUnitExact(1000) // KILO_BYTES |
| | | * getBestFitUnitExact(1024) // KIBI_BYTES |
| | | * getBestFitUnitExact(1025) // BYTES |
| | | * getBestFitUnitExact(999999) // BYTES |
| | | * getBestFitUnitExact(1000000) // MEGA_BYTES |
| | | * </pre> |
| | | * |
| | | * @param bytes |
| | | * The number of bytes. |
| | | * @return Returns the best fit unit can represent the provided |
| | | * value using an integral value. |
| | | * @throws IllegalArgumentException |
| | | * If <code>bytes</code> is negative. |
| | | * @see #getBestFitUnit(long) |
| | | */ |
| | | public static SizeUnit getBestFitUnitExact(long bytes) |
| | | throws IllegalArgumentException { |
| | | if (bytes < 0) { |
| | | throw new IllegalArgumentException("negative number of bytes: " + bytes); |
| | | } else if (bytes == 0) { |
| | | // Always use bytes for zero values. |
| | | return BYTES; |
| | | } else { |
| | | // Determine best fit. |
| | | SizeUnit[] units = new SizeUnit[] { TEBI_BYTES, TERA_BYTES, GIBI_BYTES, |
| | | GIGA_BYTES, MEBI_BYTES, MEGA_BYTES, KIBI_BYTES, KILO_BYTES }; |
| | | |
| | | for (SizeUnit unit : units) { |
| | | if ((bytes % unit.getSize()) == 0) { |
| | | return unit; |
| | | return BYTES; |
| | | } |
| | | } |
| | | |
| | | return BYTES; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the unit corresponding to the provided unit name. |
| | | * |
| | | * @param s |
| | | * The name of the unit. Can be the abbreviated or long |
| | | * name and can contain white space and mixed case |
| | | * characters. |
| | | * @return Returns the unit corresponding to the provided unit name. |
| | | * @throws IllegalArgumentException |
| | | * If the provided name did not correspond to a known |
| | | * memory size unit. |
| | | */ |
| | | public static SizeUnit getUnit(String s) throws IllegalArgumentException { |
| | | SizeUnit unit = nameToUnit.get(s.trim().toLowerCase()); |
| | | if (unit == null) { |
| | | throw new IllegalArgumentException("Illegal memory size unit \"" + s |
| | | + "\""); |
| | | } |
| | | return unit; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parse the provided size string and return its equivalent size in |
| | | * bytes. The size string must specify the unit e.g. "10kb". |
| | | * |
| | | * @param s |
| | | * The size string to be parsed. |
| | | * @return Returns the parsed duration in bytes. |
| | | * @throws NumberFormatException |
| | | * If the provided size string could not be parsed. |
| | | */ |
| | | public static long parseValue(String s) throws NumberFormatException { |
| | | return parseValue(s, null); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parse the provided size string and return its equivalent size in |
| | | * bytes. |
| | | * |
| | | * @param s |
| | | * The size string to be parsed. |
| | | * @param defaultUnit |
| | | * The default unit to use if there is no unit specified in |
| | | * the size string, or <code>null</code> if the string |
| | | * must always contain a unit. |
| | | * @return Returns the parsed size in bytes. |
| | | * @throws NumberFormatException |
| | | * If the provided size string could not be parsed. |
| | | */ |
| | | public static long parseValue(String s, SizeUnit defaultUnit) |
| | | throws NumberFormatException { |
| | | // Value must be a floating point number followed by a unit. |
| | | Pattern p = Pattern.compile("^\\s*(\\d+(\\.\\d+)?)\\s*(\\w+)?\\s*$"); |
| | | Matcher m = p.matcher(s); |
| | | |
| | | if (!m.matches()) { |
| | | throw new NumberFormatException("Invalid size value \"" + s + "\""); |
| | | } |
| | | |
| | | // Group 1 is the float. |
| | | double d; |
| | | try { |
| | | d = Double.valueOf(m.group(1)); |
| | | } catch (NumberFormatException e) { |
| | | throw new NumberFormatException("Invalid size value \"" + s + "\""); |
| | | /** |
| | | * Gets the best-fit unit for the specified number of bytes which can |
| | | * represent the provided value using an integral value. Bigger units are |
| | | * chosen in preference to smaller units. If the number of bytes is zero |
| | | * then the {@link #BYTES} unit is always returned. For example: |
| | | * |
| | | * <pre> |
| | | * getBestFitUnitExact(0) // BYTES |
| | | * getBestFitUnitExact(999) // BYTES |
| | | * getBestFitUnitExact(1000) // KILO_BYTES |
| | | * getBestFitUnitExact(1024) // KIBI_BYTES |
| | | * getBestFitUnitExact(1025) // BYTES |
| | | * getBestFitUnitExact(999999) // BYTES |
| | | * getBestFitUnitExact(1000000) // MEGA_BYTES |
| | | * </pre> |
| | | * |
| | | * @param bytes |
| | | * The number of bytes. |
| | | * @return Returns the best fit unit can represent the provided value using |
| | | * an integral value. |
| | | * @throws IllegalArgumentException |
| | | * If <code>bytes</code> is negative. |
| | | * @see #getBestFitUnit(long) |
| | | */ |
| | | public static SizeUnit getBestFitUnitExact(long bytes) { |
| | | if (bytes < 0) { |
| | | throw new IllegalArgumentException("negative number of bytes: " + bytes); |
| | | } else if (bytes == 0) { |
| | | // Always use bytes for zero values. |
| | | return BYTES; |
| | | } else { |
| | | // Determine best fit. |
| | | SizeUnit[] units = |
| | | new SizeUnit[] { TEBI_BYTES, TERA_BYTES, GIBI_BYTES, GIGA_BYTES, MEBI_BYTES, MEGA_BYTES, KIBI_BYTES, |
| | | KILO_BYTES }; |
| | | |
| | | for (SizeUnit unit : units) { |
| | | if ((bytes % unit.getSize()) == 0) { |
| | | return unit; |
| | | } |
| | | } |
| | | |
| | | return BYTES; |
| | | } |
| | | } |
| | | |
| | | // Group 3 is the unit. |
| | | String unitString = m.group(3); |
| | | SizeUnit unit; |
| | | if (unitString == null) { |
| | | if (defaultUnit == null) { |
| | | throw new NumberFormatException("Invalid size value \"" + s + "\""); |
| | | } else { |
| | | unit = defaultUnit; |
| | | } |
| | | } else { |
| | | try { |
| | | unit = getUnit(unitString); |
| | | } catch (IllegalArgumentException e) { |
| | | throw new NumberFormatException("Invalid size value \"" + s + "\""); |
| | | } |
| | | /** |
| | | * Get the unit corresponding to the provided unit name. |
| | | * |
| | | * @param s |
| | | * The name of the unit. Can be the abbreviated or long name and |
| | | * can contain white space and mixed case characters. |
| | | * @return Returns the unit corresponding to the provided unit name. |
| | | * @throws IllegalArgumentException |
| | | * If the provided name did not correspond to a known memory |
| | | * size unit. |
| | | */ |
| | | public static SizeUnit getUnit(String s) { |
| | | SizeUnit unit = NAME_TO_UNIT.get(s.trim().toLowerCase()); |
| | | if (unit == null) { |
| | | throw new IllegalArgumentException("Illegal memory size unit \"" + s + "\""); |
| | | } |
| | | return unit; |
| | | } |
| | | |
| | | return unit.toBytes(d); |
| | | } |
| | | |
| | | // The long name of the unit. |
| | | private final String longName; |
| | | |
| | | // The abbreviation of the unit. |
| | | private final String shortName; |
| | | |
| | | // The size of the unit in bytes. |
| | | private final long sz; |
| | | |
| | | |
| | | |
| | | // Private constructor. |
| | | private SizeUnit(long sz, String shortName, String longName) { |
| | | this.sz = sz; |
| | | this.shortName = shortName; |
| | | this.longName = longName; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Converts the specified size in bytes to this unit. |
| | | * |
| | | * @param amount |
| | | * The size in bytes. |
| | | * @return Returns size in this unit. |
| | | */ |
| | | public double fromBytes(long amount) { |
| | | return ((double) amount / sz); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the long name of this unit. |
| | | * |
| | | * @return Returns the long name of this unit. |
| | | */ |
| | | public String getLongName() { |
| | | return longName; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the abbreviated name of this unit. |
| | | * |
| | | * @return Returns the abbreviated name of this unit. |
| | | */ |
| | | public String getShortName() { |
| | | return shortName; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the number of bytes that this unit represents. |
| | | * |
| | | * @return Returns the number of bytes that this unit represents. |
| | | */ |
| | | public long getSize() { |
| | | return sz; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Converts the specified size in this unit to bytes. |
| | | * |
| | | * @param amount |
| | | * The size as a quantity of this unit. |
| | | * @return Returns the number of bytes that the size represents. |
| | | * |
| | | * @throws NumberFormatException |
| | | * If the provided size exceeded long.MAX_VALUE. |
| | | */ |
| | | public long toBytes(double amount) throws NumberFormatException { |
| | | double value = sz * amount; |
| | | if (value > Long.MAX_VALUE) |
| | | { |
| | | throw new NumberFormatException |
| | | ("number too big (exceeded long.MAX_VALUE"); |
| | | /** |
| | | * Parse the provided size string and return its equivalent size in bytes. |
| | | * The size string must specify the unit e.g. "10kb". |
| | | * |
| | | * @param s |
| | | * The size string to be parsed. |
| | | * @return Returns the parsed duration in bytes. |
| | | * @throws NumberFormatException |
| | | * If the provided size string could not be parsed. |
| | | */ |
| | | public static long parseValue(String s) { |
| | | return parseValue(s, null); |
| | | } |
| | | return (long) (value); |
| | | } |
| | | |
| | | /** |
| | | * Parse the provided size string and return its equivalent size in bytes. |
| | | * |
| | | * @param s |
| | | * The size string to be parsed. |
| | | * @param defaultUnit |
| | | * The default unit to use if there is no unit specified in the |
| | | * size string, or <code>null</code> if the string must always |
| | | * contain a unit. |
| | | * @return Returns the parsed size in bytes. |
| | | * @throws NumberFormatException |
| | | * If the provided size string could not be parsed. |
| | | */ |
| | | public static long parseValue(String s, SizeUnit defaultUnit) { |
| | | // Value must be a floating point number followed by a unit. |
| | | Pattern p = Pattern.compile("^\\s*(\\d+(\\.\\d+)?)\\s*(\\w+)?\\s*$"); |
| | | Matcher m = p.matcher(s); |
| | | |
| | | if (!m.matches()) { |
| | | throw new NumberFormatException("Invalid size value \"" + s + "\""); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | * <p> |
| | | * This implementation returns the abbreviated name of this size |
| | | * unit. |
| | | */ |
| | | @Override |
| | | public String toString() { |
| | | return shortName; |
| | | } |
| | | // Group 1 is the float. |
| | | double d; |
| | | try { |
| | | d = Double.valueOf(m.group(1)); |
| | | } catch (NumberFormatException e) { |
| | | throw new NumberFormatException("Invalid size value \"" + s + "\""); |
| | | } |
| | | |
| | | // Group 3 is the unit. |
| | | String unitString = m.group(3); |
| | | SizeUnit unit; |
| | | if (unitString == null) { |
| | | if (defaultUnit == null) { |
| | | throw new NumberFormatException("Invalid size value \"" + s + "\""); |
| | | } else { |
| | | unit = defaultUnit; |
| | | } |
| | | } else { |
| | | try { |
| | | unit = getUnit(unitString); |
| | | } catch (IllegalArgumentException e) { |
| | | throw new NumberFormatException("Invalid size value \"" + s + "\""); |
| | | } |
| | | } |
| | | |
| | | return unit.toBytes(d); |
| | | } |
| | | |
| | | // The long name of the unit. |
| | | private final String longName; |
| | | |
| | | // The abbreviation of the unit. |
| | | private final String shortName; |
| | | |
| | | // The size of the unit in bytes. |
| | | private final long sz; |
| | | |
| | | // Private constructor. |
| | | private SizeUnit(long sz, String shortName, String longName) { |
| | | this.sz = sz; |
| | | this.shortName = shortName; |
| | | this.longName = longName; |
| | | } |
| | | |
| | | /** |
| | | * Converts the specified size in bytes to this unit. |
| | | * |
| | | * @param amount |
| | | * The size in bytes. |
| | | * @return Returns size in this unit. |
| | | */ |
| | | public double fromBytes(long amount) { |
| | | return ((double) amount / sz); |
| | | } |
| | | |
| | | /** |
| | | * Get the long name of this unit. |
| | | * |
| | | * @return Returns the long name of this unit. |
| | | */ |
| | | public String getLongName() { |
| | | return longName; |
| | | } |
| | | |
| | | /** |
| | | * Get the abbreviated name of this unit. |
| | | * |
| | | * @return Returns the abbreviated name of this unit. |
| | | */ |
| | | public String getShortName() { |
| | | return shortName; |
| | | } |
| | | |
| | | /** |
| | | * Get the number of bytes that this unit represents. |
| | | * |
| | | * @return Returns the number of bytes that this unit represents. |
| | | */ |
| | | public long getSize() { |
| | | return sz; |
| | | } |
| | | |
| | | /** |
| | | * Converts the specified size in this unit to bytes. |
| | | * |
| | | * @param amount |
| | | * The size as a quantity of this unit. |
| | | * @return Returns the number of bytes that the size represents. |
| | | * @throws NumberFormatException |
| | | * If the provided size exceeded long.MAX_VALUE. |
| | | */ |
| | | public long toBytes(double amount) { |
| | | double value = sz * amount; |
| | | if (value > Long.MAX_VALUE) { |
| | | throw new NumberFormatException("number too big (exceeded long.MAX_VALUE"); |
| | | } |
| | | return (long) (value); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | * <p> |
| | | * This implementation returns the abbreviated name of this size unit. |
| | | */ |
| | | @Override |
| | | public String toString() { |
| | | return shortName; |
| | | } |
| | | } |
| | |
| | | /** |
| | | * An interface for incrementally constructing string property definitions. |
| | | */ |
| | | public static class Builder extends AbstractBuilder<String, StringPropertyDefinition> { |
| | | public static final class Builder extends AbstractBuilder<String, StringPropertyDefinition> { |
| | | |
| | | // Flag indicating whether values of this property are |
| | | // case-insensitive. |
| | |
| | | * If the provided regular expression pattern has an invalid |
| | | * syntax. |
| | | */ |
| | | public final void setPattern(String pattern, String patternUsage) throws PatternSyntaxException { |
| | | public final void setPattern(String pattern, String patternUsage) { |
| | | if (pattern == null) { |
| | | this.pattern = null; |
| | | this.patternUsage = null; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected StringPropertyDefinition buildInstance(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<String> defaultBehavior) { |
| | | protected StringPropertyDefinition buildInstance(AbstractManagedObjectDefinition<?, ?> d, |
| | | String propertyName, EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<String> defaultBehavior) { |
| | | return new StringPropertyDefinition(d, propertyName, options, adminAction, defaultBehavior, |
| | | isCaseInsensitive, pattern, patternUsage); |
| | | isCaseInsensitive, pattern, patternUsage); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | // Private constructor. |
| | | private StringPropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<String> defaultBehavior, boolean isCaseInsensitive, Pattern pattern, |
| | | String patternUsage) { |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | | DefaultBehaviorProvider<String> defaultBehavior, boolean isCaseInsensitive, Pattern pattern, |
| | | String patternUsage) { |
| | | super(d, String.class, propertyName, options, adminAction, defaultBehavior); |
| | | this.isCaseInsensitive = isCaseInsensitive; |
| | | this.pattern = pattern; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String decodeValue(String value) throws IllegalPropertyValueStringException { |
| | | public String decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String normalizeValue(String value) throws IllegalPropertyValueException { |
| | | public String normalizeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (isCaseInsensitive()) { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(String value) throws IllegalPropertyValueException { |
| | | public void validateValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (pattern != null) { |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.admin.meta.RootCfgDefn; |
| | | |
| | | |
| | | /** |
| | | * An interface for querying the properties of a tag. |
| | | * <p> |
| | |
| | | */ |
| | | public final class Tag implements Comparable<Tag> { |
| | | |
| | | // All the tags. |
| | | private static final Map<String, Tag> tags = new HashMap<String, Tag>(); |
| | | /** All the tags. */ |
| | | private static final Map<String, Tag> TAGS = new HashMap<String, Tag>(); |
| | | |
| | | /** |
| | | * Defines a new tag with the specified name. |
| | |
| | | Tag tag = new Tag(name); |
| | | |
| | | // Register the tag. |
| | | tags.put(name, tag); |
| | | TAGS.put(name, tag); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws IllegalArgumentException |
| | | * If the tag name was not recognized. |
| | | */ |
| | | public static Tag valueOf(String name) throws IllegalArgumentException { |
| | | public static Tag valueOf(String name) { |
| | | Reject.ifNull(name); |
| | | |
| | | // Hack to force initialization of the tag definitions. |
| | | RootCfgDefn.getInstance(); |
| | | |
| | | Tag tag = tags.get(name.toLowerCase()); |
| | | Tag tag = TAGS.get(name.toLowerCase()); |
| | | |
| | | if (tag == null) { |
| | | throw new IllegalArgumentException("Unknown tag \"" + name + "\""); |
| | |
| | | // Hack to force initialization of the tag definitions. |
| | | RootCfgDefn.getInstance(); |
| | | |
| | | return Collections.unmodifiableCollection(tags.values()); |
| | | return Collections.unmodifiableCollection(TAGS.values()); |
| | | } |
| | | |
| | | // The name of the tag. |
| | | /** The name of the tag. */ |
| | | private final String name; |
| | | |
| | | // Private constructor. |
| | | /** Private constructor. */ |
| | | private Tag(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | public final int compareTo(Tag o) { |
| | | return name.compareTo(o.name); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public final boolean equals(Object obj) { |
| | | if (this == obj) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public final int hashCode() { |
| | | return name.hashCode(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public final String toString() { |
| | | return name; |
| | |
| | | */ |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A default behavior provider which indicates undefined behavior. It should |
| | | * be used by properties which have no default values or behavior as such. For |
| | | * A default behavior provider which indicates undefined behavior. It should be |
| | | * used by properties which have no default values or behavior as such. For |
| | | * example, a description property, when left unset, has no default value and no |
| | | * side-effects. |
| | | * |
| | | * @param <T> |
| | | * The type of values represented by this provider. |
| | | * The type of values represented by this provider. |
| | | */ |
| | | public final class UndefinedDefaultBehaviorProvider<T> extends |
| | | DefaultBehaviorProvider<T> { |
| | | public final class UndefinedDefaultBehaviorProvider<T> extends DefaultBehaviorProvider<T> { |
| | | |
| | | /** |
| | | * Create an undefined default behavior provider. |
| | | */ |
| | | public UndefinedDefaultBehaviorProvider() { |
| | | // No implementation required. |
| | | } |
| | | /** |
| | | * Create an undefined default behavior provider. |
| | | */ |
| | | public UndefinedDefaultBehaviorProvider() { |
| | | // No implementation required. |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <R, P> R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p) { |
| | | return v.visitUndefined(this, p); |
| | | } |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <R, P> R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p) { |
| | | return v.visitUndefined(this, p); |
| | | } |
| | | |
| | | } |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | |
| | | * A list of messages to which error messages should be added. |
| | | * @return Returns <code>true</code> if this constraint is satisfied, or |
| | | * <code>false</code> if it is not. |
| | | * @throws AuthorizationException |
| | | * If an authorization failure prevented this constraint from |
| | | * being evaluated. |
| | | * @throws CommunicationException |
| | | * If a communications problem prevented this constraint from |
| | | * being evaluated. |
| | | * @throws ErrorResultException |
| | | * If an error occurs. |
| | | */ |
| | | public boolean isAddAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | return true; |
| | | } |
| | | |
| | |
| | | * A list of messages to which error messages should be added. |
| | | * @return Returns <code>true</code> if this modify is satisfied, or |
| | | * <code>false</code> if it is not. |
| | | * @throws AuthorizationException |
| | | * If an authorization failure prevented this constraint from |
| | | * being evaluated. |
| | | * @throws CommunicationException |
| | | * If a communications problem prevented this constraint from |
| | | * being evaluated. |
| | | * @throws ErrorResultException |
| | | * If an error occurs. |
| | | */ |
| | | public boolean isModifyAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | return true; |
| | | } |
| | | |
| | |
| | | * If an error occurs. |
| | | */ |
| | | public boolean isDeleteAcceptable(ManagementContext context, ManagedObjectPath<?, ?> path, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | return true; |
| | | } |
| | | } |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | |
| | | |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.opends.server.admin.OperationsException; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This exception is thrown when a critical concurrent modification is |
| | | * detected by the client. This may be caused by another client |
| | | * application removing a managed object whilst it is being managed. |
| | | * This exception is thrown when a critical concurrent modification is detected |
| | | * by the client. This may be caused by another client application removing a |
| | | * managed object whilst it is being managed. |
| | | */ |
| | | public class ConcurrentModificationException extends OperationsException { |
| | | |
| | | /** |
| | | * Serialization ID. |
| | | */ |
| | | private static final long serialVersionUID = -1467024486347612820L; |
| | | /** |
| | | * Serialization ID. |
| | | */ |
| | | private static final long serialVersionUID = -1467024486347612820L; |
| | | |
| | | /** |
| | | * Create a concurrent modification exception with a default message. |
| | | */ |
| | | public ConcurrentModificationException() { |
| | | super(ERR_CONCURRENT_MODIFICATION_EXCEPTION_DEFAULT.get()); |
| | | } |
| | | |
| | | /** |
| | | * Create a concurrent modification exception with a cause and a default |
| | | * message. |
| | | * |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | public ConcurrentModificationException(Throwable cause) { |
| | | super(ERR_CONCURRENT_MODIFICATION_EXCEPTION_DEFAULT.get(), cause); |
| | | } |
| | | |
| | | /** |
| | | * Create a concurrent modification exception with a default |
| | | * message. |
| | | */ |
| | | public ConcurrentModificationException() { |
| | | super(ERR_CONCURRENT_MODIFICATION_EXCEPTION_DEFAULT.get()); |
| | | } |
| | | /** |
| | | * Create a concurrent modification exception with a message and cause. |
| | | * |
| | | * @param message |
| | | * The message. |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | public ConcurrentModificationException(LocalizableMessage message, Throwable cause) { |
| | | super(message, cause); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a concurrent modification exception with a cause and a |
| | | * default message. |
| | | * |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | public ConcurrentModificationException(Throwable cause) { |
| | | super(ERR_CONCURRENT_MODIFICATION_EXCEPTION_DEFAULT.get(), cause); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a concurrent modification exception with a message and |
| | | * cause. |
| | | * |
| | | * @param message |
| | | * The message. |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | public ConcurrentModificationException(LocalizableMessage message, Throwable cause) { |
| | | super(message, cause); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a concurrent modification exception with a message. |
| | | * |
| | | * @param message |
| | | * The message. |
| | | */ |
| | | public ConcurrentModificationException(LocalizableMessage message) { |
| | | super(message); |
| | | } |
| | | /** |
| | | * Create a concurrent modification exception with a message. |
| | | * |
| | | * @param message |
| | | * The message. |
| | | */ |
| | | public ConcurrentModificationException(LocalizableMessage message) { |
| | | super(message); |
| | | } |
| | | } |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | |
| | | |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | |
| | | import org.opends.server.admin.PropertyDefinition; |
| | | import org.opends.server.admin.PropertyDefinitionUsageBuilder; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Thrown when an attempt is made to create a new managed object with |
| | | * an illegal name. |
| | | * Thrown when an attempt is made to create a new managed object with an illegal |
| | | * name. |
| | | * <p> |
| | | * This exception can occur when a new managed object is given a name |
| | | * which is either an empty string, a string containing just |
| | | * white-spaces, or a string which is invalid according to the managed |
| | | * object's naming property (if it has one). |
| | | * This exception can occur when a new managed object is given a name which is |
| | | * either an empty string, a string containing just white-spaces, or a string |
| | | * which is invalid according to the managed object's naming property (if it has |
| | | * one). |
| | | */ |
| | | public class IllegalManagedObjectNameException extends OperationsException { |
| | | |
| | | /** |
| | | * Serialization ID. |
| | | */ |
| | | private static final long serialVersionUID = 7491748228684293291L; |
| | | /** |
| | | * Serialization ID. |
| | | */ |
| | | private static final long serialVersionUID = 7491748228684293291L; |
| | | |
| | | /** Create the message. */ |
| | | // @Checkstyle:ignore |
| | | private static LocalizableMessage createMessage(String illegalName, PropertyDefinition<?> namingPropertyDefinition) { |
| | | if (illegalName.length() == 0) { |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_EMPTY.get(); |
| | | } else if (illegalName.trim().length() == 0) { |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_BLANK.get(); |
| | | } else if (namingPropertyDefinition != null) { |
| | | try { |
| | | namingPropertyDefinition.decodeValue(illegalName); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | PropertyDefinitionUsageBuilder builder = new PropertyDefinitionUsageBuilder(true); |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_SYNTAX.get(illegalName, |
| | | namingPropertyDefinition.getName(), builder.getUsage(namingPropertyDefinition)); |
| | | } |
| | | } |
| | | |
| | | |
| | | // Create the message |
| | | private static LocalizableMessage createMessage(String illegalName, |
| | | PropertyDefinition<?> namingPropertyDefinition) { |
| | | if (illegalName.length() == 0) { |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_EMPTY.get(); |
| | | } else if (illegalName.trim().length() == 0) { |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_BLANK.get(); |
| | | } else if (namingPropertyDefinition != null) { |
| | | try { |
| | | namingPropertyDefinition.decodeValue(illegalName); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | PropertyDefinitionUsageBuilder builder = |
| | | new PropertyDefinitionUsageBuilder(true); |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_SYNTAX.get( |
| | | illegalName, namingPropertyDefinition.getName(), builder |
| | | .getUsage(namingPropertyDefinition)); |
| | | } |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_OTHER.get(illegalName); |
| | | } |
| | | |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_OTHER.get(illegalName); |
| | | } |
| | | /** The illegal name. */ |
| | | private final String illegalName; |
| | | |
| | | // The illegal name. |
| | | private final String illegalName; |
| | | /** The naming property definition if applicable. */ |
| | | private final PropertyDefinition<?> namingPropertyDefinition; |
| | | |
| | | // The naming property definition if applicable. |
| | | private final PropertyDefinition<?> namingPropertyDefinition; |
| | | /** |
| | | * Create a new illegal name exception and no naming property definition. |
| | | * |
| | | * @param illegalName |
| | | * The illegal managed object name. |
| | | */ |
| | | public IllegalManagedObjectNameException(String illegalName) { |
| | | this(illegalName, null); |
| | | } |
| | | |
| | | /** |
| | | * Create a new illegal name exception and a naming property definition. |
| | | * |
| | | * @param illegalName |
| | | * The illegal managed object name. |
| | | * @param namingPropertyDefinition |
| | | * The naming property definition. |
| | | */ |
| | | public IllegalManagedObjectNameException(String illegalName, PropertyDefinition<?> namingPropertyDefinition) { |
| | | super(createMessage(illegalName, namingPropertyDefinition)); |
| | | |
| | | this.illegalName = illegalName; |
| | | this.namingPropertyDefinition = namingPropertyDefinition; |
| | | } |
| | | |
| | | /** |
| | | * Create a new illegal name exception and no naming property |
| | | * definition. |
| | | * |
| | | * @param illegalName |
| | | * The illegal managed object name. |
| | | */ |
| | | public IllegalManagedObjectNameException(String illegalName) { |
| | | this(illegalName, null); |
| | | } |
| | | /** |
| | | * Get the illegal managed object name. |
| | | * |
| | | * @return Returns the illegal managed object name. |
| | | */ |
| | | public String getIllegalName() { |
| | | return illegalName; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a new illegal name exception and a naming property |
| | | * definition. |
| | | * |
| | | * @param illegalName |
| | | * The illegal managed object name. |
| | | * @param namingPropertyDefinition |
| | | * The naming property definition. |
| | | */ |
| | | public IllegalManagedObjectNameException(String illegalName, |
| | | PropertyDefinition<?> namingPropertyDefinition) { |
| | | super(createMessage(illegalName, namingPropertyDefinition)); |
| | | |
| | | this.illegalName = illegalName; |
| | | this.namingPropertyDefinition = namingPropertyDefinition; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the illegal managed object name. |
| | | * |
| | | * @return Returns the illegal managed object name. |
| | | */ |
| | | public String getIllegalName() { |
| | | return illegalName; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the naming property definition if applicable. |
| | | * |
| | | * @return Returns naming property definition, or <code>null</code> |
| | | * if none was specified. |
| | | */ |
| | | public PropertyDefinition<?> getNamingPropertyDefinition() { |
| | | return namingPropertyDefinition; |
| | | } |
| | | /** |
| | | * Get the naming property definition if applicable. |
| | | * |
| | | * @return Returns naming property definition, or <code>null</code> if none |
| | | * was specified. |
| | | */ |
| | | public PropertyDefinition<?> getNamingPropertyDefinition() { |
| | | return namingPropertyDefinition; |
| | | } |
| | | |
| | | } |
| | |
| | | import org.opends.server.admin.Configuration; |
| | | import org.opends.server.admin.DefaultBehaviorException; |
| | | import org.opends.server.admin.DefinitionDecodingException; |
| | | import org.opends.server.admin.IllegalPropertyValueException; |
| | | import org.opends.server.admin.InstantiableRelationDefinition; |
| | | import org.opends.server.admin.ManagedObjectAlreadyExistsException; |
| | | import org.opends.server.admin.ManagedObjectDefinition; |
| | |
| | | * @param <S> |
| | | * The expected type of the child managed object server |
| | | * configuration. |
| | | * @param <CC> |
| | | * @param <C1> |
| | | * The actual type of the added managed object configuration |
| | | * client. |
| | | * @param r |
| | |
| | | * If the relation definition is not associated with this |
| | | * managed object's definition. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration, CC extends C> ManagedObject<CC> createChild( |
| | | InstantiableRelationDefinition<C, S> r, ManagedObjectDefinition<CC, ? extends S> d, String name, |
| | | Collection<DefaultBehaviorException> exceptions) throws IllegalManagedObjectNameException, |
| | | IllegalArgumentException; |
| | | <C extends ConfigurationClient, S extends Configuration, C1 extends C> ManagedObject<C1> createChild( |
| | | InstantiableRelationDefinition<C, S> r, ManagedObjectDefinition<C1, ? extends S> d, String name, |
| | | Collection<DefaultBehaviorException> exceptions) throws IllegalManagedObjectNameException; |
| | | |
| | | /** |
| | | * Creates a new child managed object bound to the specified optional |
| | |
| | | * @param <S> |
| | | * The expected type of the child managed object server |
| | | * configuration. |
| | | * @param <CC> |
| | | * @param <C1> |
| | | * The actual type of the added managed object configuration |
| | | * client. |
| | | * @param r |
| | |
| | | * If the relation definition is not associated with this |
| | | * managed object's definition. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration, CC extends C> ManagedObject<CC> createChild( |
| | | OptionalRelationDefinition<C, S> r, ManagedObjectDefinition<CC, ? extends S> d, |
| | | Collection<DefaultBehaviorException> exceptions) throws IllegalArgumentException; |
| | | <C extends ConfigurationClient, S extends Configuration, C1 extends C> ManagedObject<C1> createChild( |
| | | OptionalRelationDefinition<C, S> r, ManagedObjectDefinition<C1, ? extends S> d, |
| | | Collection<DefaultBehaviorException> exceptions); |
| | | |
| | | /** |
| | | * Creates a new child managed object bound to the specified set relation. |
| | |
| | | * @param <S> |
| | | * The expected type of the child managed object server |
| | | * configuration. |
| | | * @param <CC> |
| | | * @param <C1> |
| | | * The actual type of the added managed object configuration |
| | | * client. |
| | | * @param r |
| | |
| | | * If the relation definition is not associated with this |
| | | * managed object's definition. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration, CC extends C> ManagedObject<CC> createChild( |
| | | SetRelationDefinition<C, S> r, ManagedObjectDefinition<CC, ? extends S> d, |
| | | Collection<DefaultBehaviorException> exceptions) throws IllegalArgumentException; |
| | | <C extends ConfigurationClient, S extends Configuration, C1 extends C> ManagedObject<C1> createChild( |
| | | SetRelationDefinition<C, S> r, ManagedObjectDefinition<C1, ? extends S> d, |
| | | Collection<DefaultBehaviorException> exceptions); |
| | | |
| | | /** |
| | | * Retrieves an instantiable child managed object. |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | InstantiableRelationDefinition<C, S> r, String name) throws IllegalArgumentException, |
| | | InstantiableRelationDefinition<C, S> r, String name) throws |
| | | DefinitionDecodingException, ManagedObjectDecodingException, ManagedObjectNotFoundException, |
| | | ConcurrentModificationException, ErrorResultException; |
| | | |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | OptionalRelationDefinition<C, S> r) throws IllegalArgumentException, DefinitionDecodingException, |
| | | OptionalRelationDefinition<C, S> r) throws DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException; |
| | | |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | SingletonRelationDefinition<C, S> r) throws IllegalArgumentException, DefinitionDecodingException, |
| | | SingletonRelationDefinition<C, S> r) throws DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException; |
| | | |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | SetRelationDefinition<C, S> r, String name) throws IllegalArgumentException, DefinitionDecodingException, |
| | | SetRelationDefinition<C, S> r, String name) throws DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException; |
| | | |
| | |
| | | * Gets a mutable copy of the set of default values for the specified |
| | | * property. |
| | | * |
| | | * @param <PD> |
| | | * @param <P> |
| | | * The type of the property to be retrieved. |
| | | * @param pd |
| | | * The property to be retrieved. |
| | |
| | | * If the property definition is not associated with this |
| | | * managed object's definition. |
| | | */ |
| | | <PD> SortedSet<PD> getPropertyDefaultValues(PropertyDefinition<PD> pd) throws IllegalArgumentException; |
| | | <P> SortedSet<P> getPropertyDefaultValues(PropertyDefinition<P> pd); |
| | | |
| | | /** |
| | | * Gets the effective value of the specified property. |
| | |
| | | * See the class description for more information about how the effective |
| | | * property value is derived. |
| | | * |
| | | * @param <PD> |
| | | * @param <P> |
| | | * The type of the property to be retrieved. |
| | | * @param pd |
| | | * The property to be retrieved. |
| | |
| | | * If the property definition is not associated with this |
| | | * managed object's definition. |
| | | */ |
| | | <PD> PD getPropertyValue(PropertyDefinition<PD> pd) throws IllegalArgumentException; |
| | | <P> P getPropertyValue(PropertyDefinition<P> pd); |
| | | |
| | | /** |
| | | * Gets a mutable copy of the set of effective values for the specified |
| | |
| | | * See the class description for more information about how the effective |
| | | * property values are derived. |
| | | * |
| | | * @param <PD> |
| | | * @param <P> |
| | | * The type of the property to be retrieved. |
| | | * @param pd |
| | | * The property to be retrieved. |
| | |
| | | * If the property definition is not associated with this |
| | | * managed object's definition. |
| | | */ |
| | | <PD> SortedSet<PD> getPropertyValues(PropertyDefinition<PD> pd) throws IllegalArgumentException; |
| | | @Override |
| | | <P> SortedSet<P> getPropertyValues(PropertyDefinition<P> pd); |
| | | |
| | | /** |
| | | * Determines whether or not the specified property is set. If the property |
| | |
| | | * If the property definition is not associated with this |
| | | * managed object's definition. |
| | | */ |
| | | boolean isPropertyPresent(PropertyDefinition<?> pd) throws IllegalArgumentException; |
| | | boolean isPropertyPresent(PropertyDefinition<?> pd); |
| | | |
| | | /** |
| | | * Determines whether or not the optional managed object associated with the |
| | |
| | | * The optional relation definition. |
| | | * @return Returns <code>true</code> if the optional managed object exists, |
| | | * <code>false</code> otherwise. |
| | | * @throws IllegalArgumentException |
| | | * If the relation definition is not associated with this |
| | | * managed object's definition. |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | |
| | | * If there is any other error. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> boolean hasChild(OptionalRelationDefinition<C, S> r) |
| | | throws IllegalArgumentException, ConcurrentModificationException, ErrorResultException; |
| | | throws ConcurrentModificationException, ErrorResultException; |
| | | |
| | | /** |
| | | * Lists the child managed objects associated with the specified |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> String[] listChildren( |
| | | InstantiableRelationDefinition<C, S> r) throws IllegalArgumentException, ConcurrentModificationException, |
| | | InstantiableRelationDefinition<C, S> r) throws ConcurrentModificationException, |
| | | ErrorResultException; |
| | | |
| | | /** |
| | |
| | | * The managed object definition. |
| | | * @return Returns the names of the child managed objects which are a |
| | | * sub-type of the specified managed object definition. |
| | | * @throws IllegalArgumentException |
| | | * If the relation definition is not associated with this |
| | | * managed object's definition. |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> String[] listChildren( |
| | | InstantiableRelationDefinition<C, S> r, AbstractManagedObjectDefinition<? extends C, ? extends S> d) |
| | | throws IllegalArgumentException, ConcurrentModificationException, ErrorResultException; |
| | | throws ConcurrentModificationException, ErrorResultException; |
| | | |
| | | /** |
| | | * Lists the child managed objects associated with the specified set |
| | |
| | | * The set relation definition. |
| | | * @return Returns the names of the child managed objects which for set |
| | | * relations are the definition names of each managed object. |
| | | * @throws IllegalArgumentException |
| | | * If the relation definition is not associated with this |
| | | * managed object's definition. |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> String[] listChildren(SetRelationDefinition<C, S> r) |
| | | throws IllegalArgumentException, ConcurrentModificationException, ErrorResultException; |
| | | throws ConcurrentModificationException, ErrorResultException; |
| | | |
| | | /** |
| | | * Lists the child managed objects associated with the specified set |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> String[] listChildren(SetRelationDefinition<C, S> r, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws IllegalArgumentException, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws |
| | | ConcurrentModificationException, ErrorResultException; |
| | | |
| | | /** |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> void removeChild(InstantiableRelationDefinition<C, S> r, |
| | | String name) throws IllegalArgumentException, ManagedObjectNotFoundException, OperationRejectedException, |
| | | String name) throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ConcurrentModificationException, ErrorResultException; |
| | | |
| | | /** |
| | |
| | | * relation definition refers to. |
| | | * @param r |
| | | * The optional relation definition. |
| | | * @throws IllegalArgumentException |
| | | * If the relation definition is not associated with this |
| | | * managed object's definition. |
| | | * @throws ManagedObjectNotFoundException |
| | | * If the managed object could not be removed because it could |
| | | * not found on the server. |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> void removeChild(OptionalRelationDefinition<C, S> r) |
| | | throws IllegalArgumentException, ManagedObjectNotFoundException, OperationRejectedException, |
| | | throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ConcurrentModificationException, ErrorResultException; |
| | | |
| | | /** |
| | |
| | | * The set relation definition. |
| | | * @param name |
| | | * The name of the child managed object to be removed. |
| | | * @throws IllegalArgumentException |
| | | * If the relation definition is not associated with this |
| | | * managed object's definition. |
| | | * @throws ManagedObjectNotFoundException |
| | | * If the managed object could not be removed because it could |
| | | * not found on the server. |
| | |
| | | * @throws ErrorResultException |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> void removeChild(SetRelationDefinition<C, S> r, String name) |
| | | throws IllegalArgumentException, ManagedObjectNotFoundException, OperationRejectedException, |
| | | <C extends ConfigurationClient, S extends Configuration> void removeChild(SetRelationDefinition<C, S> r, |
| | | String name) throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ConcurrentModificationException, ErrorResultException; |
| | | |
| | | /** |
| | |
| | | * <p> |
| | | * See the class description for more information regarding pending values. |
| | | * |
| | | * @param <PD> |
| | | * @param <P> |
| | | * The type of the property to be modified. |
| | | * @param pd |
| | | * The property to be modified. |
| | | * @param value |
| | | * The new pending value for the property, or <code>null</code> |
| | | * if the property should be reset to its default behavior. |
| | | * @throws IllegalPropertyValueException |
| | | * If the new pending value is deemed to be invalid according to |
| | | * the property definition. |
| | | * @throws PropertyIsReadOnlyException |
| | | * If this is not a new managed object and the property is |
| | | * read-only or for monitoring purposes. |
| | | * @throws PropertyIsMandatoryException |
| | | * If an attempt was made to remove a mandatory property. |
| | | * @throws IllegalArgumentException |
| | | * If the specified property definition is not associated with |
| | | * this managed object. |
| | | */ |
| | | <PD> void setPropertyValue(PropertyDefinition<PD> pd, PD value) throws IllegalPropertyValueException, |
| | | PropertyIsReadOnlyException, PropertyIsMandatoryException, IllegalArgumentException; |
| | | <P> void setPropertyValue(PropertyDefinition<P> pd, P value); |
| | | |
| | | /** |
| | | * Sets a new pending values for the specified property. |
| | | * <p> |
| | | * See the class description for more information regarding pending values. |
| | | * |
| | | * @param <PD> |
| | | * @param <P> |
| | | * The type of the property to be modified. |
| | | * @param pd |
| | | * The property to be modified. |
| | |
| | | * 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 IllegalPropertyValueException |
| | | * If a new pending value is deemed to be invalid according to |
| | | * the property definition. |
| | | * @throws PropertyIsSingleValuedException |
| | | * If an attempt was made to add multiple pending values to a |
| | | * single-valued property. |
| | |
| | | * read-only or for monitoring purposes. |
| | | * @throws PropertyIsMandatoryException |
| | | * If an attempt was made to remove a mandatory property. |
| | | * @throws IllegalArgumentException |
| | | * If the specified property definition is not associated with |
| | | * this managed object. |
| | | */ |
| | | <PD> void setPropertyValues(PropertyDefinition<PD> pd, Collection<PD> values) throws IllegalPropertyValueException, |
| | | PropertyIsSingleValuedException, PropertyIsReadOnlyException, PropertyIsMandatoryException, |
| | | IllegalArgumentException; |
| | | <P> void setPropertyValues(PropertyDefinition<P> pd, Collection<P> values); |
| | | |
| | | } |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | |
| | | |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | | |
| | | import java.util.Collection; |
| | |
| | | import org.opends.server.admin.ManagedObjectDefinition; |
| | | import org.opends.server.admin.PropertyException; |
| | | |
| | | |
| | | |
| | | /** |
| | | * The requested managed object was found but one or more of its |
| | | * properties could not be decoded successfully. |
| | | * The requested managed object was found but one or more of its properties |
| | | * could not be decoded successfully. |
| | | */ |
| | | public class ManagedObjectDecodingException extends DecodingException { |
| | | |
| | | /** |
| | | * Version ID required by serializable classes. |
| | | */ |
| | | private static final long serialVersionUID = -4268510652395945357L; |
| | | /** |
| | | * Version ID required by serializable classes. |
| | | */ |
| | | private static final long serialVersionUID = -4268510652395945357L; |
| | | |
| | | // Create the message. |
| | | private static LocalizableMessage createMessage(ManagedObject<?> partialManagedObject, |
| | | Collection<PropertyException> causes) { |
| | | Reject.ifNull(causes); |
| | | Reject.ifFalse(!causes.isEmpty(), "causes should not be empty"); |
| | | |
| | | ManagedObjectDefinition<?, ?> d = partialManagedObject.getManagedObjectDefinition(); |
| | | if (causes.size() == 1) { |
| | | return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_SINGLE.get(d.getUserFriendlyName(), causes.iterator().next() |
| | | .getLocalizableMessageObject()); |
| | | } else { |
| | | LocalizableMessageBuilder builder = new LocalizableMessageBuilder(); |
| | | |
| | | // Create the message. |
| | | private static LocalizableMessage createMessage(ManagedObject<?> partialManagedObject, |
| | | Collection<PropertyException> causes) { |
| | | Reject.ifNull(causes); |
| | | Reject.ifFalse(!causes.isEmpty(), "causes should not be empty"); |
| | | boolean isFirst = true; |
| | | for (PropertyException cause : causes) { |
| | | if (!isFirst) { |
| | | builder.append("; "); |
| | | } |
| | | builder.append(cause.getLocalizableMessageObject()); |
| | | isFirst = false; |
| | | } |
| | | |
| | | ManagedObjectDefinition<?, ?> d = partialManagedObject |
| | | .getManagedObjectDefinition(); |
| | | if (causes.size() == 1) { |
| | | return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_SINGLE.get(d |
| | | .getUserFriendlyName(), causes.iterator().next().getLocalizableMessageObject()); |
| | | } else { |
| | | LocalizableMessageBuilder builder = new LocalizableMessageBuilder(); |
| | | |
| | | boolean isFirst = true; |
| | | for (PropertyException cause : causes) { |
| | | if (!isFirst) { |
| | | builder.append("; "); |
| | | return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_PLURAL.get(d.getUserFriendlyName(), builder.toMessage()); |
| | | } |
| | | builder.append(cause.getLocalizableMessageObject()); |
| | | isFirst = false; |
| | | } |
| | | |
| | | return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_PLURAL.get(d |
| | | .getUserFriendlyName(), builder.toMessage()); |
| | | } |
| | | } |
| | | |
| | | // The exception(s) that caused this decoding exception. |
| | | private final Collection<PropertyException> causes; |
| | | // The exception(s) that caused this decoding exception. |
| | | private final Collection<PropertyException> causes; |
| | | |
| | | // The partially created managed object. |
| | | private final ManagedObject<?> partialManagedObject; |
| | | // The partially created managed object. |
| | | private final ManagedObject<?> partialManagedObject; |
| | | |
| | | /** |
| | | * Create a new property decoding exception. |
| | | * |
| | | * @param partialManagedObject |
| | | * The partially created managed object containing properties |
| | | * which were successfully decoded and empty properties for those |
| | | * which were not (this may include empty mandatory properties). |
| | | * @param causes |
| | | * The exception(s) that caused this decoding exception. |
| | | */ |
| | | public ManagedObjectDecodingException(ManagedObject<?> partialManagedObject, Collection<PropertyException> causes) { |
| | | super(createMessage(partialManagedObject, causes)); |
| | | |
| | | this.partialManagedObject = partialManagedObject; |
| | | this.causes = Collections.unmodifiableList(new LinkedList<PropertyException>(causes)); |
| | | } |
| | | |
| | | /** |
| | | * Create a new property decoding exception. |
| | | * |
| | | * @param partialManagedObject |
| | | * The partially created managed object containing |
| | | * properties which were successfully decoded and empty |
| | | * properties for those which were not (this may include |
| | | * empty mandatory properties). |
| | | * @param causes |
| | | * The exception(s) that caused this decoding exception. |
| | | */ |
| | | public ManagedObjectDecodingException(ManagedObject<?> partialManagedObject, |
| | | Collection<PropertyException> causes) { |
| | | super(createMessage(partialManagedObject, causes)); |
| | | /** |
| | | * Get an unmodifiable collection view of the causes of this exception. |
| | | * |
| | | * @return Returns an unmodifiable collection view of the causes of this |
| | | * exception. |
| | | */ |
| | | public Collection<PropertyException> getCauses() { |
| | | return causes; |
| | | } |
| | | |
| | | this.partialManagedObject = partialManagedObject; |
| | | this.causes = Collections |
| | | .unmodifiableList(new LinkedList<PropertyException>(causes)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get an unmodifiable collection view of the causes of this |
| | | * exception. |
| | | * |
| | | * @return Returns an unmodifiable collection view of the causes of |
| | | * this exception. |
| | | */ |
| | | public Collection<PropertyException> getCauses() { |
| | | return causes; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the partially created managed object containing properties |
| | | * which were successfully decoded and empty properties for those |
| | | * which were not (this may include empty mandatory properties). |
| | | * |
| | | * @return Returns the partially created managed object containing |
| | | * properties which were successfully decoded and empty |
| | | * properties for those which were not (this may include |
| | | * empty mandatory properties). |
| | | */ |
| | | public ManagedObject<?> getPartialManagedObject() { |
| | | return partialManagedObject; |
| | | } |
| | | /** |
| | | * Get the partially created managed object containing properties which were |
| | | * successfully decoded and empty properties for those which were not (this |
| | | * may include empty mandatory properties). |
| | | * |
| | | * @return Returns the partially created managed object containing |
| | | * properties which were successfully decoded and empty properties |
| | | * for those which were not (this may include empty mandatory |
| | | * properties). |
| | | */ |
| | | public ManagedObject<?> getPartialManagedObject() { |
| | | return partialManagedObject; |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, String name) |
| | | throws IllegalArgumentException, ManagedObjectNotFoundException, OperationRejectedException, |
| | | throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ErrorResultException { |
| | | return getDriver().deleteManagedObject(parent, rd, name); |
| | | } |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( |
| | | ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd) throws IllegalArgumentException, |
| | | ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd) throws |
| | | ManagedObjectNotFoundException, OperationRejectedException, ErrorResultException { |
| | | return getDriver().deleteManagedObject(parent, rd); |
| | | } |
| | |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( |
| | | ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, String name) |
| | | throws IllegalArgumentException, ManagedObjectNotFoundException, OperationRejectedException, |
| | | throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ErrorResultException { |
| | | return getDriver().deleteManagedObject(parent, rd, name); |
| | | } |
| | |
| | | /** |
| | | * Gets the effective value of a property in the named managed object. |
| | | * |
| | | * @param <PD> |
| | | * @param <P> |
| | | * The type of the property to be retrieved. |
| | | * @param path |
| | | * The path of the managed object containing the property. |
| | |
| | | * @throws ErrorResultException |
| | | * If any other error occurs. |
| | | */ |
| | | public final <PD> PD getPropertyValue(ManagedObjectPath<?, ?> path, PropertyDefinition<PD> pd) |
| | | throws IllegalArgumentException, DefinitionDecodingException, ErrorResultException, |
| | | ManagedObjectNotFoundException, PropertyException { |
| | | Set<PD> values = getPropertyValues(path, pd); |
| | | public final <P> P getPropertyValue(ManagedObjectPath<?, ?> path, PropertyDefinition<P> pd) |
| | | throws DefinitionDecodingException, ErrorResultException, ManagedObjectNotFoundException { |
| | | Set<P> values = getPropertyValues(path, pd); |
| | | if (values.isEmpty()) { |
| | | return null; |
| | | } else { |
| | |
| | | /** |
| | | * Gets the effective values of a property in the named managed object. |
| | | * |
| | | * @param <PD> |
| | | * @param <P> |
| | | * The type of the property to be retrieved. |
| | | * @param path |
| | | * The path of the managed object containing the property. |
| | |
| | | * @throws ErrorResultException |
| | | * If any other error occurs. |
| | | */ |
| | | public final <PD> SortedSet<PD> getPropertyValues(ManagedObjectPath<?, ?> path, PropertyDefinition<PD> pd) |
| | | throws IllegalArgumentException, DefinitionDecodingException, ErrorResultException, |
| | | ManagedObjectNotFoundException, PropertyException { |
| | | public final <P> SortedSet<P> getPropertyValues(ManagedObjectPath<?, ?> path, PropertyDefinition<P> pd) |
| | | throws DefinitionDecodingException, ErrorResultException, ManagedObjectNotFoundException { |
| | | return getDriver().getPropertyValues(path, pd); |
| | | } |
| | | |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd) throws IllegalArgumentException, |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd) throws |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | return listManagedObjects(parent, rd, rd.getChildDefinition()); |
| | | } |
| | |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws IllegalArgumentException, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | return getDriver().listManagedObjects(parent, rd, d); |
| | | } |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd) throws IllegalArgumentException, |
| | | ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd) throws |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | return getDriver().listManagedObjects(parent, rd, rd.getChildDefinition()); |
| | | } |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | |
| | | |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | | |
| | | import java.util.ArrayList; |
| | |
| | | import org.opends.server.admin.OperationsException; |
| | | import org.opends.server.admin.PropertyIsMandatoryException; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This exception is thrown when an attempt is made to add or modify a |
| | | * managed object when one or more of its mandatory properties are |
| | | * undefined. |
| | | * This exception is thrown when an attempt is made to add or modify a managed |
| | | * object when one or more of its mandatory properties are undefined. |
| | | */ |
| | | public class MissingMandatoryPropertiesException extends OperationsException { |
| | | |
| | | /** |
| | | * Serialization ID. |
| | | */ |
| | | private static final long serialVersionUID = 6342522125252055588L; |
| | | /** |
| | | * Serialization ID. |
| | | */ |
| | | private static final long serialVersionUID = 6342522125252055588L; |
| | | |
| | | // Create the message. |
| | | private static LocalizableMessage createMessage(Collection<PropertyIsMandatoryException> causes) { |
| | | Reject.ifNull(causes); |
| | | Reject.ifFalse(!causes.isEmpty(), "causes should not be empty"); |
| | | |
| | | if (causes.size() == 1) { |
| | | return ERR_MISSING_MANDATORY_PROPERTIES_EXCEPTION_SINGLE.get(causes.iterator().next() |
| | | .getPropertyDefinition().getName()); |
| | | } else { |
| | | LocalizableMessageBuilder builder = new LocalizableMessageBuilder(); |
| | | |
| | | // Create the message. |
| | | private static LocalizableMessage createMessage( |
| | | Collection<PropertyIsMandatoryException> causes) { |
| | | Reject.ifNull(causes); |
| | | Reject.ifFalse(!causes.isEmpty(), "causes should not be empty"); |
| | | boolean isFirst = true; |
| | | for (PropertyIsMandatoryException cause : causes) { |
| | | if (!isFirst) { |
| | | builder.append(", "); |
| | | } |
| | | builder.append(cause.getPropertyDefinition().getName()); |
| | | isFirst = false; |
| | | } |
| | | |
| | | if (causes.size() == 1) { |
| | | return ERR_MISSING_MANDATORY_PROPERTIES_EXCEPTION_SINGLE.get(causes |
| | | .iterator().next().getPropertyDefinition().getName()); |
| | | } else { |
| | | LocalizableMessageBuilder builder = new LocalizableMessageBuilder(); |
| | | |
| | | boolean isFirst = true; |
| | | for (PropertyIsMandatoryException cause : causes) { |
| | | if (!isFirst) { |
| | | builder.append(", "); |
| | | return ERR_MISSING_MANDATORY_PROPERTIES_EXCEPTION_PLURAL.get(builder.toMessage()); |
| | | } |
| | | builder.append(cause.getPropertyDefinition().getName()); |
| | | isFirst = false; |
| | | } |
| | | |
| | | return ERR_MISSING_MANDATORY_PROPERTIES_EXCEPTION_PLURAL.get(builder |
| | | .toMessage()); |
| | | } |
| | | } |
| | | |
| | | // The causes of this exception. |
| | | private final Collection<PropertyIsMandatoryException> causes; |
| | | // The causes of this exception. |
| | | private final Collection<PropertyIsMandatoryException> causes; |
| | | |
| | | // Indicates whether the exception occurred during managed object |
| | | // creation. |
| | | private final boolean isCreate; |
| | | // Indicates whether the exception occurred during managed object |
| | | // creation. |
| | | private final boolean isCreate; |
| | | |
| | | // The user friendly name of the component that caused this |
| | | // exception. |
| | | private final LocalizableMessage ufn; |
| | | // The user friendly name of the component that caused this |
| | | // exception. |
| | | private final LocalizableMessage ufn; |
| | | |
| | | /** |
| | | * Creates a new missing mandatory properties exception with the provided |
| | | * causes. |
| | | * |
| | | * @param ufn |
| | | * The user friendly name of the component that caused this |
| | | * exception. |
| | | * @param causes |
| | | * The causes of this exception (must be non-<code>null</code> |
| | | * and non-empty). |
| | | * @param isCreate |
| | | * Indicates whether the exception occurred during managed object |
| | | * creation. |
| | | */ |
| | | public MissingMandatoryPropertiesException(LocalizableMessage ufn, |
| | | Collection<PropertyIsMandatoryException> causes, boolean isCreate) { |
| | | super(createMessage(causes)); |
| | | |
| | | this.causes = new ArrayList<PropertyIsMandatoryException>(causes); |
| | | this.ufn = ufn; |
| | | this.isCreate = isCreate; |
| | | } |
| | | |
| | | /** |
| | | * Creates a new missing mandatory properties exception with the |
| | | * provided causes. |
| | | * |
| | | * @param ufn |
| | | * The user friendly name of the component that caused this |
| | | * exception. |
| | | * @param causes |
| | | * The causes of this exception (must be non-<code>null</code> |
| | | * and non-empty). |
| | | * @param isCreate |
| | | * Indicates whether the exception occurred during managed |
| | | * object creation. |
| | | */ |
| | | public MissingMandatoryPropertiesException(LocalizableMessage ufn, |
| | | Collection<PropertyIsMandatoryException> causes, boolean isCreate) { |
| | | super(createMessage(causes)); |
| | | /** |
| | | * Gets the first exception that caused this exception. |
| | | * |
| | | * @return Returns the first exception that caused this exception. |
| | | */ |
| | | @Override |
| | | public PropertyIsMandatoryException getCause() { |
| | | return causes.iterator().next(); |
| | | } |
| | | |
| | | this.causes = new ArrayList<PropertyIsMandatoryException>(causes); |
| | | this.ufn = ufn; |
| | | this.isCreate = isCreate; |
| | | } |
| | | /** |
| | | * Gets an unmodifiable collection view of the causes of this exception. |
| | | * |
| | | * @return Returns an unmodifiable collection view of the causes of this |
| | | * exception. |
| | | */ |
| | | public Collection<PropertyIsMandatoryException> getCauses() { |
| | | return Collections.unmodifiableCollection(causes); |
| | | } |
| | | |
| | | /** |
| | | * Gets the user friendly name of the component that caused this exception. |
| | | * |
| | | * @return Returns the user friendly name of the component that caused this |
| | | * exception. |
| | | */ |
| | | public LocalizableMessage getUserFriendlyName() { |
| | | return ufn; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Gets the first exception that caused this exception. |
| | | * |
| | | * @return Returns the first exception that caused this exception. |
| | | */ |
| | | @Override |
| | | public PropertyIsMandatoryException getCause() { |
| | | return causes.iterator().next(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets an unmodifiable collection view of the causes of this |
| | | * exception. |
| | | * |
| | | * @return Returns an unmodifiable collection view of the causes of |
| | | * this exception. |
| | | */ |
| | | public Collection<PropertyIsMandatoryException> getCauses() { |
| | | return Collections.unmodifiableCollection(causes); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the user friendly name of the component that caused this |
| | | * exception. |
| | | * |
| | | * @return Returns the user friendly name of the component that |
| | | * caused this exception. |
| | | */ |
| | | public LocalizableMessage getUserFriendlyName() { |
| | | return ufn; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether or not this exception was thrown during managed |
| | | * object creation or during modification. |
| | | * |
| | | * @return Returns <code>true</code> if this exception was thrown |
| | | * during managed object creation. |
| | | */ |
| | | public boolean isCreate() { |
| | | return isCreate; |
| | | } |
| | | /** |
| | | * Indicates whether or not this exception was thrown during managed object |
| | | * creation or during modification. |
| | | * |
| | | * @return Returns <code>true</code> if this exception was thrown during |
| | | * managed object creation. |
| | | */ |
| | | public boolean isCreate() { |
| | | return isCreate; |
| | | } |
| | | |
| | | } |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | |
| | | * The messages describing the constraint violations that |
| | | * occurred (must be non-<code>null</code> and non-empty). |
| | | */ |
| | | public OperationRejectedException(OperationType type, LocalizableMessage ufn, Collection<LocalizableMessage> messages) { |
| | | public OperationRejectedException(OperationType type, LocalizableMessage ufn, |
| | | Collection<LocalizableMessage> messages) { |
| | | super(getDefaultMessage(messages)); |
| | | |
| | | this.messages = new ArrayList<LocalizableMessage>(messages); |
| | |
| | | import org.opends.server.admin.Reference; |
| | | import org.opends.server.admin.RelationDefinition; |
| | | import org.opends.server.admin.SetRelationDefinition; |
| | | import org.opends.server.admin.UnknownPropertyDefinitionException; |
| | | import org.opends.server.admin.DefinitionDecodingException.Reason; |
| | | import org.opends.server.admin.client.ManagedObject; |
| | | import org.opends.server.admin.client.ManagedObjectDecodingException; |
| | |
| | | /** |
| | | * Decodes the provided property LDAP value. |
| | | * |
| | | * @param <PD> |
| | | * @param <P> |
| | | * The type of the property. |
| | | * @param pd |
| | | * The property definition. |
| | |
| | | * If the property value could not be decoded because it was |
| | | * invalid. |
| | | */ |
| | | public static <PD> PD decode(PropertyDefinition<PD> pd, Object value) |
| | | throws IllegalPropertyValueStringException { |
| | | public static <P> P decode(PropertyDefinition<P> pd, Object value) { |
| | | String s = String.valueOf(value); |
| | | return pd.castValue(pd.accept(new ValueDecoder(), s)); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> Object visitAggregation( |
| | | AggregationPropertyDefinition<C, S> d, String p) { |
| | | AggregationPropertyDefinition<C, S> d, String p) { |
| | | // Aggregations values are stored as full DNs in LDAP, but |
| | | // just their common name is exposed in the admin framework. |
| | | try { |
| | |
| | | * {@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); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getManagedObject( |
| | | ManagedObjectPath<C, S> path) throws DefinitionDecodingException, ManagedObjectDecodingException, |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | ManagedObjectPath<C, S> path) throws DefinitionDecodingException, ManagedObjectDecodingException, |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | if (!managedObjectExists(path)) { |
| | | throw new ManagedObjectNotFoundException(); |
| | | } |
| | |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration, PD> SortedSet<PD> getPropertyValues( |
| | | ManagedObjectPath<C, S> path, PropertyDefinition<PD> propertyDef) throws IllegalArgumentException, |
| | | DefinitionDecodingException, ManagedObjectNotFoundException, ErrorResultException, PropertyException { |
| | | public <C extends ConfigurationClient, S extends Configuration, P> SortedSet<P> getPropertyValues( |
| | | ManagedObjectPath<C, S> path, PropertyDefinition<P> propertyDef) throws DefinitionDecodingException, |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | // Check that the requested property is from the definition |
| | | // associated with the path. |
| | | AbstractManagedObjectDefinition<C, S> d = path.getManagedObjectDefinition(); |
| | | PropertyDefinition<?> tmp = d.getPropertyDefinition(propertyDef.getName()); |
| | | if (tmp != propertyDef) { |
| | | throw new IllegalArgumentException("The property " + propertyDef.getName() + " is not associated with a " |
| | | + d.getName()); |
| | | + d.getName()); |
| | | } |
| | | |
| | | if (!managedObjectExists(path)) { |
| | |
| | | // Make sure we use the correct property definition, the |
| | | // provided one might have been overridden in the resolved |
| | | // definition. |
| | | propertyDef = (PropertyDefinition<PD>) objectDef.getPropertyDefinition(propertyDef.getName()); |
| | | propertyDef = (PropertyDefinition<P>) objectDef.getPropertyDefinition(propertyDef.getName()); |
| | | |
| | | String attrID = profile.getAttributeName(objectDef, propertyDef); |
| | | SearchResultEntry resultEntry = connection.readEntry(dn, Collections.singleton(attrID)); |
| | | Attribute attribute = resultEntry.getAttribute(attrID); |
| | | |
| | | // Decode the values. |
| | | SortedSet<PD> values = new TreeSet<PD>(propertyDef); |
| | | SortedSet<P> values = new TreeSet<P>(propertyDef); |
| | | if (attribute != null) { |
| | | for (ByteString byteValue : attribute) { |
| | | PD value = ValueDecoder.decode(propertyDef, byteValue); |
| | | P value = ValueDecoder.decode(propertyDef, byteValue); |
| | | values.add(value); |
| | | } |
| | | } |
| | |
| | | @Override |
| | | public ManagedObject<RootCfgClient> getRootConfigurationManagedObject() { |
| | | return new LDAPManagedObject<RootCfgClient>(this, RootCfgDefn.getInstance(), ManagedObjectPath.emptyPath(), |
| | | new PropertySet(), true, null); |
| | | new PropertySet(), true, null); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws IllegalArgumentException, |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws ManagedObjectNotFoundException, |
| | | ErrorResultException { |
| | | validateRelationDefinition(parent, rd); |
| | | |
| | | if (!managedObjectExists(parent)) { |
| | |
| | | */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws IllegalArgumentException, |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws ManagedObjectNotFoundException, |
| | | ErrorResultException { |
| | | validateRelationDefinition(parent, rd); |
| | | |
| | | if (!managedObjectExists(parent)) { |
| | |
| | | */ |
| | | @Override |
| | | public boolean managedObjectExists(ManagedObjectPath<?, ?> path) throws ManagedObjectNotFoundException, |
| | | ErrorResultException { |
| | | ErrorResultException { |
| | | if (path.isEmpty()) { |
| | | return true; |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | protected <C extends ConfigurationClient, S extends Configuration> void deleteManagedObject( |
| | | ManagedObjectPath<C, S> path) throws OperationRejectedException, ErrorResultException { |
| | | ManagedObjectPath<C, S> path) throws OperationRejectedException, ErrorResultException { |
| | | // Delete the entry and any subordinate entries. |
| | | DN dn = LDAPNameBuilder.create(path, profile); |
| | | try { |
| | | connection.deleteSubtree(dn); |
| | | } catch(ErrorResultException e) { |
| | | if (e.getResult().getResultCode()==ResultCode.UNWILLING_TO_PERFORM) { |
| | | } catch (ErrorResultException e) { |
| | | if (e.getResult().getResultCode() == ResultCode.UNWILLING_TO_PERFORM) { |
| | | AbstractManagedObjectDefinition<?, ?> d = path.getManagedObjectDefinition(); |
| | | LocalizableMessage m = LocalizableMessage.raw("%s", e.getMessage()); |
| | | throw new OperationRejectedException(OperationType.DELETE, d.getUserFriendlyName(), m); |
| | |
| | | |
| | | // Create a managed object which already exists on the server. |
| | | private <M extends ConfigurationClient, N extends Configuration> ManagedObject<M> createExistingManagedObject( |
| | | ManagedObjectDefinition<M, N> d, ManagedObjectPath<? super M, ? super N> p, PropertySet properties) { |
| | | ManagedObjectDefinition<M, N> d, ManagedObjectPath<? super M, ? super N> p, PropertySet properties) { |
| | | RelationDefinition<?, ?> rd = p.getRelationDefinition(); |
| | | PropertyDefinition<?> pd = null; |
| | | if (rd instanceof InstantiableRelationDefinition) { |
| | |
| | | } |
| | | |
| | | // Create a property using the provided string values. |
| | | private <PD> void decodeProperty(PropertySet newProperties, ManagedObjectPath<?, ?> path, |
| | | PropertyDefinition<PD> propertyDef, Attribute attribute) throws PropertyException { |
| | | private <P> void decodeProperty(PropertySet newProperties, ManagedObjectPath<?, ?> path, |
| | | PropertyDefinition<P> propertyDef, Attribute attribute) { |
| | | PropertyException exception = null; |
| | | |
| | | // Get the property's active values. |
| | | SortedSet<PD> activeValues = new TreeSet<PD>(propertyDef); |
| | | SortedSet<P> activeValues = new TreeSet<P>(propertyDef); |
| | | if (attribute != null) { |
| | | for (ByteString byteValue : attribute) { |
| | | PD value = ValueDecoder.decode(propertyDef, byteValue); |
| | | P value = ValueDecoder.decode(propertyDef, byteValue); |
| | | activeValues.add(value); |
| | | } |
| | | } |
| | |
| | | if (activeValues.size() > 1 && !propertyDef.hasOption(PropertyOption.MULTI_VALUED)) { |
| | | // This exception takes precedence over previous exceptions. |
| | | exception = new PropertyIsSingleValuedException(propertyDef); |
| | | PD value = activeValues.first(); |
| | | P value = activeValues.first(); |
| | | activeValues.clear(); |
| | | activeValues.add(value); |
| | | } |
| | | |
| | | // Get the property's default values. |
| | | Collection<PD> defaultValues; |
| | | Collection<P> defaultValues; |
| | | try { |
| | | defaultValues = findDefaultValues(path, propertyDef, false); |
| | | } catch (DefaultBehaviorException e) { |
| | |
| | | |
| | | // Determine the type of managed object associated with the named |
| | | // entry. |
| | | private <C extends ConfigurationClient, S extends Configuration> ManagedObjectDefinition<? extends C, ? extends S> getEntryDefinition( |
| | | AbstractManagedObjectDefinition<C, S> d, DN dn) throws ErrorResultException, DefinitionDecodingException { |
| | | // @Checkstyle:off |
| | | private <C extends ConfigurationClient, S extends Configuration> ManagedObjectDefinition<? extends C, ? extends S> |
| | | getEntryDefinition(AbstractManagedObjectDefinition<C, S> d, DN dn) throws ErrorResultException, |
| | | DefinitionDecodingException { |
| | | // @Checkstyle:on |
| | | SearchResultEntry searchResultEntry = connection.readEntry(dn, Collections.singleton("objectclass")); |
| | | Attribute objectClassAttr = searchResultEntry.getAttribute("objectclass"); |
| | | |
| | |
| | | |
| | | // Resolve the appropriate sub-type based on the object classes. |
| | | DefinitionResolver resolver = new DefinitionResolver() { |
| | | @Override |
| | | public boolean matches(AbstractManagedObjectDefinition<?, ?> d) { |
| | | String objectClass = profile.getObjectClass(d); |
| | | return objectClasses.contains(objectClass); |
| | |
| | | import org.opends.server.admin.Reference; |
| | | import org.opends.server.admin.RelationDefinition; |
| | | import org.opends.server.admin.SetRelationDefinition; |
| | | import org.opends.server.admin.UnknownPropertyDefinitionException; |
| | | import org.opends.server.admin.client.ConcurrentModificationException; |
| | | import org.opends.server.admin.client.ManagedObject; |
| | | import org.opends.server.admin.client.OperationRejectedException; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <PD> Object visitUnknown(PropertyDefinition<PD> pd, PD v, Void p) |
| | | throws UnknownPropertyDefinitionException { |
| | | return pd.encodeValue(v); |
| | | public <P> Object visitUnknown(PropertyDefinition<P> propertyDef, P value, Void p) { |
| | | return propertyDef.encodeValue(value); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // Encode a property into LDAP string values. |
| | | private <PD> void encodeProperty(Attribute attribute, PropertyDefinition<PD> propertyDef) { |
| | | private <P> void encodeProperty(Attribute attribute, PropertyDefinition<P> propertyDef) { |
| | | PropertyValueVisitor<Object, Void> visitor = new ValueEncoder(); |
| | | Property<PD> property = getProperty(propertyDef); |
| | | Property<P> property = getProperty(propertyDef); |
| | | if (propertyDef.hasOption(PropertyOption.MANDATORY)) { |
| | | // For mandatory properties we fall-back to the default values |
| | | // if defined which can sometimes be the case e.g when a |
| | | // mandatory property is overridden. |
| | | for (PD value : property.getEffectiveValues()) { |
| | | for (P value : property.getEffectiveValues()) { |
| | | attribute.add(propertyDef.accept(visitor, value, null)); |
| | | } |
| | | } else { |
| | | for (PD value : property.getPendingValues()) { |
| | | for (P value : property.getPendingValues()) { |
| | | attribute.add(propertyDef.accept(visitor, value, null)); |
| | | } |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | InstantiableRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d, String name) { |
| | | InstantiableRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d, |
| | | String name) { |
| | | // Add the RDN sequence representing the relation. |
| | | appendManagedObjectPathElement(r); |
| | | |
| | |
| | | import org.opends.server.admin.DefaultBehaviorException; |
| | | import org.opends.server.admin.DefaultManagedObject; |
| | | import org.opends.server.admin.DefinitionDecodingException; |
| | | import org.opends.server.admin.IllegalPropertyValueException; |
| | | import org.opends.server.admin.IllegalPropertyValueStringException; |
| | | import org.opends.server.admin.InstantiableRelationDefinition; |
| | | import org.opends.server.admin.ManagedObjectAlreadyExistsException; |
| | |
| | | import org.opends.server.admin.PropertyDefinition; |
| | | import org.opends.server.admin.PropertyIsMandatoryException; |
| | | import org.opends.server.admin.PropertyIsReadOnlyException; |
| | | import org.opends.server.admin.PropertyIsSingleValuedException; |
| | | import org.opends.server.admin.PropertyOption; |
| | | import org.opends.server.admin.RelationDefinition; |
| | | import org.opends.server.admin.RelationDefinitionVisitor; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> Void visitInstantiable( |
| | | InstantiableRelationDefinition<C, S> rd, Void p) { |
| | | InstantiableRelationDefinition<C, S> rd, Void p) { |
| | | for (String name : rd.getDefaultManagedObjectNames()) { |
| | | DefaultManagedObject<? extends C, ? extends S> dmo = rd.getDefaultManagedObject(name); |
| | | ManagedObjectDefinition<? extends C, ? extends S> d = dmo.getManagedObjectDefinition(); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> Void visitOptional( |
| | | OptionalRelationDefinition<C, S> rd, Void p) { |
| | | OptionalRelationDefinition<C, S> rd, Void p) { |
| | | if (rd.getDefaultManagedObject() != null) { |
| | | DefaultManagedObject<? extends C, ? extends S> dmo = rd.getDefaultManagedObject(); |
| | | ManagedObjectDefinition<? extends C, ? extends S> d = dmo.getManagedObjectDefinition(); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> Void visitSingleton( |
| | | SingletonRelationDefinition<C, S> rd, Void p) { |
| | | SingletonRelationDefinition<C, S> rd, Void p) { |
| | | // Do nothing - not possible to create singletons |
| | | // dynamically. |
| | | return null; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> Void visitSet(SetRelationDefinition<C, S> rd, |
| | | Void p) { |
| | | Void p) { |
| | | for (String name : rd.getDefaultManagedObjectNames()) { |
| | | DefaultManagedObject<? extends C, ? extends S> dmo = rd.getDefaultManagedObject(name); |
| | | ManagedObjectDefinition<? extends C, ? extends S> d = dmo.getManagedObjectDefinition(); |
| | |
| | | |
| | | // Create the child managed object. |
| | | private void createDefaultManagedObject(ManagedObjectDefinition<?, ?> d, ManagedObject<?> child, |
| | | DefaultManagedObject<?, ?> dmo) { |
| | | DefaultManagedObject<?, ?> dmo) { |
| | | for (PropertyDefinition<?> pd : d.getAllPropertyDefinitions()) { |
| | | setPropertyValues(child, pd, dmo); |
| | | } |
| | |
| | | * The relation definition. |
| | | */ |
| | | private void createDefaultManagedObjects(RelationDefinition<?, ?> rd) throws ErrorResultException, |
| | | ConcurrentModificationException, MissingMandatoryPropertiesException, |
| | | ManagedObjectAlreadyExistsException, OperationRejectedException { |
| | | ConcurrentModificationException, MissingMandatoryPropertiesException, |
| | | ManagedObjectAlreadyExistsException, OperationRejectedException { |
| | | rd.accept(this, null); |
| | | |
| | | if (ere != null) { |
| | |
| | | } |
| | | |
| | | // Set property values. |
| | | private <PD> void setPropertyValues(ManagedObject<?> mo, PropertyDefinition<PD> pd, |
| | | DefaultManagedObject<?, ?> dmo) { |
| | | private <P> void setPropertyValues(ManagedObject<?> mo, PropertyDefinition<P> pd, |
| | | DefaultManagedObject<?, ?> dmo) { |
| | | mo.setPropertyValues(pd, dmo.getPropertyValues(pd)); |
| | | } |
| | | } |
| | |
| | | * Optional naming property definition. |
| | | */ |
| | | protected AbstractManagedObject(ManagedObjectDefinition<T, ? extends Configuration> d, |
| | | ManagedObjectPath<T, ? extends Configuration> path, PropertySet properties, boolean existsOnServer, |
| | | PropertyDefinition<?> namingPropertyDefinition) { |
| | | ManagedObjectPath<T, ? extends Configuration> path, PropertySet properties, boolean existsOnServer, |
| | | PropertyDefinition<?> namingPropertyDefinition) { |
| | | this.definition = d; |
| | | this.path = path; |
| | | this.properties = properties; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final void commit() throws ManagedObjectAlreadyExistsException, MissingMandatoryPropertiesException, |
| | | ConcurrentModificationException, OperationRejectedException, ErrorResultException { |
| | | ConcurrentModificationException, OperationRejectedException, ErrorResultException { |
| | | // First make sure all mandatory properties are defined. |
| | | List<PropertyIsMandatoryException> exceptions = new LinkedList<PropertyIsMandatoryException>(); |
| | | |
| | |
| | | } |
| | | |
| | | if (!exceptions.isEmpty()) { |
| | | throw new MissingMandatoryPropertiesException(definition.getUserFriendlyName(), exceptions, !existsOnServer); |
| | | throw new MissingMandatoryPropertiesException(definition.getUserFriendlyName(), exceptions, |
| | | !existsOnServer); |
| | | } |
| | | |
| | | // Now enforce any constraints. |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration, CC extends C> ManagedObject<CC> createChild( |
| | | InstantiableRelationDefinition<C, S> r, ManagedObjectDefinition<CC, ? extends S> d, String name, |
| | | Collection<DefaultBehaviorException> exceptions) throws IllegalManagedObjectNameException, |
| | | IllegalArgumentException { |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration, C1 extends C> ManagedObject<C1> createChild( |
| | | InstantiableRelationDefinition<C, S> r, ManagedObjectDefinition<C1, ? extends S> d, String name, |
| | | Collection<DefaultBehaviorException> exceptions) throws IllegalManagedObjectNameException { |
| | | validateRelationDefinition(r); |
| | | |
| | | // Empty names are not allowed. |
| | |
| | | } |
| | | } |
| | | |
| | | ManagedObjectPath<CC, ? extends S> childPath = path.child(r, d, name); |
| | | ManagedObjectPath<C1, ? extends S> childPath = path.child(r, d, name); |
| | | return createNewManagedObject(d, childPath, pd, name, exceptions); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration, CC extends C> ManagedObject<CC> createChild( |
| | | OptionalRelationDefinition<C, S> r, ManagedObjectDefinition<CC, ? extends S> d, |
| | | Collection<DefaultBehaviorException> exceptions) throws IllegalArgumentException { |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration, C1 extends C> ManagedObject<C1> createChild( |
| | | OptionalRelationDefinition<C, S> r, ManagedObjectDefinition<C1, ? extends S> d, |
| | | Collection<DefaultBehaviorException> exceptions) { |
| | | validateRelationDefinition(r); |
| | | ManagedObjectPath<CC, ? extends S> childPath = path.child(r, d); |
| | | ManagedObjectPath<C1, ? extends S> childPath = path.child(r, d); |
| | | return createNewManagedObject(d, childPath, null, null, exceptions); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration, CC extends C> ManagedObject<CC> createChild( |
| | | SetRelationDefinition<C, S> r, ManagedObjectDefinition<CC, ? extends S> d, |
| | | Collection<DefaultBehaviorException> exceptions) throws IllegalArgumentException { |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration, C1 extends C> ManagedObject<C1> createChild( |
| | | SetRelationDefinition<C, S> r, ManagedObjectDefinition<C1, ? extends S> d, |
| | | Collection<DefaultBehaviorException> exceptions) { |
| | | validateRelationDefinition(r); |
| | | |
| | | ManagedObjectPath<CC, ? extends S> childPath = path.child(r, d); |
| | | ManagedObjectPath<C1, ? extends S> childPath = path.child(r, d); |
| | | return createNewManagedObject(d, childPath, null, null, exceptions); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | InstantiableRelationDefinition<C, S> r, String name) throws IllegalArgumentException, |
| | | DefinitionDecodingException, ManagedObjectDecodingException, ManagedObjectNotFoundException, |
| | | ConcurrentModificationException, ErrorResultException { |
| | | InstantiableRelationDefinition<C, S> r, String name) throws DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException { |
| | | validateRelationDefinition(r); |
| | | ensureThisManagedObjectExists(); |
| | | Driver ctx = getDriver(); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | OptionalRelationDefinition<C, S> r) throws IllegalArgumentException, DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException { |
| | | OptionalRelationDefinition<C, S> r) throws DefinitionDecodingException, ManagedObjectDecodingException, |
| | | ManagedObjectNotFoundException, ConcurrentModificationException, ErrorResultException { |
| | | validateRelationDefinition(r); |
| | | ensureThisManagedObjectExists(); |
| | | Driver ctx = getDriver(); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | SingletonRelationDefinition<C, S> r) throws IllegalArgumentException, DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException { |
| | | SingletonRelationDefinition<C, S> r) throws DefinitionDecodingException, ManagedObjectDecodingException, |
| | | ManagedObjectNotFoundException, ConcurrentModificationException, ErrorResultException { |
| | | validateRelationDefinition(r); |
| | | ensureThisManagedObjectExists(); |
| | | Driver ctx = getDriver(); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | SetRelationDefinition<C, S> r, String name) throws IllegalArgumentException, DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException { |
| | | SetRelationDefinition<C, S> r, String name) throws DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException { |
| | | validateRelationDefinition(r); |
| | | ensureThisManagedObjectExists(); |
| | | Driver ctx = getDriver(); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final T getConfiguration() { |
| | | return definition.createClientConfiguration(this); |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final ManagedObjectDefinition<T, ? extends Configuration> getManagedObjectDefinition() { |
| | | return definition; |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final ManagedObjectPath<T, ? extends Configuration> getManagedObjectPath() { |
| | | return path; |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final <PD> SortedSet<PD> getPropertyDefaultValues(PropertyDefinition<PD> pd) throws IllegalArgumentException { |
| | | return new TreeSet<PD>(getProperty(pd).getDefaultValues()); |
| | | @Override |
| | | public final <P> SortedSet<P> getPropertyDefaultValues(PropertyDefinition<P> pd) { |
| | | return new TreeSet<P>(getProperty(pd).getDefaultValues()); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final <PD> PD getPropertyValue(PropertyDefinition<PD> pd) throws IllegalArgumentException { |
| | | Set<PD> values = getProperty(pd).getEffectiveValues(); |
| | | @Override |
| | | public final <P> P getPropertyValue(PropertyDefinition<P> pd) { |
| | | Set<P> values = getProperty(pd).getEffectiveValues(); |
| | | if (values.isEmpty()) { |
| | | return null; |
| | | } else { |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final <PD> SortedSet<PD> getPropertyValues(PropertyDefinition<PD> pd) throws IllegalArgumentException { |
| | | return new TreeSet<PD>(getProperty(pd).getEffectiveValues()); |
| | | @Override |
| | | public final <P> SortedSet<P> getPropertyValues(PropertyDefinition<P> pd) { |
| | | return new TreeSet<P>(getProperty(pd).getEffectiveValues()); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> boolean hasChild( |
| | | OptionalRelationDefinition<C, S> r) throws IllegalArgumentException, ConcurrentModificationException, |
| | | ErrorResultException { |
| | | OptionalRelationDefinition<C, S> r) throws ConcurrentModificationException, ErrorResultException { |
| | | validateRelationDefinition(r); |
| | | Driver ctx = getDriver(); |
| | | try { |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final boolean isPropertyPresent(PropertyDefinition<?> pd) throws IllegalArgumentException { |
| | | @Override |
| | | public final boolean isPropertyPresent(PropertyDefinition<?> pd) { |
| | | return !getProperty(pd).isEmpty(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> String[] listChildren( |
| | | InstantiableRelationDefinition<C, S> r) throws IllegalArgumentException, ConcurrentModificationException, |
| | | ErrorResultException { |
| | | InstantiableRelationDefinition<C, S> r) throws ConcurrentModificationException, ErrorResultException { |
| | | return listChildren(r, r.getChildDefinition()); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> String[] listChildren( |
| | | InstantiableRelationDefinition<C, S> r, AbstractManagedObjectDefinition<? extends C, ? extends S> d) |
| | | throws IllegalArgumentException, ConcurrentModificationException, ErrorResultException { |
| | | InstantiableRelationDefinition<C, S> r, AbstractManagedObjectDefinition<? extends C, ? extends S> d) |
| | | throws ConcurrentModificationException, ErrorResultException { |
| | | validateRelationDefinition(r); |
| | | Driver ctx = getDriver(); |
| | | try { |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> String[] listChildren( |
| | | SetRelationDefinition<C, S> r) throws IllegalArgumentException, ConcurrentModificationException, |
| | | ErrorResultException { |
| | | SetRelationDefinition<C, S> r) throws ConcurrentModificationException, ErrorResultException { |
| | | return listChildren(r, r.getChildDefinition()); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> String[] listChildren( |
| | | SetRelationDefinition<C, S> r, AbstractManagedObjectDefinition<? extends C, ? extends S> d) |
| | | throws IllegalArgumentException, ConcurrentModificationException, ErrorResultException { |
| | | SetRelationDefinition<C, S> r, AbstractManagedObjectDefinition<? extends C, ? extends S> d) |
| | | throws ConcurrentModificationException, ErrorResultException { |
| | | validateRelationDefinition(r); |
| | | Driver ctx = getDriver(); |
| | | try { |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> void removeChild( |
| | | InstantiableRelationDefinition<C, S> r, String name) throws IllegalArgumentException, |
| | | ManagedObjectNotFoundException, OperationRejectedException, ConcurrentModificationException, |
| | | ErrorResultException { |
| | | InstantiableRelationDefinition<C, S> r, String name) throws ManagedObjectNotFoundException, |
| | | OperationRejectedException, ConcurrentModificationException, ErrorResultException { |
| | | validateRelationDefinition(r); |
| | | Driver ctx = getDriver(); |
| | | boolean found; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> void removeChild( |
| | | OptionalRelationDefinition<C, S> r) throws IllegalArgumentException, ManagedObjectNotFoundException, |
| | | OperationRejectedException, ConcurrentModificationException, ErrorResultException { |
| | | OptionalRelationDefinition<C, S> r) throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ConcurrentModificationException, ErrorResultException { |
| | | validateRelationDefinition(r); |
| | | Driver ctx = getDriver(); |
| | | boolean found; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> void removeChild( |
| | | SetRelationDefinition<C, S> r, String name) throws IllegalArgumentException, |
| | | ManagedObjectNotFoundException, OperationRejectedException, ConcurrentModificationException, |
| | | ErrorResultException { |
| | | SetRelationDefinition<C, S> r, String name) throws ManagedObjectNotFoundException, |
| | | OperationRejectedException, ConcurrentModificationException, ErrorResultException { |
| | | validateRelationDefinition(r); |
| | | Driver ctx = getDriver(); |
| | | boolean found; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final <PD> void setPropertyValue(PropertyDefinition<PD> pd, PD value) throws IllegalPropertyValueException, |
| | | PropertyIsReadOnlyException, PropertyIsMandatoryException, IllegalArgumentException { |
| | | @Override |
| | | public final <P> void setPropertyValue(PropertyDefinition<P> pd, P value) { |
| | | if (value == null) { |
| | | setPropertyValues(pd, Collections.<PD> emptySet()); |
| | | setPropertyValues(pd, Collections.<P> emptySet()); |
| | | } else { |
| | | setPropertyValues(pd, Collections.singleton(value)); |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final <PD> void setPropertyValues(PropertyDefinition<PD> pd, Collection<PD> values) |
| | | throws IllegalPropertyValueException, PropertyIsSingleValuedException, PropertyIsReadOnlyException, |
| | | PropertyIsMandatoryException, IllegalArgumentException { |
| | | @Override |
| | | public final <P> void setPropertyValues(PropertyDefinition<P> pd, Collection<P> values) { |
| | | if (pd.hasOption(PropertyOption.MONITORING)) { |
| | | throw new PropertyIsReadOnlyException(pd); |
| | | } |
| | |
| | | * @throws ErrorResultException |
| | | * If any other error occurs. |
| | | */ |
| | | protected abstract void addNewManagedObject() throws ErrorResultException, |
| | | OperationRejectedException, ConcurrentModificationException, ManagedObjectAlreadyExistsException; |
| | | protected abstract void addNewManagedObject() throws ErrorResultException, OperationRejectedException, |
| | | ConcurrentModificationException, ManagedObjectAlreadyExistsException; |
| | | |
| | | /** |
| | | * Gets the management context driver associated with this managed object. |
| | |
| | | /** |
| | | * Gets the property associated with the specified property definition. |
| | | * |
| | | * @param <PD> |
| | | * @param <P> |
| | | * The underlying type of the property. |
| | | * @param pd |
| | | * The Property definition. |
| | |
| | | * If this property provider does not recognize the requested |
| | | * property definition. |
| | | */ |
| | | protected final <PD> Property<PD> getProperty(PropertyDefinition<PD> pd) throws IllegalArgumentException { |
| | | protected final <P> Property<P> getProperty(PropertyDefinition<P> pd) { |
| | | return properties.getProperty(pd); |
| | | } |
| | | |
| | |
| | | * @throws OperationRejectedException |
| | | * If the managed object cannot be added due to some client-side |
| | | * or server-side constraint which cannot be satisfied. |
| | | * @throws AuthorizationException |
| | | * If the server refuses to modify this managed object because |
| | | * the client does not have the correct privileges. |
| | | * @throws CommunicationException |
| | | * If the client cannot contact the server due to an underlying |
| | | * communication problem. |
| | | * @throws ErrorResultException |
| | | * If any other error occurs. |
| | | */ |
| | | protected abstract void modifyExistingManagedObject() throws ConcurrentModificationException, |
| | | OperationRejectedException, ErrorResultException; |
| | | OperationRejectedException, ErrorResultException; |
| | | |
| | | /** |
| | | * Creates a new managed object. |
| | |
| | | * @return Returns the new managed object. |
| | | */ |
| | | protected abstract <M extends ConfigurationClient> ManagedObject<M> newInstance(ManagedObjectDefinition<M, ?> d, |
| | | ManagedObjectPath<M, ?> path, PropertySet properties, boolean existsOnServer, |
| | | PropertyDefinition<?> namingPropertyDefinition); |
| | | ManagedObjectPath<M, ?> path, PropertySet properties, boolean existsOnServer, |
| | | PropertyDefinition<?> namingPropertyDefinition); |
| | | |
| | | // Creates a new managed object with no active values, just default |
| | | // values. |
| | | private <M extends ConfigurationClient, PD> ManagedObject<M> createNewManagedObject( |
| | | ManagedObjectDefinition<M, ?> d, ManagedObjectPath<M, ?> p, |
| | | PropertyDefinition<PD> namingPropertyDefinition, String name, |
| | | Collection<DefaultBehaviorException> exceptions) { |
| | | private <M extends ConfigurationClient, P> ManagedObject<M> createNewManagedObject( |
| | | ManagedObjectDefinition<M, ?> d, ManagedObjectPath<M, ?> p, PropertyDefinition<P> namingPropertyDefinition, |
| | | String name, Collection<DefaultBehaviorException> exceptions) { |
| | | PropertySet childProperties = new PropertySet(); |
| | | for (PropertyDefinition<?> pd : d.getAllPropertyDefinitions()) { |
| | | try { |
| | |
| | | |
| | | // Set the naming property if there is one. |
| | | if (namingPropertyDefinition != null) { |
| | | PD value = namingPropertyDefinition.decodeValue(name); |
| | | P value = namingPropertyDefinition.decodeValue(name); |
| | | childProperties.setPropertyValues(namingPropertyDefinition, Collections.singleton(value)); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // Create an empty property. |
| | | private <PD> void createProperty(PropertySet properties, ManagedObjectPath<?, ?> p, PropertyDefinition<PD> pd) |
| | | throws DefaultBehaviorException { |
| | | private <P> void createProperty(PropertySet properties, ManagedObjectPath<?, ?> p, PropertyDefinition<P> pd) { |
| | | try { |
| | | Driver context = getDriver(); |
| | | Collection<PD> defaultValues = context.findDefaultValues(p, pd, true); |
| | | properties.addProperty(pd, defaultValues, Collections.<PD> emptySet()); |
| | | Collection<P> defaultValues = context.findDefaultValues(p, pd, true); |
| | | properties.addProperty(pd, defaultValues, Collections.<P> emptySet()); |
| | | } catch (DefaultBehaviorException e) { |
| | | // Make sure that we have still created the property. |
| | | properties.addProperty(pd, Collections.<PD> emptySet(), Collections.<PD> emptySet()); |
| | | properties.addProperty(pd, Collections.<P> emptySet(), Collections.<P> emptySet()); |
| | | throw e; |
| | | } |
| | | } |
| | |
| | | |
| | | // Validate that a relation definition belongs to this managed |
| | | // object. |
| | | private void validateRelationDefinition(RelationDefinition<?, ?> rd) throws IllegalArgumentException { |
| | | private void validateRelationDefinition(RelationDefinition<?, ?> rd) { |
| | | ManagedObjectDefinition<T, ?> d = getManagedObjectDefinition(); |
| | | RelationDefinition<?, ?> tmp = d.getRelationDefinition(rd.getName()); |
| | | if (tmp != rd) { |
| | | throw new IllegalArgumentException("The relation " + rd.getName() + " is not associated with a " |
| | | + d.getName()); |
| | | + d.getName()); |
| | | } |
| | | } |
| | | |
| | |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.admin.client.spi; |
| | | |
| | | import java.util.ArrayList; |
| | |
| | | * @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. |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Collection<T> visitAbsoluteInherited(AbsoluteInheritedDefaultBehaviorProvider<T> d, Void p) { |
| | | try { |
| | | return getInheritedProperty(d.getManagedObjectPath(), d.getManagedObjectDefinition(), |
| | | d.getPropertyName()); |
| | | d.getPropertyName()); |
| | | } catch (DefaultBehaviorException e) { |
| | | exception = e; |
| | | return Collections.emptySet(); |
| | |
| | | /** |
| | | * {@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()); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Collection<T> visitRelativeInherited(RelativeInheritedDefaultBehaviorProvider<T> d, Void p) { |
| | | try { |
| | | return getInheritedProperty(d.getManagedObjectPath(nextPath), d.getManagedObjectDefinition(), |
| | | d.getPropertyName()); |
| | | d.getPropertyName()); |
| | | } catch (DefaultBehaviorException e) { |
| | | exception = e; |
| | | return Collections.emptySet(); |
| | |
| | | /** |
| | | * {@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 DefaultBehaviorException { |
| | | private Collection<T> find(ManagedObjectPath<?, ?> p, PropertyDefinition<T> pd) { |
| | | this.nextPath = p; |
| | | this.nextProperty = pd; |
| | | |
| | |
| | | // Get an inherited property value. |
| | | @SuppressWarnings("unchecked") |
| | | private Collection<T> getInheritedProperty(ManagedObjectPath target, AbstractManagedObjectDefinition<?, ?> d, |
| | | String propertyName) throws DefaultBehaviorException { |
| | | String propertyName) { |
| | | // First check that the requested type of managed object |
| | | // corresponds to the path. |
| | | AbstractManagedObjectDefinition<?, ?> supr = target.getManagedObjectDefinition(); |
| | | if (!supr.isParentOf(d)) { |
| | | throw new DefaultBehaviorException(nextProperty, new DefinitionDecodingException(supr, |
| | | Reason.WRONG_TYPE_INFORMATION)); |
| | | Reason.WRONG_TYPE_INFORMATION)); |
| | | } |
| | | |
| | | // Save the current property in case of recursion. |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, String name) |
| | | throws IllegalArgumentException, ManagedObjectNotFoundException, OperationRejectedException, |
| | | ErrorResultException { |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, String name) |
| | | throws ManagedObjectNotFoundException, OperationRejectedException, ErrorResultException { |
| | | validateRelationDefinition(parent, rd); |
| | | ManagedObjectPath<?, ?> child = parent.child(rd, name); |
| | | return doDeleteManagedObject(child); |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( |
| | | ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd) throws IllegalArgumentException, |
| | | ManagedObjectNotFoundException, OperationRejectedException, ErrorResultException { |
| | | ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd) throws ManagedObjectNotFoundException, |
| | | OperationRejectedException, ErrorResultException { |
| | | validateRelationDefinition(parent, rd); |
| | | ManagedObjectPath<?, ?> child = parent.child(rd); |
| | | return doDeleteManagedObject(child); |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( |
| | | ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, String name) |
| | | throws IllegalArgumentException, ManagedObjectNotFoundException, OperationRejectedException, |
| | | ErrorResultException { |
| | | ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, String name) |
| | | throws ManagedObjectNotFoundException, OperationRejectedException, ErrorResultException { |
| | | validateRelationDefinition(parent, rd); |
| | | ManagedObjectPath<?, ?> child = parent.child(rd, name); |
| | | return doDeleteManagedObject(child); |
| | |
| | | * @throws ErrorResultException |
| | | * If any other error occurs. |
| | | */ |
| | | // @Checkstyle:ignore |
| | | public abstract <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getManagedObject( |
| | | ManagedObjectPath<C, S> path) throws DefinitionDecodingException, ManagedObjectDecodingException, |
| | | ManagedObjectNotFoundException, ErrorResultException; |
| | | ManagedObjectPath<C, S> path) throws DefinitionDecodingException, ManagedObjectDecodingException, |
| | | ManagedObjectNotFoundException, ErrorResultException; |
| | | |
| | | /** |
| | | * Gets the effective values of a property in the named managed object. |
| | |
| | | * @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. |
| | |
| | | * @throws ErrorResultException |
| | | * If any other error occurs. |
| | | */ |
| | | public abstract <C extends ConfigurationClient, S extends Configuration, PD> SortedSet<PD> getPropertyValues( |
| | | ManagedObjectPath<C, S> path, PropertyDefinition<PD> pd) throws IllegalArgumentException, |
| | | DefinitionDecodingException, ManagedObjectNotFoundException, ErrorResultException, PropertyException; |
| | | public abstract <C extends ConfigurationClient, S extends Configuration, P> SortedSet<P> getPropertyValues( |
| | | ManagedObjectPath<C, S> path, PropertyDefinition<P> pd) throws DefinitionDecodingException, |
| | | ManagedObjectNotFoundException, ErrorResultException; |
| | | |
| | | /** |
| | | * Gets the root configuration managed object associated with this |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | public abstract <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws IllegalArgumentException, |
| | | ManagedObjectNotFoundException, ErrorResultException; |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws ManagedObjectNotFoundException, |
| | | ErrorResultException; |
| | | |
| | | /** |
| | | * Lists the child managed objects of the named parent managed object which |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | public abstract <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws IllegalArgumentException, |
| | | ManagedObjectNotFoundException, ErrorResultException; |
| | | ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws ManagedObjectNotFoundException, |
| | | ErrorResultException; |
| | | |
| | | /** |
| | | * Determines whether or not the named managed object exists. |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | public abstract boolean managedObjectExists(ManagedObjectPath<?, ?> path) throws ManagedObjectNotFoundException, |
| | | ErrorResultException; |
| | | ErrorResultException; |
| | | |
| | | /** |
| | | * Deletes the named managed object. |
| | |
| | | * If any other error occurs. |
| | | */ |
| | | protected abstract <C extends ConfigurationClient, S extends Configuration> void deleteManagedObject( |
| | | ManagedObjectPath<C, S> path) throws OperationRejectedException, ErrorResultException; |
| | | ManagedObjectPath<C, S> path) throws OperationRejectedException, ErrorResultException; |
| | | |
| | | /** |
| | | * Gets the default values for the specified property. |
| | | * |
| | | * @param <PD> |
| | | * @param <P> |
| | | * The type of the property. |
| | | * @param p |
| | | * The managed object path of the current managed object. |
| | |
| | | * If the default values could not be retrieved or decoded |
| | | * properly. |
| | | */ |
| | | protected final <PD> Collection<PD> findDefaultValues(ManagedObjectPath<?, ?> p, PropertyDefinition<PD> pd, |
| | | boolean isCreate) throws DefaultBehaviorException { |
| | | DefaultValueFinder<PD> v = new DefaultValueFinder<PD>(p, isCreate); |
| | | protected final <P> Collection<P> findDefaultValues(ManagedObjectPath<?, ?> p, PropertyDefinition<P> pd, |
| | | boolean isCreate) { |
| | | DefaultValueFinder<P> v = new DefaultValueFinder<P>(p, isCreate); |
| | | return v.find(p, pd); |
| | | } |
| | | |
| | |
| | | * If the relation definition does not belong to the managed |
| | | * object definition. |
| | | */ |
| | | protected final void validateRelationDefinition(ManagedObjectPath<?, ?> path, RelationDefinition<?, ?> rd) |
| | | throws IllegalArgumentException { |
| | | protected final void validateRelationDefinition(ManagedObjectPath<?, ?> path, RelationDefinition<?, ?> rd) { |
| | | AbstractManagedObjectDefinition<?, ?> d = path.getManagedObjectDefinition(); |
| | | RelationDefinition<?, ?> tmp = d.getRelationDefinition(rd.getName()); |
| | | if (tmp != rd) { |
| | | throw new IllegalArgumentException("The relation " + rd.getName() + " is not associated with a " |
| | | + d.getName()); |
| | | + d.getName()); |
| | | } |
| | | } |
| | | |
| | |
| | | // then ensuring that the child exists, before ensuring that any |
| | | // constraints are satisfied. |
| | | private <C extends ConfigurationClient, S extends Configuration> boolean doDeleteManagedObject( |
| | | ManagedObjectPath<C, S> path) throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ErrorResultException { |
| | | ManagedObjectPath<C, S> path) throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ErrorResultException { |
| | | // First make sure that the parent exists. |
| | | if (!managedObjectExists(path.parent())) { |
| | | throw new ManagedObjectNotFoundException(); |
| | |
| | | |
| | | package org.opends.server.admin.client.spi; |
| | | |
| | | |
| | | |
| | | import java.util.SortedSet; |
| | | |
| | | import org.opends.server.admin.PropertyDefinition; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A managed object property comprising of the property's definition |
| | | * and its set of values. |
| | | * A managed object property comprising of the property's definition and its set |
| | | * of values. |
| | | * <p> |
| | | * The property stores the values in a sorted set in which values are |
| | | * compared using the comparator defined by the property definition. |
| | | * The property stores the values in a sorted set in which values are compared |
| | | * using the comparator defined by the property definition. |
| | | * <p> |
| | | * The property keeps track of whether or not its pending set of |
| | | * values differs from its active values. |
| | | * The property keeps track of whether or not its pending set of values differs |
| | | * from its active values. |
| | | * |
| | | * @param <T> |
| | | * The type of the property. |
| | | * The type of the property. |
| | | */ |
| | | public interface Property<T> { |
| | | |
| | | /** |
| | | * Get an immutable set view of this property's active values. |
| | | * |
| | | * @return Returns an immutable set view of this property's active |
| | | * values. An empty set indicates that there are no active |
| | | * values, and any default values are applicable. |
| | | */ |
| | | SortedSet<T> getActiveValues(); |
| | | /** |
| | | * Get an immutable set view of this property's active values. |
| | | * |
| | | * @return Returns an immutable set view of this property's active values. |
| | | * An empty set indicates that there are no active values, and any |
| | | * default values are applicable. |
| | | */ |
| | | SortedSet<T> getActiveValues(); |
| | | |
| | | /** |
| | | * Get an immutable set view of this property's default values. |
| | | * |
| | | * @return Returns an immutable set view of this property's default values. |
| | | * An empty set indicates that there are no default values. |
| | | */ |
| | | SortedSet<T> getDefaultValues(); |
| | | |
| | | /** |
| | | * Get an immutable set view of this property's effective values. |
| | | * |
| | | * @return Returns an immutable set view of this property's effective |
| | | * values. |
| | | */ |
| | | SortedSet<T> getEffectiveValues(); |
| | | |
| | | /** |
| | | * Get an immutable set view of this property's default values. |
| | | * |
| | | * @return Returns an immutable set view of this property's default |
| | | * values. An empty set indicates that there are no default |
| | | * values. |
| | | */ |
| | | SortedSet<T> getDefaultValues(); |
| | | /** |
| | | * Get an immutable set view of this property's pending values. |
| | | * <p> |
| | | * Immediately after construction, the pending values matches the active |
| | | * values. |
| | | * |
| | | * @return Returns an immutable set view of this property's pending values. |
| | | * An empty set indicates that there are no pending values, and any |
| | | * default values are applicable. |
| | | */ |
| | | SortedSet<T> getPendingValues(); |
| | | |
| | | /** |
| | | * Get the property definition associated with this property. |
| | | * |
| | | * @return Returns the property definition associated with this property. |
| | | */ |
| | | PropertyDefinition<T> getPropertyDefinition(); |
| | | |
| | | /** |
| | | * Determines whether or not this property contains any pending values. |
| | | * |
| | | * @return Returns <code>true</code> if this property does not contain any |
| | | * pending values. |
| | | */ |
| | | boolean isEmpty(); |
| | | |
| | | /** |
| | | * Get an immutable set view of this property's effective values. |
| | | * |
| | | * @return Returns an immutable set view of this property's |
| | | * effective values. |
| | | */ |
| | | SortedSet<T> getEffectiveValues(); |
| | | /** |
| | | * Determines whether or not this property has been modified since it was |
| | | * constructed. In other words, whether or not the set of pending values |
| | | * differs from the set of active values. |
| | | * |
| | | * @return Returns <code>true</code> if this property has been modified |
| | | * since it was constructed. |
| | | */ |
| | | boolean isModified(); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get an immutable set view of this property's pending values. |
| | | * <p> |
| | | * Immediately after construction, the pending values matches the |
| | | * active values. |
| | | * |
| | | * @return Returns an immutable set view of this property's pending |
| | | * values. An empty set indicates that there are no pending |
| | | * values, and any default values are applicable. |
| | | */ |
| | | SortedSet<T> getPendingValues(); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the property definition associated with this property. |
| | | * |
| | | * @return Returns the property definition associated with this |
| | | * property. |
| | | */ |
| | | PropertyDefinition<T> getPropertyDefinition(); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Determines whether or not this property contains any pending |
| | | * values. |
| | | * |
| | | * @return Returns <code>true</code> if this property does not |
| | | * contain any pending values. |
| | | */ |
| | | boolean isEmpty(); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Determines whether or not this property has been modified since |
| | | * it was constructed. In other words, whether or not the set of |
| | | * pending values differs from the set of active values. |
| | | * |
| | | * @return Returns <code>true</code> if this property has been |
| | | * modified since it was constructed. |
| | | */ |
| | | boolean isModified(); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Determines whether or not this property contains any active |
| | | * values. |
| | | * |
| | | * @return Returns <code>true</code> if this property does not |
| | | * contain any active values. |
| | | */ |
| | | boolean wasEmpty(); |
| | | /** |
| | | * Determines whether or not this property contains any active values. |
| | | * |
| | | * @return Returns <code>true</code> if this property does not contain any |
| | | * active values. |
| | | */ |
| | | boolean wasEmpty(); |
| | | } |
| | |
| | | |
| | | package org.opends.server.admin.client.spi; |
| | | |
| | | |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | |
| | | import org.opends.server.admin.PropertyIsSingleValuedException; |
| | | import org.opends.server.admin.PropertyOption; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A set of properties. Instances of this class can be used as the |
| | | * core of a managed object implementation. |
| | | * 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> { |
| | | /** |
| | | * 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 active set of values. |
| | | private final SortedSet<T> activeValues; |
| | | |
| | | // The definition associated with this property. |
| | | private final PropertyDefinition<T> d; |
| | | // The definition associated with this property. |
| | | private final PropertyDefinition<T> d; |
| | | |
| | | // The default set of values (read-only). |
| | | private final SortedSet<T> defaultValues; |
| | | // The default set of values (read-only). |
| | | private final SortedSet<T> defaultValues; |
| | | |
| | | // The pending set of values. |
| | | private final SortedSet<T> pendingValues; |
| | | // 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. |
| | | */ |
| | | public MyProperty(PropertyDefinition<T> pd, Collection<T> defaultValues, Collection<T> activeValues) { |
| | | this.d = pd; |
| | | |
| | | SortedSet<T> sortedDefaultValues = new TreeSet<T>(pd); |
| | | sortedDefaultValues.addAll(defaultValues); |
| | | this.defaultValues = Collections.unmodifiableSortedSet(sortedDefaultValues); |
| | | |
| | | this.activeValues = new TreeSet<T>(pd); |
| | | this.activeValues.addAll(activeValues); |
| | | |
| | | // Initially the pending values is the same as the active |
| | | // values. |
| | | this.pendingValues = new TreeSet<T>(this.activeValues); |
| | | } |
| | | |
| | | /** |
| | | * Makes the pending values active. |
| | | */ |
| | | public void commit() { |
| | | activeValues.clear(); |
| | | activeValues.addAll(pendingValues); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public SortedSet<T> getActiveValues() { |
| | | return Collections.unmodifiableSortedSet(activeValues); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public SortedSet<T> getDefaultValues() { |
| | | return defaultValues; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public SortedSet<T> getEffectiveValues() { |
| | | SortedSet<T> values = getPendingValues(); |
| | | |
| | | if (values.isEmpty()) { |
| | | values = getDefaultValues(); |
| | | } |
| | | |
| | | return values; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public SortedSet<T> getPendingValues() { |
| | | return Collections.unmodifiableSortedSet(pendingValues); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public PropertyDefinition<T> getPropertyDefinition() { |
| | | return d; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public boolean isEmpty() { |
| | | return pendingValues.isEmpty(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public boolean isModified() { |
| | | if (activeValues.size() == pendingValues.size() && activeValues.containsAll(pendingValues)) { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 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.clear(); |
| | | pendingValues.addAll(c); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String toString() { |
| | | return getEffectiveValues().toString(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public boolean wasEmpty() { |
| | | return activeValues.isEmpty(); |
| | | } |
| | | } |
| | | |
| | | // The properties. |
| | | private final Map<PropertyDefinition<?>, MyProperty<?>> properties; |
| | | |
| | | /** |
| | | * Create a property with the provided sets of pre-validated |
| | | * default and active values. |
| | | * Creates a new empty property set. |
| | | */ |
| | | public PropertySet() { |
| | | this.properties = new HashMap<PropertyDefinition<?>, MyProperty<?>>(); |
| | | } |
| | | |
| | | /** |
| | | * 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. |
| | | * The property definition. |
| | | * @param defaultValues |
| | | * The set of default values for the property. |
| | | * The set of default values for the property. |
| | | * @param activeValues |
| | | * The set of active values for the property. |
| | | * The set of active values for the property. |
| | | */ |
| | | public MyProperty(PropertyDefinition<T> pd, Collection<T> defaultValues, |
| | | Collection<T> activeValues) { |
| | | this.d = pd; |
| | | |
| | | SortedSet<T> sortedDefaultValues = new TreeSet<T>(pd); |
| | | sortedDefaultValues.addAll(defaultValues); |
| | | this.defaultValues = Collections |
| | | .unmodifiableSortedSet(sortedDefaultValues); |
| | | |
| | | this.activeValues = new TreeSet<T>(pd); |
| | | this.activeValues.addAll(activeValues); |
| | | |
| | | // Initially the pending values is the same as the active |
| | | // values. |
| | | this.pendingValues = new TreeSet<T>(this.activeValues); |
| | | public <T> void addProperty(PropertyDefinition<T> pd, Collection<T> defaultValues, Collection<T> activeValues) { |
| | | MyProperty<T> p = new MyProperty<T>(pd, defaultValues, activeValues); |
| | | properties.put(pd, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Makes the pending values active. |
| | | */ |
| | | public void commit() { |
| | | activeValues.clear(); |
| | | activeValues.addAll(pendingValues); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public SortedSet<T> getActiveValues() { |
| | | return Collections.unmodifiableSortedSet(activeValues); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public SortedSet<T> getDefaultValues() { |
| | | return defaultValues; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public SortedSet<T> getEffectiveValues() { |
| | | SortedSet<T> values = getPendingValues(); |
| | | |
| | | if (values.isEmpty()) { |
| | | values = getDefaultValues(); |
| | | } |
| | | |
| | | return values; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public SortedSet<T> getPendingValues() { |
| | | return Collections.unmodifiableSortedSet(pendingValues); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public PropertyDefinition<T> getPropertyDefinition() { |
| | | return d; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean isEmpty() { |
| | | return pendingValues.isEmpty(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean isModified() { |
| | | if (activeValues.size() == pendingValues.size() |
| | | && activeValues.containsAll(pendingValues)) { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Replace all pending values of this property with the provided |
| | | * values. |
| | | * Get the property associated with the specified property definition. |
| | | * |
| | | * @param c |
| | | * The new set of pending property values. |
| | | * @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. |
| | | */ |
| | | public void setPendingValues(Collection<T> c) { |
| | | pendingValues.clear(); |
| | | pendingValues.addAll(c); |
| | | @SuppressWarnings("unchecked") |
| | | public <T> Property<T> getProperty(PropertyDefinition<T> d) { |
| | | if (!properties.containsKey(d)) { |
| | | throw new IllegalArgumentException("Unknown property " + d.getName()); |
| | | } |
| | | |
| | | return (Property<T>) properties.get(d); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String toString() { |
| | | return getEffectiveValues().toString(); |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append('{'); |
| | | for (Map.Entry<PropertyDefinition<?>, MyProperty<?>> entry : properties.entrySet()) { |
| | | builder.append(entry.getKey().getName()); |
| | | builder.append('='); |
| | | builder.append(entry.getValue().toString()); |
| | | builder.append(' '); |
| | | } |
| | | builder.append('}'); |
| | | return builder.toString(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | * Makes all pending values active. |
| | | */ |
| | | public boolean wasEmpty() { |
| | | return activeValues.isEmpty(); |
| | | } |
| | | } |
| | | |
| | | // The properties. |
| | | private final Map<PropertyDefinition<?>, MyProperty<?>> properties; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new empty property set. |
| | | */ |
| | | public PropertySet() { |
| | | this.properties = new HashMap<PropertyDefinition<?>, MyProperty<?>>(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 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. |
| | | */ |
| | | public <T> void addProperty(PropertyDefinition<T> pd, |
| | | Collection<T> defaultValues, Collection<T> activeValues) { |
| | | MyProperty<T> p = new MyProperty<T>(pd, defaultValues, activeValues); |
| | | properties.put(pd, p); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 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") |
| | | public <T> Property<T> getProperty(PropertyDefinition<T> d) |
| | | throws IllegalArgumentException { |
| | | if (!properties.containsKey(d)) { |
| | | throw new IllegalArgumentException("Unknown property " + d.getName()); |
| | | void commit() { |
| | | for (MyProperty<?> p : properties.values()) { |
| | | p.commit(); |
| | | } |
| | | } |
| | | |
| | | return (Property<T>) properties.get(d); |
| | | } |
| | | /** |
| | | * 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 IllegalPropertyValueException |
| | | * If a new pending value is deemed to be invalid according to |
| | | * the property definition. |
| | | * @throws PropertyIsSingleValuedException |
| | | * If an attempt was made to add multiple pending values to a |
| | | * single-valued property. |
| | | * @throws PropertyIsMandatoryException |
| | | * If an attempt was made to remove a mandatory property. |
| | | * @throws IllegalArgumentException |
| | | * If the specified property definition is not associated with |
| | | * this managed object. |
| | | */ |
| | | <T> void setPropertyValues(PropertyDefinition<T> d, Collection<T> values) { |
| | | MyProperty<T> property = (MyProperty<T>) getProperty(d); |
| | | |
| | | if (values.size() > 1 && !d.hasOption(PropertyOption.MULTI_VALUED)) { |
| | | throw new PropertyIsSingleValuedException(d); |
| | | } |
| | | |
| | | if (values.isEmpty() && d.hasOption(PropertyOption.MANDATORY)) { |
| | | // But only if there are no default values. |
| | | if (property.getDefaultValues().isEmpty()) { |
| | | throw new PropertyIsMandatoryException(d); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String toString() { |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append('{'); |
| | | for (Map.Entry<PropertyDefinition<?>, MyProperty<?>> entry : properties |
| | | .entrySet()) { |
| | | builder.append(entry.getKey().getName()); |
| | | builder.append('='); |
| | | builder.append(entry.getValue().toString()); |
| | | builder.append(' '); |
| | | // Validate each value. |
| | | for (T e : values) { |
| | | if (e == null) { |
| | | throw new NullPointerException(); |
| | | } |
| | | |
| | | d.validateValue(e); |
| | | } |
| | | |
| | | // Update the property. |
| | | property.setPendingValues(values); |
| | | } |
| | | builder.append('}'); |
| | | return builder.toString(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * Makes all pending values active. |
| | | */ |
| | | void commit() { |
| | | for (MyProperty<?> p : properties.values()) { |
| | | 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 IllegalPropertyValueException |
| | | * If a new pending value is deemed to be invalid |
| | | * according to the property definition. |
| | | * @throws PropertyIsSingleValuedException |
| | | * If an attempt was made to add multiple pending values |
| | | * to a single-valued property. |
| | | * @throws PropertyIsMandatoryException |
| | | * If an attempt was made to remove a mandatory property. |
| | | * @throws IllegalArgumentException |
| | | * If the specified property definition is not associated |
| | | * with this managed object. |
| | | */ |
| | | <T> void setPropertyValues(PropertyDefinition<T> d, |
| | | Collection<T> values) throws IllegalPropertyValueException, |
| | | PropertyIsSingleValuedException, PropertyIsMandatoryException, |
| | | IllegalArgumentException { |
| | | MyProperty<T> property = (MyProperty<T>) getProperty(d); |
| | | |
| | | if (values.size() > 1 && !d.hasOption(PropertyOption.MULTI_VALUED)) { |
| | | throw new PropertyIsSingleValuedException(d); |
| | | } |
| | | |
| | | if (values.isEmpty() && d.hasOption(PropertyOption.MANDATORY)) { |
| | | // But only if there are no default values. |
| | | if (property.getDefaultValues().isEmpty()) { |
| | | throw new PropertyIsMandatoryException(d); |
| | | } |
| | | } |
| | | |
| | | // Validate each value. |
| | | for (T e : values) { |
| | | if (e == null) { |
| | | throw new NullPointerException(); |
| | | } |
| | | |
| | | d.validateValue(e); |
| | | } |
| | | |
| | | // Update the property. |
| | | property.setPendingValues(values); |
| | | } |
| | | } |
| | |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | |
| | | |
| | | /** |
| | | * Client side driver implementation interfaces. |
| | | * <p> |
| | |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.util.Reject; |
| | | import org.opends.server.admin.AbstractManagedObjectDefinition; |
| | | import org.opends.server.admin.IllegalPropertyValueStringException; |
| | | import org.opends.server.admin.PropertyDefinition; |
| | | import org.opends.server.admin.client.ManagedObject; |
| | | import org.opends.server.admin.client.ManagementContext; |
| | |
| | | final T value; |
| | | |
| | | // Private constructor. |
| | | private Impl(PropertyDefinition<T> pd, T value) throws IllegalPropertyValueStringException { |
| | | private Impl(PropertyDefinition<T> pd, T value) { |
| | | this.pd = pd; |
| | | this.value = value; |
| | | } |
| | |
| | | } |
| | | |
| | | // Creates the new private implementation. |
| | | private <T> void buildImpl(PropertyDefinition<T> pd) throws IllegalPropertyValueStringException { |
| | | private <T> void buildImpl(PropertyDefinition<T> pd) { |
| | | T value = pd.decodeValue(propertyStringValue); |
| | | this.impl = new Impl<T>(pd, value); |
| | | } |
| | |
| | | * It is based on the Admin Framework Introspection API |
| | | */ |
| | | @SuppressWarnings({ "unchecked", "rawtypes" }) |
| | | public class ConfigGuideGeneration { |
| | | public final class ConfigGuideGeneration { |
| | | |
| | | // Note : still to be done : |
| | | // I18n support. Today all the strings are hardcoded in this file |
| | | |
| | | private final static String ACI_SYNTAX_REL_URL = "/doc/admin-guide/#about-acis"; |
| | | private final static String DURATION_SYNTAX_REL_URL = "duration-syntax.html"; |
| | | private final String CSS_FILE = "opendj-config.css"; |
| | | private static final String CSS_FILE = "opendj-config.css"; |
| | | |
| | | private final String MAIN_FILE = "index.html"; |
| | | private final String INHERITANCE_TREE_FILE = "ManagedObjectInheritanceTree.html"; |
| | | private final String RELATION_TREE_FILE = "ManagedObjectRelationTree.html"; |
| | | private final String MO_LIST_FILE = "ManagedObjectList.html"; |
| | | private final String PROPERTIES_INDEX_FILE = "PropertiesIndex.html"; |
| | | private final String WELCOME_FILE = "welcome.html"; |
| | | private final String MAINTOP_FILE = "maintop.html"; |
| | | private final String INDEX_FILE = "index.html"; |
| | | private final String FAVICON = "http://forgerock.org/favicon.ico"; |
| | | private static final String MAIN_FILE = "index.html"; |
| | | private static final String INHERITANCE_TREE_FILE = "ManagedObjectInheritanceTree.html"; |
| | | private static final String RELATION_TREE_FILE = "ManagedObjectRelationTree.html"; |
| | | private static final String MO_LIST_FILE = "ManagedObjectList.html"; |
| | | private static final String PROPERTIES_INDEX_FILE = "PropertiesIndex.html"; |
| | | private static final String WELCOME_FILE = "welcome.html"; |
| | | private static final String MAINTOP_FILE = "maintop.html"; |
| | | private static final String INDEX_FILE = "index.html"; |
| | | private static final String FAVICON = "http://forgerock.org/favicon.ico"; |
| | | |
| | | private static final String CONFIG_GUIDE_DIR = "opendj_config_guide"; |
| | | private final String MAIN_FRAME = "mainFrame"; |
| | | private static final String MAIN_FRAME = "mainFrame"; |
| | | |
| | | private ConfigGuideGeneration() { |
| | | // no implementation required. |
| | | } |
| | | |
| | | /** |
| | | * Entry point for documentation generation. Properties: GenerationDir - The |
| | |
| | | ldapMapping = true; |
| | | } |
| | | |
| | | OpenDJWiki = properties.getProperty("OpenDJWiki"); |
| | | if (OpenDJWiki == null) { |
| | | openDJWiki = properties.getProperty("OpenDJWiki"); |
| | | if (openDJWiki == null) { |
| | | // Default is current wiki |
| | | OpenDJWiki = "http://wikis.forgerock.org/confluence/display/OPENDJ"; |
| | | openDJWiki = "http://wikis.forgerock.org/confluence/display/OPENDJ"; |
| | | } |
| | | |
| | | OpenDJHome = properties.getProperty("OpenDJHome"); |
| | | if (OpenDJHome == null) { |
| | | openDJHome = properties.getProperty("OpenDJHome"); |
| | | if (openDJHome == null) { |
| | | // Default is current OpenDJ project home |
| | | OpenDJHome = "http://opendj.forgerock.org"; |
| | | openDJHome = "http://opendj.forgerock.org"; |
| | | } |
| | | |
| | | aciSyntaxPage = OpenDJHome + ACI_SYNTAX_REL_URL; |
| | | aciSyntaxPage = openDJHome + ACI_SYNTAX_REL_URL; |
| | | durationSyntaxPage = DURATION_SYNTAX_REL_URL; |
| | | |
| | | ConfigGuideGeneration myGen = new ConfigGuideGeneration(); |
| | |
| | | */ |
| | | |
| | | private void genManagedObjectInheritanceTree( |
| | | TreeMap<String, TreeMap<String, AbstractManagedObjectDefinition>> list) { |
| | | TreeMap<String, TreeMap<String, AbstractManagedObjectDefinition>> list) { |
| | | |
| | | htmlHeader(DynamicConstants.PRODUCT_NAME + " " + "Configuration Reference - Inheritance View"); |
| | | tabMenu(INHERITANCE_TREE_FILE); |
| | |
| | | TreeMap<String, AbstractManagedObjectDefinition> catList = list.get(catName); |
| | | for (AbstractManagedObjectDefinition mo : catList.values()) { |
| | | if ((relList.get(mo.getName()) != null) |
| | | && (relList.get(mo.getName()).hasOption(RelationOption.HIDDEN))) { |
| | | && (relList.get(mo.getName()).hasOption(RelationOption.HIDDEN))) { |
| | | continue; |
| | | } |
| | | paragraph(getLink(mo.getUserFriendlyName().toString(), mo.getName() + ".html", MAIN_FRAME)); |
| | |
| | | htmlHeader(DynamicConstants.PRODUCT_NAME + " Configuration Reference - Structure View"); |
| | | tabMenu(RELATION_TREE_FILE); |
| | | viewHelp("This view represents the structural relationships between " |
| | | + "components and indicates how certain components can exist only within " + "container components."); |
| | | + "components and indicates how certain components can exist only within " + "container components."); |
| | | jumpSection(); |
| | | |
| | | for (String catName : list.keySet()) { |
| | |
| | | if (rel.hasOption(RelationOption.HIDDEN)) { |
| | | continue; |
| | | } |
| | | String linkStr = getLink(childMo.getUserFriendlyName().toString(), childMo.getName() + ".html", |
| | | MAIN_FRAME); |
| | | String linkStr = |
| | | getLink(childMo.getUserFriendlyName().toString(), childMo.getName() + ".html", MAIN_FRAME); |
| | | String fromStr = ""; |
| | | if (!parentMo.getName().equals("")) { |
| | | fromStr = " (from " |
| | | fromStr = |
| | | " (from " |
| | | + getLink(parentMo.getUserFriendlyName().toString(), parentMo.getName() + ".html", MAIN_FRAME) |
| | | + ")"; |
| | | } |
| | |
| | | if (!mo.getParent().isTop()) { |
| | | heading3("Parent Component"); |
| | | paragraph("The " + mo.getUserFriendlyName() + " component inherits from the " |
| | | + getLink(mo.getParent().getUserFriendlyName().toString(), mo.getParent().getName() + ".html")); |
| | | + getLink(mo.getParent().getUserFriendlyName().toString(), mo.getParent().getName() + ".html")); |
| | | } |
| | | |
| | | // Relations |
| | |
| | | |
| | | private void homeLink() { |
| | | htmlBuff.append("<div style=\"font-size:11px;margin-top:-10px;" |
| | | + "margin-bottom:-10px; text-align:right\"><a href=\"" + MAIN_FILE |
| | | + "\" target=\"_top\">Configuration Reference Home</a></div>"); |
| | | + "margin-bottom:-10px; text-align:right\"><a href=\"" + MAIN_FILE |
| | | + "\" target=\"_top\">Configuration Reference Home</a></div>"); |
| | | } |
| | | |
| | | private void generateRelationsSection(AbstractManagedObjectDefinition mo) { |
| | |
| | | |
| | | if (!isCompRelsEmpty) { |
| | | paragraph("The following components have a direct COMPOSITION relation FROM " |
| | | + mo.getUserFriendlyPluralName() + " :"); |
| | | + mo.getUserFriendlyPluralName() + " :"); |
| | | for (RelationDefinition rel : compRels) { |
| | | if (rel.hasOption(RelationOption.HIDDEN)) { |
| | | continue; |
| | |
| | | } |
| | | if (!aggregProps.isEmpty()) { |
| | | paragraph("The following components have a direct AGGREGATION relation FROM " |
| | | + mo.getUserFriendlyPluralName() + " :"); |
| | | TreeMap<String, AbstractManagedObjectDefinition> componentList = new TreeMap<String, AbstractManagedObjectDefinition>(); |
| | | + mo.getUserFriendlyPluralName() + " :"); |
| | | TreeMap<String, AbstractManagedObjectDefinition> componentList = |
| | | new TreeMap<String, AbstractManagedObjectDefinition>(); |
| | | for (AggregationPropertyDefinition agg : aggregProps) { |
| | | RelationDefinition rel = agg.getRelationDefinition(); |
| | | AbstractManagedObjectDefinition childRel = rel.getChildDefinition(); |
| | |
| | | if (!mo.getReverseRelationDefinitions().isEmpty()) { |
| | | if (!isReverseCompRelsEmpty) { |
| | | paragraph("The following components have a direct COMPOSITION relation TO " |
| | | + mo.getUserFriendlyPluralName() + " :"); |
| | | + mo.getUserFriendlyPluralName() + " :"); |
| | | for (RelationDefinition rel : reverseCompRels) { |
| | | beginList(); |
| | | AbstractManagedObjectDefinition childRel = rel.getParentDefinition(); |
| | |
| | | } |
| | | if (!isReverseAggregPropsEmpty) { |
| | | paragraph("The following components have a direct AGGREGATION relation TO " |
| | | + mo.getUserFriendlyPluralName() + " :"); |
| | | TreeMap<String, AbstractManagedObjectDefinition> componentList = new TreeMap<String, AbstractManagedObjectDefinition>(); |
| | | + mo.getUserFriendlyPluralName() + " :"); |
| | | TreeMap<String, AbstractManagedObjectDefinition> componentList = |
| | | new TreeMap<String, AbstractManagedObjectDefinition>(); |
| | | for (AggregationPropertyDefinition agg : reverseAggregProps) { |
| | | AbstractManagedObjectDefinition fromMo = agg.getManagedObjectDefinition(); |
| | | componentList.put(fromMo.getName(), fromMo); |
| | |
| | | // Property table |
| | | startTable(); |
| | | tableRow("Description", |
| | | ((prop.getSynopsis() != null) ? prop.getSynopsis().toString() + " " : "") |
| | | + ((prop.getDescription() != null) ? prop.getDescription().toString() : "")); |
| | | ((prop.getSynopsis() != null) ? prop.getSynopsis().toString() + " " : "") |
| | | + ((prop.getDescription() != null) ? prop.getDescription().toString() : "")); |
| | | |
| | | // Default value |
| | | String defValueStr = getDefaultBehaviorString(prop); |
| | |
| | | Type actionType = prop.getAdministratorAction().getType(); |
| | | String actionStr = ""; |
| | | if (actionType == Type.COMPONENT_RESTART) { |
| | | actionStr = "The " + mo.getUserFriendlyName() |
| | | actionStr = |
| | | "The " + mo.getUserFriendlyName() |
| | | + " must be disabled and re-enabled for changes to this setting " + "to take effect"; |
| | | } else if (actionType == Type.SERVER_RESTART) { |
| | | actionStr = "Restart the server"; |
| | |
| | | } |
| | | |
| | | private void propertiesLinkTable(TreeMap<String, PropertyDefinition> basicProps, |
| | | TreeMap<String, PropertyDefinition> advancedProps) { |
| | | TreeMap<String, PropertyDefinition> advancedProps) { |
| | | htmlBuff.append("<table border=\"0\" cellspacing=\"0\" class=\"jump-table\">\n" + " <tr>\n" |
| | | + " <th>Basic Properties:</th>\n" + " <th>Advanced Properties:</th>\n" + " </tr>\n"); |
| | | + " <th>Basic Properties:</th>\n" + " <th>Advanced Properties:</th>\n" + " </tr>\n"); |
| | | |
| | | PropertyDefinition[] basicPropsArray = basicProps.values().toArray(new PropertyDefinition[0]); |
| | | PropertyDefinition[] advancedPropsArray = advancedProps.values().toArray(new PropertyDefinition[0]); |
| | |
| | | |
| | | String basicHtmlCell = ""; |
| | | if (basicPropName != null) { |
| | | basicHtmlCell = " <td>↓ <a href=\"#" + basicPropName + "\">" + basicPropName |
| | | + "</a></td>\n"; |
| | | basicHtmlCell = |
| | | " <td>↓ <a href=\"#" + basicPropName + "\">" + basicPropName + "</a></td>\n"; |
| | | } else if ((basicPropsArray.length == 0) && (ii == 0)) { |
| | | basicHtmlCell = " <td> None</td>\n"; |
| | | } else if (ii >= basicPropsArray.length) { |
| | |
| | | |
| | | String advancedHtmlCell = ""; |
| | | if (advancedPropName != null) { |
| | | advancedHtmlCell = " <td>↓ <a href=\"#" + advancedPropName + "\">" + advancedPropName |
| | | + "</a></td>\n"; |
| | | advancedHtmlCell = |
| | | " <td>↓ <a href=\"#" + advancedPropName + "\">" + advancedPropName + "</a></td>\n"; |
| | | } else if ((advancedPropsArray.length == 0) && (ii == 0)) { |
| | | advancedHtmlCell = " <td> None</td>\n"; |
| | | } |
| | |
| | | |
| | | heading3("LDAP Mapping"); |
| | | paragraph("Each configuration property can be mapped to a specific " |
| | | + "LDAP attribute under the \"cn=config\" entry. " |
| | | + "The mappings that follow are provided for information only. " |
| | | + "In general, you should avoid changing the server configuration " |
| | | + "by manipulating the LDAP attributes directly."); |
| | | + "LDAP attribute under the \"cn=config\" entry. " |
| | | + "The mappings that follow are provided for information only. " |
| | | + "In general, you should avoid changing the server configuration " |
| | | + "by manipulating the LDAP attributes directly."); |
| | | |
| | | // Managed object table |
| | | startTable(); |
| | |
| | | lettersPointers += getLink(letter, "#" + letter) + " "; |
| | | } |
| | | moPointers.append("<p> " |
| | | + getLink(mo.getUserFriendlyName().toString(), mo.getName() + ".html", MAIN_FRAME) + "</p>\n"); |
| | | + getLink(mo.getUserFriendlyName().toString(), mo.getName() + ".html", MAIN_FRAME) + "</p>\n"); |
| | | } |
| | | paragraph(lettersPointers); |
| | | htmlBuff.append(moPointers); |
| | |
| | | htmlHeader(DynamicConstants.PRODUCT_NAME + " Configuration Reference - Properties View"); |
| | | tabMenu(PROPERTIES_INDEX_FILE); |
| | | viewHelp("This view provides a list of all configuration properties, " |
| | | + "in alphabetical order, and indicates the configuration component to " |
| | | + "which each property applies."); |
| | | + "in alphabetical order, and indicates the configuration component to " + "which each property applies."); |
| | | |
| | | newline(); |
| | | paragraph(lettersPointers); |
| | |
| | | htmlHeader(DynamicConstants.PRODUCT_NAME + " Configuration Reference - Welcome"); |
| | | heading2("About This Reference"); |
| | | paragraph("This reference " + "describes the " + DynamicConstants.PRODUCT_NAME |
| | | + " configuration properties that can be manipulated " + "with the dsconfig command."); |
| | | + " configuration properties that can be manipulated " + "with the dsconfig command."); |
| | | paragraph("Configuration components are grouped according to the area of " |
| | | + "the server in which they are used, as follows:"); |
| | | + "the server in which they are used, as follows:"); |
| | | |
| | | beginList(); |
| | | for (String catName : catTopMoList.keySet()) { |
| | |
| | | endList(); |
| | | |
| | | paragraph("For ease of reference, the configuration is described on multiple " |
| | | + "tabs. These tabs provide alternative views of the configuration " + "components:"); |
| | | + "tabs. These tabs provide alternative views of the configuration " + "components:"); |
| | | beginList(); |
| | | bullet("The <strong>Inheritance</strong> view represents the inheritance " |
| | | + "relationships between configuration components. A sub-component " |
| | | + "inherits all of the properties of its parent component."); |
| | | + "relationships between configuration components. A sub-component " |
| | | + "inherits all of the properties of its parent component."); |
| | | bullet("The <strong>Structure</strong> view represents the structural " |
| | | + "relationships between components and indicates how certain components " |
| | | + "can exist only within container components. When a container " |
| | | + "component is deleted, all of the components within it are also " + "deleted."); |
| | | + "relationships between components and indicates how certain components " |
| | | + "can exist only within container components. When a container " |
| | | + "component is deleted, all of the components within it are also " + "deleted."); |
| | | bullet("The <strong>Components</strong> view provides an alphabetical list " |
| | | + "of all configuration components."); |
| | | + "of all configuration components."); |
| | | bullet("The <strong>Properties</strong> view provides an alphabetical list " |
| | | + "of all configuration properties, and indicates the configuration " |
| | | + "component to which each property applies."); |
| | | + "of all configuration properties, and indicates the configuration " |
| | | + "component to which each property applies."); |
| | | endList(); |
| | | |
| | | newline(); |
| | | paragraph("When you set up " + DynamicConstants.PRODUCT_NAME + ", certain components are created in the " |
| | | + "configuration by default. These components are configured with " |
| | | + "specific values, which are not necessarily the same as the " |
| | | + "\"default values\" of new components that you create using dsconfig. " |
| | | + "The \"default values\" listed in this document refer to the values " |
| | | + "of the new components that you create using dsconfig."); |
| | | + "configuration by default. These components are configured with " |
| | | + "specific values, which are not necessarily the same as the " |
| | | + "\"default values\" of new components that you create using dsconfig. " |
| | | + "The \"default values\" listed in this document refer to the values " |
| | | + "of the new components that you create using dsconfig."); |
| | | |
| | | htmlFooter(); |
| | | generateFile(WELCOME_FILE); |
| | |
| | | |
| | | private void genMainTopPage() { |
| | | htmlHeader(DynamicConstants.PRODUCT_NAME + " Configuration Reference - Main Top"); |
| | | htmlBuff.append("<div class=\"breadcrumb\"><span class=\"pageactions\">" + "<a href=\"" + OpenDJHome |
| | | + "\" target=\"_parent\">" + "<span style=\"font-size: 12px;\">« </span>" |
| | | + "Back to " + DynamicConstants.PRODUCT_NAME + " Home</a></span> </div>\n"); |
| | | htmlBuff.append("<div class=\"breadcrumb\"><span class=\"pageactions\">" + "<a href=\"" + openDJHome |
| | | + "\" target=\"_parent\">" + "<span style=\"font-size: 12px;\">« </span>" + "Back to " |
| | | + DynamicConstants.PRODUCT_NAME + " Home</a></span> </div>\n"); |
| | | htmlBuff.append("<table class=\"titletable\" cellspacing=\"0\" " + "width=\"100%\">\n"); |
| | | htmlBuff.append("<tbody><tr>\n"); |
| | | htmlBuff.append(" <td><h2>" + DynamicConstants.PRODUCT_NAME + " Configuration Reference</h2></td>\n"); |
| | | htmlBuff.append(" <td valign=\"bottom\" width=\"10%\">" + "<a href=\"" + OpenDJHome |
| | | + "\" target=\"_parent\">" + "<img src=\"opendj_logo_sm.png\" alt=\"OpenDJ Logo\" align=\"bottom\" " |
| | | + "border=\"0\" height=\"33\" width=\"114\"></a></td>\n"); |
| | | htmlBuff.append(" <td valign=\"bottom\" width=\"10%\">" + "<a href=\"" + openDJHome |
| | | + "\" target=\"_parent\">" + "<img src=\"opendj_logo_sm.png\" alt=\"OpenDJ Logo\" align=\"bottom\" " |
| | | + "border=\"0\" height=\"33\" width=\"114\"></a></td>\n"); |
| | | htmlBuff.append("</tr>\n"); |
| | | htmlBuff.append("</tbody></table>\n"); |
| | | |
| | |
| | | htmlBuff.append(getHtmlHeader(DynamicConstants.PRODUCT_NAME + " Configuration Reference")); |
| | | |
| | | htmlBuff.append("<frameset rows=\"80,*\" framespacing=\"1\" " |
| | | + "frameborder=\"yes\" border=\"1\" bordercolor=\"#333333\">\n"); |
| | | + "frameborder=\"yes\" border=\"1\" bordercolor=\"#333333\">\n"); |
| | | htmlBuff.append(" <frame src=\"" + MAINTOP_FILE + "\" name=\"topFrame\" " |
| | | + "id=\"topFrame\" border=\"1\" title=\"topFrame\" scrolling=\"no\">\n"); |
| | | htmlBuff.append(" <frameset cols=\"375,*\" frameborder=\"yes\" " + "border=\"1\" " + "framespacing=\"1\">\n"); |
| | | + "id=\"topFrame\" border=\"1\" title=\"topFrame\" scrolling=\"no\">\n"); |
| | | htmlBuff |
| | | .append(" <frameset cols=\"375,*\" frameborder=\"yes\" " + "border=\"1\" " + "framespacing=\"1\">\n"); |
| | | htmlBuff.append(" <frame src=\"" + INHERITANCE_TREE_FILE + "\" " |
| | | + "name=\"leftFrame\" id=\"leftFrame\" title=\"leftFrame\" " + "scrolling=\"auto\">\n"); |
| | | + "name=\"leftFrame\" id=\"leftFrame\" title=\"leftFrame\" " + "scrolling=\"auto\">\n"); |
| | | htmlBuff.append(" <frame src=\"" + WELCOME_FILE + "\" name=\"mainFrame\" " |
| | | + "id=\"mainFrame\" title=\"mainFrame\" scrolling=\"auto\">\n"); |
| | | + "id=\"mainFrame\" title=\"mainFrame\" scrolling=\"auto\">\n"); |
| | | htmlBuff.append(" </frameset>\n"); |
| | | htmlBuff.append("</frameset>\n"); |
| | | htmlBuff.append("<noframes><body>\n"); |
| | |
| | | RelationDefinition rel = prop.getRelationDefinition(); |
| | | String linkStr = getLink(rel.getUserFriendlyName().toString(), rel.getName() + ".html"); |
| | | return "The DN of any " |
| | | + linkStr |
| | | + ". " |
| | | + ((prop.getSourceConstraintSynopsis() != null) ? prop.getSourceConstraintSynopsis() |
| | | .toString() : ""); |
| | | + linkStr |
| | | + ". " |
| | | + ((prop.getSourceConstraintSynopsis() != null) ? prop.getSourceConstraintSynopsis().toString() |
| | | : ""); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (prop.getMaximumUnit() != null) { |
| | | durationStr += "Maximum unit is \"" + prop.getMaximumUnit().getLongName() + "\". "; |
| | | } |
| | | long lowerLimitStr = new Double(prop.getBaseUnit().fromMilliSeconds(prop.getLowerLimit())) |
| | | .longValue(); |
| | | long lowerLimitStr = |
| | | new Double(prop.getBaseUnit().fromMilliSeconds(prop.getLowerLimit())).longValue(); |
| | | durationStr += "Lower limit is " + lowerLimitStr + " " + prop.getBaseUnit().getLongName() + ". "; |
| | | if (prop.getUpperLimit() != null) { |
| | | long upperLimitStr = new Double(prop.getBaseUnit().fromMilliSeconds(prop.getUpperLimit())) |
| | | .longValue(); |
| | | long upperLimitStr = |
| | | new Double(prop.getBaseUnit().fromMilliSeconds(prop.getUpperLimit())).longValue(); |
| | | durationStr += "Upper limit is " + upperLimitStr + " " + prop.getBaseUnit().getLongName() + ". "; |
| | | } |
| | | |
| | |
| | | AliasDefaultBehaviorProvider aliasBehav = (AliasDefaultBehaviorProvider) defaultBehav; |
| | | defValueStr = aliasBehav.getSynopsis().toString(); |
| | | } else if (defaultBehav instanceof RelativeInheritedDefaultBehaviorProvider) { |
| | | RelativeInheritedDefaultBehaviorProvider relativBehav = (RelativeInheritedDefaultBehaviorProvider) defaultBehav; |
| | | defValueStr = getDefaultBehaviorString(relativBehav.getManagedObjectDefinition().getPropertyDefinition( |
| | | RelativeInheritedDefaultBehaviorProvider relativBehav = |
| | | (RelativeInheritedDefaultBehaviorProvider) defaultBehav; |
| | | defValueStr = |
| | | getDefaultBehaviorString(relativBehav.getManagedObjectDefinition().getPropertyDefinition( |
| | | relativBehav.getPropertyName())); |
| | | } else if (defaultBehav instanceof AbsoluteInheritedDefaultBehaviorProvider) { |
| | | AbsoluteInheritedDefaultBehaviorProvider absoluteBehav = (AbsoluteInheritedDefaultBehaviorProvider) defaultBehav; |
| | | defValueStr = getDefaultBehaviorString(absoluteBehav.getManagedObjectDefinition().getPropertyDefinition( |
| | | AbsoluteInheritedDefaultBehaviorProvider absoluteBehav = |
| | | (AbsoluteInheritedDefaultBehaviorProvider) defaultBehav; |
| | | defValueStr = |
| | | getDefaultBehaviorString(absoluteBehav.getManagedObjectDefinition().getPropertyDefinition( |
| | | absoluteBehav.getPropertyName())); |
| | | } |
| | | return defValueStr; |
| | | } |
| | | |
| | | private TreeMap<String, AbstractManagedObjectDefinition> makeMOTreeMap( |
| | | Collection<AbstractManagedObjectDefinition> coll) { |
| | | Collection<AbstractManagedObjectDefinition> coll) { |
| | | |
| | | if (coll == null) { |
| | | return null; |
| | |
| | | |
| | | } |
| | | |
| | | private final String Now = new Date().toString(); |
| | | private static final String NOW = new Date().toString(); |
| | | |
| | | private String getHtmlHeader(String pageTitle) { |
| | | return ("<html>\n" + "<head>\n" + "<meta http-equiv=\"content-type\"\n" |
| | | + "content=\"text/html; charset=ISO-8859-1\">\n" + "<title>" + pageTitle + "</title>\n" |
| | | + "<link rel=\"stylesheet\" type=\"text/css\"\n" + "href=\"" + CSS_FILE + "\">\n" |
| | | + "<link rel=\"shortcut icon\" href=\"" + FAVICON + "\">\n" |
| | | + "<meta name=\"date generated\" content=\"" + Now + "\">\n" + "</head>\n"); |
| | | + "content=\"text/html; charset=ISO-8859-1\">\n" + "<title>" + pageTitle + "</title>\n" |
| | | + "<link rel=\"stylesheet\" type=\"text/css\"\n" + "href=\"" + CSS_FILE + "\">\n" |
| | | + "<link rel=\"shortcut icon\" href=\"" + FAVICON + "\">\n" + "<meta name=\"date generated\" content=\"" |
| | | + NOW + "\">\n" + "</head>\n"); |
| | | } |
| | | |
| | | // Add a Tab Menu, the active tab is the one given as parameter |
| | | private void tabMenu(String activeTab) { |
| | | // @Checkstyle:off |
| | | htmlBuff.append("<div class=\"tabmenu\"> " + |
| | | |
| | | "<span><a " + (activeTab.equals(INHERITANCE_TREE_FILE) ? "class=\"activetab\" " : "") + "href=\"" |
| | | + INHERITANCE_TREE_FILE + "\"" + " title=\"Inheritance View of Components\">Inheritance</a></span> " + |
| | | + INHERITANCE_TREE_FILE + "\"" + " title=\"Inheritance View of Components\">Inheritance</a></span> " + |
| | | |
| | | "<span><a " + (activeTab.equals(RELATION_TREE_FILE) ? "class=\"activetab\" " : "") + "href=\"" |
| | | + RELATION_TREE_FILE + "\"" + " title=\"Relational View of Components\">Structure</a></span> " + |
| | | "<span><a " + (activeTab.equals(RELATION_TREE_FILE) ? "class=\"activetab\" " : "") + "href=\"" |
| | | + RELATION_TREE_FILE + "\"" + " title=\"Relational View of Components\">Structure</a></span> " + |
| | | |
| | | "<span><a " + (activeTab.equals(MO_LIST_FILE) ? "class=\"activetab\" " : "") + "href=\"" |
| | | + MO_LIST_FILE + "\"" + " title=\"Alphabetical Index of Components\">Components</a></span> " + |
| | | "<span><a " + (activeTab.equals(MO_LIST_FILE) ? "class=\"activetab\" " : "") + "href=\"" + MO_LIST_FILE |
| | | + "\"" + " title=\"Alphabetical Index of Components\">Components</a></span> " + |
| | | |
| | | "<span><a " + (activeTab.equals(PROPERTIES_INDEX_FILE) ? "class=\"activetab\" " : "") + "href=\"" |
| | | + PROPERTIES_INDEX_FILE + "\"" + " title=\"Alphabetical Index of Properties\" >Properties</a></span>" |
| | | + |
| | | "<span><a " + (activeTab.equals(PROPERTIES_INDEX_FILE) ? "class=\"activetab\" " : "") + "href=\"" |
| | | + PROPERTIES_INDEX_FILE + "\"" + " title=\"Alphabetical Index of Properties\" >Properties</a></span>" + |
| | | |
| | | "</div>" + "\n"); |
| | | "</div>" + "\n"); |
| | | // @Checkstyle:on |
| | | } |
| | | |
| | | private String getLink(String str, String link) { |
| | |
| | | |
| | | private String getLink(String str, String link, String target, String color) { |
| | | return "<a " + (color != null ? "style=\"color:" + color + "\" " : "") + "href=\"" + link + "\"" |
| | | + (target == null ? "" : " target=\"" + target + "\"") + ">" + str + "</a>"; |
| | | + (target == null ? "" : " target=\"" + target + "\"") + ">" + str + "</a>"; |
| | | } |
| | | |
| | | private void link(String str, String link) { |
| | |
| | | |
| | | private void startTable() { |
| | | htmlBuff.append("<table " + "style=\"width: 100%; text-align: left;\"" + "border=\"1\"" + "cellpadding=\"1\"" |
| | | + "cellspacing=\"0\"" + ">\n"); |
| | | + "cellspacing=\"0\"" + ">\n"); |
| | | |
| | | htmlBuff.append("<tbody>\n"); |
| | | } |
| | |
| | | for (int ii = 0; ii < strings.length; ii++) { |
| | | String string = strings[ii]; |
| | | htmlBuff.append("<td style=\"" + "vertical-align: top; " + ((ii == 0) ? "width: 20%;" : "") + "\">" |
| | | + string + "<br></td>"); |
| | | + string + "<br></td>"); |
| | | } |
| | | htmlBuff.append("</tr>\n"); |
| | | } |
| | |
| | | private void generateFile(String fileName) { |
| | | // Write the html buffer in a file |
| | | try { |
| | | PrintWriter file = new java.io.PrintWriter(new java.io.FileWriter(generationDir + File.separator |
| | | + fileName)); |
| | | PrintWriter file = |
| | | new java.io.PrintWriter(new java.io.FileWriter(generationDir + File.separator + fileName)); |
| | | file.write(htmlBuff.toString()); |
| | | file.close(); |
| | | } catch (Exception e) { |
| | |
| | | // Relation List from RootConfiguration |
| | | private final TreeMap<String, RelationDefinition> topRelList = new TreeMap<String, RelationDefinition>(); |
| | | private final TreeMap<String, RelationDefinition> relList = new TreeMap<String, RelationDefinition>(); |
| | | private final TreeMap<String, TreeMap<String, RelationDefinition>> catTopRelList = new TreeMap<String, TreeMap<String, RelationDefinition>>(); |
| | | private final TreeMap<String, TreeMap<String, RelationDefinition>> catTopRelList = |
| | | new TreeMap<String, TreeMap<String, RelationDefinition>>(); |
| | | // managed object list |
| | | private final TreeMap<String, AbstractManagedObjectDefinition> moList = new TreeMap<String, AbstractManagedObjectDefinition>(); |
| | | private final TreeMap<String, AbstractManagedObjectDefinition> topMoList = new TreeMap<String, AbstractManagedObjectDefinition>(); |
| | | private final TreeMap<String, TreeMap<String, AbstractManagedObjectDefinition>> catTopMoList = new TreeMap<String, TreeMap<String, AbstractManagedObjectDefinition>>(); |
| | | private final TreeMap<String, AbstractManagedObjectDefinition> moList = |
| | | new TreeMap<String, AbstractManagedObjectDefinition>(); |
| | | private final TreeMap<String, AbstractManagedObjectDefinition> topMoList = |
| | | new TreeMap<String, AbstractManagedObjectDefinition>(); |
| | | private final TreeMap<String, TreeMap<String, AbstractManagedObjectDefinition>> catTopMoList = |
| | | new TreeMap<String, TreeMap<String, AbstractManagedObjectDefinition>>(); |
| | | private final int ind = 0; |
| | | private StringBuffer htmlBuff = new StringBuffer(); |
| | | private static String generationDir; |
| | | private static boolean ldapMapping = false; |
| | | private static String OpenDJWiki; |
| | | private static String OpenDJHome; |
| | | private static String openDJWiki; |
| | | private static String openDJHome; |
| | | private static String aciSyntaxPage; |
| | | private static String durationSyntaxPage; |
| | | private boolean inList = false; |
| | |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | |
| | | |
| | | /** |
| | | * Common administration classes. |
| | | * <p> |
| | |
| | | /** The managed object path. */ |
| | | private final ManagedObjectPath<?, S> path; |
| | | |
| | | /** Repository of configuration entries */ |
| | | /** Repository of configuration entries. */ |
| | | private final ConfigurationRepository configRepository; |
| | | |
| | | private final ServerManagementContext serverContext; |
| | |
| | | * Copyright 2007-2008 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.admin.server; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | |
| | | |
| | | |
| | | import java.util.List; |
| | | |
| | | import org.opends.server.admin.Configuration; |
| | | import org.opends.server.types.ConfigChangeResult; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This interface defines the methods that a Directory Server |
| | | * configurable component should implement if it wishes to be able to |
| | | * receive notifications when a new configuration is added. |
| | | * This interface defines the methods that a Directory Server configurable |
| | | * component should implement if it wishes to be able to receive notifications |
| | | * when a new configuration is added. |
| | | * |
| | | * @param <T> |
| | | * The type of configuration that this listener should be |
| | | * notified about. |
| | | * The type of configuration that this listener should be notified |
| | | * about. |
| | | */ |
| | | public interface ConfigurationAddListener<T extends Configuration> { |
| | | |
| | | /** |
| | | * Indicates whether the proposed addition of a new configuration is |
| | | * acceptable to this add listener. |
| | | * |
| | | * @param configuration |
| | | * The configuration that will be added. |
| | | * @param unacceptableReasons |
| | | * A list that can be used to hold messages about why the |
| | | * provided configuration is not acceptable. |
| | | * @return Returns <code>true</code> if the proposed addition is |
| | | * acceptable, or <code>false</code> if it is not. |
| | | */ |
| | | public boolean isConfigurationAddAcceptable(T configuration, |
| | | List<LocalizableMessage> unacceptableReasons); |
| | | /** |
| | | * Indicates whether the proposed addition of a new configuration is |
| | | * acceptable to this add listener. |
| | | * |
| | | * @param configuration |
| | | * The configuration that will be added. |
| | | * @param unacceptableReasons |
| | | * A list that can be used to hold messages about why the |
| | | * provided configuration is not acceptable. |
| | | * @return Returns <code>true</code> if the proposed addition is acceptable, |
| | | * or <code>false</code> if it is not. |
| | | */ |
| | | public boolean isConfigurationAddAcceptable(T configuration, List<LocalizableMessage> unacceptableReasons); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Adds a new configuration to this add listener. |
| | | * |
| | | * @param configuration |
| | | * The configuration that will be added. |
| | | * @return Returns information about the result of adding the |
| | | * configuration. |
| | | */ |
| | | public ConfigChangeResult applyConfigurationAdd(T configuration); |
| | | /** |
| | | * Adds a new configuration to this add listener. |
| | | * |
| | | * @param configuration |
| | | * The configuration that will be added. |
| | | * @return Returns information about the result of adding the configuration. |
| | | */ |
| | | public ConfigChangeResult applyConfigurationAdd(T configuration); |
| | | } |
| | |
| | | * @param addListener |
| | | * The add listener to be added to the subordinate entry when it |
| | | * is added. |
| | | * @param configRepository TODO |
| | | * @param configRepository |
| | | * Repository of config entries. |
| | | */ |
| | | public DelayedConfigAddListener(DN child, ConfigAddListener addListener, ConfigurationRepository configRepository) { |
| | | this.parent = child.parent(); |
| | |
| | | * @param deleteListener |
| | | * The delete listener to be added to the subordinate entry when |
| | | * it is added. |
| | | * @param configRepository TODO |
| | | * @param configRepository |
| | | * Repository of config entries. |
| | | */ |
| | | public DelayedConfigAddListener(DN child, ConfigDeleteListener deleteListener, ConfigurationRepository configRepository) { |
| | | public DelayedConfigAddListener(DN child, ConfigDeleteListener deleteListener, |
| | | ConfigurationRepository configRepository) { |
| | | this.parent = child.parent(); |
| | | this.child = child; |
| | | this.delayedAddListener = null; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public ConfigChangeResult applyConfigurationAdd(Entry configEntry) { |
| | | if (configEntry.getName().equals(child)) { |
| | | // The subordinate entry matched our criteria so register the |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public boolean configAddIsAcceptable(Entry configEntry, LocalizableMessageBuilder unacceptableReason) { |
| | | // Always acceptable. |
| | | return true; |
| | |
| | | |
| | | private final ManagedObjectDefinition<?, S> definition; |
| | | |
| | | /** The managed object path identifying this managed object's location */ |
| | | /** The managed object path identifying this managed object's location. */ |
| | | private final ManagedObjectPath<?, S> path; |
| | | |
| | | private final Map<PropertyDefinition<?>, SortedSet<?>> properties; |
| | |
| | | * with this managed object's definition. |
| | | */ |
| | | public <M extends Configuration> void deregisterAddListener(InstantiableRelationDefinition<?, M> d, |
| | | ConfigurationAddListener<M> listener) throws IllegalArgumentException { |
| | | ConfigurationAddListener<M> listener) { |
| | | validateRelationDefinition(d); |
| | | DN baseDN = DNBuilder.create(path, d); |
| | | deregisterAddListener(baseDN, listener); |
| | |
| | | * with this managed object's definition. |
| | | */ |
| | | public <M extends Configuration> void deregisterAddListener(InstantiableRelationDefinition<?, M> d, |
| | | ServerManagedObjectAddListener<M> listener) throws IllegalArgumentException { |
| | | ServerManagedObjectAddListener<M> listener) { |
| | | validateRelationDefinition(d); |
| | | DN baseDN = DNBuilder.create(path, d); |
| | | deregisterAddListener(baseDN, listener); |
| | |
| | | * this managed object's definition. |
| | | */ |
| | | public <M extends Configuration> void deregisterAddListener(OptionalRelationDefinition<?, M> d, |
| | | ConfigurationAddListener<M> listener) throws IllegalArgumentException { |
| | | ConfigurationAddListener<M> listener) { |
| | | validateRelationDefinition(d); |
| | | DN baseDN = DNBuilder.create(path, d).parent(); |
| | | deregisterAddListener(baseDN, listener); |
| | |
| | | * this managed object's definition. |
| | | */ |
| | | public <M extends Configuration> void deregisterAddListener(OptionalRelationDefinition<?, M> d, |
| | | ServerManagedObjectAddListener<M> listener) throws IllegalArgumentException { |
| | | ServerManagedObjectAddListener<M> listener) { |
| | | validateRelationDefinition(d); |
| | | DN baseDN = DNBuilder.create(path, d).parent(); |
| | | deregisterAddListener(baseDN, listener); |
| | |
| | | * managed object's definition. |
| | | */ |
| | | public <M extends Configuration> void deregisterAddListener(SetRelationDefinition<?, M> d, |
| | | ConfigurationAddListener<M> listener) throws IllegalArgumentException { |
| | | ConfigurationAddListener<M> listener) { |
| | | validateRelationDefinition(d); |
| | | DN baseDN = DNBuilder.create(path, d); |
| | | deregisterAddListener(baseDN, listener); |
| | |
| | | * managed object's definition. |
| | | */ |
| | | public <M extends Configuration> void deregisterAddListener(SetRelationDefinition<?, M> d, |
| | | ServerManagedObjectAddListener<M> listener) throws IllegalArgumentException { |
| | | ServerManagedObjectAddListener<M> listener) { |
| | | validateRelationDefinition(d); |
| | | DN baseDN = DNBuilder.create(path, d); |
| | | deregisterAddListener(baseDN, listener); |
| | |
| | | ConfigChangeListenerAdaptor<?> adaptor = (ConfigChangeListenerAdaptor<?>) l; |
| | | ServerManagedObjectChangeListener<?> l2 = adaptor.getServerManagedObjectChangeListener(); |
| | | if (l2 instanceof ServerManagedObjectChangeListenerAdaptor<?>) { |
| | | ServerManagedObjectChangeListenerAdaptor<?> adaptor2 = (ServerManagedObjectChangeListenerAdaptor<?>) l2; |
| | | ServerManagedObjectChangeListenerAdaptor<?> adaptor2 = |
| | | (ServerManagedObjectChangeListenerAdaptor<?>) l2; |
| | | if (adaptor2.getConfigurationChangeListener() == listener) { |
| | | adaptor.finalizeChangeListener(); |
| | | configRepository.deregisterChangeListener(configDN, adaptor); |
| | |
| | | * with this managed object's definition. |
| | | */ |
| | | public <M extends Configuration> void deregisterDeleteListener(InstantiableRelationDefinition<?, M> d, |
| | | ConfigurationDeleteListener<M> listener) throws IllegalArgumentException { |
| | | ConfigurationDeleteListener<M> listener) { |
| | | validateRelationDefinition(d); |
| | | |
| | | DN baseDN = DNBuilder.create(path, d); |
| | |
| | | * with this managed object's definition. |
| | | */ |
| | | public <M extends Configuration> void deregisterDeleteListener(InstantiableRelationDefinition<?, M> d, |
| | | ServerManagedObjectDeleteListener<M> listener) throws IllegalArgumentException { |
| | | ServerManagedObjectDeleteListener<M> listener) { |
| | | validateRelationDefinition(d); |
| | | |
| | | DN baseDN = DNBuilder.create(path, d); |
| | |
| | | * this managed object's definition. |
| | | */ |
| | | public <M extends Configuration> void deregisterDeleteListener(OptionalRelationDefinition<?, M> d, |
| | | ConfigurationDeleteListener<M> listener) throws IllegalArgumentException { |
| | | ConfigurationDeleteListener<M> listener) { |
| | | validateRelationDefinition(d); |
| | | |
| | | DN baseDN = DNBuilder.create(path, d).parent(); |
| | |
| | | * this managed object's definition. |
| | | */ |
| | | public <M extends Configuration> void deregisterDeleteListener(OptionalRelationDefinition<?, M> d, |
| | | ServerManagedObjectDeleteListener<M> listener) throws IllegalArgumentException { |
| | | ServerManagedObjectDeleteListener<M> listener) { |
| | | validateRelationDefinition(d); |
| | | |
| | | DN baseDN = DNBuilder.create(path, d).parent(); |
| | |
| | | * managed object's definition. |
| | | */ |
| | | public <M extends Configuration> void deregisterDeleteListener(SetRelationDefinition<?, M> d, |
| | | ConfigurationDeleteListener<M> listener) throws IllegalArgumentException { |
| | | ConfigurationDeleteListener<M> listener) { |
| | | validateRelationDefinition(d); |
| | | |
| | | DN baseDN = DNBuilder.create(path, d); |
| | |
| | | * managed object's definition. |
| | | */ |
| | | public <M extends Configuration> void deregisterDeleteListener(SetRelationDefinition<?, M> d, |
| | | ServerManagedObjectDeleteListener<M> listener) throws IllegalArgumentException { |
| | | ServerManagedObjectDeleteListener<M> listener) { |
| | | validateRelationDefinition(d); |
| | | |
| | | DN baseDN = DNBuilder.create(path, d); |
| | |
| | | * not be decoded. |
| | | */ |
| | | public <M extends Configuration> ServerManagedObject<? extends M> getChild(InstantiableRelationDefinition<?, M> d, |
| | | String name) throws IllegalArgumentException, ConfigException { |
| | | String name) throws ConfigException { |
| | | validateRelationDefinition(d); |
| | | return serverContext.getManagedObject(path.child(d, name)); |
| | | } |
| | |
| | | * not be decoded. |
| | | */ |
| | | public <M extends Configuration> ServerManagedObject<? extends M> getChild(OptionalRelationDefinition<?, M> d) |
| | | throws IllegalArgumentException, ConfigException { |
| | | throws ConfigException { |
| | | validateRelationDefinition(d); |
| | | return serverContext.getManagedObject(path.child(d)); |
| | | } |
| | |
| | | * not be decoded. |
| | | */ |
| | | public <M extends Configuration> ServerManagedObject<? extends M> getChild(SetRelationDefinition<?, M> d, |
| | | String name) throws IllegalArgumentException, ConfigException { |
| | | String name) throws ConfigException { |
| | | validateRelationDefinition(d); |
| | | |
| | | return serverContext.getManagedObject(path.child(d, name)); |
| | |
| | | * not be decoded. |
| | | */ |
| | | public <M extends Configuration> ServerManagedObject<? extends M> getChild(SingletonRelationDefinition<?, M> d) |
| | | throws IllegalArgumentException, ConfigException { |
| | | throws ConfigException { |
| | | validateRelationDefinition(d); |
| | | return serverContext.getManagedObject(path.child(d)); |
| | | } |
| | |
| | | * If the property definition is not associated with this |
| | | * managed object's definition. |
| | | */ |
| | | public <T> T getPropertyValue(PropertyDefinition<T> d) throws IllegalArgumentException { |
| | | public <T> T getPropertyValue(PropertyDefinition<T> d) { |
| | | Set<T> values = getPropertyValues(d); |
| | | if (values.isEmpty()) { |
| | | return null; |
| | |
| | | * managed object's definition. |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public <T> SortedSet<T> getPropertyValues(PropertyDefinition<T> d) throws IllegalArgumentException { |
| | | public <T> SortedSet<T> getPropertyValues(PropertyDefinition<T> d) { |
| | | if (!properties.containsKey(d)) { |
| | | throw new IllegalArgumentException("Unknown property " + d.getName()); |
| | | } |
| | |
| | | * If the optional relation definition is not associated with |
| | | * this managed object's definition. |
| | | */ |
| | | public boolean hasChild(OptionalRelationDefinition<?, ?> d) throws IllegalArgumentException { |
| | | public boolean hasChild(OptionalRelationDefinition<?, ?> d) { |
| | | validateRelationDefinition(d); |
| | | return serverContext.managedObjectExists(path.child(d)); |
| | | } |
| | |
| | | * If the relation definition is not associated with this |
| | | * managed object's definition. |
| | | */ |
| | | public String[] listChildren(InstantiableRelationDefinition<?, ?> d) throws IllegalArgumentException { |
| | | public String[] listChildren(InstantiableRelationDefinition<?, ?> d) { |
| | | validateRelationDefinition(d); |
| | | return serverContext.listManagedObjects(path, d); |
| | | } |
| | |
| | | * If the relation definition is not associated with this |
| | | * managed object's definition. |
| | | */ |
| | | public String[] listChildren(SetRelationDefinition<?, ?> d) throws IllegalArgumentException { |
| | | public String[] listChildren(SetRelationDefinition<?, ?> d) { |
| | | validateRelationDefinition(d); |
| | | return serverContext.listManagedObjects(path, d); |
| | | } |
| | |
| | | * relation could not be retrieved. |
| | | */ |
| | | public <M extends Configuration> void registerAddListener(InstantiableRelationDefinition<?, M> d, |
| | | ConfigurationAddListener<M> listener) throws IllegalArgumentException, ConfigException { |
| | | ConfigurationAddListener<M> listener) throws ConfigException { |
| | | registerAddListener(d, new ServerManagedObjectAddListenerAdaptor<M>(listener)); |
| | | } |
| | | |
| | |
| | | * relation could not be retrieved. |
| | | */ |
| | | public <M extends Configuration> void registerAddListener(InstantiableRelationDefinition<?, M> d, |
| | | ServerManagedObjectAddListener<M> listener) throws IllegalArgumentException, ConfigException { |
| | | ServerManagedObjectAddListener<M> listener) throws ConfigException { |
| | | validateRelationDefinition(d); |
| | | DN baseDN = DNBuilder.create(path, d); |
| | | ConfigAddListener adaptor = new ConfigAddListenerAdaptor<M>(serverContext, path, d, listener); |
| | |
| | | * relation could not be retrieved. |
| | | */ |
| | | public <M extends Configuration> void registerAddListener(OptionalRelationDefinition<?, M> d, |
| | | ConfigurationAddListener<M> listener) throws IllegalArgumentException, ConfigException { |
| | | ConfigurationAddListener<M> listener) throws ConfigException { |
| | | registerAddListener(d, new ServerManagedObjectAddListenerAdaptor<M>(listener)); |
| | | } |
| | | |
| | |
| | | * relation could not be retrieved. |
| | | */ |
| | | public <M extends Configuration> void registerAddListener(OptionalRelationDefinition<?, M> d, |
| | | ServerManagedObjectAddListener<M> listener) throws IllegalArgumentException, ConfigException { |
| | | ServerManagedObjectAddListener<M> listener) throws ConfigException { |
| | | validateRelationDefinition(d); |
| | | DN baseDN = DNBuilder.create(path, d).parent(); |
| | | ConfigAddListener adaptor = new ConfigAddListenerAdaptor<M>(serverContext, path, d, listener); |
| | |
| | | * could not be retrieved. |
| | | */ |
| | | public <M extends Configuration> void registerAddListener(SetRelationDefinition<?, M> d, |
| | | ConfigurationAddListener<M> listener) throws IllegalArgumentException, ConfigException { |
| | | ConfigurationAddListener<M> listener) throws ConfigException { |
| | | registerAddListener(d, new ServerManagedObjectAddListenerAdaptor<M>(listener)); |
| | | } |
| | | |
| | |
| | | * could not be retrieved. |
| | | */ |
| | | public <M extends Configuration> void registerAddListener(SetRelationDefinition<?, M> d, |
| | | ServerManagedObjectAddListener<M> listener) throws IllegalArgumentException, ConfigException { |
| | | ServerManagedObjectAddListener<M> listener) throws ConfigException { |
| | | validateRelationDefinition(d); |
| | | DN baseDN = DNBuilder.create(path, d); |
| | | ConfigAddListener adaptor = new ConfigAddListenerAdaptor<M>(serverContext, path, d, listener); |
| | |
| | | * relation could not be retrieved. |
| | | */ |
| | | public <M extends Configuration> void registerDeleteListener(InstantiableRelationDefinition<?, M> d, |
| | | ConfigurationDeleteListener<M> listener) throws IllegalArgumentException, ConfigException { |
| | | ConfigurationDeleteListener<M> listener) throws ConfigException { |
| | | registerDeleteListener(d, new ServerManagedObjectDeleteListenerAdaptor<M>(listener)); |
| | | } |
| | | |
| | |
| | | * relation could not be retrieved. |
| | | */ |
| | | public <M extends Configuration> void registerDeleteListener(InstantiableRelationDefinition<?, M> d, |
| | | ServerManagedObjectDeleteListener<M> listener) throws IllegalArgumentException, ConfigException { |
| | | ServerManagedObjectDeleteListener<M> listener) throws ConfigException { |
| | | validateRelationDefinition(d); |
| | | DN baseDN = DNBuilder.create(path, d); |
| | | ConfigDeleteListener adaptor = new ConfigDeleteListenerAdaptor<M>(serverContext, path, d, listener); |
| | |
| | | * relation could not be retrieved. |
| | | */ |
| | | public <M extends Configuration> void registerDeleteListener(OptionalRelationDefinition<?, M> d, |
| | | ConfigurationDeleteListener<M> listener) throws IllegalArgumentException, ConfigException { |
| | | ConfigurationDeleteListener<M> listener) throws ConfigException { |
| | | registerDeleteListener(d, new ServerManagedObjectDeleteListenerAdaptor<M>(listener)); |
| | | } |
| | | |
| | |
| | | * relation could not be retrieved. |
| | | */ |
| | | public <M extends Configuration> void registerDeleteListener(OptionalRelationDefinition<?, M> d, |
| | | ServerManagedObjectDeleteListener<M> listener) throws IllegalArgumentException, ConfigException { |
| | | ServerManagedObjectDeleteListener<M> listener) throws ConfigException { |
| | | validateRelationDefinition(d); |
| | | DN baseDN = DNBuilder.create(path, d).parent(); |
| | | ConfigDeleteListener adaptor = new ConfigDeleteListenerAdaptor<M>(serverContext, path, d, listener); |
| | |
| | | * could not be retrieved. |
| | | */ |
| | | public <M extends Configuration> void registerDeleteListener(SetRelationDefinition<?, M> d, |
| | | ConfigurationDeleteListener<M> listener) throws IllegalArgumentException, ConfigException { |
| | | ConfigurationDeleteListener<M> listener) throws ConfigException { |
| | | registerDeleteListener(d, new ServerManagedObjectDeleteListenerAdaptor<M>(listener)); |
| | | } |
| | | |
| | |
| | | * could not be retrieved. |
| | | */ |
| | | public <M extends Configuration> void registerDeleteListener(SetRelationDefinition<?, M> d, |
| | | ServerManagedObjectDeleteListener<M> listener) throws IllegalArgumentException, ConfigException { |
| | | ServerManagedObjectDeleteListener<M> listener) throws ConfigException { |
| | | validateRelationDefinition(d); |
| | | DN baseDN = DNBuilder.create(path, d); |
| | | ConfigDeleteListener adaptor = new ConfigDeleteListenerAdaptor<M>(serverContext, path, d, listener); |
| | |
| | | ConfigAddListenerAdaptor<?> adaptor = (ConfigAddListenerAdaptor<?>) configListener; |
| | | ServerManagedObjectAddListener<?> smoListener = adaptor.getServerManagedObjectAddListener(); |
| | | if (smoListener instanceof ServerManagedObjectAddListenerAdaptor<?>) { |
| | | ServerManagedObjectAddListenerAdaptor<?> adaptor2 = (ServerManagedObjectAddListenerAdaptor<?>) smoListener; |
| | | ServerManagedObjectAddListenerAdaptor<?> adaptor2 = |
| | | (ServerManagedObjectAddListenerAdaptor<?>) smoListener; |
| | | if (adaptor2.getConfigurationAddListener() == listener) { |
| | | configRepository.deregisterAddListener(baseDN, adaptor); |
| | | } |
| | |
| | | } |
| | | |
| | | // Deregister an add listener. |
| | | private <M extends Configuration> void deregisterAddListener(DN baseDN, ServerManagedObjectAddListener<M> listener) { |
| | | private <M extends Configuration> void deregisterAddListener(DN baseDN, |
| | | ServerManagedObjectAddListener<M> listener) { |
| | | try { |
| | | if (configRepository.hasEntry(baseDN)) { |
| | | for (ConfigAddListener configListener : configRepository.getAddListeners(baseDN)) { |
| | |
| | | * @return a pair of (intermediate adaptor, intermediate listener) or |
| | | * {@code Pair.EMPTY} if listener can't be extracted |
| | | */ |
| | | // @Checkstyle:off |
| | | static <T extends Configuration> Pair<ConfigAddListenerAdaptor<T>, ConfigurationAddListener<T>> |
| | | extractInitialListener(ConfigAddListener configListener) { |
| | | // @Checkstyle:on |
| | | Pair<ConfigAddListenerAdaptor<T>, ServerManagedObjectAddListener<T>> pair = |
| | | extractIntermediateListener(configListener); |
| | | if (!pair.equals(Pair.EMPTY) && pair.getSecond() instanceof ServerManagedObjectAddListenerAdaptor) { |
| | |
| | | * {@code Pair.EMPTY} if listener can't be extracted |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | // @Checkstyle:off |
| | | static <T extends Configuration> Pair<ConfigAddListenerAdaptor<T>, ServerManagedObjectAddListener<T>> |
| | | extractIntermediateListener(ConfigAddListener configListener) { |
| | | // @Checkstyle:on |
| | | if (configListener instanceof ConfigAddListenerAdaptor) { |
| | | ConfigAddListenerAdaptor<T> adaptor = ((ConfigAddListenerAdaptor<T>) configListener); |
| | | return Pair.of(adaptor, adaptor.getServerManagedObjectAddListener()); |
| | |
| | | } |
| | | |
| | | // Deregister a delete listener. |
| | | private <M extends Configuration> void deregisterDeleteListener(DN baseDN, ConfigurationDeleteListener<M> listener) { |
| | | private <M extends Configuration> void deregisterDeleteListener(DN baseDN, |
| | | ConfigurationDeleteListener<M> listener) { |
| | | try { |
| | | if (configRepository.hasEntry(baseDN)) { |
| | | for (ConfigDeleteListener l : configRepository.getDeleteListeners(baseDN)) { |
| | |
| | | ConfigDeleteListenerAdaptor<?> adaptor = (ConfigDeleteListenerAdaptor<?>) l; |
| | | ServerManagedObjectDeleteListener<?> l2 = adaptor.getServerManagedObjectDeleteListener(); |
| | | if (l2 instanceof ServerManagedObjectDeleteListenerAdaptor<?>) { |
| | | ServerManagedObjectDeleteListenerAdaptor<?> adaptor2 = (ServerManagedObjectDeleteListenerAdaptor<?>) l2; |
| | | ServerManagedObjectDeleteListenerAdaptor<?> adaptor2 = |
| | | (ServerManagedObjectDeleteListenerAdaptor<?>) l2; |
| | | if (adaptor2.getConfigurationDeleteListener() == listener) { |
| | | configRepository.deregisterDeleteListener(baseDN, adaptor); |
| | | } |
| | |
| | | } |
| | | |
| | | // Register an instantiable or optional relation add listener. |
| | | private void registerAddListener(DN baseDN, ConfigAddListener adaptor) throws IllegalArgumentException, |
| | | ConfigException { |
| | | private void registerAddListener(DN baseDN, ConfigAddListener adaptor) throws |
| | | ConfigException { |
| | | if (configRepository.hasEntry(baseDN)) { |
| | | configRepository.registerAddListener(baseDN, adaptor); |
| | | } else { |
| | |
| | | |
| | | // Deregister a delayed listener with the nearest existing parent |
| | | // entry to the provided base DN. |
| | | private <M extends Configuration> void deregisterDelayedAddListener(DN baseDN, ConfigurationAddListener<M> listener) |
| | | throws ConfigException { |
| | | private <M extends Configuration> void deregisterDelayedAddListener(DN baseDN, |
| | | ConfigurationAddListener<M> listener) throws ConfigException { |
| | | DN parentDN = baseDN.parent(); |
| | | int delayWrappers = 0; |
| | | while (parentDN != null) { |
| | |
| | | ConfigAddListenerAdaptor<?> adaptor = (ConfigAddListenerAdaptor<?>) delayedListener; |
| | | ServerManagedObjectAddListener<?> l2 = adaptor.getServerManagedObjectAddListener(); |
| | | if (l2 instanceof ServerManagedObjectAddListenerAdaptor<?>) { |
| | | ServerManagedObjectAddListenerAdaptor<?> adaptor2 = (ServerManagedObjectAddListenerAdaptor<?>) l2; |
| | | ServerManagedObjectAddListenerAdaptor<?> adaptor2 = |
| | | (ServerManagedObjectAddListenerAdaptor<?>) l2; |
| | | if (adaptor2.getConfigurationAddListener() == listener) { |
| | | configRepository.deregisterAddListener(parentDN, configListener); |
| | | } |
| | |
| | | ConfigDeleteListenerAdaptor<?> adaptor = (ConfigDeleteListenerAdaptor<?>) delayedListener; |
| | | ServerManagedObjectDeleteListener<?> l2 = adaptor.getServerManagedObjectDeleteListener(); |
| | | if (l2 instanceof ServerManagedObjectDeleteListenerAdaptor<?>) { |
| | | ServerManagedObjectDeleteListenerAdaptor<?> adaptor2 = (ServerManagedObjectDeleteListenerAdaptor<?>) l2; |
| | | ServerManagedObjectDeleteListenerAdaptor<?> adaptor2 = |
| | | (ServerManagedObjectDeleteListenerAdaptor<?>) l2; |
| | | if (adaptor2.getConfigurationDeleteListener() == listener) { |
| | | configRepository.deregisterAddListener(parentDN, l); |
| | | } |
| | |
| | | |
| | | // Validate that a relation definition belongs to this managed |
| | | // object. |
| | | private void validateRelationDefinition(RelationDefinition<?, ?> rd) throws IllegalArgumentException { |
| | | private void validateRelationDefinition(RelationDefinition<?, ?> rd) { |
| | | RelationDefinition<?, ?> tmp = definition.getRelationDefinition(rd.getName()); |
| | | if (tmp != rd) { |
| | | throw new IllegalArgumentException("The relation " + rd.getName() + " is not associated with a " |
| | |
| | | * The type of server managed object that this listener should be |
| | | * notified about. |
| | | */ |
| | | final class ServerManagedObjectAddListenerAdaptor<T extends Configuration> implements ServerManagedObjectAddListener<T> { |
| | | final class ServerManagedObjectAddListenerAdaptor<T extends Configuration> implements |
| | | ServerManagedObjectAddListener<T> { |
| | | |
| | | // The underlying add listener. |
| | | private final ConfigurationAddListener<T> listener; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean isConfigurationAddAcceptable(ServerManagedObject<? extends T> mo, |
| | | List<LocalizableMessage> unacceptableReasons) { |
| | | List<LocalizableMessage> unacceptableReasons) { |
| | | return listener.isConfigurationAddAcceptable(mo.getConfiguration(), unacceptableReasons); |
| | | } |
| | | |
| | |
| | | */ |
| | | package org.opends.server.admin.server; |
| | | |
| | | |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | |
| | | import java.util.List; |
| | |
| | | import org.opends.server.admin.Configuration; |
| | | import org.opends.server.types.ConfigChangeResult; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This interface defines the methods that a Directory Server |
| | | * configurable component should implement if it wishes to be able to |
| | | * receive notifications when a its associated server managed object |
| | | * is changed. |
| | | * This interface defines the methods that a Directory Server configurable |
| | | * component should implement if it wishes to be able to receive notifications |
| | | * when a its associated server managed object is changed. |
| | | * |
| | | * @param <T> |
| | | * The type of server managed object that this listener |
| | | * should be notified about. |
| | | * The type of server managed object that this listener should be |
| | | * notified about. |
| | | */ |
| | | public interface ServerManagedObjectChangeListener<T extends Configuration> { |
| | | |
| | | /** |
| | | * Indicates whether the proposed change to the server managed |
| | | * object is acceptable to this change listener. |
| | | * |
| | | * @param mo |
| | | * The new server managed object containing the changes. |
| | | * @param unacceptableReasons |
| | | * A list that can be used to hold messages about why the |
| | | * provided server managed object is not acceptable. |
| | | * @return Returns <code>true</code> if the proposed change is |
| | | * acceptable, or <code>false</code> if it is not. |
| | | */ |
| | | public boolean isConfigurationChangeAcceptable( |
| | | ServerManagedObject<? extends T> mo, List<LocalizableMessage> unacceptableReasons); |
| | | /** |
| | | * Indicates whether the proposed change to the server managed object is |
| | | * acceptable to this change listener. |
| | | * |
| | | * @param mo |
| | | * The new server managed object containing the changes. |
| | | * @param unacceptableReasons |
| | | * A list that can be used to hold messages about why the |
| | | * provided server managed object is not acceptable. |
| | | * @return Returns <code>true</code> if the proposed change is acceptable, |
| | | * or <code>false</code> if it is not. |
| | | */ |
| | | public boolean isConfigurationChangeAcceptable(ServerManagedObject<? extends T> mo, |
| | | List<LocalizableMessage> unacceptableReasons); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Applies the server managed object changes to this change |
| | | * listener. |
| | | * |
| | | * @param mo |
| | | * The new server managed object containing the changes. |
| | | * @return Returns information about the result of changing the |
| | | * server managed object. |
| | | */ |
| | | public ConfigChangeResult applyConfigurationChange( |
| | | ServerManagedObject<? extends T> mo); |
| | | /** |
| | | * Applies the server managed object changes to this change listener. |
| | | * |
| | | * @param mo |
| | | * The new server managed object containing the changes. |
| | | * @return Returns information about the result of changing the server |
| | | * managed object. |
| | | */ |
| | | public ConfigChangeResult applyConfigurationChange(ServerManagedObject<? extends T> mo); |
| | | } |
| | |
| | | * notified about. |
| | | */ |
| | | final class ServerManagedObjectChangeListenerAdaptor<T extends Configuration> implements |
| | | ServerManagedObjectChangeListener<T> { |
| | | ServerManagedObjectChangeListener<T> { |
| | | |
| | | // The underlying change listener. |
| | | private final ConfigurationChangeListener<? super T> listener; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public ConfigChangeResult applyConfigurationChange(ServerManagedObject<? extends T> mo) { |
| | | return listener.applyConfigurationChange(mo.getConfiguration()); |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public boolean isConfigurationChangeAcceptable(ServerManagedObject<? extends T> mo, |
| | | List<LocalizableMessage> unacceptableReasons) { |
| | | List<LocalizableMessage> unacceptableReasons) { |
| | | return listener.isConfigurationChangeAcceptable(mo.getConfiguration(), unacceptableReasons); |
| | | } |
| | | |
| | |
| | | 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) { |
| New file |
| | |
| | | /* |
| | | * 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 |
| | | * or http://forgerock.org/license/CDDLv1.0.html. |
| | | * 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 2006-2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | /** |
| | | * Contains a number of API declarations for use throughout the |
| | | * Directory Server. Whenever possible, these APIs should be declared |
| | | * using abstract classes rather than interfaces so that they can be |
| | | * altered in future versions without impacting backward |
| | | * compatibility. |
| | | * <BR><BR> |
| | | * Note that the mere existence of a class or interface in this |
| | | * package does not in itself imply that it is intended for use by |
| | | * third party code. Please refer to the official product |
| | | * documentation to indicate which APIs may be safely used by anyone |
| | | * other than the core Directory Server developers. Failure to heed |
| | | * this warning may result in code that could have unintended side |
| | | * effects or that does not work properly across different Directory |
| | | * Server versions. |
| | | */ |
| | | package org.opends.server.api; |
| | | |
| | |
| | | throw new RuntimeException("This class is not implemented"); |
| | | } |
| | | |
| | | public static Aci decode(ByteString valueOf, DN rootDN) throws AciException { |
| | | /** |
| | | * Decode an ACI byte string. |
| | | * |
| | | * @param byteString |
| | | * The ByteString containing the ACI string. |
| | | * @param dn |
| | | * DN of the ACI entry. |
| | | * @return Returns a decoded ACI representing the string argument. |
| | | * @throws AciException |
| | | * If the parsing of the ACI string fails. |
| | | */ |
| | | public static Aci decode(ByteString byteString, DN dn) throws AciException { |
| | | throw new RuntimeException("This class is not implemented"); |
| | | } |
| | | } |
| | |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.authorization.dseecompat; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.opends.server.types.IdentifiedException; |
| | | |
| | | |
| | | /** |
| | | * The AciException class defines an exception that may be thrown |
| | | * either during ACI syntax verification of an "aci" attribute type value |
| | | * or during evaluation of an LDAP operation using a set of applicable |
| | | * ACIs. |
| | | * The AciException class defines an exception that may be thrown either during |
| | | * ACI syntax verification of an "aci" attribute type value or during evaluation |
| | | * of an LDAP operation using a set of applicable ACIs. |
| | | */ |
| | | public class AciException extends IdentifiedException { |
| | | /** |
| | | * The serial version identifier required to satisfy the compiler because this |
| | | * class extends <CODE>java.lang.Exception</CODE>, which implements the |
| | | * <CODE>java.io.Serializable</CODE> interface. This value was generated |
| | | * using the <CODE>serialver</CODE> command-line utility included with the |
| | | * Java SDK. |
| | | */ |
| | | private static final long serialVersionUID = -2763328522960628853L; |
| | | /** |
| | | * The serial version identifier required to satisfy the compiler because |
| | | * this class extends <CODE>java.lang.Exception</CODE>, which implements the |
| | | * <CODE>java.io.Serializable</CODE> interface. This value was generated |
| | | * using the <CODE>serialver</CODE> command-line utility included with the |
| | | * Java SDK. |
| | | */ |
| | | private static final long serialVersionUID = -2763328522960628853L; |
| | | |
| | | /** |
| | | * Constructs a new exception with <code>null</code> as its detail message. |
| | |
| | | * decode and not print duplicate messages. |
| | | */ |
| | | public AciException() { |
| | | super(); |
| | | super(); |
| | | } |
| | | |
| | | /** |
| | | * Creates a new ACI exception with the provided message. |
| | | * |
| | | * @param message The message to use for this ACI exception. |
| | | * @param message |
| | | * The message to use for this ACI exception. |
| | | */ |
| | | public AciException(LocalizableMessage message) { |
| | | super(message); |
| | | super(message); |
| | | } |
| | | |
| | | /** |
| | | * Creates a new ACI exception with the provided message and root |
| | | * cause. |
| | | * Creates a new ACI exception with the provided message and root cause. |
| | | * |
| | | * @param message The message that explains the problem that occurred. |
| | | * @param cause The exception that was caught to trigger this |
| | | * exception. |
| | | * @param message |
| | | * The message that explains the problem that occurred. |
| | | * @param cause |
| | | * The exception that was caught to trigger this exception. |
| | | */ |
| | | public AciException(LocalizableMessage message, Throwable cause) { |
| | | super(message, cause); |
| | | super(message, cause); |
| | | } |
| | | |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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 |
| | | * or http://forgerock.org/license/CDDLv1.0.html. |
| | | * 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. |
| | | */ |
| | | /** |
| | | * Contains the Directory Server Sun Java System Directory Server Enterprise |
| | | * Edition (dseecompat) compatability access control handler implementation. |
| | | */ |
| | | package org.opends.server.authorization.dseecompat; |
| | | |
| New file |
| | |
| | | /* |
| | | * 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 |
| | | * or http://forgerock.org/license/CDDLv1.0.html. |
| | | * 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 2006-2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | /** |
| | | * Contains code used to interact with the Directory Server configuration. This |
| | | * includes various kinds of configuration attributes for different data types, |
| | | * as well as the primary means of exposing configuration and operations over |
| | | * JMX. Further, it includes the code for the default configuration handler |
| | | * which stores information in an LDIF file. |
| | | * <BR><BR> |
| | | * Whenever a configuration entry is modified, assuming that the result of the |
| | | * modification is in conformance with the server schema, then any configurable |
| | | * components and configuration change listeners associated with that entry will |
| | | * be invoked and given an opportunity to reject that update if there is a |
| | | * problem with it, or dynamically react to it by applying the new |
| | | * configuration. If a new configuration entry is added, then any configuration |
| | | * add listeners associated with that entry's parent will be invoked. If an |
| | | * existing entry is removed, then any configuration delete listeners associated |
| | | * with that entry's parent will be invoked. |
| | | */ |
| | | package org.opends.server.config; |
| | | |
| | |
| | | * TODO : this is a stub, with some default implementations for some methods, |
| | | * and no implementation for others. |
| | | */ |
| | | public class DirectoryServer { |
| | | public final class DirectoryServer { |
| | | |
| | | private DirectoryServer() { |
| | | // no implementation yet |
| | | } |
| | | |
| | | /** |
| | | * Retrieves the attribute type for the provided lowercase name or OID. It |
| | |
| | | return Schema.getDefaultSchema().getAttributeType(lowerName); |
| | | } |
| | | |
| | | /** |
| | | * Returns the directory of server instance. |
| | | * |
| | | * @return the instance root directory |
| | | */ |
| | | public static String getInstanceRoot() { |
| | | throw new RuntimeException("Not implemented"); |
| | | } |
| | | |
| | | /** |
| | | * Returns the root directory of server. |
| | | * |
| | | * @return the server root directory |
| | | */ |
| | | public static String getServerRoot() { |
| | | throw new RuntimeException("Not implemented"); |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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 |
| | | * or http://forgerock.org/license/CDDLv1.0.html. |
| | | * 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 2006-2008 Sun Microsystems, Inc. |
| | | */ |
| | | /** |
| | | * Contains various classes that comprise the core of the Directory Server |
| | | * codebase. This includes: |
| | | * <BR> |
| | | * <UL> |
| | | * <LI> |
| | | * The code that is invoked to initialize the various components of the |
| | | * Directory Server when it is started. |
| | | * </LI> |
| | | * <LI> |
| | | * The code that is invoked whenever the Directory Server is in the process |
| | | * of shutting down. |
| | | * </LI> |
| | | * <LI> |
| | | * The various types of operations that may be processed within the |
| | | * Directory Server. |
| | | * </LI> |
| | | * <LI> |
| | | * Data structures for important elements of Directory Server data, |
| | | * including attributes, objectclasses, DNs, entries. |
| | | * </LI> |
| | | * <LI> |
| | | * The implementation of the work queue and worker threads responsible for |
| | | * processing operations requested by clients. |
| | | * </LI> |
| | | * </UL> |
| | | */ |
| | | package org.opends.server.core; |
| | | |
| | |
| | | return true; |
| | | } |
| | | for (int i = 0; i < s.length; i++) { |
| | | if (!hostName[i].equals("*")) // skip if wildcard |
| | | { |
| | | // skip if wildcard |
| | | if (!hostName[i].equals("*")) { |
| | | if (!s[i].equalsIgnoreCase(hostName[i])) { |
| | | return false; |
| | | } |
| | |
| | | * The rule string containing all wildcards. |
| | | */ |
| | | private void processAllWilds(final String rule) { |
| | | final String s[] = rule.split("\\.", -1); |
| | | final String []s = rule.split("\\.", -1); |
| | | if (s.length == IN4ADDRSZ) { |
| | | for (int i = 0; i < IN4ADDRSZ; i++) { |
| | | wildCard.set(i); |
| | |
| | | */ |
| | | private void processHost(final String rule) throws ConfigException { |
| | | // Note that '*' is valid in host rule |
| | | final String s[] = rule.split("^[0-9a-zA-z-.*]+"); |
| | | final String []s = rule.split("^[0-9a-zA-z-.*]+"); |
| | | if (s.length > 0) { |
| | | final LocalizableMessage message = ERR_ADDRESSMASK_FORMAT_DECODE_ERROR.get(); |
| | | throw new ConfigException(message); |
| | |
| | | */ |
| | | private void processHostPattern(final String rule) throws ConfigException { |
| | | // quick check for invalid chars like " " |
| | | final String s[] = rule.split("^[0-9a-zA-z-.]+"); |
| | | final String []s = rule.split("^[0-9a-zA-z-.]+"); |
| | | if (s.length > 0) { |
| | | final LocalizableMessage message = ERR_ADDRESSMASK_FORMAT_DECODE_ERROR.get(); |
| | | throw new ConfigException(message); |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.server.types; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | |
| | | |
| | | /** |
| | | * This class defines a base exception for OpenDS exceptions. |
| | | */ |
| | | public abstract class OpenDsException |
| | | extends Exception |
| | | { |
| | | public abstract class OpenDsException extends Exception { |
| | | |
| | | /** |
| | | * Generated serialization ID. |
| | | */ |
| | | private static final long serialVersionUID = 7310881401563732702L; |
| | | /** |
| | | * Generated serialization ID. |
| | | */ |
| | | private static final long serialVersionUID = 7310881401563732702L; |
| | | |
| | | /** LocalizableMessage that explains the problem. */ |
| | | LocalizableMessage message; |
| | | /** LocalizableMessage that explains the problem. */ |
| | | LocalizableMessage message; |
| | | |
| | | /** |
| | | * Creates a new identified exception. |
| | | */ |
| | | protected OpenDsException() |
| | | { |
| | | super(); |
| | | } |
| | | |
| | | /** |
| | | * Constructs a new instance from another |
| | | * <code>OpenDsException</code>. |
| | | * This constructor sets the message to be that of |
| | | * <code>cause</code>. |
| | | * |
| | | * @param cause exception whose message will be used for |
| | | * this exception's message. |
| | | */ |
| | | protected OpenDsException(OpenDsException cause) { |
| | | this(null, cause); |
| | | } |
| | | |
| | | /** |
| | | * Creates a new identified exception with the provided information. |
| | | * |
| | | * @param message The message that explains the problem that |
| | | * occurred. |
| | | */ |
| | | protected OpenDsException(LocalizableMessage message) |
| | | { |
| | | this(message, null); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new identified exception with the provided information. |
| | | * |
| | | * @param cause The underlying cause that triggered this |
| | | * exception. |
| | | */ |
| | | protected OpenDsException(Throwable cause) |
| | | { |
| | | this(null, cause); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new identified exception with the provided information. |
| | | * |
| | | * @param message The message that explains the problem that |
| | | * occurred. |
| | | * @param cause The underlying cause that triggered this |
| | | * exception. |
| | | */ |
| | | protected OpenDsException(LocalizableMessage message, Throwable cause) |
| | | { |
| | | super(message != null ? message.toString() : |
| | | cause != null ? cause.getMessage() : null, cause); |
| | | if (message != null) { |
| | | this.message = message; |
| | | } else if (cause instanceof OpenDsException) { |
| | | this.message = ((OpenDsException)cause).getMessageObject(); |
| | | /** |
| | | * Creates a new identified exception. |
| | | */ |
| | | protected OpenDsException() { |
| | | super(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Constructs a new instance from another <code>OpenDsException</code>. This |
| | | * constructor sets the message to be that of <code>cause</code>. |
| | | * |
| | | * @param cause |
| | | * exception whose message will be used for this exception's |
| | | * message. |
| | | */ |
| | | protected OpenDsException(OpenDsException cause) { |
| | | this(null, cause); |
| | | } |
| | | |
| | | /** |
| | | * Creates a new identified exception with the provided information. |
| | | * |
| | | * @param message |
| | | * The message that explains the problem that occurred. |
| | | */ |
| | | protected OpenDsException(LocalizableMessage message) { |
| | | this(message, null); |
| | | } |
| | | |
| | | /** |
| | | * Returns the message that explains the problem that occurred. |
| | | * |
| | | * @return LocalizableMessage of the problem |
| | | */ |
| | | public LocalizableMessage getMessageObject() { |
| | | return this.message; |
| | | } |
| | | /** |
| | | * Creates a new identified exception with the provided information. |
| | | * |
| | | * @param cause |
| | | * The underlying cause that triggered this exception. |
| | | */ |
| | | protected OpenDsException(Throwable cause) { |
| | | this(null, cause); |
| | | } |
| | | |
| | | /** |
| | | * Creates a new identified exception with the provided information. |
| | | * |
| | | * @param message |
| | | * The message that explains the problem that occurred. |
| | | * @param cause |
| | | * The underlying cause that triggered this exception. |
| | | */ |
| | | protected OpenDsException(LocalizableMessage message, Throwable cause) { |
| | | super(message != null ? message.toString() : cause != null ? cause.getMessage() : null, cause); |
| | | if (message != null) { |
| | | this.message = message; |
| | | } else if (cause instanceof OpenDsException) { |
| | | this.message = ((OpenDsException) cause).getMessageObject(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Returns the message that explains the problem that occurred. |
| | | * |
| | | * @return LocalizableMessage of the problem |
| | | */ |
| | | public LocalizableMessage getMessageObject() { |
| | | return this.message; |
| | | } |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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 |
| | | * or http://forgerock.org/license/CDDLv1.0.html. |
| | | * 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 2006-2008 Sun Microsystems, Inc. |
| | | */ |
| | | /** |
| | | * Contains implementations for a number of Directory Server data |
| | | * types. Most, but not necessarily all, of these data types may be |
| | | * considered part of the public API for use when extending the |
| | | * Directory Server. Please refer to the official documentation for |
| | | * authoritative information on what classes are considered part of |
| | | * the public API. |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | |
| | | public static void initializeForClientUse() { |
| | | throw new RuntimeException("not implemented"); |
| | | } |
| | | |
| | | private EmbeddedUtils() { |
| | | // no implementation required. |
| | | } |
| | | |
| | | |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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 |
| | | * or http://forgerock.org/license/CDDLv1.0.html. |
| | | * 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 2006-2008 Sun Microsystems, Inc. |
| | | */ |
| | | /** |
| | | * Contains implementations for various Directory Server utility classes and |
| | | * methods which may be used throughout the server but do not necessarily fit in |
| | | * elsewhere. Notable utility classes include: |
| | | * <BR> |
| | | * <UL> |
| | | * <LI> |
| | | * StaticUtils.java -- a set of static methods that may be called to perform |
| | | * all kinds of useful operations on data (e.g., get a stack trace from an |
| | | * exception, or convert the contents of a byte array to a readable form). |
| | | * </LI> |
| | | * <LI> |
| | | * Base64.java -- provides a mechanism for performing base64 encoding and |
| | | * decoding. |
| | | * </LI> |
| | | * <LI> |
| | | * DynamicConstants.java -- a set of constants that are actually generated |
| | | * automatically at build time and reflect information about the time and |
| | | * conditions under which the server was built. |
| | | * </LI> |
| | | * <LI> |
| | | * TimeThread.java -- provides a thread that will periodically retrieve |
| | | * the current time and format it in several common methods in an attempt to |
| | | * minimize the need to have multiple calls to |
| | | * <CODE>System.currentTimeMillis()</CODE> or <CODE>new Date()</CODE> |
| | | * whenever the time is needed. This thread updates internal variables |
| | | * several times each second, which should be sufficient for cases in which |
| | | * high-resolution timing is not required. |
| | | * </LI> |
| | | * </UL> |
| | | */ |
| | | package org.opends.server.util; |
| | | |
| | |
| | | */ |
| | | public final class ConfigurationMock { |
| | | |
| | | private static final ConfigAnswer configAnswer = new ConfigAnswer(); |
| | | private static final ConfigAnswer CONFIG_ANSWER = new ConfigAnswer(); |
| | | |
| | | /** |
| | | * Returns a mock for the provided configuration class. |
| | |
| | | * @return a mock |
| | | */ |
| | | public static <T extends Configuration> T mockCfg(Class<T> configClass) { |
| | | return mock(configClass, configAnswer); |
| | | return mock(configClass, CONFIG_ANSWER); |
| | | } |
| | | |
| | | /** |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | @SuppressWarnings({"javadoc", "unchecked", "rawtypes"}) |
| | | @SuppressWarnings({ "javadoc", "unchecked", "rawtypes" }) |
| | | @Test(singleThreaded = true) |
| | | public class AbstractManagedObjectDefinitionTest extends ConfigTestCase { |
| | | |
| | |
| | | { "", "cn=config" }, |
| | | { "cn=config", "cn=key manager providers, cn=config" }, |
| | | { "cn=key manager providers, cn=config", "cn=my provider, cn=key manager providers, cn=config" }, |
| | | }; |
| | | }; |
| | | } |
| | | |
| | | @DataProvider(name = "illegalValues") |
| | |
| | | @DataProvider(name = "longLimitData") |
| | | Object[][] createLongLimitData() { |
| | | return new Object[][] { |
| | | { 1L, 1L }, |
| | | { 1L, 1L }, |
| | | }; |
| | | } |
| | | |
| | |
| | | @DataProvider(name = "illegalLongLimitData") |
| | | Object[][] createIllegalLongLimitData() { |
| | | return new Object[][] { |
| | | // lower, upper, lower first |
| | | { -1L, 0L, true }, |
| | | { 0L, -1L, false }, |
| | | { 2L, 1L, true }, |
| | | { 2L, 1L, false } }; |
| | | // lower, upper, lower first |
| | | { -1L, 0L, true }, |
| | | { 0L, -1L, false }, |
| | | { 2L, 1L, true }, |
| | | { 2L, 1L, false } }; |
| | | } |
| | | |
| | | @DataProvider(name = "stringLimitData") |
| | |
| | | { 1024L, "1024 s" }, |
| | | { 1025L, "1025 s" }, |
| | | { 1000L * 1000L, "1000000 s" }, |
| | | }; |
| | | }; |
| | | } |
| | | |
| | | @Test(dataProvider = "encodeValueData") |
| | |
| | | @DataProvider(name = "decodeValueDataIllegal") |
| | | Object[][] createDecodeValueDataIllegal() { |
| | | return new Object[][] { { "" }, { "0" }, // no unit |
| | | { "123" }, // no unit |
| | | { "a s" }, |
| | | { "1 x" }, |
| | | { "0.h" }, |
| | | { "0. h" }, |
| | | { "1.h" }, |
| | | { "1. h" }, |
| | | { "1.1 h" }, // too granular |
| | | { "30 m" }, // unit too small violation |
| | | { "60 m" }, // unit too small violation |
| | | { "1 w" }, // unit too big violation |
| | | { "7 w" }, // unit too big violation |
| | | { "1 x" }, { "1 d" }, // upper limit violation |
| | | { "2 h" }, // lower limit violation |
| | | { "-1 h" } // unlimited violation |
| | | { "123" }, // no unit |
| | | { "a s" }, |
| | | { "1 x" }, |
| | | { "0.h" }, |
| | | { "0. h" }, |
| | | { "1.h" }, |
| | | { "1. h" }, |
| | | { "1.1 h" }, // too granular |
| | | { "30 m" }, // unit too small violation |
| | | { "60 m" }, // unit too small violation |
| | | { "1 w" }, // unit too big violation |
| | | { "7 w" }, // unit too big violation |
| | | { "1 x" }, { "1 d" }, // upper limit violation |
| | | { "2 h" }, // lower limit violation |
| | | { "-1 h" } // unlimited violation |
| | | }; |
| | | } |
| | | |
| | |
| | | import static org.testng.Assert.*; |
| | | |
| | | import org.forgerock.opendj.config.ConfigTestCase; |
| | | import org.testng.annotations.*; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class DurationUnitTest extends ConfigTestCase { |
| | |
| | | @DataProvider(name = "testGetUnitData") |
| | | public Object[][] createStringToSizeLimitData() { |
| | | return new Object[][] { |
| | | { "ms", MILLI_SECONDS }, |
| | | { "milliseconds", MILLI_SECONDS }, |
| | | { "s", SECONDS }, |
| | | { "seconds", SECONDS }, |
| | | { "m", MINUTES }, |
| | | { "minutes", MINUTES }, |
| | | { "h", HOURS }, |
| | | { "hours", HOURS }, |
| | | { "d", DAYS }, |
| | | { "days", DAYS }, |
| | | { "w", WEEKS }, |
| | | { "weeks", WEEKS } }; |
| | | { "ms", MILLI_SECONDS }, |
| | | { "milliseconds", MILLI_SECONDS }, |
| | | { "s", SECONDS }, |
| | | { "seconds", SECONDS }, |
| | | { "m", MINUTES }, |
| | | { "minutes", MINUTES }, |
| | | { "h", HOURS }, |
| | | { "hours", HOURS }, |
| | | { "d", DAYS }, |
| | | { "days", DAYS }, |
| | | { "w", WEEKS }, |
| | | { "weeks", WEEKS } }; |
| | | } |
| | | |
| | | @Test(dataProvider = "testGetUnitData") |
| | |
| | | @DataProvider(name = "valueToStringData") |
| | | public Object[][] createValueToStringData() { |
| | | return new Object[][] { |
| | | { 0L, "0 ms" }, |
| | | { 1L, "1 ms" }, |
| | | { 999L, "999 ms" }, |
| | | { 1000L, "1 s" }, |
| | | { 1001L, "1 s 1 ms" }, |
| | | { 59999L, "59 s 999 ms" }, |
| | | { 60000L, "1 m" }, |
| | | { 3599999L, "59 m 59 s 999 ms" }, |
| | | { 3600000L, "1 h" } }; |
| | | { 0L, "0 ms" }, |
| | | { 1L, "1 ms" }, |
| | | { 999L, "999 ms" }, |
| | | { 1000L, "1 s" }, |
| | | { 1001L, "1 s 1 ms" }, |
| | | { 59999L, "59 s 999 ms" }, |
| | | { 60000L, "1 m" }, |
| | | { 3599999L, "59 m 59 s 999 ms" }, |
| | | { 3600000L, "1 h" } }; |
| | | } |
| | | |
| | | @Test(dataProvider = "valueToStringData") |
| | |
| | | { 5, 10, false, -1 }, |
| | | { 5, 10, true, 2 }, |
| | | { 5, 10, true, 11 } |
| | | }; |
| | | }; |
| | | } |
| | | |
| | | @Test(dataProvider = "illegalValidateValueData", expectedExceptions = { AssertionError.class, |
| | |
| | | */ |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A mock LDAP profile wrapper for testing purposes. |
| | | */ |
| | | public final class MockLDAPProfile extends LDAPProfile.Wrapper { |
| | | |
| | | /** |
| | | * Creates a new mock LDAP profile. |
| | | */ |
| | | public MockLDAPProfile() { |
| | | // No implementation required. |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getAttributeName(AbstractManagedObjectDefinition<?, ?> d, |
| | | PropertyDefinition<?> pd) { |
| | | |
| | | if (d == TestParentCfgDefn.getInstance()) { |
| | | TestParentCfgDefn td = TestParentCfgDefn.getInstance(); |
| | | |
| | | if (pd == (PropertyDefinition<?>)td.getMandatoryBooleanPropertyPropertyDefinition()) { |
| | | return "ds-cfg-enabled"; |
| | | } else if (pd == (PropertyDefinition<?>)td.getMandatoryClassPropertyPropertyDefinition()) { |
| | | return "ds-cfg-java-class"; |
| | | } else if (pd == (PropertyDefinition<?>)td |
| | | .getMandatoryReadOnlyAttributeTypePropertyPropertyDefinition()) { |
| | | return "ds-cfg-attribute-type"; |
| | | } else if (pd == (PropertyDefinition<?>)td.getOptionalMultiValuedDNPropertyPropertyDefinition()) { |
| | | return "ds-cfg-base-dn"; |
| | | } else { |
| | | throw new RuntimeException("Unexpected test-parent property" |
| | | + pd.getName()); |
| | | } |
| | | } else if (d == TestChildCfgDefn.getInstance()) { |
| | | TestChildCfgDefn td = TestChildCfgDefn.getInstance(); |
| | | |
| | | if (pd == (PropertyDefinition<?>)td.getMandatoryBooleanPropertyPropertyDefinition()) { |
| | | return "ds-cfg-enabled"; |
| | | } else if (pd == (PropertyDefinition<?>)td.getMandatoryClassPropertyPropertyDefinition()) { |
| | | return "ds-cfg-java-class"; |
| | | } else if (pd == (PropertyDefinition<?>)td |
| | | .getMandatoryReadOnlyAttributeTypePropertyPropertyDefinition()) { |
| | | return "ds-cfg-attribute-type"; |
| | | } else if (pd == (PropertyDefinition<?>)td.getOptionalMultiValuedDNProperty1PropertyDefinition()) { |
| | | return "ds-cfg-base-dn"; |
| | | } else if (pd == (PropertyDefinition<?>)td.getOptionalMultiValuedDNProperty2PropertyDefinition()) { |
| | | return "ds-cfg-group-dn"; |
| | | } else if (pd.getName().equals("aggregation-property")) { |
| | | return "ds-cfg-rotation-policy"; |
| | | } else { |
| | | throw new RuntimeException("Unexpected test-child property" |
| | | + pd.getName()); |
| | | } |
| | | /** |
| | | * Creates a new mock LDAP profile. |
| | | */ |
| | | public MockLDAPProfile() { |
| | | // No implementation required. |
| | | } |
| | | |
| | | // Not known. |
| | | return null; |
| | | } |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getAttributeName(AbstractManagedObjectDefinition<?, ?> d, PropertyDefinition<?> pd) { |
| | | |
| | | if (d == TestParentCfgDefn.getInstance()) { |
| | | TestParentCfgDefn td = TestParentCfgDefn.getInstance(); |
| | | |
| | | if (pd == (PropertyDefinition<?>) td.getMandatoryBooleanPropertyPropertyDefinition()) { |
| | | return "ds-cfg-enabled"; |
| | | } else if (pd == (PropertyDefinition<?>) td.getMandatoryClassPropertyPropertyDefinition()) { |
| | | return "ds-cfg-java-class"; |
| | | } else if (pd == (PropertyDefinition<?>) td.getMandatoryReadOnlyAttributeTypePropertyPropertyDefinition()) { |
| | | return "ds-cfg-attribute-type"; |
| | | } else if (pd == (PropertyDefinition<?>) td.getOptionalMultiValuedDNPropertyPropertyDefinition()) { |
| | | return "ds-cfg-base-dn"; |
| | | } else { |
| | | throw new RuntimeException("Unexpected test-parent property" + pd.getName()); |
| | | } |
| | | } else if (d == TestChildCfgDefn.getInstance()) { |
| | | TestChildCfgDefn td = TestChildCfgDefn.getInstance(); |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getRelationChildRDNType( |
| | | InstantiableRelationDefinition<?, ?> r) { |
| | | if (r == TestCfg.getTestOneToManyParentRelationDefinition() |
| | | || r == TestParentCfgDefn.getInstance() |
| | | .getTestChildrenRelationDefinition()) { |
| | | return "cn"; |
| | | } else { |
| | | return null; |
| | | if (pd == (PropertyDefinition<?>) td.getMandatoryBooleanPropertyPropertyDefinition()) { |
| | | return "ds-cfg-enabled"; |
| | | } else if (pd == (PropertyDefinition<?>) td.getMandatoryClassPropertyPropertyDefinition()) { |
| | | return "ds-cfg-java-class"; |
| | | } else if (pd == (PropertyDefinition<?>) td.getMandatoryReadOnlyAttributeTypePropertyPropertyDefinition()) { |
| | | return "ds-cfg-attribute-type"; |
| | | } else if (pd == (PropertyDefinition<?>) td.getOptionalMultiValuedDNProperty1PropertyDefinition()) { |
| | | return "ds-cfg-base-dn"; |
| | | } else if (pd == (PropertyDefinition<?>) td.getOptionalMultiValuedDNProperty2PropertyDefinition()) { |
| | | return "ds-cfg-group-dn"; |
| | | } else if (pd.getName().equals("aggregation-property")) { |
| | | return "ds-cfg-rotation-policy"; |
| | | } else { |
| | | throw new RuntimeException("Unexpected test-child property" + pd.getName()); |
| | | } |
| | | } |
| | | |
| | | // Not known. |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getObjectClass(AbstractManagedObjectDefinition<?, ?> d) { |
| | | if (d == TestParentCfgDefn.getInstance()) { |
| | | return "ds-cfg-test-parent-dummy"; |
| | | } else if (d == TestChildCfgDefn.getInstance()) { |
| | | return "ds-cfg-test-child-dummy"; |
| | | } else { |
| | | // Not known. |
| | | return null; |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getRelationChildRDNType(InstantiableRelationDefinition<?, ?> r) { |
| | | if (r == TestCfg.getTestOneToManyParentRelationDefinition() |
| | | || r == TestParentCfgDefn.getInstance().getTestChildrenRelationDefinition()) { |
| | | return "cn"; |
| | | } else { |
| | | return null; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getRelationRDNSequence(RelationDefinition<?, ?> r) { |
| | | if (r == TestCfg.getTestOneToManyParentRelationDefinition()) { |
| | | return "cn=test parents,cn=config"; |
| | | } else if (r == TestCfg.getTestOneToZeroOrOneParentRelationDefinition()) { |
| | | return "cn=optional test parent,cn=config"; |
| | | } else if (r == TestParentCfgDefn.getInstance() |
| | | .getTestChildrenRelationDefinition()) { |
| | | return "cn=test children"; |
| | | } else if (r == TestParentCfgDefn.getInstance() |
| | | .getOptionalTestChildRelationDefinition()) { |
| | | return "cn=optional test child"; |
| | | } else { |
| | | return null; |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getObjectClass(AbstractManagedObjectDefinition<?, ?> d) { |
| | | if (d == TestParentCfgDefn.getInstance()) { |
| | | return "ds-cfg-test-parent-dummy"; |
| | | } else if (d == TestChildCfgDefn.getInstance()) { |
| | | return "ds-cfg-test-child-dummy"; |
| | | } else { |
| | | // Not known. |
| | | return null; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getRelationRDNSequence(RelationDefinition<?, ?> r) { |
| | | if (r == TestCfg.getTestOneToManyParentRelationDefinition()) { |
| | | return "cn=test parents,cn=config"; |
| | | } else if (r == TestCfg.getTestOneToZeroOrOneParentRelationDefinition()) { |
| | | return "cn=optional test parent,cn=config"; |
| | | } else if (r == TestParentCfgDefn.getInstance().getTestChildrenRelationDefinition()) { |
| | | return "cn=test children"; |
| | | } else if (r == TestParentCfgDefn.getInstance().getOptionalTestChildRelationDefinition()) { |
| | | return "cn=optional test child"; |
| | | } else { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | { "1" }, |
| | | { "1x" }, |
| | | { "1.1y" } |
| | | }; |
| | | }; |
| | | } |
| | | |
| | | |
| | |
| | | { "1.0", 1000L }, |
| | | { "1000", 1000000L }, |
| | | { "1MB", 1000000L } |
| | | }; |
| | | }; |
| | | } |
| | | |
| | | @Test(dataProvider = "valuesToKiloBytes") |
| | |
| | | { "-1b" }, |
| | | { "1x" }, |
| | | { "1.1y" } |
| | | }; |
| | | }; |
| | | } |
| | | |
| | | @Test(dataProvider = "parseValueIllegalDataKB", expectedExceptions = NumberFormatException.class) |
| | |
| | | * A one-to-zero-or-one relation between the root and a test-parent |
| | | * component. |
| | | */ |
| | | // @Checkstyle:off |
| | | private static final OptionalRelationDefinition<TestParentCfgClient, TestParentCfg> |
| | | RD_TEST_ONE_TO_ZERO_OR_ONE_PARENT; |
| | | // @Checkstyle:on |
| | | |
| | | // Create a one-to-many relation for test-parent components. |
| | | static { |
| | |
| | | LDAPProfile.getInstance().pushWrapper(new MockLDAPProfile()); |
| | | } |
| | | |
| | | private static void initializeAndRegisterBundle(ManagedObjectDefinition<?,?> definition) throws Exception { |
| | | private static void initializeAndRegisterBundle(ManagedObjectDefinition<?, ?> definition) throws Exception { |
| | | definition.initialize(); |
| | | String baseName = definition.getClass().getName(); |
| | | ResourceBundle resourceBundle = ResourceBundle.getBundle(baseName); |
| | |
| | | * @return Returns the one-to-many relation between the root and test-parent |
| | | * components. |
| | | */ |
| | | // @Checkstyle:off |
| | | public static InstantiableRelationDefinition<TestParentCfgClient, TestParentCfg> |
| | | getTestOneToManyParentRelationDefinition() { |
| | | return RD_TEST_ONE_TO_MANY_PARENT; |
| | | } |
| | | // @Checkstyle:on |
| | | |
| | | /** |
| | | * Gets the one-to-zero-or-one relation between the root and a test-parent |
| | |
| | | * @return Returns the one-to-zero-or-one relation between the root and a |
| | | * test-parent component. |
| | | */ |
| | | // @Checkstyle:off |
| | | public static OptionalRelationDefinition<TestParentCfgClient, TestParentCfg> |
| | | getTestOneToZeroOrOneParentRelationDefinition() { |
| | | return RD_TEST_ONE_TO_ZERO_OR_ONE_PARENT; |
| | | } |
| | | // @Checkstyle:on |
| | | |
| | | /** |
| | | * Initializes a property definition and its default behavior. |
| | |
| | | private static final TestChildCfgDefn INSTANCE = new TestChildCfgDefn(); |
| | | |
| | | // The "aggregation-property" property definition. |
| | | // @Checkstyle:off |
| | | private static final AggregationPropertyDefinition<ConnectionHandlerCfgClient, ConnectionHandlerCfg> |
| | | PROPDEF_AGGREGATION_PROPERTY; |
| | | // @Checkstyle:on |
| | | |
| | | // The "mandatory-boolean-property" property definition. |
| | | private static final BooleanPropertyDefinition PROPDEF_MANDATORY_BOOLEAN_PROPERTY; |
| | |
| | | * |
| | | * @return Returns the "aggregation-property" property definition. |
| | | */ |
| | | // @Checkstyle:off |
| | | public AggregationPropertyDefinition<ConnectionHandlerCfgClient, ConnectionHandlerCfg> |
| | | getAggregationPropertyPropertyDefinition() { |
| | | return PROPDEF_AGGREGATION_PROPERTY; |
| | | return PROPDEF_AGGREGATION_PROPERTY; |
| | | } |
| | | // @Checkstyle:on |
| | | |
| | | /** |
| | | * Get the "mandatory-boolean-property" property definition. |
| | |
| | | Object[][] enumerateManageObjectDefns() throws Exception { |
| | | TopCfgDefn topCfgDefn = TopCfgDefn.getInstance(); |
| | | List<AbstractManagedObjectDefinition<?, ?>> allCfgDefns = |
| | | new ArrayList<AbstractManagedObjectDefinition<?, ?>>(topCfgDefn.getAllChildren()); |
| | | new ArrayList<AbstractManagedObjectDefinition<?, ?>>(topCfgDefn.getAllChildren()); |
| | | |
| | | Object[][] params = new Object[allCfgDefns.size()][]; |
| | | for (int i = 0; i < params.length; i++) { |
| | |
| | | |
| | | // Exceptions to config objects having a different objectclass |
| | | private static final List<String> CLASS_OBJECT_CLASS_EXCEPTIONS = Arrays.asList(new String[] { |
| | | "org.opends.server.admin.std.meta.RootCfgDefn", "org.opends.server.admin.std.meta.GlobalCfgDefn", }); |
| | | "org.opends.server.admin.std.meta.RootCfgDefn", "org.opends.server.admin.std.meta.GlobalCfgDefn", }); |
| | | |
| | | // TODO : does not work because can retrieve object class objects |
| | | // TODO : does not work because can't retrieve object class objects |
| | | @Test(enabled = false, dataProvider = "enumerateManageObjectDefns") |
| | | public void validateConfigObjectDefinitions(AbstractManagedObjectDefinition<?, ?> objectDef) { |
| | | String objName = objectDef.getName(); |
| | |
| | | } else { |
| | | String expectedObjectClass = "ds-cfg-" + objName; |
| | | if (!ldapObjectclassName.equals(expectedObjectClass) |
| | | && !CLASS_OBJECT_CLASS_EXCEPTIONS.contains(objectDef.getClass().getName())) { |
| | | && !CLASS_OBJECT_CLASS_EXCEPTIONS.contains(objectDef.getClass().getName())) { |
| | | errors.append( |
| | | "For config object " + objName + ", the LDAP objectclass must be " + expectedObjectClass |
| | | + " instead of " + ldapObjectclassName).append(EOL + EOL); |
| | | "For config object " + objName + ", the LDAP objectclass must be " + expectedObjectClass |
| | | + " instead of " + ldapObjectclassName).append(EOL + EOL); |
| | | } |
| | | } |
| | | ObjectClass configObjectClass = Schema.getDefaultSchema().asNonStrictSchema(). |
| | | getObjectClass(ldapObjectclassName.toLowerCase()); |
| | | ; |
| | | ObjectClass configObjectClass = |
| | | Schema.getDefaultSchema().asNonStrictSchema().getObjectClass(ldapObjectclassName.toLowerCase()); |
| | | |
| | | for (PropertyDefinition<?> propDef : allPropertyDefs) { |
| | | validatePropertyDefinition(objectDef, configObjectClass, propDef, errors); |
| | |
| | | |
| | | if (errors.length() > 0) { |
| | | Assert.fail("The configuration definition for " + objectDef.getName() + " has the following problems: " |
| | | + EOL + errors.toString()); |
| | | + EOL + errors.toString()); |
| | | } |
| | | } |
| | | |
| | | // Exceptions to properties ending in -class being exactly 'java-class'. |
| | | private static final List<String> CLASS_PROPERTY_EXCEPTIONS = Arrays.asList(new String[] { |
| | | // e.g. "prop-name-ending-with-class" |
| | | }); |
| | | }); |
| | | |
| | | // Exceptions to properties ending in -enabled being exactly 'enabled'. |
| | | private static final List<String> ENABLED_PROPERTY_EXCEPTIONS = Arrays.asList(new String[] { |
| | | "index-filter-analyzer-enabled", "subordinate-indexes-enabled" |
| | | "index-filter-analyzer-enabled", "subordinate-indexes-enabled" |
| | | // e.g. "prop-name-ending-with-enabled" |
| | | }); |
| | | }); |
| | | |
| | | // Exceptions to properties not starting with the name of their config |
| | | // object |
| | | private static final List<String> OBJECT_PREFIX_PROPERTY_EXCEPTIONS = Arrays.asList(new String[] { "backend-id", |
| | | "plugin-type", "replication-server-id", "network-group-id", "workflow-id", "workflow-element-id", |
| | | "workflow-element" |
| | | "plugin-type", "replication-server-id", "network-group-id", "workflow-id", "workflow-element-id", |
| | | "workflow-element" |
| | | // e.g. "prop-name-starting-with-object-prefix" |
| | | }); |
| | | }); |
| | | |
| | | private void validatePropertyDefinition(AbstractManagedObjectDefinition<?, ?> objectDef, |
| | | ObjectClass configObjectClass, PropertyDefinition<?> propDef, StringBuilder errors) { |
| | | ObjectClass configObjectClass, PropertyDefinition<?> propDef, StringBuilder errors) { |
| | | String objName = objectDef.getName(); |
| | | String propName = propDef.getName(); |
| | | |
| | | // We want class properties to be exactly java-class |
| | | if (propName.endsWith("-class") && !propName.equals("java-class") |
| | | && !CLASS_PROPERTY_EXCEPTIONS.contains(propName)) { |
| | | && !CLASS_PROPERTY_EXCEPTIONS.contains(propName)) { |
| | | errors.append("The " + propName + " property on config object " + objName |
| | | + " should probably be java-class. If not, then add " + propName |
| | | + " to the CLASS_PROPERTY_EXCEPTIONS array in " + ValidateConfigDefinitionsTest.class.getName() |
| | | + " to suppress" + " this warning."); |
| | | + " should probably be java-class. If not, then add " + propName |
| | | + " to the CLASS_PROPERTY_EXCEPTIONS array in " + ValidateConfigDefinitionsTest.class.getName() |
| | | + " to suppress" + " this warning."); |
| | | } |
| | | |
| | | // We want enabled properties to be exactly enabled |
| | | if (propName.endsWith("-enabled") && !ENABLED_PROPERTY_EXCEPTIONS.contains(propName)) { |
| | | errors.append("The " + propName + " property on config object " + objName |
| | | + " should probably be just 'enabled'. If not, then add " + propName |
| | | + " to the ENABLED_PROPERTY_EXCEPTIONS array in " + ValidateConfigDefinitionsTest.class.getName() |
| | | + " to suppress" + " this warning."); |
| | | + " should probably be just 'enabled'. If not, then add " + propName |
| | | + " to the ENABLED_PROPERTY_EXCEPTIONS array in " + ValidateConfigDefinitionsTest.class.getName() |
| | | + " to suppress" + " this warning."); |
| | | } |
| | | |
| | | // It's redundant for properties to be prefixed with the name of their |
| | | // objecty |
| | | if (propName.startsWith(objName) && !propName.equals(objName) |
| | | && !OBJECT_PREFIX_PROPERTY_EXCEPTIONS.contains(propName)) { |
| | | && !OBJECT_PREFIX_PROPERTY_EXCEPTIONS.contains(propName)) { |
| | | errors.append("The " + propName + " property on config object " + objName |
| | | + " should not be prefixed with the name of the config object because" |
| | | + " this is redundant. If you disagree, then add " + propName |
| | | + " to the OBJECT_PREFIX_PROPERTY_EXCEPTIONS array in " |
| | | + ValidateConfigDefinitionsTest.class.getName() + " to suppress" + " this warning."); |
| | | + " should not be prefixed with the name of the config object because" |
| | | + " this is redundant. If you disagree, then add " + propName |
| | | + " to the OBJECT_PREFIX_PROPERTY_EXCEPTIONS array in " |
| | | + ValidateConfigDefinitionsTest.class.getName() + " to suppress" + " this warning."); |
| | | } |
| | | |
| | | LDAPProfile ldapProfile = LDAPProfile.getInstance(); |
| | |
| | | String expectedLdapAttr = "ds-cfg-" + propName; |
| | | if (!ldapAttrName.equals(expectedLdapAttr)) { |
| | | errors.append( |
| | | "For the " + propName + " property on config object " + objName + ", the LDAP attribute must be " |
| | | + expectedLdapAttr + " instead of " + ldapAttrName).append(EOL + EOL); |
| | | "For the " + propName + " property on config object " + objName + ", the LDAP attribute must be " |
| | | + expectedLdapAttr + " instead of " + ldapAttrName).append(EOL + EOL); |
| | | } |
| | | |
| | | Schema schema = Schema.getDefaultSchema(); |
| | |
| | | // LDAP attribute exists |
| | | if (attrType == null) { |
| | | errors.append( |
| | | propName + " property on config object " + objName + " is declared" + " to use ldap attribute " |
| | | + ldapAttrName + ", but this attribute is not in the schema ").append(EOL + EOL); |
| | | propName + " property on config object " + objName + " is declared" + " to use ldap attribute " |
| | | + ldapAttrName + ", but this attribute is not in the schema ").append(EOL + EOL); |
| | | } else { |
| | | |
| | | // LDAP attribute is multivalued if the property is multivalued |
| | | if (propDef.hasOption(PropertyOption.MULTI_VALUED) && attrType.isSingleValue()) { |
| | | errors.append( |
| | | propName + " property on config object " + objName + " is declared" |
| | | + " as multi-valued, but the corresponding ldap attribute " + ldapAttrName |
| | | + " is declared as single-valued.").append(EOL + EOL); |
| | | propName + " property on config object " + objName + " is declared" |
| | | + " as multi-valued, but the corresponding ldap attribute " + ldapAttrName |
| | | + " is declared as single-valued.").append(EOL + EOL); |
| | | } |
| | | |
| | | if (configObjectClass != null) { |
| | |
| | | Set<AttributeType> mandatoryAttributes = configObjectClass.getRequiredAttributes(); |
| | | if (mandatoryAttributes.contains(attrType) && !propDef.hasOption(PropertyOption.MANDATORY)) { |
| | | errors.append( |
| | | propName + " property on config object " + objName + " is not declared" |
| | | + " as mandatory even though the corresponding ldap attribute " + ldapAttrName |
| | | + " is declared as mandatory in the schema.").append(EOL + EOL); |
| | | propName + " property on config object " + objName + " is not declared" |
| | | + " as mandatory even though the corresponding ldap attribute " + ldapAttrName |
| | | + " is declared as mandatory in the schema.").append(EOL + EOL); |
| | | } |
| | | |
| | | Set<AttributeType> allowedAttributes = new HashSet<AttributeType>(mandatoryAttributes); |
| | | allowedAttributes.addAll(configObjectClass.getOptionalAttributes()); |
| | | if (!allowedAttributes.contains(attrType)) { |
| | | errors.append( |
| | | propName + " property on config object " + objName + " has" |
| | | + " the corresponding ldap attribute " + ldapAttrName |
| | | + ", but this attribute is not an allowed attribute on the configuration " |
| | | + " object's objectclass " + configObjectClass.getNameOrOID()).append(EOL + EOL); |
| | | propName + " property on config object " + objName + " has" |
| | | + " the corresponding ldap attribute " + ldapAttrName |
| | | + ", but this attribute is not an allowed attribute on the configuration " |
| | | + " object's objectclass " + configObjectClass.getNameOrOID()).append(EOL + EOL); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | // Test LDIF. |
| | | private static final String[] TEST_LDIF = new String[] { |
| | | // Base entries. |
| | | "dn: cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-branch", |
| | | "cn: config", |
| | | "", |
| | | "dn: cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-branch", |
| | | "cn: test-parents", |
| | | "", |
| | | // Parent 1 - uses default values for |
| | | // optional-multi-valued-dn-property. |
| | | "dn: cn=test parent 1,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-parent-dummy", |
| | | "cn: test parent 1", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "", |
| | | // Parent 2 - overrides default values for |
| | | // optional-multi-valued-dn-property. |
| | | "dn: cn=test parent 2,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-parent-dummy", |
| | | "cn: test parent 2", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-base-dn: dc=default value p2v1,dc=com", |
| | | "ds-cfg-base-dn: dc=default value p2v2,dc=com", |
| | | "", |
| | | // Parent 3 - overrides default values for |
| | | // optional-multi-valued-dn-property. |
| | | "dn: cn=test parent 3,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-parent-dummy", |
| | | "cn: test parent 3", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-base-dn: dc=default value p3v1,dc=com", |
| | | "ds-cfg-base-dn: dc=default value p3v2,dc=com", |
| | | "", |
| | | // Child base entries. |
| | | "dn:cn=test children,cn=test parent 1,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-branch", |
| | | "cn: multiple children", |
| | | "", |
| | | "dn:cn=test children,cn=test parent 2,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-branch", |
| | | "cn: multiple children", |
| | | "", |
| | | // Child 1 inherits defaults for both |
| | | // optional-multi-valued-dn-property1 and |
| | | // optional-multi-valued-dn-property2. |
| | | "dn: cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-child-dummy", |
| | | "cn: test child 1", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "", |
| | | // Child 2 inherits defaults for |
| | | // optional-multi-valued-dn-property2. |
| | | "dn: cn=test child 2,cn=test children,cn=test parent 1,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-child-dummy", |
| | | "cn: test child 2", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-base-dn: dc=default value c2v1,dc=com", |
| | | "ds-cfg-base-dn: dc=default value c2v2,dc=com", |
| | | "", |
| | | // Child 3 overrides defaults for |
| | | // optional-multi-valued-dn-property1 and |
| | | // optional-multi-valued-dn-property2. |
| | | "dn: cn=test child 3,cn=test children,cn=test parent 1,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-child-dummy", |
| | | "cn: test child 3", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-base-dn: dc=default value c3v1,dc=com", |
| | | "ds-cfg-base-dn: dc=default value c3v2,dc=com", |
| | | "ds-cfg-group-dn: dc=default value c3v3,dc=com", |
| | | "ds-cfg-group-dn: dc=default value c3v4,dc=com", |
| | | "", |
| | | // Child 4 inherits overridden defaults for both |
| | | // optional-multi-valued-dn-property1 and |
| | | // optional-multi-valued-dn-property2. |
| | | "dn: cn=test child 1,cn=test children,cn=test parent 2,cn=test parents,cn=config", "objectclass: top", |
| | | "objectclass: ds-cfg-test-child-dummy", "cn: test child 1", "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", "", }; |
| | | // Base entries. |
| | | "dn: cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-branch", |
| | | "cn: config", |
| | | "", |
| | | "dn: cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-branch", |
| | | "cn: test-parents", |
| | | "", |
| | | // Parent 1 - uses default values for |
| | | // optional-multi-valued-dn-property. |
| | | "dn: cn=test parent 1,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-parent-dummy", |
| | | "cn: test parent 1", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "", |
| | | // Parent 2 - overrides default values for |
| | | // optional-multi-valued-dn-property. |
| | | "dn: cn=test parent 2,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-parent-dummy", |
| | | "cn: test parent 2", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-base-dn: dc=default value p2v1,dc=com", |
| | | "ds-cfg-base-dn: dc=default value p2v2,dc=com", |
| | | "", |
| | | // Parent 3 - overrides default values for |
| | | // optional-multi-valued-dn-property. |
| | | "dn: cn=test parent 3,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-parent-dummy", |
| | | "cn: test parent 3", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-base-dn: dc=default value p3v1,dc=com", |
| | | "ds-cfg-base-dn: dc=default value p3v2,dc=com", |
| | | "", |
| | | // Child base entries. |
| | | "dn:cn=test children,cn=test parent 1,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-branch", |
| | | "cn: multiple children", |
| | | "", |
| | | "dn:cn=test children,cn=test parent 2,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-branch", |
| | | "cn: multiple children", |
| | | "", |
| | | // Child 1 inherits defaults for both |
| | | // optional-multi-valued-dn-property1 and |
| | | // optional-multi-valued-dn-property2. |
| | | "dn: cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-child-dummy", |
| | | "cn: test child 1", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "", |
| | | // Child 2 inherits defaults for |
| | | // optional-multi-valued-dn-property2. |
| | | "dn: cn=test child 2,cn=test children,cn=test parent 1,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-child-dummy", |
| | | "cn: test child 2", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-base-dn: dc=default value c2v1,dc=com", |
| | | "ds-cfg-base-dn: dc=default value c2v2,dc=com", |
| | | "", |
| | | // Child 3 overrides defaults for |
| | | // optional-multi-valued-dn-property1 and |
| | | // optional-multi-valued-dn-property2. |
| | | "dn: cn=test child 3,cn=test children,cn=test parent 1,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-child-dummy", |
| | | "cn: test child 3", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-base-dn: dc=default value c3v1,dc=com", |
| | | "ds-cfg-base-dn: dc=default value c3v2,dc=com", |
| | | "ds-cfg-group-dn: dc=default value c3v3,dc=com", |
| | | "ds-cfg-group-dn: dc=default value c3v4,dc=com", |
| | | "", |
| | | // Child 4 inherits overridden defaults for both |
| | | // optional-multi-valued-dn-property1 and |
| | | // optional-multi-valued-dn-property2. |
| | | "dn: cn=test child 1,cn=test children,cn=test parent 2,cn=test parents,cn=config", "objectclass: top", |
| | | "objectclass: ds-cfg-test-child-dummy", "cn: test child 1", "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", "", }; |
| | | |
| | | /** |
| | | * Provide valid naming exception to client API exception mappings. |
| | |
| | | { ResultCode.UNAVAILABLE , ErrorResultException.class, ResultCode.UNAVAILABLE }, |
| | | { ResultCode.ENTRY_ALREADY_EXISTS, ManagedObjectAlreadyExistsException.class, null }, |
| | | { ResultCode.INSUFFICIENT_ACCESS_RIGHTS, ErrorResultException.class, |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS }, |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS }, |
| | | { ResultCode.UNWILLING_TO_PERFORM, OperationRejectedException.class, null } |
| | | }; |
| | | } |
| | |
| | | { ResultCode.UNAVAILABLE, ErrorResultException.class, ResultCode.UNAVAILABLE }, |
| | | { ResultCode.NO_SUCH_OBJECT, ManagedObjectNotFoundException.class, null }, |
| | | { ResultCode.INSUFFICIENT_ACCESS_RIGHTS, ErrorResultException.class, |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS }, |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS }, |
| | | { ResultCode.UNWILLING_TO_PERFORM, ErrorResultException.class, |
| | | ResultCode.UNWILLING_TO_PERFORM } |
| | | ResultCode.UNWILLING_TO_PERFORM } |
| | | }; |
| | | } |
| | | |
| | |
| | | if (expectedExceptionClass.equals(ErrorResultException.class)) { |
| | | assertThat(e).isInstanceOf(ErrorResultException.class); |
| | | assertThat(((ErrorResultException) e).getResult().getResultCode()).isEqualTo(expectedCode); |
| | | } |
| | | else { |
| | | } else { |
| | | assertThat(e).isInstanceOf(expectedExceptionClass); |
| | | } |
| | | } |
| | |
| | | if (expectedExceptionClass.equals(ErrorResultException.class)) { |
| | | assertThat(e).isInstanceOf(ErrorResultException.class); |
| | | assertThat(((ErrorResultException) e).getResult().getResultCode()).isEqualTo(expectedCode); |
| | | } |
| | | else { |
| | | } else { |
| | | assertThat(e).isInstanceOf(expectedExceptionClass); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public <C extends Control> C getControl(ControlDecoder<C> decoder, DecodeOptions options) throws DecodeException { |
| | | public <C extends Control> C getControl(ControlDecoder<C> decoder, DecodeOptions options) |
| | | throws DecodeException { |
| | | throw new RuntimeException("not implemented"); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | // Construct a dummy path. |
| | | private synchronized static <C extends ConfigurationClient, S extends Configuration> ManagedObjectPath<C, S> getPath( |
| | | AbstractManagedObjectDefinition<C, S> d) { |
| | | /** Construct a dummy path. */ |
| | | // @Checkstyle:off |
| | | private synchronized static <C extends ConfigurationClient, S extends Configuration> ManagedObjectPath<C, S> |
| | | getPath(AbstractManagedObjectDefinition<C, S> d) { |
| | | // @Checkstyle:on |
| | | if (!isProfileRegistered) { |
| | | LDAPProfile.Wrapper profile = new LDAPProfile.Wrapper() { |
| | | |
| | | @Override |
| | | public String getRelationRDNSequence(RelationDefinition<?, ?> r) { |
| | | if (r.getName().equals(DUMMY_TEST_RELATION)) { |
| | |
| | | } |
| | | |
| | | }; |
| | | |
| | | LDAPProfile.getInstance().pushWrapper(profile); |
| | | isProfileRegistered = true; |
| | | } |
| | | |
| | | SingletonRelationDefinition.Builder<C, S> builder = new SingletonRelationDefinition.Builder<C, S>( |
| | | RootCfgDefn.getInstance(), DUMMY_TEST_RELATION, d); |
| | | SingletonRelationDefinition.Builder<C, S> builder = |
| | | new SingletonRelationDefinition.Builder<C, S>(RootCfgDefn.getInstance(), DUMMY_TEST_RELATION, d); |
| | | ManagedObjectPath<?, ?> root = ManagedObjectPath.emptyPath(); |
| | | return root.child(builder.getInstance()); |
| | | |
| | | } |
| | | } |
| | |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-listen-address: 0.0.0.0", "ds-cfg-listen-port: 389"); |
| | | |
| | | // @Checkstyle:off |
| | | /** |
| | | * The default test child configuration "aggregation-property" property |
| | | * definition. |
| | |
| | | /** An aggregation where the target must be enabled. */ |
| | | private AggregationPropertyDefinition<ConnectionHandlerCfgClient, ConnectionHandlerCfg> |
| | | aggregationPropertyDefinitionTargetMustBeEnabled = null; |
| | | // @Checkstyle:on |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | |
| | | TestParentCfg parentCfg = getParentCfg(entryName(TEST_PARENT_1), context); |
| | | parentCfg.addTestChildDeleteListener(deleteListener); |
| | | |
| | | ArgumentCaptor<ConfigDeleteListener> registeredListener = ArgumentCaptor.forClass(ConfigDeleteListener.class); |
| | | verify(configRepository).registerDeleteListener(eq(TEST_BASE_CHILD.getName()), registeredListener.capture()); |
| | | ArgumentCaptor<ConfigDeleteListener> registeredListener = |
| | | ArgumentCaptor.forClass(ConfigDeleteListener.class); |
| | | verify(configRepository).registerDeleteListener(eq(TEST_BASE_CHILD.getName()), |
| | | registeredListener.capture()); |
| | | |
| | | // Now simulate the delete ofthe referenced connection handler. |
| | | assertThat(registeredListener.getValue(). |
| | |
| | | TestChildCfg testChildCfg = parentCfg.getTestChild(entryName(TEST_CHILD_7)); |
| | | testChildCfg.addChangeListener(changeListener); |
| | | |
| | | ArgumentCaptor<ConfigChangeListener> registeredListener = ArgumentCaptor.forClass(ConfigChangeListener.class); |
| | | ArgumentCaptor<ConfigChangeListener> registeredListener = |
| | | ArgumentCaptor.forClass(ConfigChangeListener.class); |
| | | verify(configRepository).registerChangeListener(eq(TEST_CHILD_7.getName()), registeredListener.capture()); |
| | | |
| | | // Now simulate the disabling ofthe referenced connection handler. |
| | | assertThat(registeredListener.getValue(). |
| | | configChangeIsAcceptable(TEST_CONNECTION_HANDLER_ENTRY_DISABLED, new LocalizableMessageBuilder())). |
| | | isFalse(); |
| | | configChangeIsAcceptable(TEST_CONNECTION_HANDLER_ENTRY_DISABLED, new LocalizableMessageBuilder())). |
| | | isFalse(); |
| | | |
| | | } finally { |
| | | putBackDefaultAggregationDefinitionFromTargetEnabled(); |
| | |
| | | |
| | | @Test |
| | | public void createWithInstantiableRelationDefinition() throws Exception { |
| | | ManagedObjectPath<?,?> parentPath = ManagedObjectPath.emptyPath(). |
| | | child(TestCfg.getTestOneToManyParentRelationDefinition(), "test-parent-1"); |
| | | ManagedObjectPath<?,?> childPath = parentPath.child(TestParentCfgDefn.getInstance().getTestChildrenRelationDefinition(), "test-child-1"); |
| | | ManagedObjectPath<?, ?> parentPath = ManagedObjectPath.emptyPath(). |
| | | child(TestCfg.getTestOneToManyParentRelationDefinition(), "test-parent-1"); |
| | | ManagedObjectPath<?, ?> childPath = parentPath.child(TestParentCfgDefn.getInstance(). |
| | | getTestChildrenRelationDefinition(), "test-child-1"); |
| | | |
| | | assertEquals( |
| | | DNBuilder.create(childPath), |
| | |
| | | { TEST_PARENT_2, TEST_CHILD_BASE_2, TEST_CHILD_4, |
| | | Arrays.asList("dc=default value p2v1,dc=com", "dc=default value p2v2,dc=com"), |
| | | Arrays.asList("dc=default value p2v1,dc=com", "dc=default value p2v2,dc=com") } |
| | | }; |
| | | }; |
| | | } |
| | | |
| | | /** |
| | |
| | | import org.testng.annotations.Test; |
| | | |
| | | |
| | | @SuppressWarnings({"javadoc", "rawtypes", "unchecked"}) |
| | | @SuppressWarnings({ "javadoc", "rawtypes", "unchecked" }) |
| | | public class ListenerTest extends AdminTestCase { |
| | | |
| | | private static final DN ROOT_CONFIG_DN = DN.valueOf("cn=config"); |
| | |
| | | /** Register a listener for test parent entry and return the actual registered listener */ |
| | | private ConfigAddListener registerAddListenerForTestParent(ConfigurationRepository configRepository, |
| | | ServerManagedObject<RootCfg> root, ConfigurationAddListener<TestParentCfg> parentListener) |
| | | throws Exception { |
| | | throws Exception { |
| | | root.registerAddListener(TestCfg.getTestOneToManyParentRelationDefinition(), parentListener); |
| | | |
| | | ArgumentCaptor<ConfigAddListener> registered = ArgumentCaptor.forClass(ConfigAddListener.class); |
| | |
| | | /** Register a listener for test parent entry in delayed scenario and return the actual registered listener */ |
| | | private DelayedConfigAddListener registerAddListenerForTestParentDelayed(ConfigurationRepository configRepository, |
| | | ServerManagedObject<RootCfg> root, ConfigurationAddListener<TestParentCfg> parentListener) |
| | | throws Exception { |
| | | throws Exception { |
| | | root.registerAddListener(TestCfg.getTestOneToManyParentRelationDefinition(), parentListener); |
| | | |
| | | ArgumentCaptor<DelayedConfigAddListener> registered = ArgumentCaptor.forClass(DelayedConfigAddListener.class); |
| | |
| | | // check that actual listener is the one provided to the root |
| | | ConfigurationDeleteListener actualListener = |
| | | ((ServerManagedObjectDeleteListenerAdaptor) |
| | | ((ConfigDeleteListenerAdaptor)argument.getValue().getDelayedDeleteListener()). |
| | | ((ConfigDeleteListenerAdaptor) argument.getValue().getDelayedDeleteListener()). |
| | | getServerManagedObjectDeleteListener()).getConfigurationDeleteListener(); |
| | | assertThat(actualListener).isEqualTo(parentListener); |
| | | } |
| | |
| | | verify(configRepository).deregisterAddListener(eq(ROOT_CONFIG_DN), same(registeredListener)); |
| | | } |
| | | |
| | | } |
| | | } |