001    /*
002     * CDDL HEADER START
003     *
004     * The contents of this file are subject to the terms of the
005     * Common Development and Distribution License, Version 1.0 only
006     * (the "License").  You may not use this file except in compliance
007     * with the License.
008     *
009     * You can obtain a copy of the license at
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2008 Sun Microsystems, Inc.
026     */
027    
028    package org.opends.server.admin;
029    
030    
031    
032    import static org.opends.server.util.Validator.ensureNotNull;
033    
034    import java.util.EnumSet;
035    
036    import org.opends.server.config.ConfigException;
037    import org.opends.server.types.AddressMask;
038    
039    
040    
041    /**
042     * IP address mask property definition.
043     */
044    public final class IPAddressMaskPropertyDefinition extends
045        PropertyDefinition<AddressMask> {
046    
047      /**
048       * An interface for incrementally constructing IP address mask property
049       * definitions.
050       */
051      public static class Builder extends
052          AbstractBuilder<AddressMask, IPAddressMaskPropertyDefinition> {
053    
054        // Private constructor
055        private Builder(
056            AbstractManagedObjectDefinition<?, ?> d, String propertyName) {
057          super(d, propertyName);
058        }
059    
060    
061    
062        /**
063         * {@inheritDoc}
064         */
065        @Override
066        protected IPAddressMaskPropertyDefinition buildInstance(
067            AbstractManagedObjectDefinition<?, ?> d,
068            String propertyName, EnumSet<PropertyOption> options,
069            AdministratorAction adminAction,
070            DefaultBehaviorProvider<AddressMask> defaultBehavior) {
071          return new IPAddressMaskPropertyDefinition(d, propertyName, options,
072              adminAction, defaultBehavior);
073        }
074    
075      }
076    
077    
078    
079      /**
080       * Create a IP address mask property definition builder.
081       *
082       * @param d
083       *          The managed object definition associated with this
084       *          property definition.
085       * @param propertyName
086       *          The property name.
087       * @return Returns the new IP address mask property definition builder.
088       */
089      public static Builder createBuilder(
090          AbstractManagedObjectDefinition<?, ?> d, String propertyName) {
091        return new Builder(d, propertyName);
092      }
093    
094    
095    
096      // Private constructor.
097      private IPAddressMaskPropertyDefinition(
098          AbstractManagedObjectDefinition<?, ?> d, String propertyName,
099          EnumSet<PropertyOption> options,
100          AdministratorAction adminAction,
101          DefaultBehaviorProvider<AddressMask> defaultBehavior) {
102        super(d, AddressMask.class, propertyName, options, adminAction,
103            defaultBehavior);
104      }
105    
106    
107    
108      /**
109       * {@inheritDoc}
110       */
111      @Override
112      public void validateValue(AddressMask value)
113          throws IllegalPropertyValueException {
114        ensureNotNull(value);
115    
116        // No additional validation required.
117      }
118    
119    
120    
121      /**
122       * {@inheritDoc}
123       */
124      @Override
125      public AddressMask decodeValue(String value)
126          throws IllegalPropertyValueStringException {
127        ensureNotNull(value);
128    
129        try {
130          return AddressMask.decode(value);
131        } catch (ConfigException e) {
132          // TODO: it would be nice to throw the cause.
133          throw new IllegalPropertyValueStringException(this, value);
134        }
135      }
136    
137    
138    
139      /**
140       * {@inheritDoc}
141       */
142      @Override
143      public <R, P> R accept(PropertyDefinitionVisitor<R, P> v, P p) {
144        return v.visitIPAddressMask(this, p);
145      }
146    
147    
148    
149      /**
150       * {@inheritDoc}
151       */
152      @Override
153      public <R, P> R accept(PropertyValueVisitor<R, P> v, AddressMask value, P p) {
154        return v.visitIPAddressMask(this, value, p);
155      }
156    
157    
158    
159      /**
160       * {@inheritDoc}
161       */
162      @Override
163      public int compare(AddressMask o1, AddressMask o2) {
164        return o1.toString().compareTo(o2.toString());
165      }
166    }