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 *
1008N/A * You can obtain a copy of the license at
1008N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
1008N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
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
1008N/A * file and include the License file at
1008N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
1008N/A * add the following below this CDDL HEADER, with the fields enclosed
1008N/A * by brackets "[]" replaced with your own identifying information:
1008N/A * Portions Copyright [yyyy] [name of copyright owner]
1008N/A *
1008N/A * CDDL HEADER END
1008N/A *
1008N/A *
4129N/A * Copyright 2008-2009 Sun Microsystems, Inc.
1008N/A */
1008N/A
1008N/Apackage org.opends.server.admin;
1008N/A
1008N/A
1008N/A
1008N/A/**
1008N/A * A managed object composite relationship definition which represents
1008N/A * a composition of an optional single managed object (i.e. the
1008N/A * referenced managed object may or may not be present).
1008N/A *
1008N/A * @param <C>
1008N/A * The type of client managed object configuration that this
1008N/A * relation definition refers to.
1008N/A * @param <S>
1008N/A * The type of server managed object configuration that this
1008N/A * relation definition refers to.
1008N/A */
1008N/Apublic final class OptionalRelationDefinition
1008N/A <C extends ConfigurationClient, S extends Configuration>
1008N/A extends RelationDefinition<C, S> {
1008N/A
1008N/A /**
1893N/A * An interface for incrementally constructing optional relation
1893N/A * definitions.
1008N/A *
1893N/A * @param <C>
1893N/A * The type of client managed object configuration that
1893N/A * this relation definition refers to.
1893N/A * @param <S>
1893N/A * The type of server managed object configuration that
1893N/A * this relation definition refers to.
1008N/A */
2989N/A public static final class Builder
1893N/A <C extends ConfigurationClient, S extends Configuration>
1893N/A extends AbstractBuilder<C, S, OptionalRelationDefinition<C, S>> {
1893N/A
2989N/A // The optional default managed object associated with this
2989N/A // optional relation.
2989N/A private DefaultManagedObject<? extends C, ? extends S>
2989N/A defaultManagedObject = null;
2989N/A
2989N/A
2989N/A
1893N/A /**
1893N/A * Creates a new builder which can be used to incrementally build
1893N/A * an optional relation definition.
1893N/A *
1893N/A * @param pd
1893N/A * The parent managed object definition.
1893N/A * @param name
1893N/A * The name of the relation.
1893N/A * @param cd
1893N/A * The child managed object definition.
1893N/A */
1893N/A public Builder(AbstractManagedObjectDefinition<?, ?> pd, String name,
1893N/A AbstractManagedObjectDefinition<C, S> cd) {
1893N/A super(pd, name, cd);
1893N/A }
1893N/A
1893N/A
1893N/A
1893N/A /**
2989N/A * Sets the optional default managed object associated with this
2989N/A * optional relation definition.
2989N/A *
2989N/A * @param defaultManagedObject
2989N/A * The default managed object or <code>null</code> if
2989N/A * there is no default managed object defined for this
2989N/A * relation definition.
2989N/A */
2989N/A public void setDefaultManagedObject(
2989N/A DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) {
2989N/A this.defaultManagedObject = defaultManagedObject;
2989N/A }
2989N/A
2989N/A
2989N/A
2989N/A /**
1893N/A * {@inheritDoc}
1893N/A */
1893N/A @Override
1893N/A protected OptionalRelationDefinition<C, S> buildInstance(
1893N/A Common<C, S> common) {
2989N/A return new OptionalRelationDefinition<C, S>(common, defaultManagedObject);
1893N/A }
1893N/A
1893N/A }
1893N/A
1893N/A
1893N/A
2989N/A // The optional default managed object associated with this
2989N/A // optional relation.
2989N/A private final DefaultManagedObject<? extends C, ? extends S>
2989N/A defaultManagedObject;
2989N/A
2989N/A
2989N/A
1893N/A // Private constructor.
2989N/A private OptionalRelationDefinition(Common<C, S> common,
2989N/A DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) {
1893N/A super(common);
2989N/A this.defaultManagedObject = defaultManagedObject;
1893N/A }
1893N/A
1893N/A
1893N/A
1893N/A /**
1893N/A * {@inheritDoc}
1893N/A */
1893N/A @Override
1893N/A public <R, P> R accept(RelationDefinitionVisitor<R, P> v, P p) {
1893N/A return v.visitOptional(this, p);
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A /**
2989N/A * Gets the optional default managed object associated with this
2989N/A * optional relation definition.
2989N/A *
2989N/A * @return Returns the default managed object or <code>null</code>
2989N/A * if there is no default managed object defined for this
2989N/A * relation definition.
2989N/A */
2989N/A public DefaultManagedObject<? extends C, ? extends S>
2989N/A getDefaultManagedObject() {
2989N/A return defaultManagedObject;
2989N/A }
2989N/A
2989N/A
2989N/A
2989N/A /**
1008N/A * {@inheritDoc}
1008N/A */
1008N/A @Override
2989N/A public void toString(StringBuilder builder) {
1008N/A builder.append("name=");
1008N/A builder.append(getName());
4129N/A builder.append(" type=optional parent=");
1008N/A builder.append(getParentDefinition().getName());
1008N/A builder.append(" child=");
1008N/A builder.append(getChildDefinition().getName());
1008N/A }
1008N/A
2989N/A
2989N/A
2989N/A /**
2989N/A * {@inheritDoc}
2989N/A */
2989N/A @Override
2989N/A protected void initialize() throws Exception {
2989N/A if (defaultManagedObject != null) {
2989N/A defaultManagedObject.initialize();
2989N/A }
2989N/A }
2989N/A
1008N/A}