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