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    import org.opends.server.authorization.dseecompat.Aci;
031    import org.opends.server.authorization.dseecompat.AciException;
032    import org.opends.server.types.DN;
033    import static org.opends.server.util.Validator.ensureNotNull;
034    import org.opends.server.protocols.asn1.ASN1OctetString;
035    
036    import java.util.EnumSet;
037    
038    /**
039     * ACI property definition.
040     */
041    public class ACIPropertyDefinition extends PropertyDefinition<Aci> {
042    
043    
044      /**
045       * An interface for incrementally constructing ACI property
046       * definitions.
047       */
048      public static class Builder extends
049          AbstractBuilder<Aci, ACIPropertyDefinition> {
050    
051        // Private constructor
052        private Builder(
053            AbstractManagedObjectDefinition<?, ?> d, String propertyName) {
054          super(d, propertyName);
055        }
056    
057        /**
058         * {@inheritDoc}
059         */
060        @Override
061        protected ACIPropertyDefinition buildInstance(
062            AbstractManagedObjectDefinition<?, ?> d,
063            String propertyName, EnumSet<PropertyOption> options,
064            AdministratorAction adminAction,
065            DefaultBehaviorProvider<Aci> defaultBehavior) {
066          return new ACIPropertyDefinition(d, propertyName, options,
067              adminAction, defaultBehavior);
068        }
069      }
070    
071    
072      /**
073       * Create a ACI property definition builder.
074       *
075       * @param d
076       *          The managed object definition associated with this
077       *          property definition.
078       * @param propertyName
079       *          The property name.
080       * @return Returns the new ACI property definition builder.
081       */
082      public static Builder createBuilder(
083          AbstractManagedObjectDefinition<?, ?> d, String propertyName) {
084        return new Builder(d, propertyName);
085      }
086    
087    
088      // Private constructor.
089      private ACIPropertyDefinition(
090          AbstractManagedObjectDefinition<?, ?> d, String propertyName,
091          EnumSet<PropertyOption> options,
092          AdministratorAction adminAction,
093          DefaultBehaviorProvider<Aci> defaultBehavior) {
094        super(d, Aci.class, propertyName, options, adminAction,
095            defaultBehavior);
096      }
097    
098    
099      /**
100       * {@inheritDoc}
101       */
102      @Override
103      public void validateValue(Aci value)
104          throws IllegalPropertyValueException {
105        ensureNotNull(value);
106    
107        // No additional validation required.
108      }
109    
110      /**
111       * {@inheritDoc}
112       */
113      @Override
114      public Aci decodeValue(String value)
115          throws IllegalPropertyValueStringException {
116        ensureNotNull(value);
117    
118        try {
119          return Aci.decode(new ASN1OctetString(value), DN.NULL_DN);
120        } catch (AciException e) {
121          // TODO: it would be nice to throw the cause.
122          throw new IllegalPropertyValueStringException(this, value);
123        }
124      }
125    
126    
127      /**
128       * {@inheritDoc}
129       */
130      @Override
131      public <R, P> R accept(PropertyDefinitionVisitor<R, P> v, P p) {
132        return v.visitACI(this, p);
133      }
134    
135      /**
136       * {@inheritDoc}
137       */
138      @Override
139      public <R, P> R accept(PropertyValueVisitor<R, P> v, Aci value, P p) {
140        return v.visitACI(this, value, p);
141      }
142    
143    
144      /**
145       * {@inheritDoc}
146       */
147      @Override
148      public int compare(Aci o1, Aci o2) {
149        return o1.toString().compareTo(o2.toString());
150      }
151    }