Simplify config framework exception hierarchy by removing and pulling up the following exceptions:
* DefaultBehaviorException
* IllegalPropertyValueException
* IllegalPropertyValueStringException
* PropertyIsMandatoryException
* PropertyIsReadOnlyException
* PropertyIsSingleValuedException
* UnknownPropertyDefinitionException
7 files deleted
44 files modified
| | |
| | | ' The definition of the ', $ufn,' to be created.
', |
| | | '@param exceptions
', |
| | | ' An optional collection in which to place any ', |
| | | '{@link DefaultBehaviorException}s that occurred whilst ', |
| | | '{@link PropertyException}s that occurred whilst ', |
| | | 'attempting to determine the default values of the ', $ufn, |
| | | '. This argument can be <code>null<code>.
', |
| | | '@return Returns a new ', $ufn,' configuration instance.
')" /> |
| | | </xsl:call-template> |
| | | <xsl:value-of |
| | | select="concat(' <C extends ', $java-class-name,'CfgClient> C create', $java-relation-name, '(
', |
| | | ' ManagedObjectDefinition<C, ? extends ', $java-class-name,'Cfg> d, Collection<DefaultBehaviorException> exceptions);
')" /> |
| | | ' ManagedObjectDefinition<C, ? extends ', $java-class-name,'Cfg> d, Collection<PropertyException> exceptions);
')" /> |
| | | <xsl:text>
</xsl:text> |
| | | <xsl:text>
</xsl:text> |
| | | <xsl:text>
</xsl:text> |
| | |
| | | ' The name of the new ', $ufn,'.
', |
| | | '@param exceptions
', |
| | | ' An optional collection in which to place any ', |
| | | '{@link DefaultBehaviorException}s that occurred whilst ', |
| | | '{@link PropertyException}s that occurred whilst ', |
| | | 'attempting to determine the default values of the ', $ufn, |
| | | '. This argument can be <code>null<code>.
', |
| | | '@return Returns a new ', $ufn,' configuration instance.
', |
| | |
| | | </xsl:call-template> |
| | | <xsl:value-of |
| | | select="concat(' <C extends ', $java-class-name,'CfgClient> C create', $java-relation-name, '(
', |
| | | ' ManagedObjectDefinition<C, ? extends ', $java-class-name,'Cfg> d, String name, Collection<DefaultBehaviorException> exceptions) throws IllegalManagedObjectNameException;
')" /> |
| | | ' ManagedObjectDefinition<C, ? extends ', $java-class-name,'Cfg> d, String name, Collection<PropertyException> exceptions) throws IllegalManagedObjectNameException;
')" /> |
| | | </xsl:when> |
| | | <xsl:when test="string(adm:one-to-many/@unique) = 'true'"> |
| | | <xsl:call-template name="add-java-comment2"> |
| | |
| | | ' The definition of the ', $ufn,' to be created.
', |
| | | '@param exceptions
', |
| | | ' An optional collection in which to place any ', |
| | | '{@link DefaultBehaviorException}s that occurred whilst ', |
| | | '{@link PropertyException}s that occurred whilst ', |
| | | 'attempting to determine the default values of the ', $ufn, |
| | | '. This argument can be <code>null<code>.
', |
| | | '@return Returns a new ', $ufn,' configuration instance.
')" /> |
| | | </xsl:call-template> |
| | | <xsl:value-of |
| | | select="concat(' <C extends ', $java-class-name,'CfgClient> C create', $java-relation-name, '(
', |
| | | ' ManagedObjectDefinition<C, ? extends ', $java-class-name,'Cfg> d, Collection<DefaultBehaviorException> exceptions);
')" /> |
| | | ' ManagedObjectDefinition<C, ? extends ', $java-class-name,'Cfg> d, Collection<PropertyException> exceptions);
')" /> |
| | | </xsl:when> |
| | | </xsl:choose> |
| | | <xsl:text>
</xsl:text> |
| | |
| | | <xsl:if |
| | | test="$this-local-properties[not(@monitoring='true')]"> |
| | | <import> |
| | | org.forgerock.opendj.config.IllegalPropertyValueException |
| | | org.forgerock.opendj.config.PropertyException |
| | | </import> |
| | | </xsl:if> |
| | | <xsl:if test="$this-local-properties[@read-only='true']"> |
| | | <import> |
| | | org.forgerock.opendj.config.PropertyIsReadOnlyException |
| | | org.forgerock.opendj.config.PropertyException |
| | | </import> |
| | | </xsl:if> |
| | | <xsl:if test="$this-local-relations"> |
| | |
| | | test="$this-local-relations/adm:one-to-zero-or-one|$this-local-relations/adm:one-to-many"> |
| | | <import>java.util.Collection</import> |
| | | <import> |
| | | org.forgerock.opendj.config.DefaultBehaviorException |
| | | org.forgerock.opendj.config.PropertyException |
| | | </import> |
| | | <import> |
| | | org.forgerock.opendj.config.client.OperationRejectedException |
| | |
| | | ' * {@inheritDoc}
', |
| | | ' */
', |
| | | ' public <M extends ', $java-class-name, 'CfgClient> M create', $java-relation-name, '(
', |
| | | ' ManagedObjectDefinition<M, ? extends ', $java-class-name,'Cfg> d, Collection<DefaultBehaviorException> exceptions) {
', |
| | | ' ManagedObjectDefinition<M, ? extends ', $java-class-name,'Cfg> d, Collection<PropertyException> exceptions) {
', |
| | | ' return impl.createChild(INSTANCE.get', $java-relation-name,'RelationDefinition(), d, exceptions).getConfiguration();
', |
| | | ' }
')" /> |
| | | <xsl:text>
</xsl:text> |
| | |
| | | ' * {@inheritDoc}
', |
| | | ' */
', |
| | | ' public <M extends ', $java-class-name, 'CfgClient> M create', $java-relation-name, '(
', |
| | | ' ManagedObjectDefinition<M, ? extends ', $java-class-name,'Cfg> d, String name, Collection<DefaultBehaviorException> exceptions) throws IllegalManagedObjectNameException {
', |
| | | ' ManagedObjectDefinition<M, ? extends ', $java-class-name,'Cfg> d, String name, Collection<PropertyException> exceptions) throws IllegalManagedObjectNameException {
', |
| | | ' return impl.createChild(INSTANCE.get', $java-relation-plural-name,'RelationDefinition(), d, name, exceptions).getConfiguration();
', |
| | | ' }
')" /> |
| | | </xsl:when> |
| | |
| | | ' * {@inheritDoc}
', |
| | | ' */
', |
| | | ' public <M extends ', $java-class-name, 'CfgClient> M create', $java-relation-name, '(
', |
| | | ' ManagedObjectDefinition<M, ? extends ', $java-class-name,'Cfg> d, Collection<DefaultBehaviorException> exceptions) {
', |
| | | ' ManagedObjectDefinition<M, ? extends ', $java-class-name,'Cfg> d, Collection<PropertyException> exceptions) {
', |
| | | ' return impl.createChild(INSTANCE.get', $java-relation-plural-name,'RelationDefinition(), d, exceptions).getConfiguration();
', |
| | | ' }
')" /> |
| | | </xsl:when> |
| | |
| | | </import> |
| | | </xsl:if> |
| | | <import> |
| | | org.forgerock.opendj.config.DefaultBehaviorException |
| | | org.forgerock.opendj.config.PropertyException |
| | | </import> |
| | | <import> |
| | | org.forgerock.opendj.config.server.ConfigurationAddListener |
| | |
| | | <xsl:if test="$this-all-relations/adm:one-to-zero-or-one"> |
| | | <import>java.util.Collection</import> |
| | | <import> |
| | | org.forgerock.opendj.config.DefaultBehaviorException |
| | | org.forgerock.opendj.config.PropertyException |
| | | </import> |
| | | <import> |
| | | org.forgerock.opendj.config.server.ConfigurationAddListener |
| | |
| | | </xsl:if> |
| | | <xsl:if test="$this-all-properties[@read-only='true']"> |
| | | <import> |
| | | org.forgerock.opendj.config.PropertyIsReadOnlyException |
| | | org.forgerock.opendj.config.PropertyException |
| | | </import> |
| | | </xsl:if> |
| | | </xsl:otherwise> |
| | |
| | | <xsl:value-of |
| | | select="concat(' *
', |
| | | ' * @param value The value of the "', $name, '" property.
', |
| | | ' * @throws IllegalPropertyValueException
', |
| | | ' * @throws PropertyException
', |
| | | ' * If the new value is invalid.
')" /> |
| | | <xsl:if test="@read-only='true'"> |
| | | <xsl:value-of |
| | | select="concat( |
| | | ' * @throws PropertyIsReadOnlyException
', |
| | | ' * @throws PropertyException
', |
| | | ' * If this ', $this-ufn, ' is not being initialized.
')" /> |
| | | </xsl:if> |
| | | <xsl:value-of |
| | |
| | | <xsl:value-of |
| | | select="concat(' *
', |
| | | ' * @param values The values of the "', $name, '" property.
', |
| | | ' * @throws IllegalPropertyValueException
', |
| | | ' * @throws PropertyException
', |
| | | ' * If one or more of the new values are invalid.
')" /> |
| | | <xsl:if test="@read-only='true'"> |
| | | <xsl:value-of |
| | | select="concat( |
| | | ' * @throws PropertyIsReadOnlyException
', |
| | | ' * @throws PropertyException
', |
| | | ' * If this ', $this-ufn, ' is not being initialized.
')" /> |
| | | </xsl:if> |
| | | <xsl:value-of |
| | |
| | | <xsl:value-of select="'> values'" /> |
| | | </xsl:otherwise> |
| | | </xsl:choose> |
| | | <xsl:value-of select="') throws IllegalPropertyValueException'" /> |
| | | <xsl:value-of select="') throws PropertyException'" /> |
| | | <xsl:if test="@read-only='true'"> |
| | | <xsl:value-of select="', PropertyIsReadOnlyException'" /> |
| | | <xsl:value-of select="', PropertyException'" /> |
| | | </xsl:if> |
| | | <xsl:value-of select="';
'" /> |
| | | </xsl:if> |
| | |
| | | <xsl:value-of select="' value)'" /> |
| | | <xsl:if test="@read-only='true'"> |
| | | <xsl:value-of |
| | | select="' throws PropertyIsReadOnlyException'" /> |
| | | select="' throws PropertyException'" /> |
| | | </xsl:if> |
| | | <xsl:value-of |
| | | select="concat(' {
' , |
| | |
| | | <xsl:value-of select="'> values)'" /> |
| | | <xsl:if test="@read-only='true'"> |
| | | <xsl:value-of |
| | | select="' throws PropertyIsReadOnlyException'" /> |
| | | select="' throws PropertyException'" /> |
| | | </xsl:if> |
| | | <xsl:value-of |
| | | select="concat(' {
' , |
| | |
| | | return Aci.decode(ByteString.valueOf(value), DN.rootDN()); |
| | | } catch (LocalizedIllegalArgumentException e) { |
| | | // TODO: it would be nice to throw the cause. |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | |
| | |
| | | try { |
| | | validateValue(value, options); |
| | | return value; |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | |
| | |
| | | Reference<C, S> reference = Reference.parseName(parentPath, relationDefinition, value); |
| | | return reference.getNormalizedName(); |
| | | } catch (IllegalArgumentException e) { |
| | | throw new IllegalPropertyValueException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | |
| | |
| | | try { |
| | | Reference.parseName(parentPath, relationDefinition, value); |
| | | } catch (IllegalArgumentException e) { |
| | | throw new IllegalPropertyValueException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | |
| | |
| | | AttributeType type = DirectoryServer.getAttributeType(name, !options.checkSchemaForAttributes()); |
| | | |
| | | if (type == null) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } else { |
| | | try { |
| | | validateValue(type, options); |
| | | return type; |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | } |
| | |
| | | Boolean b = VALUE_MAP.get(nvalue); |
| | | |
| | | if (b == null) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } else { |
| | | return b; |
| | | } |
| | |
| | | |
| | | try { |
| | | validateValue(value, options); |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value, e.getCause()); |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value, e.getCause()); |
| | | } |
| | | |
| | | return value; |
| | |
| | | * The class representing the requested type. |
| | | * @return Returns the named class cast to a subclass of the specified |
| | | * class. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If the named class was invalid, could not be loaded, or did |
| | | * not implement the required interfaces. |
| | | * @throws ClassCastException |
| | |
| | | private void validateClassName(String className) { |
| | | String nvalue = className.trim(); |
| | | if (!nvalue.matches(CLASS_RE)) { |
| | | throw new IllegalPropertyValueException(this, className); |
| | | throw PropertyException.illegalPropertyValueException(this, className); |
| | | } |
| | | } |
| | | |
| | |
| | | for (String i : instanceOfInterfaces) { |
| | | Class<?> instanceOfClass = loadClassForValidation(className, i, initialize); |
| | | if (!instanceOfClass.isAssignableFrom(theClass)) { |
| | | throw new IllegalPropertyValueException(this, className); |
| | | throw PropertyException.illegalPropertyValueException(this, className); |
| | | } |
| | | } |
| | | return theClass; |
| | |
| | | return loadClass(classToBeLoaded.trim(), initialize); |
| | | } catch (ClassNotFoundException e) { |
| | | // If the class cannot be loaded then it is an invalid value. |
| | | throw new IllegalPropertyValueException(this, componentClassName, e); |
| | | throw PropertyException.illegalPropertyValueException(this, componentClassName, e); |
| | | } catch (LinkageError e) { |
| | | // If the class cannot be initialized then it is an invalid value. |
| | | throw new IllegalPropertyValueException(this, componentClassName, e); |
| | | throw PropertyException.illegalPropertyValueException(this, componentClassName, e); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | if (!parent.equals(baseDN)) { |
| | | throw new IllegalPropertyValueException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | } |
| | |
| | | DN dn = DN.valueOf(value); |
| | | validateValue(dn, options); |
| | | return dn; |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | long nvalue = baseUnit.toMilliSeconds(value); |
| | | if (!allowUnlimited && nvalue < lowerLimit) { |
| | | throw new IllegalPropertyValueException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | |
| | | // unlimited allowed |
| | | } else if (nvalue >= 0 && nvalue < lowerLimit) { |
| | | throw new IllegalPropertyValueException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | |
| | | if ((upperLimit != null) && (nvalue > upperLimit)) { |
| | | throw new IllegalPropertyValueException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | |
| | |
| | | try { |
| | | ms = DurationUnit.parseValue(value); |
| | | } catch (NumberFormatException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | |
| | | // Check the unit is in range - values must not be more granular |
| | | // than the base unit. |
| | | if ((ms % baseUnit.getDuration()) != 0) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | |
| | | // Convert the value a long in the property's required unit. |
| | | Long i = (long) baseUnit.fromMilliSeconds(ms); |
| | | try { |
| | | validateValue(i, options); |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | return i; |
| | | } |
| | |
| | | String nvalue = value.trim().toLowerCase(); |
| | | E eValue = decodeMap.get(nvalue); |
| | | if (eValue == null) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } else { |
| | | return eValue; |
| | | } |
| | |
| | | return AddressMask.decode(value); |
| | | } catch (ConfigException e) { |
| | | // TODO: it would be nice to throw the cause. |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | |
| | |
| | | return InetAddress.getByName(value); |
| | | } catch (UnknownHostException e) { |
| | | // TODO: it would be nice to throw the cause. |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | |
| | |
| | | Reject.ifNull(value); |
| | | |
| | | if (!allowUnlimited && value < lowerLimit) { |
| | | throw new IllegalPropertyValueException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | |
| | | // unlimited allowed |
| | | } else if (value >= 0 && value < lowerLimit) { |
| | | throw new IllegalPropertyValueException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | |
| | | if ((upperLimit != null) && (value > upperLimit)) { |
| | | throw new IllegalPropertyValueException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | |
| | |
| | | try { |
| | | i = Integer.valueOf(value); |
| | | } catch (NumberFormatException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | |
| | | try { |
| | | validateValue(i, options); |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | |
| | | return i; |
| | |
| | | * @param options |
| | | * Options to use when decoding value. |
| | | * @return Returns the decoded property value. |
| | | * @throws IllegalPropertyValueStringException |
| | | * @throws PropertyException |
| | | * If the property value string is invalid. |
| | | */ |
| | | public abstract T decodeValue(String value, PropertyDefinitionsOptions options); |
| | |
| | | * @param value |
| | | * The property value (must not be <code>null</code>). |
| | | * @return Returns the encoded property string value. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If the property value is invalid. |
| | | */ |
| | | public String encodeValue(T value) { |
| | |
| | | * @param value |
| | | * The property value to be normalized. |
| | | * @return Returns the normalized property value. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If the property value is invalid. |
| | | */ |
| | | public String normalizeValue(T value) { |
| | |
| | | * The property value (must not be <code>null</code>). |
| | | * @param options |
| | | * Options to use when decoding value. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If the property value is invalid. |
| | | */ |
| | | public abstract void validateValue(T value, PropertyDefinitionsOptions options); |
| | |
| | | * types. |
| | | * <p> |
| | | * The default implementation of this method throws an |
| | | * {@link UnknownPropertyDefinitionException}. Sub-classes can override this |
| | | * {@link PropertyException}. Sub-classes can override this |
| | | * method with their own default behavior. |
| | | * |
| | | * @param <T> |
| | |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | * @throws UnknownPropertyDefinitionException |
| | | * @throws PropertyException |
| | | * Visitor implementations may optionally throw this exception. |
| | | */ |
| | | public <T> R visitUnknown(PropertyDefinition<T> pd, P p) { |
| | | throw new UnknownPropertyDefinitionException(pd, p); |
| | | throw PropertyException.unknownPropertyDefinitionException(pd, p); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | package org.forgerock.opendj.config; |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.ERR_DEFAULT_BEHAVIOR_PROPERTY_EXCEPTION; |
| | | import static com.forgerock.opendj.ldap.AdminMessages.ERR_ILLEGAL_PROPERTY_VALUE_EXCEPTION; |
| | | import static com.forgerock.opendj.ldap.AdminMessages.ERR_PROPERTY_IS_MANDATORY_EXCEPTION; |
| | | import static com.forgerock.opendj.ldap.AdminMessages.ERR_PROPERTY_IS_READ_ONLY_EXCEPTION; |
| | | import static com.forgerock.opendj.ldap.AdminMessages.ERR_PROPERTY_IS_SINGLE_VALUED_EXCEPTION; |
| | | import static com.forgerock.opendj.ldap.AdminMessages.ERR_UNKNOWN_PROPERTY_DEFINITION_EXCEPTION; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | |
| | | /** |
| | | * Exceptions thrown as a result of errors that occurred when decoding and |
| | | * modifying property values. |
| | | */ |
| | | public abstract class PropertyException extends AdminRuntimeException { |
| | | public final class PropertyException extends AdminRuntimeException { |
| | | |
| | | /** |
| | | * Version ID required by serializable classes. |
| | | */ |
| | | private static final long serialVersionUID = -8465109598081914482L; |
| | | |
| | | /** |
| | | * Creates a new default behavior exception with a cause. |
| | | * |
| | | * @param pd |
| | | * The property definition whose default values could not be |
| | | * determined. |
| | | * @param cause |
| | | * The exception that prevented the default values from being |
| | | * determined. |
| | | * @return A new default behavior exception with a cause. |
| | | */ |
| | | public static PropertyException defaultBehaviorException(final PropertyDefinition<?> pd, |
| | | final Throwable cause) { |
| | | return new PropertyException(pd, ERR_DEFAULT_BEHAVIOR_PROPERTY_EXCEPTION.get(pd.getName()), |
| | | cause); |
| | | } |
| | | |
| | | /** |
| | | * Creates a new illegal property value exception. |
| | | * |
| | | * @param pd |
| | | * The property definition. |
| | | * @param value |
| | | * The illegal property value. |
| | | * @return A new illegal property value exception. |
| | | */ |
| | | public static PropertyException illegalPropertyValueException(final PropertyDefinition<?> pd, |
| | | final Object value) { |
| | | return new PropertyException(pd, createMessage(pd, value)); |
| | | } |
| | | |
| | | /** |
| | | * Creates a new illegal property value exception. |
| | | * |
| | | * @param pd |
| | | * The property definition. |
| | | * @param value |
| | | * The illegal property value. |
| | | * @param cause |
| | | * The cause. |
| | | * @return A new illegal property value exception. |
| | | */ |
| | | public static PropertyException illegalPropertyValueException(final PropertyDefinition<?> pd, |
| | | final Object value, final Throwable cause) { |
| | | return new PropertyException(pd, createMessage(pd, value), cause); |
| | | } |
| | | |
| | | /** |
| | | * Create a new property is mandatory exception. |
| | | * |
| | | * @param pd |
| | | * The property definition. |
| | | * @return A new property is mandatory exception. |
| | | */ |
| | | public static PropertyException propertyIsMandatoryException(final PropertyDefinition<?> pd) { |
| | | return new PropertyException(pd, ERR_PROPERTY_IS_MANDATORY_EXCEPTION.get(pd.getName())); |
| | | } |
| | | |
| | | /** |
| | | * Create a new property is read-only exception. |
| | | * |
| | | * @param pd |
| | | * The property definition. |
| | | * @return A new property is read-only exception. |
| | | */ |
| | | public static PropertyException propertyIsReadOnlyException(final PropertyDefinition<?> pd) { |
| | | return new PropertyException(pd, ERR_PROPERTY_IS_READ_ONLY_EXCEPTION.get(pd.getName())); |
| | | } |
| | | |
| | | /** |
| | | * Create a new property is single valued exception. |
| | | * |
| | | * @param pd |
| | | * The property definition. |
| | | * @return A new property is single valued exception. |
| | | */ |
| | | public static PropertyException propertyIsSingleValuedException(final PropertyDefinition<?> pd) { |
| | | return new PropertyException(pd, ERR_PROPERTY_IS_SINGLE_VALUED_EXCEPTION.get(pd.getName())); |
| | | } |
| | | |
| | | /** |
| | | * Creates a new unknown property definition exception. |
| | | * |
| | | * @param pd |
| | | * The unknown property definition. |
| | | * @param p |
| | | * The visitor parameter if there was one. |
| | | * @return A new unknown property definition exception. |
| | | */ |
| | | public static PropertyException unknownPropertyDefinitionException( |
| | | final PropertyDefinition<?> pd, final Object p) { |
| | | return new PropertyException(pd, ERR_UNKNOWN_PROPERTY_DEFINITION_EXCEPTION.get( |
| | | pd.getName(), pd.getClass().getName())); |
| | | } |
| | | |
| | | // Create the message. |
| | | private static LocalizableMessage createMessage(final PropertyDefinition<?> pd, |
| | | final Object value) { |
| | | final PropertyDefinitionUsageBuilder builder = new PropertyDefinitionUsageBuilder(true); |
| | | return ERR_ILLEGAL_PROPERTY_VALUE_EXCEPTION.get(String.valueOf(value), pd.getName(), |
| | | builder.getUsage(pd)); |
| | | } |
| | | |
| | | // The property definition associated with the property that caused |
| | | // the exception. |
| | | private final PropertyDefinition<?> pd; |
| | | |
| | | /** |
| | | * Creates property exception without a cause. |
| | | * |
| | | * @param pd |
| | | * The property definition associated with the property that |
| | | * caused the exception. |
| | | * @param message |
| | | * The message. |
| | | */ |
| | | protected PropertyException(PropertyDefinition<?> pd, LocalizableMessage message) { |
| | | private PropertyException(final PropertyDefinition<?> pd, final LocalizableMessage message) { |
| | | super(message); |
| | | this.pd = pd; |
| | | } |
| | | |
| | | /** |
| | | * Creates property exception with a cause. |
| | | * |
| | | * @param pd |
| | | * The property definition associated with the property that |
| | | * caused the exception. |
| | | * @param message |
| | | * The message. |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | protected PropertyException(PropertyDefinition<?> pd, LocalizableMessage message, Throwable cause) { |
| | | private PropertyException(final PropertyDefinition<?> pd, final LocalizableMessage message, |
| | | final Throwable cause) { |
| | | super(message, cause); |
| | | this.pd = pd; |
| | | } |
| | |
| | | * 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 |
| | | * {@link PropertyException}. Sub-classes can override this |
| | | * method with their own default behavior. |
| | | * |
| | | * @param <T> |
| | |
| | | * @param p |
| | | * A visitor specified parameter. |
| | | * @return Returns a visitor specified result. |
| | | * @throws UnknownPropertyDefinitionException |
| | | * @throws PropertyException |
| | | * Visitor implementations may optionally throw this exception. |
| | | */ |
| | | public <T> R visitUnknown(PropertyDefinition<T> pd, T v, P p) { |
| | | throw new UnknownPropertyDefinitionException(pd, p); |
| | | throw PropertyException.unknownPropertyDefinitionException(pd, p); |
| | | } |
| | | |
| | | } |
| | |
| | | // TODO : is it correct to have no validation ? |
| | | T tvalue = pd.decodeValue(name, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | return pd.normalizeValue(tvalue); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | } catch (PropertyException e) { |
| | | // Fall through to default normalization. |
| | | } |
| | | } |
| | |
| | | Reject.ifNull(value); |
| | | |
| | | if (!allowUnlimited && value < lowerLimit) { |
| | | throw new IllegalPropertyValueException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | |
| | | // unlimited allowed |
| | | } else if (value >= 0 && value < lowerLimit) { |
| | | throw new IllegalPropertyValueException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | |
| | | if ((upperLimit != null) && (value > upperLimit)) { |
| | | throw new IllegalPropertyValueException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | |
| | |
| | | try { |
| | | i = SizeUnit.parseValue(value, SizeUnit.BYTES); |
| | | } catch (NumberFormatException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | |
| | | try { |
| | | validateValue(i, options); |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | return i; |
| | | } |
| | |
| | | |
| | | try { |
| | | validateValue(value, options); |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | |
| | | return value; |
| | |
| | | if (pattern != null) { |
| | | Matcher matcher = pattern.matcher(value); |
| | | if (!matcher.matches()) { |
| | | throw new IllegalPropertyValueException(this, value); |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | } |
| | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.config.IllegalPropertyValueStringException; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.OperationsException; |
| | | import org.forgerock.opendj.config.PropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinitionUsageBuilder; |
| | |
| | | } else if (namingPropertyDefinition != null) { |
| | | try { |
| | | namingPropertyDefinition.decodeValue(illegalName, options); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | } catch (PropertyException e) { |
| | | PropertyDefinitionUsageBuilder builder = new PropertyDefinitionUsageBuilder(true); |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_SYNTAX.get(illegalName, |
| | | namingPropertyDefinition.getName(), builder.getUsage(namingPropertyDefinition)); |
| | |
| | | import org.forgerock.opendj.config.AbstractManagedObjectDefinition; |
| | | import org.forgerock.opendj.config.Configuration; |
| | | import org.forgerock.opendj.config.ConfigurationClient; |
| | | import org.forgerock.opendj.config.DefaultBehaviorException; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.DefinitionDecodingException; |
| | | import org.forgerock.opendj.config.InstantiableRelationDefinition; |
| | | import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; |
| | |
| | | import org.forgerock.opendj.config.ManagedObjectPath; |
| | | import org.forgerock.opendj.config.OptionalRelationDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyIsMandatoryException; |
| | | import org.forgerock.opendj.config.PropertyIsReadOnlyException; |
| | | import org.forgerock.opendj.config.PropertyIsSingleValuedException; |
| | | import org.forgerock.opendj.config.PropertyProvider; |
| | | import org.forgerock.opendj.config.SetRelationDefinition; |
| | | import org.forgerock.opendj.config.SingletonRelationDefinition; |
| | |
| | | * The name of the child managed object. |
| | | * @param exceptions |
| | | * A collection in which to place any |
| | | * {@link DefaultBehaviorException}s that occurred whilst |
| | | * {@link PropertyException}s that occurred whilst |
| | | * attempting to determine the managed object's default values. |
| | | * @return Returns a new child managed object bound to the specified |
| | | * instantiable relation. |
| | |
| | | */ |
| | | <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; |
| | | Collection<PropertyException> exceptions) throws IllegalManagedObjectNameException; |
| | | |
| | | /** |
| | | * Creates a new child managed object bound to the specified optional |
| | |
| | | * The definition of the managed object to be created. |
| | | * @param exceptions |
| | | * A collection in which to place any |
| | | * {@link DefaultBehaviorException}s that occurred whilst |
| | | * {@link PropertyException}s that occurred whilst |
| | | * attempting to determine the managed object's default values. |
| | | * @return Returns a new child managed object bound to the specified |
| | | * optional relation. |
| | |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration, C1 extends C> ManagedObject<C1> createChild( |
| | | OptionalRelationDefinition<C, S> r, ManagedObjectDefinition<C1, ? extends S> d, |
| | | Collection<DefaultBehaviorException> exceptions); |
| | | Collection<PropertyException> exceptions); |
| | | |
| | | /** |
| | | * Creates a new child managed object bound to the specified set relation. |
| | |
| | | * The definition of the managed object to be created. |
| | | * @param exceptions |
| | | * A collection in which to place any |
| | | * {@link DefaultBehaviorException}s that occurred whilst |
| | | * {@link PropertyException}s that occurred whilst |
| | | * attempting to determine the managed object's default values. |
| | | * @return Returns a new child managed object bound to the specified set |
| | | * relation. |
| | |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration, C1 extends C> ManagedObject<C1> createChild( |
| | | SetRelationDefinition<C, S> r, ManagedObjectDefinition<C1, ? extends S> d, |
| | | Collection<DefaultBehaviorException> exceptions); |
| | | Collection<PropertyException> exceptions); |
| | | |
| | | /** |
| | | * Retrieves an instantiable child managed object. |
| | |
| | | * @param value |
| | | * The new pending value for the property, or <code>null</code> |
| | | * if the property should be reset to its default behavior. |
| | | * @throws PropertyIsReadOnlyException |
| | | * @throws PropertyException |
| | | * If this is not a new managed object and the property is |
| | | * read-only or for monitoring purposes. |
| | | * @throws PropertyIsMandatoryException |
| | | * @throws PropertyException |
| | | * If an attempt was made to remove a mandatory property. |
| | | */ |
| | | <P> void setPropertyValue(PropertyDefinition<P> pd, P value); |
| | |
| | | * 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 PropertyIsSingleValuedException |
| | | * @throws PropertyException |
| | | * If an attempt was made to add multiple pending values to a |
| | | * single-valued property. |
| | | * @throws PropertyIsReadOnlyException |
| | | * @throws PropertyException |
| | | * If this is not a new managed object and the property is |
| | | * read-only or for monitoring purposes. |
| | | * @throws PropertyIsMandatoryException |
| | | * @throws PropertyException |
| | | * If an attempt was made to remove a mandatory property. |
| | | */ |
| | | <P> void setPropertyValues(PropertyDefinition<P> pd, Collection<P> values); |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.opendj.config.OperationsException; |
| | | import org.forgerock.opendj.config.PropertyIsMandatoryException; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.util.Reject; |
| | | |
| | | /** |
| | |
| | | private static final long serialVersionUID = 6342522125252055588L; |
| | | |
| | | // Create the message. |
| | | private static LocalizableMessage createMessage(Collection<PropertyIsMandatoryException> causes) { |
| | | private static LocalizableMessage createMessage(Collection<PropertyException> causes) { |
| | | Reject.ifNull(causes); |
| | | Reject.ifFalse(!causes.isEmpty(), "causes should not be empty"); |
| | | |
| | |
| | | LocalizableMessageBuilder builder = new LocalizableMessageBuilder(); |
| | | |
| | | boolean isFirst = true; |
| | | for (PropertyIsMandatoryException cause : causes) { |
| | | for (PropertyException cause : causes) { |
| | | if (!isFirst) { |
| | | builder.append(", "); |
| | | } |
| | |
| | | } |
| | | |
| | | // The causes of this exception. |
| | | private final Collection<PropertyIsMandatoryException> causes; |
| | | private final Collection<PropertyException> causes; |
| | | |
| | | // Indicates whether the exception occurred during managed object |
| | | // creation. |
| | |
| | | * creation. |
| | | */ |
| | | public MissingMandatoryPropertiesException(LocalizableMessage ufn, |
| | | Collection<PropertyIsMandatoryException> causes, boolean isCreate) { |
| | | Collection<PropertyException> causes, boolean isCreate) { |
| | | super(createMessage(causes)); |
| | | |
| | | this.causes = new ArrayList<PropertyIsMandatoryException>(causes); |
| | | this.causes = new ArrayList<PropertyException>(causes); |
| | | this.ufn = ufn; |
| | | this.isCreate = isCreate; |
| | | } |
| | |
| | | * @return Returns the first exception that caused this exception. |
| | | */ |
| | | @Override |
| | | public PropertyIsMandatoryException getCause() { |
| | | public PropertyException getCause() { |
| | | return causes.iterator().next(); |
| | | } |
| | | |
| | |
| | | * @return Returns an unmodifiable collection view of the causes of this |
| | | * exception. |
| | | */ |
| | | public Collection<PropertyIsMandatoryException> getCauses() { |
| | | public Collection<PropertyException> getCauses() { |
| | | return Collections.unmodifiableCollection(causes); |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.config.AggregationPropertyDefinition; |
| | | import org.forgerock.opendj.config.Configuration; |
| | | import org.forgerock.opendj.config.ConfigurationClient; |
| | | import org.forgerock.opendj.config.DefaultBehaviorException; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.DefinitionDecodingException; |
| | | import org.forgerock.opendj.config.DefinitionResolver; |
| | | import org.forgerock.opendj.config.IllegalPropertyValueStringException; |
| | | import org.forgerock.opendj.config.InstantiableRelationDefinition; |
| | | import org.forgerock.opendj.config.LDAPProfile; |
| | | import org.forgerock.opendj.config.ManagedObjectDefinition; |
| | |
| | | import org.forgerock.opendj.config.PropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinitionVisitor; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.PropertyIsMandatoryException; |
| | | import org.forgerock.opendj.config.PropertyIsSingleValuedException; |
| | | import org.forgerock.opendj.config.PropertyOption; |
| | | import org.forgerock.opendj.config.Reference; |
| | | import org.forgerock.opendj.config.RelationDefinition; |
| | |
| | | * @param options |
| | | * Decoding options for property definitions. |
| | | * @return Returns the decoded LDAP value. |
| | | * @throws IllegalPropertyValueStringException |
| | | * @throws PropertyException |
| | | * If the property value could not be decoded because it was |
| | | * invalid. |
| | | */ |
| | |
| | | Reference<C, S> reference = Reference.parseDN(d.getParentPath(), d.getRelationDefinition(), p); |
| | | return reference.getName(); |
| | | } catch (IllegalArgumentException e) { |
| | | throw new IllegalPropertyValueStringException(d, p); |
| | | throw PropertyException.illegalPropertyValueException(d, p); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | // Sanity check the returned values. |
| | | if (values.size() > 1 && !propertyDef.hasOption(PropertyOption.MULTI_VALUED)) { |
| | | throw new PropertyIsSingleValuedException(propertyDef); |
| | | throw PropertyException.propertyIsSingleValuedException(propertyDef); |
| | | } |
| | | |
| | | if (values.isEmpty() && propertyDef.hasOption(PropertyOption.MANDATORY)) { |
| | | throw new PropertyIsMandatoryException(propertyDef); |
| | | throw PropertyException.propertyIsMandatoryException(propertyDef); |
| | | } |
| | | |
| | | if (values.isEmpty()) { |
| | |
| | | |
| | | if (activeValues.size() > 1 && !propertyDef.hasOption(PropertyOption.MULTI_VALUED)) { |
| | | // This exception takes precedence over previous exceptions. |
| | | exception = new PropertyIsSingleValuedException(propertyDef); |
| | | exception = PropertyException.propertyIsSingleValuedException(propertyDef); |
| | | P value = activeValues.first(); |
| | | activeValues.clear(); |
| | | activeValues.add(value); |
| | |
| | | Collection<P> defaultValues; |
| | | try { |
| | | defaultValues = findDefaultValues(path, propertyDef, false); |
| | | } catch (DefaultBehaviorException e) { |
| | | } catch (PropertyException e) { |
| | | defaultValues = Collections.emptySet(); |
| | | exception = e; |
| | | } |
| | |
| | | // The active values maybe empty because of a previous |
| | | // exception. |
| | | if (exception == null) { |
| | | exception = new PropertyIsMandatoryException(propertyDef); |
| | | exception = PropertyException.propertyIsMandatoryException(propertyDef); |
| | | } |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.config.Configuration; |
| | | import org.forgerock.opendj.config.ConfigurationClient; |
| | | import org.forgerock.opendj.config.Constraint; |
| | | import org.forgerock.opendj.config.DefaultBehaviorException; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.DefaultManagedObject; |
| | | import org.forgerock.opendj.config.DefinitionDecodingException; |
| | | import org.forgerock.opendj.config.IllegalPropertyValueStringException; |
| | | import org.forgerock.opendj.config.InstantiableRelationDefinition; |
| | | import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; |
| | | import org.forgerock.opendj.config.ManagedObjectDefinition; |
| | |
| | | import org.forgerock.opendj.config.OptionalRelationDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.PropertyIsMandatoryException; |
| | | import org.forgerock.opendj.config.PropertyIsReadOnlyException; |
| | | import org.forgerock.opendj.config.PropertyOption; |
| | | import org.forgerock.opendj.config.RelationDefinition; |
| | | import org.forgerock.opendj.config.RelationDefinitionVisitor; |
| | |
| | | public final void commit() throws ManagedObjectAlreadyExistsException, MissingMandatoryPropertiesException, |
| | | ConcurrentModificationException, OperationRejectedException, ErrorResultException { |
| | | // First make sure all mandatory properties are defined. |
| | | List<PropertyIsMandatoryException> exceptions = new LinkedList<PropertyIsMandatoryException>(); |
| | | List<PropertyException> exceptions = new LinkedList<PropertyException>(); |
| | | |
| | | for (PropertyDefinition<?> pd : definition.getAllPropertyDefinitions()) { |
| | | Property<?> p = getProperty(pd); |
| | | if (pd.hasOption(PropertyOption.MANDATORY) && p.getEffectiveValues().isEmpty()) { |
| | | exceptions.add(new PropertyIsMandatoryException(pd)); |
| | | exceptions.add(PropertyException.propertyIsMandatoryException(pd)); |
| | | } |
| | | } |
| | | |
| | |
| | | @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 { |
| | | Collection<PropertyException> exceptions) throws IllegalManagedObjectNameException { |
| | | validateRelationDefinition(r); |
| | | |
| | | // Empty names are not allowed. |
| | |
| | | if (pd != null) { |
| | | try { |
| | | pd.decodeValue(name, propertyDefOptions); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | } catch (PropertyException e) { |
| | | throw new IllegalManagedObjectNameException(name, pd, propertyDefOptions); |
| | | } |
| | | } |
| | |
| | | @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) { |
| | | Collection<PropertyException> exceptions) { |
| | | validateRelationDefinition(r); |
| | | ManagedObjectPath<C1, ? extends S> childPath = path.child(r, d); |
| | | return createNewManagedObject(d, childPath, null, null, exceptions); |
| | |
| | | @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) { |
| | | Collection<PropertyException> exceptions) { |
| | | validateRelationDefinition(r); |
| | | |
| | | ManagedObjectPath<C1, ? extends S> childPath = path.child(r, d); |
| | |
| | | @Override |
| | | public final <P> void setPropertyValues(PropertyDefinition<P> pd, Collection<P> values) { |
| | | if (pd.hasOption(PropertyOption.MONITORING)) { |
| | | throw new PropertyIsReadOnlyException(pd); |
| | | throw PropertyException.propertyIsReadOnlyException(pd); |
| | | } |
| | | |
| | | if (existsOnServer && pd.hasOption(PropertyOption.READ_ONLY)) { |
| | | throw new PropertyIsReadOnlyException(pd); |
| | | throw PropertyException.propertyIsReadOnlyException(pd); |
| | | } |
| | | |
| | | properties.setPropertyValues(pd, values, propertyDefOptions); |
| | |
| | | // values. |
| | | private <M extends ConfigurationClient, P> ManagedObject<M> createNewManagedObject( |
| | | ManagedObjectDefinition<M, ?> d, ManagedObjectPath<M, ?> p, PropertyDefinition<P> namingPropertyDefinition, |
| | | String name, Collection<DefaultBehaviorException> exceptions) { |
| | | String name, Collection<PropertyException> exceptions) { |
| | | PropertySet childProperties = new PropertySet(); |
| | | for (PropertyDefinition<?> pd : d.getAllPropertyDefinitions()) { |
| | | try { |
| | | createProperty(childProperties, p, pd); |
| | | } catch (DefaultBehaviorException e) { |
| | | } catch (PropertyException e) { |
| | | // Add the exception if requested. |
| | | if (exceptions != null) { |
| | | exceptions.add(e); |
| | |
| | | Driver context = getDriver(); |
| | | Collection<P> defaultValues = context.findDefaultValues(p, pd, true); |
| | | properties.addProperty(pd, defaultValues, Collections.<P> emptySet()); |
| | | } catch (DefaultBehaviorException e) { |
| | | } catch (PropertyException e) { |
| | | // Make sure that we have still created the property. |
| | | properties.addProperty(pd, Collections.<P> emptySet(), Collections.<P> emptySet()); |
| | | throw e; |
| | |
| | | */ |
| | | package org.forgerock.opendj.config.client.spi; |
| | | |
| | | import static org.forgerock.opendj.config.PropertyException.defaultBehaviorException; |
| | | import static org.forgerock.opendj.config.PropertyException.propertyIsSingleValuedException; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | |
| | | import org.forgerock.opendj.config.Configuration; |
| | | import org.forgerock.opendj.config.ConfigurationClient; |
| | | import org.forgerock.opendj.config.Constraint; |
| | | import org.forgerock.opendj.config.DefaultBehaviorException; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.DefaultBehaviorProviderVisitor; |
| | | import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; |
| | | import org.forgerock.opendj.config.DefinitionDecodingException; |
| | | import org.forgerock.opendj.config.IllegalPropertyValueStringException; |
| | | import org.forgerock.opendj.config.InstantiableRelationDefinition; |
| | | import org.forgerock.opendj.config.ManagedObjectNotFoundException; |
| | | import org.forgerock.opendj.config.ManagedObjectPath; |
| | | import org.forgerock.opendj.config.OptionalRelationDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.PropertyIsSingleValuedException; |
| | | import org.forgerock.opendj.config.PropertyNotFoundException; |
| | | import org.forgerock.opendj.config.PropertyOption; |
| | | import org.forgerock.opendj.config.RelationDefinition; |
| | |
| | | |
| | | // Any exception that occurred whilst retrieving inherited default |
| | | // values. |
| | | private DefaultBehaviorException exception = null; |
| | | private PropertyException exception = null; |
| | | |
| | | // The path of the managed object containing the first property. |
| | | private final ManagedObjectPath<?, ?> firstPath; |
| | |
| | | try { |
| | | return getInheritedProperty(d.getManagedObjectPath(), d.getManagedObjectDefinition(), |
| | | d.getPropertyName()); |
| | | } catch (DefaultBehaviorException e) { |
| | | } catch (PropertyException e) { |
| | | exception = e; |
| | | return Collections.emptySet(); |
| | | } |
| | |
| | | for (String stringValue : stringValues) { |
| | | try { |
| | | values.add(nextProperty.decodeValue(stringValue, propertyDefOptions)); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | exception = new DefaultBehaviorException(nextProperty, e); |
| | | } catch (PropertyException e) { |
| | | exception = PropertyException.defaultBehaviorException(nextProperty, e); |
| | | break; |
| | | } |
| | | } |
| | |
| | | try { |
| | | return getInheritedProperty(d.getManagedObjectPath(nextPath), d.getManagedObjectDefinition(), |
| | | d.getPropertyName()); |
| | | } catch (DefaultBehaviorException e) { |
| | | } catch (PropertyException e) { |
| | | exception = e; |
| | | return Collections.emptySet(); |
| | | } |
| | |
| | | } |
| | | |
| | | if (values.size() > 1 && !pd.hasOption(PropertyOption.MULTI_VALUED)) { |
| | | throw new DefaultBehaviorException(pd, new PropertyIsSingleValuedException(pd)); |
| | | throw defaultBehaviorException(pd, propertyIsSingleValuedException(pd)); |
| | | } |
| | | |
| | | return values; |
| | |
| | | // corresponds to the path. |
| | | AbstractManagedObjectDefinition<?, ?> supr = target.getManagedObjectDefinition(); |
| | | if (!supr.isParentOf(d)) { |
| | | throw new DefaultBehaviorException(nextProperty, new DefinitionDecodingException(supr, |
| | | throw PropertyException.defaultBehaviorException(nextProperty, new DefinitionDecodingException(supr, |
| | | Reason.WRONG_TYPE_INFORMATION)); |
| | | } |
| | | |
| | |
| | | // object. |
| | | return getPropertyValues(target, pd2); |
| | | } |
| | | } catch (DefaultBehaviorException e) { |
| | | // Wrap any errors due to recursion. |
| | | throw new DefaultBehaviorException(pd1, e); |
| | | } catch (DefinitionDecodingException e) { |
| | | throw new DefaultBehaviorException(pd1, e); |
| | | } catch (PropertyNotFoundException e) { |
| | | throw new DefaultBehaviorException(pd1, e); |
| | | } catch (ErrorResultException e) { |
| | | throw new DefaultBehaviorException(pd1, e); |
| | | } catch (ManagedObjectNotFoundException e) { |
| | | throw new DefaultBehaviorException(pd1, e); |
| | | } catch (PropertyException e) { |
| | | throw new DefaultBehaviorException(pd1, e); |
| | | // Wrap any errors due to recursion. |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | | } catch (DefinitionDecodingException e) { |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | | } catch (PropertyNotFoundException e) { |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | | } catch (ErrorResultException e) { |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | | } catch (ManagedObjectNotFoundException e) { |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | | } |
| | | } |
| | | }; |
| | |
| | | * @param isCreate |
| | | * Indicates whether the managed object has been created yet. |
| | | * @return Returns the default values for the specified property. |
| | | * @throws DefaultBehaviorException |
| | | * @throws PropertyException |
| | | * If the default values could not be retrieved or decoded |
| | | * properly. |
| | | */ |
| | |
| | | import java.util.SortedSet; |
| | | import java.util.TreeSet; |
| | | |
| | | import org.forgerock.opendj.config.IllegalPropertyValueException; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.PropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.PropertyIsMandatoryException; |
| | | import org.forgerock.opendj.config.PropertyIsSingleValuedException; |
| | | import org.forgerock.opendj.config.PropertyOption; |
| | | |
| | | /** |
| | |
| | | * by this managed object. |
| | | * @param options |
| | | * Options to validate property definitions values. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If a new pending value is deemed to be invalid according to |
| | | * the property definition. |
| | | * @throws PropertyIsSingleValuedException |
| | | * @throws PropertyException |
| | | * If an attempt was made to add multiple pending values to a |
| | | * single-valued property. |
| | | * @throws PropertyIsMandatoryException |
| | | * @throws PropertyException |
| | | * If an attempt was made to remove a mandatory property. |
| | | * @throws IllegalArgumentException |
| | | * If the specified property definition is not associated with |
| | |
| | | MyProperty<T> property = (MyProperty<T>) getProperty(d); |
| | | |
| | | if (values.size() > 1 && !d.hasOption(PropertyOption.MULTI_VALUED)) { |
| | | throw new PropertyIsSingleValuedException(d); |
| | | throw PropertyException.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); |
| | | throw PropertyException.propertyIsMandatoryException(d); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | | import static com.forgerock.opendj.util.StaticUtils.*; |
| | | import static org.forgerock.opendj.config.PropertyException.defaultBehaviorException; |
| | | import static org.forgerock.opendj.config.PropertyException.propertyIsSingleValuedException; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | |
| | | import org.forgerock.opendj.config.AliasDefaultBehaviorProvider; |
| | | import org.forgerock.opendj.config.Configuration; |
| | | import org.forgerock.opendj.config.ConfigurationClient; |
| | | import org.forgerock.opendj.config.DefaultBehaviorException; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.DefaultBehaviorProviderVisitor; |
| | | import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; |
| | | import org.forgerock.opendj.config.DefinitionDecodingException; |
| | | import org.forgerock.opendj.config.DefinitionResolver; |
| | | import org.forgerock.opendj.config.IllegalPropertyValueException; |
| | | import org.forgerock.opendj.config.IllegalPropertyValueStringException; |
| | | import org.forgerock.opendj.config.LDAPProfile; |
| | | import org.forgerock.opendj.config.ManagedObjectDefinition; |
| | | import org.forgerock.opendj.config.ManagedObjectPath; |
| | | import org.forgerock.opendj.config.PropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinitionVisitor; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.PropertyIsMandatoryException; |
| | | import org.forgerock.opendj.config.PropertyIsSingleValuedException; |
| | | import org.forgerock.opendj.config.PropertyNotFoundException; |
| | | import org.forgerock.opendj.config.PropertyOption; |
| | | import org.forgerock.opendj.config.Reference; |
| | |
| | | |
| | | // Any exception that occurred whilst retrieving inherited default |
| | | // values. |
| | | private DefaultBehaviorException exception = null; |
| | | private PropertyException exception = null; |
| | | |
| | | // Optional new configuration entry which does not yet exist in |
| | | // the configuration back-end. |
| | |
| | | try { |
| | | return getInheritedProperty(d.getManagedObjectPath(), d.getManagedObjectDefinition(), |
| | | d.getPropertyName()); |
| | | } catch (DefaultBehaviorException e) { |
| | | } catch (PropertyException e) { |
| | | exception = e; |
| | | return Collections.emptySet(); |
| | | } |
| | |
| | | for (String stringValue : stringValues) { |
| | | try { |
| | | values.add(nextProperty.decodeValue(stringValue, propertyDefOptions)); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | exception = new DefaultBehaviorException(nextProperty, e); |
| | | } catch (PropertyException e) { |
| | | exception = PropertyException.defaultBehaviorException(nextProperty, e); |
| | | break; |
| | | } |
| | | } |
| | |
| | | try { |
| | | return getInheritedProperty(d.getManagedObjectPath(nextPath), d.getManagedObjectDefinition(), |
| | | d.getPropertyName()); |
| | | } catch (DefaultBehaviorException e) { |
| | | } catch (PropertyException e) { |
| | | exception = e; |
| | | return Collections.emptySet(); |
| | | } |
| | |
| | | } |
| | | |
| | | if (values.size() > 1 && !propertyDef.hasOption(PropertyOption.MULTI_VALUED)) { |
| | | throw new DefaultBehaviorException(propertyDef, new PropertyIsSingleValuedException(propertyDef)); |
| | | throw defaultBehaviorException(propertyDef, propertyIsSingleValuedException(propertyDef)); |
| | | } |
| | | |
| | | return values; |
| | |
| | | // corresponds to the path. |
| | | AbstractManagedObjectDefinition<?, ?> supr = target.getManagedObjectDefinition(); |
| | | if (!supr.isParentOf(definition)) { |
| | | throw new DefaultBehaviorException(nextProperty, new DefinitionDecodingException(supr, |
| | | throw PropertyException.defaultBehaviorException(nextProperty, new DefinitionDecodingException(supr, |
| | | Reason.WRONG_TYPE_INFORMATION)); |
| | | } |
| | | |
| | |
| | | return pvalues; |
| | | } |
| | | } catch (DefinitionDecodingException e) { |
| | | throw new DefaultBehaviorException(propDef1, e); |
| | | throw PropertyException.defaultBehaviorException(propDef1, e); |
| | | } catch (PropertyNotFoundException e) { |
| | | throw new DefaultBehaviorException(propDef1, e); |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new DefaultBehaviorException(propDef1, e); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | throw new DefaultBehaviorException(propDef1, e); |
| | | throw PropertyException.defaultBehaviorException(propDef1, e); |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.defaultBehaviorException(propDef1, e); |
| | | } catch (ConfigException e) { |
| | | throw new DefaultBehaviorException(propDef1, e); |
| | | throw PropertyException.defaultBehaviorException(propDef1, e); |
| | | } |
| | | } |
| | | } |
| | |
| | | * @param options |
| | | * Options to decode property definitions values. |
| | | * @return Returns the decoded LDAP value. |
| | | * @throws IllegalPropertyValueStringException |
| | | * @throws PropertyException |
| | | * If the property value could not be decoded because it was |
| | | * invalid. |
| | | */ |
| | |
| | | Reference<C, S> reference = Reference.parseDN(d.getParentPath(), d.getRelationDefinition(), p); |
| | | return reference.getName(); |
| | | } catch (IllegalArgumentException e) { |
| | | throw new IllegalPropertyValueStringException(d, p); |
| | | throw PropertyException.illegalPropertyValueException(d, p); |
| | | } |
| | | } |
| | | |
| | |
| | | for (String value : attributeValues) { |
| | | try { |
| | | pvalues.add(ValueDecoder.decode(propertyDef, value, propertyDefOptions)); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | } catch (PropertyException e) { |
| | | exception = e; |
| | | } |
| | | } |
| | |
| | | // No values defined so get the defaults. |
| | | try { |
| | | pvalues.addAll(getDefaultValues(path, propertyDef, newConfigEntry)); |
| | | } catch (DefaultBehaviorException e) { |
| | | } catch (PropertyException e) { |
| | | exception = e; |
| | | } |
| | | } |
| | | |
| | | if (pvalues.size() > 1 && !propertyDef.hasOption(PropertyOption.MULTI_VALUED)) { |
| | | // This exception takes precedence over previous exceptions. |
| | | exception = new PropertyIsSingleValuedException(propertyDef); |
| | | exception = PropertyException.propertyIsSingleValuedException(propertyDef); |
| | | T value = pvalues.first(); |
| | | pvalues.clear(); |
| | | pvalues.add(value); |
| | |
| | | if (pvalues.isEmpty() && propertyDef.hasOption(PropertyOption.MANDATORY)) { |
| | | // The values maybe empty because of a previous exception. |
| | | if (exception == null) { |
| | | exception = new PropertyIsMandatoryException(propertyDef); |
| | | exception = PropertyException.propertyIsMandatoryException(propertyDef); |
| | | } |
| | | } |
| | | |
| | |
| | | return new Object[][] { { "dummy-type-xxx" } }; |
| | | } |
| | | |
| | | @Test(dataProvider = "valueIllegalData", expectedExceptions = { IllegalPropertyValueStringException.class }) |
| | | @Test(dataProvider = "valueIllegalData", expectedExceptions = { PropertyException.class }) |
| | | public void testDecodeValueIllegal(String value) { |
| | | AttributeTypePropertyDefinition propertyDef = createPropertyDefinition(); |
| | | propertyDef.decodeValue(value, new PropertyDefinitionsOptions()); |
| | |
| | | } |
| | | |
| | | @Test(dataProvider = "decodeValueDataIllegal", expectedExceptions = { NullPointerException.class, |
| | | IllegalPropertyValueStringException.class }) |
| | | PropertyException.class }) |
| | | public void testDecodeValueIllegal(String value) { |
| | | BooleanPropertyDefinition def = createPropertyDefinition(); |
| | | def.decodeValue(value, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | |
| | | { "java.lang.Runnable", "java.lang.String", Number.class, Number.class }, }; |
| | | } |
| | | |
| | | @Test(dataProvider = "loadClassesIllegal", expectedExceptions = { IllegalPropertyValueException.class }) |
| | | @Test(dataProvider = "loadClassesIllegal", expectedExceptions = { PropertyException.class }) |
| | | public <T> void testLoadClassIllegal(String interfaceName, String loadClassName, Class<T> instanceOfClass, |
| | | Class<?> expectedClass) { |
| | | ClassPropertyDefinition.Builder localBuilder = ClassPropertyDefinition.createBuilder(RootCfgDefn.getInstance(), |
| | |
| | | propertyDef.validateValue(DN.valueOf(valueToValidate), PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(dataProvider = "illegalValues", expectedExceptions = IllegalPropertyValueException.class) |
| | | @Test(dataProvider = "illegalValues", expectedExceptions = PropertyException.class) |
| | | public void testValidateIllegalValues(String baseDN, String valueToValidate) { |
| | | DNPropertyDefinition.Builder localBuilder = DNPropertyDefinition.createBuilder(RootCfgDefn.getInstance(), |
| | | "test-property"); |
| | |
| | | propertyDef.decodeValue(valueToValidate, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(dataProvider = "illegalValues", expectedExceptions = IllegalPropertyValueStringException.class) |
| | | @Test(dataProvider = "illegalValues", expectedExceptions = PropertyException.class) |
| | | public void testDecodeIllegalValues(String baseDN, String valueToValidate) { |
| | | DNPropertyDefinition.Builder localBuilder = DNPropertyDefinition.createBuilder(RootCfgDefn.getInstance(), |
| | | "test-property"); |
| | |
| | | def.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(expectedExceptions = IllegalPropertyValueStringException.class) |
| | | @Test(expectedExceptions = PropertyException.class) |
| | | public void testAllowUnlimitedIsFalse() { |
| | | DurationPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | |
| | | def.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(expectedExceptions = IllegalPropertyValueException.class) |
| | | @Test(expectedExceptions = PropertyException.class) |
| | | public void testAllowUnlimitedIsFalseNumValue() { |
| | | DurationPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | |
| | | } |
| | | |
| | | @Test(dataProvider = "illegalValidateValueData", expectedExceptions = { AssertionError.class, |
| | | NullPointerException.class, IllegalPropertyValueException.class }) |
| | | NullPointerException.class, PropertyException.class }) |
| | | public void testValidateValueIllegal(Long lowLimitInMillis, Long highLimitInMillis, |
| | | boolean isAllowUnlimited, Long valueInSeconds) { |
| | | DurationPropertyDefinition.Builder builder = createTestBuilder(); |
| | |
| | | return true; |
| | | } |
| | | @SuppressWarnings("unused") |
| | | public Boolean visitUnknown(PropertyDefinition<?> d, Void o) throws UnknownPropertyDefinitionException { |
| | | public Boolean visitUnknown(PropertyDefinition<?> d, Void o) throws PropertyException { |
| | | return false; |
| | | } |
| | | }; |
| | |
| | | }; |
| | | } |
| | | |
| | | @Test(dataProvider = "decodeValueDataIllegal", expectedExceptions = { IllegalPropertyValueStringException.class }) |
| | | @Test(dataProvider = "decodeValueDataIllegal", expectedExceptions = { PropertyException.class }) |
| | | public void testDecodeValue(String valueToDecode) { |
| | | DurationPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | |
| | | * to decode |
| | | */ |
| | | @Test(dataProvider = "decodeValueIllegalData", expectedExceptions = { NullPointerException.class, |
| | | IllegalPropertyValueStringException.class }) |
| | | PropertyException.class }) |
| | | public void testDecodeValueIllegalData(String value) { |
| | | EnumPropertyDefinition<?> def = builder.getInstance(); |
| | | def.decodeValue(value, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | |
| | | propertyDef.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(expectedExceptions = IllegalPropertyValueStringException.class) |
| | | @Test(expectedExceptions = PropertyException.class) |
| | | public void testIsAllowUnlimitedFalse() { |
| | | IntegerPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | |
| | | propertyDef.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(expectedExceptions = IllegalPropertyValueException.class) |
| | | @Test(expectedExceptions = PropertyException.class) |
| | | public void testIsAllowUnlimitedInteger() { |
| | | IntegerPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | |
| | | } |
| | | |
| | | @Test(dataProvider = "illegalValidateValueData", expectedExceptions = { AssertionError.class, |
| | | NullPointerException.class, IllegalPropertyValueException.class }) |
| | | NullPointerException.class, PropertyException.class }) |
| | | public void testValidateValueIllegal(Integer low, Integer high, boolean allowUnlimited, Integer value) { |
| | | IntegerPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setLowerLimit(low); |
| | |
| | | } |
| | | |
| | | @SuppressWarnings("unused") |
| | | public Boolean visitUnknown(PropertyDefinition<?> d, Void o) throws UnknownPropertyDefinitionException { |
| | | public Boolean visitUnknown(PropertyDefinition<?> d, Void o) throws PropertyException { |
| | | return false; |
| | | } |
| | | }; |
| | |
| | | propertyDef.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(expectedExceptions = IllegalPropertyValueStringException.class) |
| | | @Test(expectedExceptions = PropertyException.class) |
| | | public void testIsAllowUnlimitedFalse() { |
| | | SizePropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | |
| | | propertyDef.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(expectedExceptions = IllegalPropertyValueException.class) |
| | | @Test(expectedExceptions = PropertyException.class) |
| | | public void testIsAllowUnlimitedNumeric() { |
| | | SizePropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | |
| | | } |
| | | |
| | | @Test(dataProvider = "illegalValidateValueData", expectedExceptions = { AssertionError.class, |
| | | NullPointerException.class, IllegalPropertyValueException.class }) |
| | | NullPointerException.class, PropertyException.class }) |
| | | public void testValidateValueIllegal(Long low, Long high, boolean allowUnlimited, Long valueToValidate) { |
| | | SizePropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setLowerLimit(low); |
| | |
| | | return true; |
| | | } |
| | | @SuppressWarnings("unused") |
| | | public Boolean visitUnknown(PropertyDefinition<?> d, Void o) throws UnknownPropertyDefinitionException { |
| | | public Boolean visitUnknown(PropertyDefinition<?> d, Void o) throws PropertyException { |
| | | return false; |
| | | } |
| | | }; |
| | |
| | | } |
| | | |
| | | // TODO : I18N problem |
| | | @Test(enabled = false, expectedExceptions = IllegalPropertyValueException.class) |
| | | @Test(enabled = false, expectedExceptions = PropertyException.class) |
| | | public void testValidateValuePatternDoesNotMatch() { |
| | | StringPropertyDefinition d = getDefinition(true, "^[a-z]+$"); |
| | | d.validateValue("abc123", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | |
| | | } |
| | | |
| | | // TODO : I18N problem |
| | | @Test(enabled = false, expectedExceptions = IllegalPropertyValueStringException.class) |
| | | @Test(enabled = false, expectedExceptions = PropertyException.class) |
| | | public void testDecodeValuePatternDoesNotMatch() { |
| | | StringPropertyDefinition d = getDefinition(true, "^[a-z]+$"); |
| | | d.decodeValue("abc123", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | |
| | | * |
| | | * @param values |
| | | * The values of the "aggregation-property" property. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If one or more of the new values are invalid. |
| | | */ |
| | | void setAggregationProperty(Collection<String> values) throws IllegalPropertyValueException; |
| | | void setAggregationProperty(Collection<String> values) throws PropertyException; |
| | | |
| | | /** |
| | | * Get the "mandatory-boolean-property" property. |
| | |
| | | * |
| | | * @param value |
| | | * The value of the "mandatory-boolean-property" property. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If the new value is invalid. |
| | | */ |
| | | void setMandatoryBooleanProperty(boolean value) throws IllegalPropertyValueException; |
| | | void setMandatoryBooleanProperty(boolean value) throws PropertyException; |
| | | |
| | | /** |
| | | * Get the "mandatory-class-property" property. |
| | |
| | | * |
| | | * @param value |
| | | * The value of the "mandatory-class-property" property. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If the new value is invalid. |
| | | */ |
| | | void setMandatoryClassProperty(String value) throws IllegalPropertyValueException; |
| | | void setMandatoryClassProperty(String value) throws PropertyException; |
| | | |
| | | /** |
| | | * Get the "mandatory-read-only-attribute-type-property" property. |
| | |
| | | * @param value |
| | | * The value of the "mandatory-read-only-attribute-type-property" |
| | | * property. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If the new value is invalid. |
| | | * @throws PropertyIsReadOnlyException |
| | | * @throws PropertyException |
| | | * If this Test Child is not being initialized. |
| | | */ |
| | | void setMandatoryReadOnlyAttributeTypeProperty(AttributeType value) throws IllegalPropertyValueException, |
| | | PropertyIsReadOnlyException; |
| | | void setMandatoryReadOnlyAttributeTypeProperty(AttributeType value) throws PropertyException, |
| | | PropertyException; |
| | | |
| | | /** |
| | | * Get the "optional-multi-valued-dn-property1" property. |
| | |
| | | * @param values |
| | | * The values of the "optional-multi-valued-dn-property1" |
| | | * property. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If one or more of the new values are invalid. |
| | | */ |
| | | void setOptionalMultiValuedDNProperty1(Collection<DN> values) throws IllegalPropertyValueException; |
| | | void setOptionalMultiValuedDNProperty1(Collection<DN> values) throws PropertyException; |
| | | |
| | | /** |
| | | * Get the "optional-multi-valued-dn-property2" property. |
| | |
| | | * @param values |
| | | * The values of the "optional-multi-valued-dn-property2" |
| | | * property. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If one or more of the new values are invalid. |
| | | */ |
| | | void setOptionalMultiValuedDNProperty2(Collection<DN> values) throws IllegalPropertyValueException; |
| | | void setOptionalMultiValuedDNProperty2(Collection<DN> values) throws PropertyException; |
| | | |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public void setMandatoryReadOnlyAttributeTypeProperty(AttributeType value) throws PropertyIsReadOnlyException { |
| | | public void setMandatoryReadOnlyAttributeTypeProperty(AttributeType value) throws PropertyException { |
| | | impl.setPropertyValue(INSTANCE.getMandatoryReadOnlyAttributeTypePropertyPropertyDefinition(), value); |
| | | } |
| | | |
| | |
| | | * |
| | | * @param value |
| | | * The value of the "mandatory-boolean-property" property. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If the new value is invalid. |
| | | */ |
| | | void setMandatoryBooleanProperty(boolean value) throws IllegalPropertyValueException; |
| | | void setMandatoryBooleanProperty(boolean value) throws PropertyException; |
| | | |
| | | /** |
| | | * Get the "mandatory-class-property" property. |
| | |
| | | * |
| | | * @param value |
| | | * The value of the "mandatory-class-property" property. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If the new value is invalid. |
| | | */ |
| | | void setMandatoryClassProperty(String value) throws IllegalPropertyValueException; |
| | | void setMandatoryClassProperty(String value) throws PropertyException; |
| | | |
| | | /** |
| | | * Get the "mandatory-read-only-attribute-type-property" property. |
| | |
| | | * @param value |
| | | * The value of the "mandatory-read-only-attribute-type-property" |
| | | * property. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If the new value is invalid. |
| | | * @throws PropertyIsReadOnlyException |
| | | * @throws PropertyException |
| | | * If this Test Parent is not being initialized. |
| | | */ |
| | | void setMandatoryReadOnlyAttributeTypeProperty(AttributeType value) throws IllegalPropertyValueException, |
| | | PropertyIsReadOnlyException; |
| | | void setMandatoryReadOnlyAttributeTypeProperty(AttributeType value) throws PropertyException, |
| | | PropertyException; |
| | | |
| | | /** |
| | | * Get the "optional-multi-valued-dn-property" property. |
| | |
| | | * @param values |
| | | * The values of the "optional-multi-valued-dn-property" |
| | | * property. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If one or more of the new values are invalid. |
| | | */ |
| | | void setOptionalMultiValuedDNProperty(Collection<DN> values) throws IllegalPropertyValueException; |
| | | void setOptionalMultiValuedDNProperty(Collection<DN> values) throws PropertyException; |
| | | |
| | | /** |
| | | * Lists the Test Children. |
| | |
| | | * The name of the new Test Child. |
| | | * @param exceptions |
| | | * An optional collection in which to place any |
| | | * {@link DefaultBehaviorException}s that occurred whilst |
| | | * {@link PropertyException}s that occurred whilst |
| | | * attempting to determine the default values of the Test Child. |
| | | * This argument can be <code>null<code>. |
| | | * @return Returns a new Test Child configuration instance. |
| | |
| | | * If the name is invalid. |
| | | */ |
| | | <C extends TestChildCfgClient> C createTestChild(ManagedObjectDefinition<C, ? extends TestChildCfg> d, String name, |
| | | Collection<DefaultBehaviorException> exceptions) throws IllegalManagedObjectNameException; |
| | | Collection<PropertyException> exceptions) throws IllegalManagedObjectNameException; |
| | | |
| | | /** |
| | | * Removes the named Test Child. |
| | |
| | | * The definition of the Optional Test Child to be created. |
| | | * @param exceptions |
| | | * An optional collection in which to place any |
| | | * {@link DefaultBehaviorException}s that occurred whilst |
| | | * {@link PropertyException}s that occurred whilst |
| | | * attempting to determine the default values of the Optional |
| | | * Test Child. This argument can be <code>null<code>. |
| | | * @return Returns a new Optional Test Child configuration instance. |
| | | */ |
| | | <C extends TestChildCfgClient> C createOptionalTestChild(ManagedObjectDefinition<C, ? extends TestChildCfg> d, |
| | | Collection<DefaultBehaviorException> exceptions); |
| | | Collection<PropertyException> exceptions); |
| | | |
| | | /** |
| | | * Removes the Optional Test Child if it exists. |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public void setMandatoryReadOnlyAttributeTypeProperty(AttributeType value) throws PropertyIsReadOnlyException { |
| | | public void setMandatoryReadOnlyAttributeTypeProperty(AttributeType value) throws PropertyException { |
| | | impl.setPropertyValue(INSTANCE.getMandatoryReadOnlyAttributeTypePropertyPropertyDefinition(), value); |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public <M extends TestChildCfgClient> M createTestChild(ManagedObjectDefinition<M, ? extends TestChildCfg> d, |
| | | String name, Collection<DefaultBehaviorException> exceptions) throws IllegalManagedObjectNameException { |
| | | String name, Collection<PropertyException> exceptions) throws IllegalManagedObjectNameException { |
| | | return impl.createChild(INSTANCE.getTestChildrenRelationDefinition(), d, name, exceptions) |
| | | .getConfiguration(); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public <M extends TestChildCfgClient> M createOptionalTestChild( |
| | | ManagedObjectDefinition<M, ? extends TestChildCfg> d, Collection<DefaultBehaviorException> exceptions) { |
| | | ManagedObjectDefinition<M, ? extends TestChildCfg> d, Collection<PropertyException> exceptions) { |
| | | return impl.createChild(INSTANCE.getOptionalTestChildRelationDefinition(), d, exceptions) |
| | | .getConfiguration(); |
| | | } |
| | |
| | | import java.util.TreeSet; |
| | | |
| | | import org.forgerock.opendj.config.AdminTestCase; |
| | | import org.forgerock.opendj.config.IllegalPropertyValueStringException; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.LDAPProfile; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.TestCfg; |
| | | import org.forgerock.opendj.config.TestChildCfgClient; |
| | | import org.forgerock.opendj.config.TestChildCfgDefn; |
| | |
| | | Assert.assertEquals(causes.size(), 1); |
| | | |
| | | Throwable cause = causes.iterator().next(); |
| | | if (cause instanceof IllegalPropertyValueStringException) { |
| | | IllegalPropertyValueStringException pe = (IllegalPropertyValueStringException) cause; |
| | | if (cause instanceof PropertyException) { |
| | | PropertyException pe = (PropertyException) cause; |
| | | Assert.assertEquals(pe.getPropertyDefinition(), TestChildCfgDefn.getInstance() |
| | | .getAggregationPropertyPropertyDefinition()); |
| | | Assert.assertEquals(pe.getIllegalValueString(), "cn=LDAP Connection Handler, cn=bad rdn, cn=config"); |
| | | } else { |
| | | // Got an unexpected cause. |
| | | throw e; |
| | |
| | | import org.forgerock.opendj.config.AdminTestCase; |
| | | import org.forgerock.opendj.config.AdministratorAction; |
| | | import org.forgerock.opendj.config.AggregationPropertyDefinition; |
| | | import org.forgerock.opendj.config.IllegalPropertyValueStringException; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.PropertyOption; |
| | | import org.forgerock.opendj.config.TestCfg; |
| | | import org.forgerock.opendj.config.TestChildCfg; |
| | |
| | | ServerManagedObjectDecodingException de = (ServerManagedObjectDecodingException) e.getCause(); |
| | | assertThat(de.getCauses()).hasSize(1); |
| | | PropertyException propertyException = de.getCauses().iterator().next(); |
| | | assertThat(propertyException).isInstanceOf(IllegalPropertyValueStringException.class); |
| | | IllegalPropertyValueStringException pe = (IllegalPropertyValueStringException) propertyException; |
| | | assertEquals(pe.getPropertyDefinition(), TestChildCfgDefn.getInstance() |
| | | assertThat(propertyException).isInstanceOf(PropertyException.class); |
| | | assertEquals(propertyException.getPropertyDefinition(), TestChildCfgDefn.getInstance() |
| | | .getAggregationPropertyPropertyDefinition()); |
| | | assertEquals(pe.getIllegalValueString(), "cn=LDAP Connection Handler, cn=bad rdn, cn=config"); |
| | | } |
| | | } |
| | | |