001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008-2009 Sun Microsystems, Inc. 015 * Portions Copyright 2015 ForgeRock AS. 016 */ 017 018package org.opends.server.admin; 019 020 021 022/** 023 * A managed object composite relationship definition which represents 024 * a composition of a single managed object (i.e. the managed object 025 * must be present). 026 * 027 * @param <C> 028 * The type of client managed object configuration that this 029 * relation definition refers to. 030 * @param <S> 031 * The type of server managed object configuration that this 032 * relation definition refers to. 033 */ 034public final class SingletonRelationDefinition 035 <C extends ConfigurationClient, S extends Configuration> 036 extends RelationDefinition<C, S> { 037 038 /** 039 * An interface for incrementally constructing singleton relation 040 * definitions. 041 * 042 * @param <C> 043 * The type of client managed object configuration that 044 * this relation definition refers to. 045 * @param <S> 046 * The type of server managed object configuration that 047 * this relation definition refers to. 048 */ 049 public static final class Builder 050 <C extends ConfigurationClient, S extends Configuration> 051 extends AbstractBuilder<C, S, SingletonRelationDefinition<C, S>> { 052 053 /** 054 * The optional default managed object associated with this 055 * singleton relation. 056 */ 057 private DefaultManagedObject<? extends C, ? extends S> defaultManagedObject; 058 059 060 061 /** 062 * Creates a new builder which can be used to incrementally build 063 * an singleton relation definition. 064 * 065 * @param pd 066 * The parent managed object definition. 067 * @param name 068 * The name of the relation. 069 * @param cd 070 * The child managed object definition. 071 */ 072 public Builder(AbstractManagedObjectDefinition<?, ?> pd, String name, 073 AbstractManagedObjectDefinition<C, S> cd) { 074 super(pd, name, cd); 075 } 076 077 078 079 /** 080 * Sets the optional default managed object associated with this 081 * singleton relation definition. 082 * 083 * @param defaultManagedObject 084 * The default managed object or <code>null</code> if 085 * there is no default managed object defined for this 086 * relation definition. 087 */ 088 public void setDefaultManagedObject( 089 DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { 090 this.defaultManagedObject = defaultManagedObject; 091 } 092 093 094 095 /** {@inheritDoc} */ 096 @Override 097 protected SingletonRelationDefinition<C, S> buildInstance( 098 Common<C, S> common) { 099 return new SingletonRelationDefinition<>(common, defaultManagedObject); 100 } 101 } 102 103 104 105 /** 106 * The optional default managed object associated with this 107 * singleton relation. 108 */ 109 private final DefaultManagedObject<? extends C, ? extends S> defaultManagedObject; 110 111 112 113 /** Private constructor. */ 114 private SingletonRelationDefinition(Common<C, S> common, 115 DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { 116 super(common); 117 this.defaultManagedObject = defaultManagedObject; 118 } 119 120 121 122 /** {@inheritDoc} */ 123 @Override 124 public <R, P> R accept(RelationDefinitionVisitor<R, P> v, P p) { 125 return v.visitSingleton(this, p); 126 } 127 128 129 130 /** 131 * Gets the optional default managed object associated with this 132 * singleton relation definition. 133 * 134 * @return Returns the default managed object or <code>null</code> 135 * if there is no default managed object defined for this 136 * relation definition. 137 */ 138 public DefaultManagedObject<? extends C, ? extends S> 139 getDefaultManagedObject() { 140 return defaultManagedObject; 141 } 142 143 144 145 /** {@inheritDoc} */ 146 @Override 147 public void toString(StringBuilder builder) { 148 builder.append("name="); 149 builder.append(getName()); 150 builder.append(" type=singleton parent="); 151 builder.append(getParentDefinition().getName()); 152 builder.append(" child="); 153 builder.append(getChildDefinition().getName()); 154 } 155 156 157 158 /** {@inheritDoc} */ 159 @Override 160 protected void initialize() throws Exception { 161 if (defaultManagedObject != null) { 162 defaultManagedObject.initialize(); 163 } 164 } 165 166}