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 Sun Microsystems, Inc. 025 */ 026package org.forgerock.opendj.server.config.meta; 027 028 029 030import org.forgerock.opendj.config.AdministratorAction; 031import org.forgerock.opendj.config.BooleanPropertyDefinition; 032import org.forgerock.opendj.config.ClassPropertyDefinition; 033import org.forgerock.opendj.config.client.ConcurrentModificationException; 034import org.forgerock.opendj.config.client.ManagedObject; 035import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 036import org.forgerock.opendj.config.client.OperationRejectedException; 037import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 038import org.forgerock.opendj.config.ManagedObjectDefinition; 039import org.forgerock.opendj.config.PropertyException; 040import org.forgerock.opendj.config.PropertyOption; 041import org.forgerock.opendj.config.PropertyProvider; 042import org.forgerock.opendj.config.server.ConfigurationChangeListener; 043import org.forgerock.opendj.config.server.ServerManagedObject; 044import org.forgerock.opendj.config.Tag; 045import org.forgerock.opendj.config.TopCfgDefn; 046import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 047import org.forgerock.opendj.ldap.DN; 048import org.forgerock.opendj.ldap.LdapException; 049import org.forgerock.opendj.server.config.client.AttributeSyntaxCfgClient; 050import org.forgerock.opendj.server.config.server.AttributeSyntaxCfg; 051 052 053 054/** 055 * An interface for querying the Attribute Syntax managed object 056 * definition meta information. 057 * <p> 058 * Attribute Syntaxes define the type of data that may be stored in an 059 * attribute with that syntax. A syntax is generally associated with a 060 * set of matching rules that indicate how to perform matching 061 * operations against values of that syntax. 062 */ 063public final class AttributeSyntaxCfgDefn extends ManagedObjectDefinition<AttributeSyntaxCfgClient, AttributeSyntaxCfg> { 064 065 /** The singleton configuration definition instance. */ 066 private static final AttributeSyntaxCfgDefn INSTANCE = new AttributeSyntaxCfgDefn(); 067 068 069 070 /** The "enabled" property definition. */ 071 private static final BooleanPropertyDefinition PD_ENABLED; 072 073 074 075 /** The "java-class" property definition. */ 076 private static final ClassPropertyDefinition PD_JAVA_CLASS; 077 078 079 080 /** Build the "enabled" property definition. */ 081 static { 082 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled"); 083 builder.setOption(PropertyOption.MANDATORY); 084 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled")); 085 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 086 PD_ENABLED = builder.getInstance(); 087 INSTANCE.registerPropertyDefinition(PD_ENABLED); 088 } 089 090 091 092 /** Build the "java-class" property definition. */ 093 static { 094 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 095 builder.setOption(PropertyOption.READ_ONLY); 096 builder.setOption(PropertyOption.MANDATORY); 097 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 098 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 099 builder.addInstanceOf("org.opends.server.api.AttributeSyntax"); 100 PD_JAVA_CLASS = builder.getInstance(); 101 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 102 } 103 104 105 106 // Register the tags associated with this managed object definition. 107 static { 108 INSTANCE.registerTag(Tag.valueOf("core-server")); 109 } 110 111 112 113 /** 114 * Get the Attribute Syntax configuration definition singleton. 115 * 116 * @return Returns the Attribute Syntax configuration definition 117 * singleton. 118 */ 119 public static AttributeSyntaxCfgDefn getInstance() { 120 return INSTANCE; 121 } 122 123 124 125 /** 126 * Private constructor. 127 */ 128 private AttributeSyntaxCfgDefn() { 129 super("attribute-syntax", TopCfgDefn.getInstance()); 130 } 131 132 133 134 /** {@inheritDoc} */ 135 public AttributeSyntaxCfgClient createClientConfiguration( 136 ManagedObject<? extends AttributeSyntaxCfgClient> impl) { 137 return new AttributeSyntaxCfgClientImpl(impl); 138 } 139 140 141 142 /** {@inheritDoc} */ 143 public AttributeSyntaxCfg createServerConfiguration( 144 ServerManagedObject<? extends AttributeSyntaxCfg> impl) { 145 return new AttributeSyntaxCfgServerImpl(impl); 146 } 147 148 149 150 /** {@inheritDoc} */ 151 public Class<AttributeSyntaxCfg> getServerConfigurationClass() { 152 return AttributeSyntaxCfg.class; 153 } 154 155 156 157 /** 158 * Get the "enabled" property definition. 159 * <p> 160 * Indicates whether the Attribute Syntax is enabled. 161 * 162 * @return Returns the "enabled" property definition. 163 */ 164 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 165 return PD_ENABLED; 166 } 167 168 169 170 /** 171 * Get the "java-class" property definition. 172 * <p> 173 * Specifies the fully-qualified name of the Java class that 174 * provides the Attribute Syntax implementation. 175 * 176 * @return Returns the "java-class" property definition. 177 */ 178 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 179 return PD_JAVA_CLASS; 180 } 181 182 183 184 /** 185 * Managed object client implementation. 186 */ 187 private static class AttributeSyntaxCfgClientImpl implements 188 AttributeSyntaxCfgClient { 189 190 /** Private implementation. */ 191 private ManagedObject<? extends AttributeSyntaxCfgClient> impl; 192 193 194 195 /** Private constructor. */ 196 private AttributeSyntaxCfgClientImpl( 197 ManagedObject<? extends AttributeSyntaxCfgClient> impl) { 198 this.impl = impl; 199 } 200 201 202 203 /** {@inheritDoc} */ 204 public Boolean isEnabled() { 205 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 206 } 207 208 209 210 /** {@inheritDoc} */ 211 public void setEnabled(boolean value) { 212 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 213 } 214 215 216 217 /** {@inheritDoc} */ 218 public String getJavaClass() { 219 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 220 } 221 222 223 224 /** {@inheritDoc} */ 225 public void setJavaClass(String value) throws PropertyException { 226 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 227 } 228 229 230 231 /** {@inheritDoc} */ 232 public ManagedObjectDefinition<? extends AttributeSyntaxCfgClient, ? extends AttributeSyntaxCfg> definition() { 233 return INSTANCE; 234 } 235 236 237 238 /** {@inheritDoc} */ 239 public PropertyProvider properties() { 240 return impl; 241 } 242 243 244 245 /** {@inheritDoc} */ 246 public void commit() throws ManagedObjectAlreadyExistsException, 247 MissingMandatoryPropertiesException, ConcurrentModificationException, 248 OperationRejectedException, LdapException { 249 impl.commit(); 250 } 251 252 253 254 /** {@inheritDoc} */ 255 public String toString() { 256 return impl.toString(); 257 } 258 } 259 260 261 262 /** 263 * Managed object server implementation. 264 */ 265 private static class AttributeSyntaxCfgServerImpl implements 266 AttributeSyntaxCfg { 267 268 /** Private implementation. */ 269 private ServerManagedObject<? extends AttributeSyntaxCfg> impl; 270 271 /** The value of the "enabled" property. */ 272 private final boolean pEnabled; 273 274 /** The value of the "java-class" property. */ 275 private final String pJavaClass; 276 277 278 279 /** Private constructor. */ 280 private AttributeSyntaxCfgServerImpl(ServerManagedObject<? extends AttributeSyntaxCfg> impl) { 281 this.impl = impl; 282 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 283 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 284 } 285 286 287 288 /** {@inheritDoc} */ 289 public void addChangeListener( 290 ConfigurationChangeListener<AttributeSyntaxCfg> listener) { 291 impl.registerChangeListener(listener); 292 } 293 294 295 296 /** {@inheritDoc} */ 297 public void removeChangeListener( 298 ConfigurationChangeListener<AttributeSyntaxCfg> listener) { 299 impl.deregisterChangeListener(listener); 300 } 301 302 303 304 /** {@inheritDoc} */ 305 public boolean isEnabled() { 306 return pEnabled; 307 } 308 309 310 311 /** {@inheritDoc} */ 312 public String getJavaClass() { 313 return pJavaClass; 314 } 315 316 317 318 /** {@inheritDoc} */ 319 public Class<? extends AttributeSyntaxCfg> configurationClass() { 320 return AttributeSyntaxCfg.class; 321 } 322 323 324 325 /** {@inheritDoc} */ 326 public DN dn() { 327 return impl.getDN(); 328 } 329 330 331 332 /** {@inheritDoc} */ 333 public String toString() { 334 return impl.toString(); 335 } 336 } 337}