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 /** 033 * A managed object composite relationship definition which represents 034 * a composition of a single managed object (i.e. the managed object 035 * must be present). 036 * 037 * @param <C> 038 * The type of client managed object configuration that this 039 * relation definition refers to. 040 * @param <S> 041 * The type of server managed object configuration that this 042 * relation definition refers to. 043 */ 044 public final class SingletonRelationDefinition 045 <C extends ConfigurationClient, S extends Configuration> 046 extends RelationDefinition<C, S> { 047 048 /** 049 * An interface for incrementally constructing singleton relation 050 * definitions. 051 * 052 * @param <C> 053 * The type of client managed object configuration that 054 * this relation definition refers to. 055 * @param <S> 056 * The type of server managed object configuration that 057 * this relation definition refers to. 058 */ 059 public static final class Builder 060 <C extends ConfigurationClient, S extends Configuration> 061 extends AbstractBuilder<C, S, SingletonRelationDefinition<C, S>> { 062 063 // The optional default managed object associated with this 064 // singleton relation. 065 private DefaultManagedObject<? extends C, ? extends S> 066 defaultManagedObject = null; 067 068 069 070 /** 071 * Creates a new builder which can be used to incrementally build 072 * an singleton relation definition. 073 * 074 * @param pd 075 * The parent managed object definition. 076 * @param name 077 * The name of the relation. 078 * @param cd 079 * The child managed object definition. 080 */ 081 public Builder(AbstractManagedObjectDefinition<?, ?> pd, String name, 082 AbstractManagedObjectDefinition<C, S> cd) { 083 super(pd, name, cd); 084 } 085 086 087 088 /** 089 * Sets the optional default managed object associated with this 090 * singleton relation definition. 091 * 092 * @param defaultManagedObject 093 * The default managed object or <code>null</code> if 094 * there is no default managed object defined for this 095 * relation definition. 096 */ 097 public void setDefaultManagedObject( 098 DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { 099 this.defaultManagedObject = defaultManagedObject; 100 } 101 102 103 104 /** 105 * {@inheritDoc} 106 */ 107 @Override 108 protected SingletonRelationDefinition<C, S> buildInstance( 109 Common<C, S> common) { 110 return new SingletonRelationDefinition<C, S>(common, 111 defaultManagedObject); 112 } 113 114 } 115 116 117 118 // The optional default managed object associated with this 119 // singleton relation. 120 private final DefaultManagedObject<? extends C, ? extends S> 121 defaultManagedObject; 122 123 124 125 // Private constructor. 126 private SingletonRelationDefinition(Common<C, S> common, 127 DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { 128 super(common); 129 this.defaultManagedObject = defaultManagedObject; 130 } 131 132 133 134 /** 135 * {@inheritDoc} 136 */ 137 @Override 138 public <R, P> R accept(RelationDefinitionVisitor<R, P> v, P p) { 139 return v.visitSingleton(this, p); 140 } 141 142 143 144 /** 145 * Gets the optional default managed object associated with this 146 * singleton relation definition. 147 * 148 * @return Returns the default managed object or <code>null</code> 149 * if there is no default managed object defined for this 150 * relation definition. 151 */ 152 public DefaultManagedObject<? extends C, ? extends S> 153 getDefaultManagedObject() { 154 return defaultManagedObject; 155 } 156 157 158 159 /** 160 * {@inheritDoc} 161 */ 162 @Override 163 public void toString(StringBuilder builder) { 164 builder.append("name="); 165 builder.append(getName()); 166 builder.append(" type=composition parent="); 167 builder.append(getParentDefinition().getName()); 168 builder.append(" child="); 169 builder.append(getChildDefinition().getName()); 170 builder.append(" minOccurs=1 maxOccurs=1"); 171 } 172 173 174 175 /** 176 * {@inheritDoc} 177 */ 178 @Override 179 protected void initialize() throws Exception { 180 if (defaultManagedObject != null) { 181 defaultManagedObject.initialize(); 182 } 183 } 184 185 }