StringPropertyDefinition.java revision bb8874d71cdd8e5288297b9727703437c6dfcfed
0N/A/*
2975N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License, Version 1.0 only
0N/A * (the "License"). You may not use this file except in compliance
0N/A * with the License.
0N/A *
0N/A * You can obtain a copy of the license at
0N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
0N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
0N/A * See the License for the specific language governing permissions
0N/A * and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at
0N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
0N/A * add the following below this CDDL HEADER, with the fields enclosed
1472N/A * by brackets "[]" replaced with your own identifying information:
1472N/A * Portions Copyright [yyyy] [name of copyright owner]
1472N/A *
0N/A * CDDL HEADER END
0N/A *
0N/A *
1879N/A * Portions Copyright 2007 Sun Microsystems, Inc.
1879N/A */
1879N/A
2941N/Apackage org.opends.server.admin;
1879N/A
1879N/A
1879N/A
1879N/Aimport static org.opends.server.util.Validator.ensureNotNull;
0N/A
0N/Aimport java.util.EnumSet;
0N/A
0N/A
0N/A
0N/A/**
0N/A * String property definition.
0N/A * <p>
0N/A * TODO: pattern matching.
0N/A */
0N/Apublic final class StringPropertyDefinition extends
0N/A AbstractPropertyDefinition<String> {
0N/A
0N/A /**
0N/A * Serialization ID.
0N/A */
0N/A private static final long serialVersionUID = -2739105900274621416L;
0N/A
0N/A // Flag indicating whether values of this property are
0N/A // case-insensitive.
0N/A private final boolean isCaseInsensitive;
0N/A
0N/A
2975N/A
2975N/A /**
2975N/A * An interface for incrementally constructing string property definitions.
0N/A */
0N/A public static class Builder extends
0N/A AbstractBuilder<String, StringPropertyDefinition> {
0N/A
0N/A // Flag indicating whether values of this property are
0N/A // case-insensitive.
0N/A private boolean isCaseInsensitive = true;
0N/A
0N/A
0N/A
0N/A // Private constructor
0N/A private Builder(String propertyName) {
0N/A super(propertyName);
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Set a flag indicating whether values of this property are
0N/A * case-insensitive.
0N/A *
0N/A * @param value
0N/A * <code>true</code> if values are case-insensitive, or
0N/A * <code>false</code> otherwise.
0N/A */
0N/A public final void setCaseInsensitive(boolean value) {
0N/A isCaseInsensitive = value;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A */
0N/A @Override
0N/A protected StringPropertyDefinition buildInstance(String propertyName,
0N/A EnumSet<PropertyOption> options,
0N/A DefaultBehaviorProvider<String> defaultBehavior) {
0N/A return new StringPropertyDefinition(propertyName, options,
0N/A defaultBehavior, isCaseInsensitive);
0N/A }
0N/A
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Create a string property definition builder.
0N/A *
0N/A * @param propertyName
0N/A * The property name.
0N/A * @return Returns the new string property definition builder.
0N/A */
0N/A public static Builder createBuilder(String propertyName) {
0N/A return new Builder(propertyName);
0N/A }
0N/A
0N/A
0N/A
0N/A // Private constructor.
0N/A private StringPropertyDefinition(String propertyName,
0N/A EnumSet<PropertyOption> options,
0N/A DefaultBehaviorProvider<String> defaultBehavior,
0N/A boolean isCaseInsensitive) {
0N/A super(String.class, propertyName, options, defaultBehavior);
0N/A this.isCaseInsensitive = isCaseInsensitive;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Query whether values of this property are case-insensitive.
0N/A *
0N/A * @return Returns <code>true</code> if values are case-insensitive, or
0N/A * <code>false</code> otherwise.
0N/A */
0N/A public boolean isCaseInsensitive() {
0N/A return isCaseInsensitive;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A */
0N/A @Override
0N/A public String normalizeValue(String value)
0N/A throws IllegalPropertyValueException {
0N/A ensureNotNull(value);
0N/A
0N/A if (isCaseInsensitive()) {
0N/A return value.trim().toLowerCase();
0N/A } else {
0N/A return value.trim();
0N/A }
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A */
0N/A @Override
0N/A public void validateValue(String value) throws IllegalPropertyValueException {
0N/A ensureNotNull(value);
0N/A
0N/A // No additional validation required for now (might do pattern
0N/A // matching in future).
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A */
0N/A @Override
0N/A public String decodeValue(String value)
0N/A throws IllegalPropertyValueStringException {
0N/A ensureNotNull(value);
0N/A
0N/A return value;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A */
0N/A @Override
2941N/A public <R, P> R accept(PropertyDefinitionVisitor<R, P> v, P p) {
0N/A return v.visitString(this, p);
0N/A }
0N/A}
0N/A