Fix issue 1443: Admin framework: improve error logging in server
This change removes all the ugly hard-coded error strings from the admin framework exception classes and replaces them with nicer and at times more user friendly messages stored in I18N property files. In particular, the server side decoding error messages have been improved.
| | |
| | | administrator's properties |
| | | INFO_ADMIN_ARG_USERID_DESCRIPTION_73=The administrator's unique identifier. \ |
| | | This is a required argument |
| | | SEVERE_ERR_OPERATION_REJECTED_DEFAULT_74=The operation was rejected for an \ |
| | | unspecified reason |
| | | SEVERE_ERR_OPERATION_REJECTED_DEFAULT_74=Reason unknown |
| | | SEVERE_ERR_SERVER_CONSTRAINT_EXCEPTION_75=A configuration exception \ |
| | | occurred while evaluating a constraint: %s |
| | | SEVERE_ERR_DECODING_EXCEPTION_NO_TYPE_INFO_82=The %s could \ |
| | | be found but did not contain any type information (e.g. missing object \ |
| | | classes in LDAP) |
| | | SEVERE_ERR_DECODING_EXCEPTION_WRONG_TYPE_INFO_83=The %s could \ |
| | | be found but did not contain the expected type information (e.g. incorrect \ |
| | | object classes in LDAP) |
| | | SEVERE_ERR_DECODING_EXCEPTION_ABSTRACT_TYPE_INFO_84=The %s \ |
| | | could be found but its type resolved to an abstract managed object \ |
| | | definition |
| | | SEVERE_ERR_DECODING_EXCEPTION_UNKNOWN_85=The managed object could not \ |
| | | be decoded due to an unspecified reason |
| | | SEVERE_ERR_DEFAULT_BEHAVIOR_PROPERTY_EXCEPTION_86=The default values \ |
| | | for the "%s" property could not be determined |
| | | SEVERE_ERR_ILLEGAL_PROPERTY_VALUE_EXCEPTION_87=The value "%s" is not \ |
| | | a valid value for the "%s" property, which must have the following \ |
| | | syntax: %s |
| | | SEVERE_ERR_ILLEGAL_PROPERTY_VALUE_STRING_EXCEPTION_88=The string value \ |
| | | "%s" is not a valid value for the "%s" property, which must have the \ |
| | | following syntax: %s |
| | | SEVERE_ERR_PROPERTY_IS_MANDATORY_EXCEPTION_89=The "%s" property must be \ |
| | | specified as it is mandatory |
| | | SEVERE_ERR_PROPERTY_IS_READ_ONLY_EXCEPTION_90=The "%s" property must not \ |
| | | be modified as it is read-only |
| | | SEVERE_ERR_PROPERTY_IS_SINGLE_VALUED_EXCEPTION_91=The "%s" property \ |
| | | must not contain more than one value |
| | | SEVERE_ERR_UNKNOWN_PROPERTY_DEFINITION_EXCEPTION_92=An internal error \ |
| | | occurred while processing property "%s": unknown property type "%s" |
| | | SEVERE_ERR_AUTHENTICATION_EXCEPTION_DEFAULT_93=Authentication failure |
| | | SEVERE_ERR_AUTHENTICATION_NOT_SUPPORTED_EXCEPTION_DEFAULT_94=The \ |
| | | requested authentication mechanism is not supported by the server |
| | | SEVERE_ERR_AUTHORIZATION_EXCEPTION_DEFAULT_95=Authorization failure |
| | | SEVERE_ERR_COMMUNICATION_EXCEPTION_DEFAULT_96=A communication problem \ |
| | | occurred while contacting the server |
| | | SEVERE_ERR_OPERATION_REJECTED_EXCEPTION_SINGLE_97=The operation was rejected \ |
| | | for the following reason: %s |
| | | SEVERE_ERR_OPERATION_REJECTED_EXCEPTION_PLURAL_98=The operation was rejected \ |
| | | for the following reasons: %s |
| | | SEVERE_ERR_CONCURRENT_MODIFICATION_EXCEPTION_DEFAULT_99=The operation could \ |
| | | not be performed because a conflicting change has already occurred. There \ |
| | | may be another client administration tool in use |
| | | SEVERE_ERR_MANAGED_OBJECT_DECODING_EXCEPTION_SINGLE_100=The %s could not \ |
| | | be decoded due to the following property exception: %s |
| | | SEVERE_ERR_MANAGED_OBJECT_DECODING_EXCEPTION_PLURAL_101=The %s could not \ |
| | | be decoded due to the following property exceptions: %s |
| | | SEVERE_ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_EMPTY_102=Empty managed \ |
| | | object names are not permitted |
| | | SEVERE_ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_BLANK_103=Blank managed \ |
| | | object names are not permitted |
| | | SEVERE_ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_SYNTAX_104=The managed \ |
| | | object name "%s" is not a valid value for the naming property "%s", \ |
| | | which must have the following syntax: %s |
| | | SEVERE_ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_OTHER_105=The managed \ |
| | | object name "%s" is not permitted |
| | | SEVERE_ERR_MANAGED_OBJECT_ALREADY_EXISTS_EXCEPTION_106=The managed object \ |
| | | could not be created because there is an existing managed object with \ |
| | | the same name |
| | | SEVERE_ERR_MANAGED_OBJECT_NOT_FOUND_EXCEPTION_107=The requested managed \ |
| | | object could not be found |
| | | SEVERE_ERR_MISSING_MANDATORY_PROPERTIES_EXCEPTION_SINGLE_108=The "%s" \ |
| | | property is mandatory |
| | | SEVERE_ERR_MISSING_MANDATORY_PROPERTIES_EXCEPTION_PLURAL_109=The following \ |
| | | properties are mandatory: %s |
| | | SEVERE_ERR_PROPERTY_NOT_FOUND_EXCEPTION_110=The property "%s" was not \ |
| | | recognized |
| | |
| | | rd = resolveManagedObjectDefinitionAux(this, r); |
| | | if (rd == null) { |
| | | // Unable to resolve the definition. |
| | | throw new DefinitionDecodingException(Reason.WRONG_TYPE_INFORMATION); |
| | | throw new DefinitionDecodingException(this, |
| | | Reason.WRONG_TYPE_INFORMATION); |
| | | } else if (rd instanceof ManagedObjectDefinition) { |
| | | return (ManagedObjectDefinition<? extends C, ? extends S>) rd; |
| | | } else { |
| | | // Resolved definition was abstract. |
| | | throw new DefinitionDecodingException(Reason.ABSTRACT_TYPE_INFORMATION); |
| | | throw new DefinitionDecodingException(this, |
| | | Reason.ABSTRACT_TYPE_INFORMATION); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | import org.opends.server.types.OpenDsException; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Exceptions thrown when interacting with administration framework. |
| | | */ |
| | | public abstract class AdminException extends OpenDsException { |
| | | |
| | | /** |
| | | * Create an admin exception. |
| | | */ |
| | | protected AdminException() { |
| | | // No implementation required. |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create an admin exception with a cause. |
| | | * |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | protected AdminException(Throwable cause) { |
| | | super(cause); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create an admin exception with a message and cause. |
| | | * |
| | | * @param message |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Exceptions thrown when interacting with administration framework that |
| | | * applications are not expected to catch. |
| | | * Exceptions thrown when interacting with administration framework |
| | | * that applications are not expected to catch. |
| | | */ |
| | | public abstract class AdminRuntimeException extends RuntimeException { |
| | | |
| | | /** |
| | | * Create an admin runtime exception. |
| | | */ |
| | | protected AdminRuntimeException() { |
| | | // No implementation required. |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create an admin runtime exception with a cause. |
| | | * |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | protected AdminRuntimeException(Throwable cause) { |
| | | super(cause); |
| | | } |
| | | // Message that explains the problem. |
| | | private final Message message; |
| | | |
| | | |
| | | |
| | |
| | | */ |
| | | protected AdminRuntimeException(Message message, Throwable cause) { |
| | | super(message.toString(), cause); |
| | | this.message = message; |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | protected AdminRuntimeException(Message message) { |
| | | super(message.toString()); |
| | | this.message = message; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Returns the message that explains the problem that occurred. |
| | | * |
| | | * @return Returns the message describing the problem that occurred |
| | | * (never <code>null</code>). |
| | | */ |
| | | public Message getMessageObject() { |
| | | return this.message; |
| | | } |
| | | } |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | /** |
| | | * The requested managed object was found but it could not be decoded. |
| | | */ |
| | | public abstract class DecodingException extends OperationsException { |
| | | |
| | | /** |
| | | * Create a decoding exception. |
| | | * Create a decoding exception with a message. |
| | | * |
| | | * @param message |
| | | * The message. |
| | | */ |
| | | protected DecodingException() { |
| | | // No implementation required. |
| | | protected DecodingException(Message message) { |
| | | super(message); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public abstract Message getMessageObject(); |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This exception is thrown when a property's default values cannot be |
| | | * determined. This can occur in the following situations: |
| | |
| | | */ |
| | | private static final long serialVersionUID = -2542117466747573053L; |
| | | |
| | | // The cause of this exception. |
| | | private final Throwable cause; |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | * being determined. |
| | | */ |
| | | public DefaultBehaviorException(PropertyDefinition<?> pd, Throwable cause) { |
| | | super(pd); |
| | | this.cause = cause; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Throwable getCause() { |
| | | return cause; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getMessage() { |
| | | return "The default values could not be determined " |
| | | + "for the property \"" + getPropertyDefinition().getName() + "\""; |
| | | super(pd, ERR_DEFAULT_BEHAVIOR_PROPERTY_EXCEPTION.get(pd.getName()), cause); |
| | | } |
| | | } |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 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. |
| | | */ |
| | | 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 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; |
| | | |
| | | |
| | | |
| | | /** |
| | | * An enumeration defining the reasons why the definition could not be |
| | | * resolved. |
| | | */ |
| | | public static enum Reason { |
| | | /** |
| | | * The managed object could be found but did not contain any type |
| | | * information (eg missing object classes in LDAP). |
| | | */ |
| | | NO_TYPE_INFORMATION(Message.raw( // TODO: i18n? |
| | | "The managed object could be found but did not contain any" |
| | | + " type information (e.g. missing object classes in LDAP).")), |
| | | |
| | | /** |
| | | * The managed object could be found but did not contain the expected type |
| | | * information (eg incorrect object classes in LDAP). |
| | | */ |
| | | WRONG_TYPE_INFORMATION(Message.raw( // TODO: i18n? |
| | | "The managed object could be found but did not contain the" |
| | | + " expected type information (e.g. incorrect object" |
| | | + " classes in LDAP).")), |
| | | |
| | | /** |
| | | * The managed object could be found but its type resolved to an abstract |
| | | * managed object definition. |
| | | */ |
| | | ABSTRACT_TYPE_INFORMATION(Message.raw( // TODO: i18n? |
| | | "The managed object could be found but its type resolved to an" |
| | | + " abstract managed object definition.")); |
| | | |
| | | // Simple description of this reason for debugging. |
| | | private Message msg; |
| | | |
| | | |
| | | |
| | | // Private constructor. |
| | | private Reason(Message msg) { |
| | | this.msg = msg; |
| | | // Create the message. |
| | | private static Message createMessage(AbstractManagedObjectDefinition<?, ?> d, |
| | | Reason reason) { |
| | | Message 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(Reason reason) { |
| | | public DefinitionDecodingException(AbstractManagedObjectDefinition<?, ?> d, |
| | | Reason reason) { |
| | | super(createMessage(d, reason)); |
| | | this.d = d; |
| | | this.reason = reason; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the reason why the definition could not be determined. |
| | | * Gets the expected managed object definition. |
| | | * |
| | | * @return Returns the reason why the definition could not be determined. |
| | | * @return Returns the expected managed object definition. |
| | | */ |
| | | public Reason getReason() { |
| | | return reason; |
| | | public AbstractManagedObjectDefinition<?, ?> getManagedObjectDefinition() { |
| | | return d; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | * Gets the reason why the definition could not be determined. |
| | | * |
| | | * @return Returns the reason why the definition could not be |
| | | * determined. |
| | | */ |
| | | @Override |
| | | public Message getMessageObject() { |
| | | return reason.msg; |
| | | public Reason getReason() { |
| | | return reason; |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Thrown to indicate that a property value was invalid according to its |
| | | * associated property definition. |
| | | * Thrown to indicate that a property value was invalid according to |
| | | * its associated property definition. |
| | | */ |
| | | public class IllegalPropertyValueException extends PropertyException { |
| | | |
| | |
| | | /** |
| | | * Create a new illegal property value exception. |
| | | * |
| | | * @param d |
| | | * @param pd |
| | | * The property definition. |
| | | * @param value |
| | | * The illegal property value. |
| | | */ |
| | | public IllegalPropertyValueException(PropertyDefinition<?> d, Object value) { |
| | | super(d); |
| | | public IllegalPropertyValueException(PropertyDefinition<?> pd, Object value) { |
| | | super(pd, createMessage(pd, value)); |
| | | this.value = value; |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getMessage() { |
| | | String msg = "The value \"%s\" is not a valid value for the " |
| | | + "property \"%s\", which must have the following syntax: %s"; |
| | | PropertyDefinition<?> pd = getPropertyDefinition(); |
| | | // Create the message. |
| | | private static Message createMessage(PropertyDefinition<?> pd, Object value) { |
| | | PropertyDefinitionUsageBuilder builder = new PropertyDefinitionUsageBuilder( |
| | | true); |
| | | return String.format(msg, String.valueOf(value), pd.getName(), builder |
| | | .getUsage(pd)); |
| | | return ERR_ILLEGAL_PROPERTY_VALUE_EXCEPTION.get(String.valueOf(value), pd |
| | | .getName(), builder.getUsage(pd)); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Thrown to indicate that a property value string was invalid according to its |
| | | * associated property definition. |
| | | * Thrown to indicate that a property value string was invalid |
| | | * according to its associated property definition. |
| | | */ |
| | | public class IllegalPropertyValueStringException extends PropertyException { |
| | | |
| | |
| | | /** |
| | | * Create a new illegal property value string exception. |
| | | * |
| | | * @param d |
| | | * @param pd |
| | | * The property definition. |
| | | * @param value |
| | | * The illegal property value string. |
| | | */ |
| | | public IllegalPropertyValueStringException(PropertyDefinition<?> d, |
| | | public IllegalPropertyValueStringException(PropertyDefinition<?> pd, |
| | | String value) { |
| | | super(d); |
| | | super(pd, createMessage(pd, value)); |
| | | this.value = value; |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getMessage() { |
| | | String msg = "The string value \"%s\" is not a valid value for the " |
| | | + "property \"%s\", which must have the following syntax: %s"; |
| | | PropertyDefinition<?> pd = getPropertyDefinition(); |
| | | // Create the message. |
| | | private static Message createMessage(PropertyDefinition<?> pd, String value) { |
| | | PropertyDefinitionUsageBuilder builder = new PropertyDefinitionUsageBuilder( |
| | | true); |
| | | return String.format(msg, value, pd.getName(), builder.getUsage(pd)); |
| | | return ERR_ILLEGAL_PROPERTY_VALUE_STRING_EXCEPTION.get(value, pd.getName(), |
| | | builder.getUsage(pd)); |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | private static final long serialVersionUID = -2344653674171609366L; |
| | | |
| | | // Simple description of this exception for debugging. |
| | | private static final String MSG = "A managed object could not be created" |
| | | + " because there is an existing managed object with the same name"; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a managed object already exists exception. |
| | | */ |
| | | public ManagedObjectAlreadyExistsException() { |
| | | super(Message.raw(MSG)); |
| | | super(ERR_MANAGED_OBJECT_ALREADY_EXISTS_EXCEPTION.get()); |
| | | } |
| | | } |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | private static final long serialVersionUID = -477551786551892978L; |
| | | |
| | | // Simple description of this exception for debugging. |
| | | private static final String MSG = // TODO: i18n |
| | | "The requested managed object could not be found"; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a managed object not found exception. |
| | | */ |
| | | public ManagedObjectNotFoundException() { |
| | | super(Message.raw(MSG)); |
| | | super(ERR_MANAGED_OBJECT_NOT_FOUND_EXCEPTION.get()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a managed object not found exception with the specified cause. |
| | | * Create a managed object not found exception with the specified |
| | | * cause. |
| | | * |
| | | * @param cause |
| | | * The cause of this exception. |
| | | */ |
| | | public ManagedObjectNotFoundException(Throwable cause) { |
| | | super(Message.raw(MSG), cause); |
| | | super(ERR_MANAGED_OBJECT_NOT_FOUND_EXCEPTION.get(), cause); |
| | | } |
| | | } |
| | |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Exceptions thrown as a result of errors that occurred when reading, listing, |
| | | * and modifying managed objects. |
| | | * Exceptions thrown as a result of errors that occurred when reading, |
| | | * listing, and modifying managed objects. |
| | | */ |
| | | public class OperationsException extends AdminException { |
| | | public abstract class OperationsException extends AdminException { |
| | | |
| | | /** |
| | | * Serialization ID. |
| | |
| | | |
| | | |
| | | /** |
| | | * Create an operations exception. |
| | | */ |
| | | public OperationsException() { |
| | | // No implementation required. |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create an operations exception with a cause. |
| | | * |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | public OperationsException(Throwable cause) { |
| | | super(cause); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create an operations exception with a message and cause. |
| | | * |
| | | * @param message |
| | |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | public OperationsException(Message message, Throwable cause) { |
| | | protected OperationsException(Message message, Throwable cause) { |
| | | super(message, cause); |
| | | } |
| | | |
| | |
| | | * @param message |
| | | * The message. |
| | | */ |
| | | public OperationsException(Message message) { |
| | | protected OperationsException(Message message) { |
| | | super(message); |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Exceptions thrown as a result of errors that occurred when decoding and |
| | | * modifying property values. |
| | | * Exceptions thrown as a result of errors that occurred when decoding |
| | | * and modifying property values. |
| | | */ |
| | | public abstract class PropertyException extends AdminRuntimeException { |
| | | |
| | |
| | | */ |
| | | private static final long serialVersionUID = -8465109598081914482L; |
| | | |
| | | // The property definition associated with the property that caused the |
| | | // exception. |
| | | private final PropertyDefinition<?> definition; |
| | | // The property definition associated with the property that caused |
| | | // the exception. |
| | | private final PropertyDefinition<?> pd; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create an operations exception with a cause. |
| | | * Creates property exception without a cause. |
| | | * |
| | | * @param definition |
| | | * The property definition associated with the property that caused |
| | | * the exception. |
| | | * @param pd |
| | | * The property definition associated with the property |
| | | * that caused the exception. |
| | | * @param message |
| | | * The message. |
| | | */ |
| | | protected PropertyException(PropertyDefinition<?> definition) { |
| | | this.definition = definition; |
| | | protected PropertyException(PropertyDefinition<?> pd, Message message) { |
| | | super(message); |
| | | this.pd = pd; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the property definition associated with the property that caused the |
| | | * exception. |
| | | * Creates property exception with a cause. |
| | | * |
| | | * @return Returns the property definition associated with the property that |
| | | * caused the exception. |
| | | * @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, Message message, |
| | | Throwable cause) { |
| | | super(message, cause); |
| | | this.pd = pd; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the property definition associated with the property that |
| | | * caused the exception. |
| | | * |
| | | * @return Returns the property definition associated with the |
| | | * property that caused the exception. |
| | | */ |
| | | public final PropertyDefinition<?> getPropertyDefinition() { |
| | | return definition; |
| | | return pd; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public abstract String getMessage(); |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Thrown when an attempt is made to remove a mandatory property. |
| | | */ |
| | |
| | | /** |
| | | * Create a new property is mandatory exception. |
| | | * |
| | | * @param d |
| | | * @param pd |
| | | * The property definition. |
| | | */ |
| | | public PropertyIsMandatoryException(PropertyDefinition<?> d) { |
| | | super(d); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getMessage() { |
| | | return "The property \"" + getPropertyDefinition().getName() |
| | | + "\" must be specified as it is mandatory"; |
| | | public PropertyIsMandatoryException(PropertyDefinition<?> pd) { |
| | | super(pd, ERR_PROPERTY_IS_MANDATORY_EXCEPTION.get(pd.getName())); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Thrown when an attempt is made to modify a read-only property. |
| | | */ |
| | |
| | | /** |
| | | * Create a new property is read-only exception. |
| | | * |
| | | * @param d |
| | | * @param pd |
| | | * The property definition. |
| | | */ |
| | | public PropertyIsReadOnlyException(PropertyDefinition<?> d) { |
| | | super(d); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getMessage() { |
| | | return "The property \"" + getPropertyDefinition().getName() |
| | | + "\" must not be modified as it is read-only"; |
| | | public PropertyIsReadOnlyException(PropertyDefinition<?> pd) { |
| | | super(pd, ERR_PROPERTY_IS_READ_ONLY_EXCEPTION.get(pd.getName())); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Thrown when an attempt is made to add more than value to a single-valued |
| | | * property. |
| | | * Thrown when an attempt is made to add more than value to a |
| | | * single-valued property. |
| | | */ |
| | | public class PropertyIsSingleValuedException extends PropertyException { |
| | | |
| | |
| | | /** |
| | | * Create a new property is single valued exception. |
| | | * |
| | | * @param d |
| | | * @param pd |
| | | * The property definition. |
| | | */ |
| | | public PropertyIsSingleValuedException(PropertyDefinition<?> d) { |
| | | super(d); |
| | | public PropertyIsSingleValuedException(PropertyDefinition<?> pd) { |
| | | super(pd, ERR_PROPERTY_IS_SINGLE_VALUED_EXCEPTION.get(pd.getName())); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getMessage() { |
| | | return "The property \"" + getPropertyDefinition().getName() |
| | | + "\" must not contain more than one value"; |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | package org.opends.server.admin; |
| | | |
| | | import org.opends.messages.Message; |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | |
| | | /** |
| | |
| | | * The name of the property that could not be found. |
| | | */ |
| | | public PropertyNotFoundException(String propertyName) { |
| | | super(Message.raw("The property \"" + propertyName + |
| | | "\" was not recognized")); // TODO: i18n |
| | | super(ERR_PROPERTY_NOT_FOUND_EXCEPTION.get(propertyName)); |
| | | |
| | | this.propertyName = propertyName; |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates that an unknown type of property definition was encountered. This |
| | | * can occur as the management prototype develops and new kinds of property |
| | | * definitions are added. |
| | | * Indicates that an unknown type of property definition was |
| | | * encountered. This can occur as the management prototype develops |
| | | * and new kinds of property definitions are added. |
| | | */ |
| | | public final class UnknownPropertyDefinitionException |
| | | extends PropertyException { |
| | |
| | | /** |
| | | * Creates a new unknown property definition exception. |
| | | * |
| | | * @param d |
| | | * @param pd |
| | | * The unknown property definition. |
| | | * @param p |
| | | * The visitor parameter if there was one. |
| | | */ |
| | | public UnknownPropertyDefinitionException(PropertyDefinition<?> d, Object p) { |
| | | super(d); |
| | | public UnknownPropertyDefinitionException(PropertyDefinition<?> pd, |
| | | Object p) { |
| | | super(pd, ERR_UNKNOWN_PROPERTY_DEFINITION_EXCEPTION.get(pd.getName(), pd |
| | | .getClass().getName())); |
| | | this.parameter = p; |
| | | } |
| | | |
| | |
| | | return parameter; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getMessage() { |
| | | return "Unhandled property definition type encountered \"" |
| | | + getPropertyDefinition().getClass().getName() + "\""; |
| | | } |
| | | } |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | |
| | | |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import org.opends.server.admin.AdminException; |
| | | |
| | | |
| | |
| | | * Client exceptions represent communications problems, security |
| | | * problems, and service related problems. |
| | | */ |
| | | public class AdminClientException extends AdminException { |
| | | public abstract class AdminClientException extends AdminException { |
| | | |
| | | /** |
| | | * Serialization ID. |
| | |
| | | |
| | | |
| | | /** |
| | | * Create an administration client exception. |
| | | */ |
| | | public AdminClientException() { |
| | | // No implementation required. |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create an administration client exception with a cause. |
| | | * |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | public AdminClientException(Throwable cause) { |
| | | super(cause); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create an administration client exception with a message and |
| | | * cause. |
| | | * |
| | |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | public AdminClientException(Message message, Throwable cause) { |
| | | protected AdminClientException(Message message, Throwable cause) { |
| | | super(message, cause); |
| | | } |
| | | |
| | |
| | | * @param message |
| | | * The message. |
| | | */ |
| | | public AdminClientException(Message message) { |
| | | protected AdminClientException(Message message) { |
| | | super(message); |
| | | } |
| | | } |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This exception is thrown when a security related problem occurs |
| | |
| | | public abstract class AdminSecurityException extends AdminClientException { |
| | | |
| | | /** |
| | | * Create a security exception. |
| | | */ |
| | | protected AdminSecurityException() { |
| | | // No implementation required. |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a security exception with a cause. |
| | | * |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | protected AdminSecurityException(Throwable cause) { |
| | | super(cause); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a security exception with a message and cause. |
| | | * |
| | | * @param message |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This exception is thrown when an authentication error occurs while |
| | |
| | | |
| | | |
| | | /** |
| | | * Create an authentication exception. |
| | | * Creates an authentication exception with a default message. |
| | | */ |
| | | public AuthenticationException() { |
| | | // No implementation required. |
| | | super(ERR_AUTHENTICATION_EXCEPTION_DEFAULT.get()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create an authentication exception with a cause. |
| | | * Create an authentication exception with a cause and a default |
| | | * message. |
| | | * |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | public AuthenticationException(Throwable cause) { |
| | | super(cause); |
| | | super(ERR_AUTHENTICATION_EXCEPTION_DEFAULT.get(), cause); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This exception is thrown when the particular flavor of |
| | |
| | | |
| | | |
| | | /** |
| | | * Create an authentication not supported exception. |
| | | * Creates an authentication not supported exception with a default |
| | | * message. |
| | | */ |
| | | public AuthenticationNotSupportedException() { |
| | | // No implementation required. |
| | | super(ERR_AUTHENTICATION_NOT_SUPPORTED_EXCEPTION_DEFAULT.get()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create an authentication not supported exception with a cause. |
| | | * Creates an authentication not supported exception with a cause |
| | | * and a default message. |
| | | * |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | public AuthenticationNotSupportedException(Throwable cause) { |
| | | super(cause); |
| | | super(ERR_AUTHENTICATION_NOT_SUPPORTED_EXCEPTION_DEFAULT.get(), cause); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This exception is thrown when an authorization error occurs while |
| | |
| | | |
| | | |
| | | /** |
| | | * Create an authorization exception. |
| | | * Create an authorization exception with a default message. |
| | | */ |
| | | public AuthorizationException() { |
| | | // No implementation required. |
| | | super(ERR_AUTHORIZATION_EXCEPTION_DEFAULT.get()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create an authorization exception with a cause. |
| | | * Create an authorization exception with a cause and a default |
| | | * message. |
| | | * |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | public AuthorizationException(Throwable cause) { |
| | | super(cause); |
| | | super(ERR_AUTHORIZATION_EXCEPTION_DEFAULT.get(), cause); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This exception is thrown when a communications related problem |
| | |
| | | |
| | | |
| | | /** |
| | | * Create a communication exception. |
| | | * Create a communication exception with a default message. |
| | | */ |
| | | public CommunicationException() { |
| | | // No implementation required. |
| | | super(ERR_COMMUNICATION_EXCEPTION_DEFAULT.get()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a communication exception with a cause. |
| | | * Create a communication exception with a cause and a default |
| | | * message. |
| | | * |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | public CommunicationException(Throwable cause) { |
| | | super(cause); |
| | | super(ERR_COMMUNICATION_EXCEPTION_DEFAULT.get(), cause); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import org.opends.server.admin.OperationsException; |
| | | |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * Create a concurrent modification exception. |
| | | * Create a concurrent modification exception with a default |
| | | * message. |
| | | */ |
| | | public ConcurrentModificationException() { |
| | | // No implementation required. |
| | | super(ERR_CONCURRENT_MODIFICATION_EXCEPTION_DEFAULT.get()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a concurrent modification exception with a cause. |
| | | * Create a concurrent modification exception with a cause and a |
| | | * default message. |
| | | * |
| | | * @param cause |
| | | * The cause. |
| | | */ |
| | | public ConcurrentModificationException(Throwable cause) { |
| | | super(cause); |
| | | super(ERR_CONCURRENT_MODIFICATION_EXCEPTION_DEFAULT.get(), cause); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import org.opends.server.admin.IllegalPropertyValueStringException; |
| | | import org.opends.server.admin.OperationsException; |
| | | import org.opends.server.admin.PropertyDefinition; |
| | |
| | | */ |
| | | private static final long serialVersionUID = 7491748228684293291L; |
| | | |
| | | |
| | | |
| | | // Create the message |
| | | private static Message 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); |
| | | } |
| | | |
| | | // The illegal name. |
| | | private final String illegalName; |
| | | |
| | |
| | | */ |
| | | public IllegalManagedObjectNameException(String illegalName, |
| | | PropertyDefinition<?> namingPropertyDefinition) { |
| | | super(createMessage(illegalName, namingPropertyDefinition)); |
| | | |
| | | this.illegalName = illegalName; |
| | | this.namingPropertyDefinition = namingPropertyDefinition; |
| | | } |
| | |
| | | return namingPropertyDefinition; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Message getMessageObject() { |
| | | if (illegalName.length() == 0) { |
| | | return Message.raw("Empty managed object names are not permitted"); |
| | | } else if (illegalName.trim().length() == 0) { |
| | | return Message.raw("Blank managed object names are not permitted"); |
| | | } else if (namingPropertyDefinition != null) { |
| | | try { |
| | | namingPropertyDefinition.decodeValue(illegalName); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | String msg = "The managed object name \"%s\" is not a valid value " |
| | | + "for the naming property \"%s\", which must have the following " |
| | | + "syntax: %s"; |
| | | PropertyDefinitionUsageBuilder builder = |
| | | new PropertyDefinitionUsageBuilder(true); |
| | | return Message.raw(String.format(msg, illegalName, |
| | | namingPropertyDefinition.getName(), |
| | | builder.getUsage(namingPropertyDefinition))); |
| | | } |
| | | } |
| | | |
| | | return Message.raw("The managed object name \"" + illegalName + |
| | | "\" is not permitted"); |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | import org.opends.messages.MessageBuilder; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.LinkedList; |
| | | |
| | | import org.opends.server.admin.DecodingException; |
| | | import org.opends.server.admin.ManagedObjectDefinition; |
| | | import org.opends.server.admin.PropertyException; |
| | | import org.opends.server.util.Validator; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 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 { |
| | | |
| | |
| | | */ |
| | | private static final long serialVersionUID = -4268510652395945357L; |
| | | |
| | | // The partially created managed object. |
| | | private final ManagedObject<?> partialManagedObject; |
| | | |
| | | |
| | | // Create the message. |
| | | private static Message createMessage(ManagedObject<?> partialManagedObject, |
| | | Collection<PropertyException> causes) { |
| | | Validator.ensureNotNull(causes); |
| | | Validator.ensureTrue(!causes.isEmpty()); |
| | | |
| | | ManagedObjectDefinition<?, ?> d = partialManagedObject |
| | | .getManagedObjectDefinition(); |
| | | if (causes.size() == 1) { |
| | | return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_SINGLE.get(d |
| | | .getUserFriendlyName(), causes.iterator().next().getMessageObject()); |
| | | } else { |
| | | MessageBuilder builder = new MessageBuilder(); |
| | | |
| | | boolean isFirst = true; |
| | | for (PropertyException cause : causes) { |
| | | if (!isFirst) { |
| | | builder.append("; "); |
| | | } |
| | | builder.append(cause.getMessageObject()); |
| | | 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 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). |
| | | * 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)); |
| | |
| | | |
| | | |
| | | /** |
| | | * Get an unmodifiable collection view of the causes of this exception. |
| | | * Get an unmodifiable collection view of the causes of this |
| | | * exception. |
| | | * |
| | | * @return Returns 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; |
| | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Message getMessageObject() { |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append("The managed object could not be decoded due" |
| | | + " to the following property exceptions: "); |
| | | // FIXME: better formatting. |
| | | builder.append(causes.toString()); |
| | | return Message.raw(builder.toString()); // TODO: i18n? |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 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). |
| | | * 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). |
| | | * @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; |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin.client; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.messages.MessageBuilder; |
| | | import org.opends.server.admin.OperationsException; |
| | | import org.opends.server.admin.PropertyIsMandatoryException; |
| | | import org.opends.server.util.Validator; |
| | |
| | | */ |
| | | private static final long serialVersionUID = 6342522125252055588L; |
| | | |
| | | |
| | | |
| | | // Create the message. |
| | | private static Message createMessage( |
| | | Collection<PropertyIsMandatoryException> causes) { |
| | | Validator.ensureNotNull(causes); |
| | | Validator.ensureTrue(!causes.isEmpty()); |
| | | |
| | | if (causes.size() == 1) { |
| | | return ERR_MISSING_MANDATORY_PROPERTIES_EXCEPTION_SINGLE.get(causes |
| | | .iterator().next().getPropertyDefinition().getName()); |
| | | } else { |
| | | MessageBuilder builder = new MessageBuilder(); |
| | | |
| | | boolean isFirst = true; |
| | | for (PropertyIsMandatoryException cause : causes) { |
| | | if (!isFirst) { |
| | | builder.append(", "); |
| | | } |
| | | 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; |
| | | |
| | |
| | | */ |
| | | public MissingMandatoryPropertiesException( |
| | | Collection<PropertyIsMandatoryException> causes) { |
| | | Validator.ensureNotNull(causes); |
| | | Validator.ensureTrue(!causes.isEmpty()); |
| | | super(createMessage(causes)); |
| | | |
| | | this.causes = new ArrayList<PropertyIsMandatoryException>(causes); |
| | | } |
| | |
| | | return Collections.unmodifiableCollection(causes); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Message getMessageObject() { |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append("The following properties are mandatory: "); |
| | | boolean isFirst = true; |
| | | for (PropertyIsMandatoryException e : causes) { |
| | | if (!isFirst) { |
| | | builder.append(", "); |
| | | } |
| | | builder.append(e.getPropertyDefinition().getName()); |
| | | isFirst = false; |
| | | } |
| | | return Message.raw(builder.toString()); |
| | | } |
| | | |
| | | } |
| | |
| | | Validator.ensureNotNull(messages); |
| | | Validator.ensureTrue(!messages.isEmpty()); |
| | | |
| | | MessageBuilder builder = new MessageBuilder(); |
| | | if (messages.size() == 1) { |
| | | return ERR_OPERATION_REJECTED_EXCEPTION_SINGLE.get(messages.iterator() |
| | | .next()); |
| | | } else { |
| | | MessageBuilder builder = new MessageBuilder(); |
| | | |
| | | boolean isFirst = true; |
| | | for (Message m : messages) { |
| | | if (!isFirst) { |
| | | builder.append("; "); |
| | | boolean isFirst = true; |
| | | for (Message m : messages) { |
| | | if (!isFirst) { |
| | | builder.append("; "); |
| | | } |
| | | builder.append(m); |
| | | isFirst = false; |
| | | } |
| | | builder.append(m); |
| | | isFirst = false; |
| | | } |
| | | |
| | | return builder.toMessage(); |
| | | return ERR_OPERATION_REJECTED_EXCEPTION_PLURAL.get(builder.toMessage()); |
| | | } |
| | | } |
| | | |
| | | // The messages describing the constraint violations that occurred. |
| | |
| | | * |
| | | * @param message |
| | | * The message describing the constraint violation that |
| | | * occurred (must be non-<code>null</code> and |
| | | * non-empty). |
| | | * occurred. |
| | | */ |
| | | public OperationRejectedException(Message message) { |
| | | this(Collections.singleton(message)); |
| | |
| | | |
| | | if (oc == null) { |
| | | // No object classes. |
| | | throw new DefinitionDecodingException(Reason.NO_TYPE_INFORMATION); |
| | | throw new DefinitionDecodingException(d, Reason.NO_TYPE_INFORMATION); |
| | | } |
| | | |
| | | final Set<String> objectClasses = new HashSet<String>(); |
| | |
| | | |
| | | if (objectClasses.isEmpty()) { |
| | | // No object classes. |
| | | throw new DefinitionDecodingException(Reason.NO_TYPE_INFORMATION); |
| | | throw new DefinitionDecodingException(d, Reason.NO_TYPE_INFORMATION); |
| | | } |
| | | |
| | | // Resolve the appropriate sub-type based on the object classes. |
| | |
| | | AbstractManagedObjectDefinition<?, ?> supr = target |
| | | .getManagedObjectDefinition(); |
| | | if (!supr.isParentOf(d)) { |
| | | throw new DefaultBehaviorException(nextProperty, |
| | | new DefinitionDecodingException(Reason.WRONG_TYPE_INFORMATION)); |
| | | throw new DefaultBehaviorException( |
| | | nextProperty, new DefinitionDecodingException(supr, |
| | | Reason.WRONG_TYPE_INFORMATION)); |
| | | } |
| | | |
| | | // Save the current property in case of recursion. |
| | |
| | | AbstractManagedObjectDefinition<?, ?> supr = target |
| | | .getManagedObjectDefinition(); |
| | | if (!supr.isParentOf(d)) { |
| | | throw new DefaultBehaviorException(nextProperty, |
| | | new DefinitionDecodingException(Reason.WRONG_TYPE_INFORMATION)); |
| | | throw new DefaultBehaviorException( |
| | | nextProperty, new DefinitionDecodingException(supr, |
| | | Reason.WRONG_TYPE_INFORMATION)); |
| | | } |
| | | |
| | | // Save the current property in case of recursion. |
| | |
| | | */ |
| | | |
| | | package org.opends.server.admin.server; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.AdminMessages.*; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.LinkedList; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.messages.MessageBuilder; |
| | | import org.opends.server.admin.DecodingException; |
| | | import org.opends.server.admin.ManagedObjectDefinition; |
| | | import org.opends.server.admin.PropertyException; |
| | | import org.opends.server.util.Validator; |
| | | |
| | | |
| | | |
| | | /** |
| | | * The requested server managed object was found but one or more of its |
| | | * properties could not be decoded successfully. |
| | | * The requested server managed object was found but one or more of |
| | | * its properties could not be decoded successfully. |
| | | */ |
| | | public class ServerManagedObjectDecodingException extends DecodingException { |
| | | |
| | |
| | | */ |
| | | private static final long serialVersionUID = 1598401431084729853L; |
| | | |
| | | // The partially created server managed object. |
| | | private final ServerManagedObject<?> partialManagedObject; |
| | | |
| | | |
| | | // Create the message. |
| | | private static Message createMessage( |
| | | ServerManagedObject<?> partialManagedObject, |
| | | Collection<PropertyException> causes) { |
| | | Validator.ensureNotNull(causes); |
| | | Validator.ensureTrue(!causes.isEmpty()); |
| | | |
| | | ManagedObjectDefinition<?, ?> d = partialManagedObject |
| | | .getManagedObjectDefinition(); |
| | | if (causes.size() == 1) { |
| | | return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_SINGLE.get(d |
| | | .getUserFriendlyName(), causes.iterator().next().getMessageObject()); |
| | | } else { |
| | | MessageBuilder builder = new MessageBuilder(); |
| | | |
| | | boolean isFirst = true; |
| | | for (PropertyException cause : causes) { |
| | | if (!isFirst) { |
| | | builder.append("; "); |
| | | } |
| | | builder.append(cause.getMessageObject()); |
| | | 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 partially created server managed object. |
| | | private final ServerManagedObject<?> partialManagedObject; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a new property decoding exception. |
| | | * |
| | | * @param partialManagedObject |
| | | * The partially created server managed object containing properties |
| | | * which were successfully decoded and empty properties for those |
| | | * which were not (this may include empty mandatory properties). |
| | | * The partially created server 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 ServerManagedObjectDecodingException( |
| | | ServerManagedObject<?> partialManagedObject, |
| | | Collection<PropertyException> causes) { |
| | | super(createMessage(partialManagedObject, causes)); |
| | | |
| | | this.partialManagedObject = partialManagedObject; |
| | | this.causes = Collections |
| | | .unmodifiableList(new LinkedList<PropertyException>(causes)); |
| | |
| | | |
| | | |
| | | /** |
| | | * Get an unmodifiable collection view of the causes of this exception. |
| | | * Get an unmodifiable collection view of the causes of this |
| | | * exception. |
| | | * |
| | | * @return Returns 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; |
| | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Message getMessageObject() { |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append("The managed object could not be decoded due" |
| | | + " to the following property exceptions: "); |
| | | // FIXME: better formatting. |
| | | builder.append(causes.toString()); |
| | | return Message.raw(builder.toString()); // TODO: i18n? |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the partially created server managed object containing properties which |
| | | * were successfully decoded and empty properties for those which were not |
| | | * (this may include empty mandatory properties). |
| | | * Get the partially created server 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 server 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 server managed object |
| | | * containing properties which were successfully decoded and |
| | | * empty properties for those which were not (this may |
| | | * include empty mandatory properties). |
| | | */ |
| | | public ServerManagedObject<?> getPartialManagedObject() { |
| | | return partialManagedObject; |