1008N/A/*
1008N/A * CDDL HEADER START
1008N/A *
1008N/A * The contents of this file are subject to the terms of the
1008N/A * Common Development and Distribution License, Version 1.0 only
1008N/A * (the "License"). You may not use this file except in compliance
1008N/A * with the License.
1008N/A *
6983N/A * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
6983N/A * or http://forgerock.org/license/CDDLv1.0.html.
1008N/A * See the License for the specific language governing permissions
1008N/A * and limitations under the License.
1008N/A *
1008N/A * When distributing Covered Code, include this CDDL HEADER in each
6983N/A * file and include the License file at legal-notices/CDDLv1_0.txt.
6983N/A * If applicable, add the following below this CDDL HEADER, with the
6983N/A * fields enclosed by brackets "[]" replaced with your own identifying
6983N/A * information:
1008N/A * Portions Copyright [yyyy] [name of copyright owner]
1008N/A *
1008N/A * CDDL HEADER END
1008N/A *
1008N/A *
3215N/A * Copyright 2008 Sun Microsystems, Inc.
1008N/A */
1008N/A
1008N/Apackage org.opends.server.admin;
1008N/A
1008N/A
1008N/A
1008N/Aimport static org.opends.server.util.Validator.ensureNotNull;
1008N/A
1008N/Aimport java.util.EnumSet;
1008N/A
1008N/Aimport org.opends.server.types.DN;
1008N/Aimport org.opends.server.types.DirectoryException;
1008N/A
1008N/A
1008N/A
1008N/A/**
1008N/A * DN property definition.
1008N/A */
1470N/Apublic final class DNPropertyDefinition extends PropertyDefinition<DN> {
1008N/A
1008N/A // Optional base DN which all valid values must be immediately
1008N/A // subordinate to.
1008N/A private final DN baseDN;
1008N/A
1008N/A
1008N/A
1008N/A /**
1008N/A * An interface for incrementally constructing DN property
1008N/A * definitions.
1008N/A */
1008N/A public static class Builder extends
1008N/A AbstractBuilder<DN, DNPropertyDefinition> {
1008N/A
1008N/A // Optional base DN which all valid values must be immediately
1008N/A // subordinate to.
1008N/A private DN baseDN = null;
1008N/A
1008N/A
1008N/A
1008N/A // Private constructor
1140N/A private Builder(
1140N/A AbstractManagedObjectDefinition<?, ?> d, String propertyName) {
1140N/A super(d, propertyName);
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A /**
1008N/A * Set the base DN which all valid values must be immediately
1008N/A * subordinate to. By default there is no based DN.
1008N/A *
1008N/A * @param baseDN
1008N/A * The string representation of the base DN.
1008N/A * @throws IllegalArgumentException
1008N/A * If the provided string is not a valid DN string
1008N/A * representation.
1008N/A */
1008N/A public void setBaseDN(String baseDN)
1008N/A throws IllegalArgumentException {
1008N/A if (baseDN == null) {
1008N/A setBaseDN((DN) null);
1008N/A } else {
1008N/A try {
1008N/A setBaseDN(DN.decode(baseDN));
1008N/A } catch (DirectoryException e) {
1008N/A throw new IllegalArgumentException(e);
1008N/A }
1008N/A }
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A /**
1008N/A * Set the base DN which all valid values must be immediately
1008N/A * subordinate to. By default there is no based DN.
1008N/A *
1008N/A * @param baseDN
1008N/A * The base DN.
1008N/A */
1008N/A public void setBaseDN(DN baseDN) {
1008N/A this.baseDN = baseDN;
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A /**
1008N/A * {@inheritDoc}
1008N/A */
1008N/A @Override
1140N/A protected DNPropertyDefinition buildInstance(
1140N/A AbstractManagedObjectDefinition<?, ?> d, String propertyName,
1008N/A EnumSet<PropertyOption> options,
1565N/A AdministratorAction adminAction,
1008N/A DefaultBehaviorProvider<DN> defaultBehavior) {
1140N/A return new DNPropertyDefinition(d, propertyName, options,
1565N/A adminAction, defaultBehavior, baseDN);
1008N/A }
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A /**
1008N/A * Create a DN property definition builder.
1008N/A *
1140N/A * @param d
1140N/A * The managed object definition associated with this
1140N/A * property definition.
1008N/A * @param propertyName
1008N/A * The property name.
1008N/A * @return Returns the new boolean property definition builder.
1008N/A */
1140N/A public static Builder createBuilder(
1140N/A AbstractManagedObjectDefinition<?, ?> d, String propertyName) {
1140N/A return new Builder(d, propertyName);
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A // Private constructor.
1140N/A private DNPropertyDefinition(
1140N/A AbstractManagedObjectDefinition<?, ?> d, String propertyName,
1008N/A EnumSet<PropertyOption> options,
1565N/A AdministratorAction adminAction,
1008N/A DefaultBehaviorProvider<DN> defaultBehavior, DN baseDN) {
1565N/A super(d, DN.class, propertyName, options, adminAction, defaultBehavior);
1008N/A this.baseDN = baseDN;
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A /**
1008N/A * Get the base DN which all valid values must be immediately
1008N/A * subordinate to, or <code>null</code> if there is no based DN.
1008N/A *
1008N/A * @return Returns the base DN which all valid values must be
1008N/A * immediately subordinate to.
1008N/A */
1008N/A public DN getBaseDN() {
1008N/A return baseDN;
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A /**
1008N/A * {@inheritDoc}
1008N/A */
1008N/A @Override
1008N/A public void validateValue(DN value)
1008N/A throws IllegalPropertyValueException {
1008N/A ensureNotNull(value);
1008N/A
1008N/A if (baseDN != null) {
1008N/A DN parent = value.getParent();
1008N/A
1008N/A if (parent == null) {
1008N/A parent = DN.nullDN();
1008N/A }
1008N/A
1008N/A if (!parent.equals(baseDN)) {
1008N/A throw new IllegalPropertyValueException(this, value);
1008N/A }
1008N/A }
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A /**
1008N/A * {@inheritDoc}
1008N/A */
1008N/A @Override
1008N/A public DN decodeValue(String value)
1008N/A throws IllegalPropertyValueStringException {
1008N/A ensureNotNull(value);
1008N/A
1008N/A try {
1008N/A DN dn = DN.decode(value);
1008N/A validateValue(dn);
1008N/A return dn;
1008N/A } catch (DirectoryException e) {
1008N/A throw new IllegalPropertyValueStringException(this, value);
1008N/A } catch (IllegalPropertyValueException e) {
1008N/A throw new IllegalPropertyValueStringException(this, value);
1008N/A }
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A /**
1008N/A * {@inheritDoc}
1008N/A */
1008N/A @Override
1008N/A public <R, P> R accept(PropertyDefinitionVisitor<R, P> v, P p) {
1008N/A return v.visitDN(this, p);
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A /**
1008N/A * {@inheritDoc}
1008N/A */
1008N/A @Override
1470N/A public <R, P> R accept(PropertyValueVisitor<R, P> v, DN value, P p) {
1470N/A return v.visitDN(this, value, p);
1470N/A }
1470N/A
1470N/A
1470N/A
1470N/A /**
1470N/A * {@inheritDoc}
1470N/A */
1470N/A @Override
1008N/A public int compare(DN o1, DN o2) {
1008N/A return o1.compareTo(o2);
1008N/A }
1008N/A}