| | |
| | | import static org.opends.server.util.Validator.ensureNotNull; |
| | | |
| | | import java.util.EnumSet; |
| | | import java.util.Locale; |
| | | import java.util.MissingResourceException; |
| | | import java.util.Set; |
| | | |
| | | |
| | |
| | | protected abstract static class AbstractBuilder<T, |
| | | D extends PropertyDefinition<T>> { |
| | | |
| | | // The abstract managed object |
| | | private final AbstractManagedObjectDefinition<?, ?> definition; |
| | | |
| | | // The name of this property definition. |
| | | private final String propertyName; |
| | | |
| | |
| | | /** |
| | | * Create a property definition builder. |
| | | * |
| | | * @param d |
| | | * The managed object definition associated with this |
| | | * property definition. |
| | | * @param propertyName |
| | | * The property name. |
| | | */ |
| | | protected AbstractBuilder(String propertyName) { |
| | | protected AbstractBuilder( |
| | | AbstractManagedObjectDefinition<?, ?> d, String propertyName) { |
| | | this.definition = d; |
| | | this.propertyName = propertyName; |
| | | this.options = EnumSet.noneOf(PropertyOption.class); |
| | | this.defaultBehavior = new UndefinedDefaultBehaviorProvider<T>(); |
| | |
| | | * @return The new property definition. |
| | | */ |
| | | public final D getInstance() { |
| | | return buildInstance(propertyName, options, defaultBehavior); |
| | | return buildInstance(definition, propertyName, options, defaultBehavior); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * Build a property definition based on the properties of this builder. |
| | | * Build a property definition based on the properties of this |
| | | * builder. |
| | | * |
| | | * @param d |
| | | * The managed object definition associated with this |
| | | * property definition. |
| | | * @param propertyName |
| | | * The property name. |
| | | * @param options |
| | |
| | | * The default behavior provider. |
| | | * @return The new property definition. |
| | | */ |
| | | protected abstract D buildInstance(String propertyName, |
| | | protected abstract D buildInstance( |
| | | AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, |
| | | DefaultBehaviorProvider<T> defaultBehavior); |
| | | } |
| | |
| | | // The default behavior provider. |
| | | private final DefaultBehaviorProvider<T> defaultBehavior; |
| | | |
| | | // The abstract managed object |
| | | private final AbstractManagedObjectDefinition<?, ?> definition; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create a property definition. |
| | | * |
| | | * @param d |
| | | * The managed object definition associated with this |
| | | * property definition. |
| | | * @param theClass |
| | | * The property value class. |
| | | * @param propertyName |
| | |
| | | * @param defaultBehavior |
| | | * The default behavior provider. |
| | | */ |
| | | protected AbstractPropertyDefinition(Class<T> theClass, String propertyName, |
| | | protected AbstractPropertyDefinition(AbstractManagedObjectDefinition<?,?> d, |
| | | Class<T> theClass, String propertyName, |
| | | EnumSet<PropertyOption> options, |
| | | DefaultBehaviorProvider<T> defaultBehavior) { |
| | | ensureNotNull(theClass, propertyName, options, defaultBehavior); |
| | | ensureNotNull(d, theClass, propertyName); |
| | | ensureNotNull(options, defaultBehavior); |
| | | |
| | | this.definition = d; |
| | | this.theClass = theClass; |
| | | this.propertyName = propertyName; |
| | | this.options = EnumSet.copyOf(options); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final String getDescription() { |
| | | return getDescription(Locale.getDefault()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final String getDescription(Locale locale) { |
| | | ManagedObjectDefinitionI18NResource resource = |
| | | ManagedObjectDefinitionI18NResource.getInstance(); |
| | | String property = "property." + propertyName + ".description"; |
| | | try { |
| | | return resource.getMessage(definition, property, locale); |
| | | } catch (MissingResourceException e) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the managed object definition associated with this property |
| | | * definition. |
| | | * |
| | | * @return Returns the managed object definition associated with |
| | | * this property definition. |
| | | */ |
| | | public final AbstractManagedObjectDefinition<?, ?> |
| | | getManagedObjectDefinition() { |
| | | return definition; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final String getName() { |
| | | return propertyName; |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final String getSynopsis() { |
| | | return getSynopsis(Locale.getDefault()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final String getSynopsis(Locale locale) { |
| | | ManagedObjectDefinitionI18NResource resource = |
| | | ManagedObjectDefinitionI18NResource.getInstance(); |
| | | String property = "property." + propertyName + ".synopsis"; |
| | | try { |
| | | return resource.getMessage(definition, property, locale); |
| | | } catch (MissingResourceException e) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public int hashCode() { |
| | | // TODO: see comment in equals(). |