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 legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027
028package org.opends.server.admin;
029
030import org.opends.server.authorization.dseecompat.Aci;
031import org.opends.server.authorization.dseecompat.AciException;
032import org.opends.server.types.DN;
033import org.forgerock.opendj.ldap.ByteString;
034import static org.forgerock.util.Reject.ifNull;
035
036import java.util.EnumSet;
037
038/**
039 * ACI property definition.
040 */
041public 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    /** {@inheritDoc} */
058    @Override
059    protected ACIPropertyDefinition buildInstance(
060        AbstractManagedObjectDefinition<?, ?> d,
061        String propertyName, EnumSet<PropertyOption> options,
062        AdministratorAction adminAction,
063        DefaultBehaviorProvider<Aci> defaultBehavior) {
064      return new ACIPropertyDefinition(d, propertyName, options,
065          adminAction, defaultBehavior);
066    }
067  }
068
069
070  /**
071   * Create a ACI property definition builder.
072   *
073   * @param d
074   *          The managed object definition associated with this
075   *          property definition.
076   * @param propertyName
077   *          The property name.
078   * @return Returns the new ACI property definition builder.
079   */
080  public static Builder createBuilder(
081      AbstractManagedObjectDefinition<?, ?> d, String propertyName) {
082    return new Builder(d, propertyName);
083  }
084
085
086  /** Private constructor. */
087  private ACIPropertyDefinition(
088      AbstractManagedObjectDefinition<?, ?> d, String propertyName,
089      EnumSet<PropertyOption> options,
090      AdministratorAction adminAction,
091      DefaultBehaviorProvider<Aci> defaultBehavior) {
092    super(d, Aci.class, propertyName, options, adminAction,
093        defaultBehavior);
094  }
095
096
097  /** {@inheritDoc} */
098  @Override
099  public void validateValue(Aci value)
100      throws PropertyException {
101    ifNull(value);
102
103    // No additional validation required.
104  }
105
106  /** {@inheritDoc} */
107  @Override
108  public Aci decodeValue(String value)
109      throws PropertyException {
110    ifNull(value);
111
112    try {
113      return Aci.decode(ByteString.valueOfUtf8(value), DN.NULL_DN);
114    } catch (AciException e) {
115      // TODO: it would be nice to throw the cause.
116      throw PropertyException.illegalPropertyValueException(this, value);
117    }
118  }
119
120
121  /** {@inheritDoc} */
122  @Override
123  public <R, P> R accept(PropertyDefinitionVisitor<R, P> v, P p) {
124    return v.visitACI(this, p);
125  }
126
127  /** {@inheritDoc} */
128  @Override
129  public <R, P> R accept(PropertyValueVisitor<R, P> v, Aci value, P p) {
130    return v.visitACI(this, value, p);
131  }
132
133
134  /** {@inheritDoc} */
135  @Override
136  public int compare(Aci o1, Aci o2) {
137    return o1.toString().compareTo(o2.toString());
138  }
139}