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-2009 Sun Microsystems, Inc. 025 * Portions Copyright 2015 ForgeRock AS 026 */ 027 028package 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 */ 044public 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 /** 064 * The optional default managed object associated with this 065 * singleton relation. 066 */ 067 private DefaultManagedObject<? extends C, ? extends S> defaultManagedObject; 068 069 070 071 /** 072 * Creates a new builder which can be used to incrementally build 073 * an singleton relation definition. 074 * 075 * @param pd 076 * The parent managed object definition. 077 * @param name 078 * The name of the relation. 079 * @param cd 080 * The child managed object definition. 081 */ 082 public Builder(AbstractManagedObjectDefinition<?, ?> pd, String name, 083 AbstractManagedObjectDefinition<C, S> cd) { 084 super(pd, name, cd); 085 } 086 087 088 089 /** 090 * Sets the optional default managed object associated with this 091 * singleton relation definition. 092 * 093 * @param defaultManagedObject 094 * The default managed object or <code>null</code> if 095 * there is no default managed object defined for this 096 * relation definition. 097 */ 098 public void setDefaultManagedObject( 099 DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { 100 this.defaultManagedObject = defaultManagedObject; 101 } 102 103 104 105 /** {@inheritDoc} */ 106 @Override 107 protected SingletonRelationDefinition<C, S> buildInstance( 108 Common<C, S> common) { 109 return new SingletonRelationDefinition<>(common, defaultManagedObject); 110 } 111 } 112 113 114 115 /** 116 * The optional default managed object associated with this 117 * singleton relation. 118 */ 119 private final DefaultManagedObject<? extends C, ? extends S> defaultManagedObject; 120 121 122 123 /** Private constructor. */ 124 private SingletonRelationDefinition(Common<C, S> common, 125 DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) { 126 super(common); 127 this.defaultManagedObject = defaultManagedObject; 128 } 129 130 131 132 /** {@inheritDoc} */ 133 @Override 134 public <R, P> R accept(RelationDefinitionVisitor<R, P> v, P p) { 135 return v.visitSingleton(this, p); 136 } 137 138 139 140 /** 141 * Gets the optional default managed object associated with this 142 * singleton relation definition. 143 * 144 * @return Returns the default managed object or <code>null</code> 145 * if there is no default managed object defined for this 146 * relation definition. 147 */ 148 public DefaultManagedObject<? extends C, ? extends S> 149 getDefaultManagedObject() { 150 return defaultManagedObject; 151 } 152 153 154 155 /** {@inheritDoc} */ 156 @Override 157 public void toString(StringBuilder builder) { 158 builder.append("name="); 159 builder.append(getName()); 160 builder.append(" type=singleton parent="); 161 builder.append(getParentDefinition().getName()); 162 builder.append(" child="); 163 builder.append(getChildDefinition().getName()); 164 } 165 166 167 168 /** {@inheritDoc} */ 169 @Override 170 protected void initialize() throws Exception { 171 if (defaultManagedObject != null) { 172 defaultManagedObject.initialize(); 173 } 174 } 175 176}