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 Sun Microsystems, Inc. 015 */ 016package org.forgerock.opendj.server.config.meta; 017 018 019 020import java.util.Collection; 021import java.util.SortedSet; 022import org.forgerock.opendj.config.AdministratorAction; 023import org.forgerock.opendj.config.BooleanPropertyDefinition; 024import org.forgerock.opendj.config.ClassPropertyDefinition; 025import org.forgerock.opendj.config.client.ConcurrentModificationException; 026import org.forgerock.opendj.config.client.ManagedObject; 027import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 028import org.forgerock.opendj.config.client.OperationRejectedException; 029import org.forgerock.opendj.config.DefaultBehaviorProvider; 030import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 031import org.forgerock.opendj.config.EnumPropertyDefinition; 032import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 033import org.forgerock.opendj.config.ManagedObjectDefinition; 034import org.forgerock.opendj.config.PropertyOption; 035import org.forgerock.opendj.config.PropertyProvider; 036import org.forgerock.opendj.config.server.ConfigurationChangeListener; 037import org.forgerock.opendj.config.server.ServerManagedObject; 038import org.forgerock.opendj.config.Tag; 039import org.forgerock.opendj.ldap.DN; 040import org.forgerock.opendj.ldap.LdapException; 041import org.forgerock.opendj.server.config.client.LastModPluginCfgClient; 042import org.forgerock.opendj.server.config.meta.PluginCfgDefn.PluginType; 043import org.forgerock.opendj.server.config.server.LastModPluginCfg; 044import org.forgerock.opendj.server.config.server.PluginCfg; 045 046 047 048/** 049 * An interface for querying the Last Mod Plugin managed object 050 * definition meta information. 051 * <p> 052 * The Last Mod Plugin is used to ensure that the creatorsName and 053 * createTimestamp attributes are included in an entry whenever it is 054 * added to the server and also to ensure that the modifiersName and 055 * modifyTimestamp attributes are updated whenever an entry is modified 056 * or renamed. 057 */ 058public final class LastModPluginCfgDefn extends ManagedObjectDefinition<LastModPluginCfgClient, LastModPluginCfg> { 059 060 /** The singleton configuration definition instance. */ 061 private static final LastModPluginCfgDefn INSTANCE = new LastModPluginCfgDefn(); 062 063 064 065 /** The "java-class" property definition. */ 066 private static final ClassPropertyDefinition PD_JAVA_CLASS; 067 068 069 070 /** The "plugin-type" property definition. */ 071 private static final EnumPropertyDefinition<PluginType> PD_PLUGIN_TYPE; 072 073 074 075 /** Build the "java-class" property definition. */ 076 static { 077 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 078 builder.setOption(PropertyOption.MANDATORY); 079 builder.setOption(PropertyOption.ADVANCED); 080 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 081 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.plugins.LastModPlugin"); 082 builder.setDefaultBehaviorProvider(provider); 083 builder.addInstanceOf("org.opends.server.api.plugin.DirectoryServerPlugin"); 084 PD_JAVA_CLASS = builder.getInstance(); 085 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 086 } 087 088 089 090 /** Build the "plugin-type" property definition. */ 091 static { 092 EnumPropertyDefinition.Builder<PluginType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "plugin-type"); 093 builder.setOption(PropertyOption.MULTI_VALUED); 094 builder.setOption(PropertyOption.MANDATORY); 095 builder.setOption(PropertyOption.ADVANCED); 096 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "plugin-type")); 097 DefaultBehaviorProvider<PluginType> provider = new DefinedDefaultBehaviorProvider<PluginType>("preoperationadd", "preoperationmodify", "preoperationmodifydn"); 098 builder.setDefaultBehaviorProvider(provider); 099 builder.setEnumClass(PluginType.class); 100 PD_PLUGIN_TYPE = builder.getInstance(); 101 INSTANCE.registerPropertyDefinition(PD_PLUGIN_TYPE); 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 Last Mod Plugin configuration definition singleton. 115 * 116 * @return Returns the Last Mod Plugin configuration definition 117 * singleton. 118 */ 119 public static LastModPluginCfgDefn getInstance() { 120 return INSTANCE; 121 } 122 123 124 125 /** 126 * Private constructor. 127 */ 128 private LastModPluginCfgDefn() { 129 super("last-mod-plugin", PluginCfgDefn.getInstance()); 130 } 131 132 133 134 /** {@inheritDoc} */ 135 public LastModPluginCfgClient createClientConfiguration( 136 ManagedObject<? extends LastModPluginCfgClient> impl) { 137 return new LastModPluginCfgClientImpl(impl); 138 } 139 140 141 142 /** {@inheritDoc} */ 143 public LastModPluginCfg createServerConfiguration( 144 ServerManagedObject<? extends LastModPluginCfg> impl) { 145 return new LastModPluginCfgServerImpl(impl); 146 } 147 148 149 150 /** {@inheritDoc} */ 151 public Class<LastModPluginCfg> getServerConfigurationClass() { 152 return LastModPluginCfg.class; 153 } 154 155 156 157 /** 158 * Get the "enabled" property definition. 159 * <p> 160 * Indicates whether the plug-in is enabled for use. 161 * 162 * @return Returns the "enabled" property definition. 163 */ 164 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 165 return PluginCfgDefn.getInstance().getEnabledPropertyDefinition(); 166 } 167 168 169 170 /** 171 * Get the "invoke-for-internal-operations" property definition. 172 * <p> 173 * Indicates whether the plug-in should be invoked for internal 174 * operations. 175 * <p> 176 * Any plug-in that can be invoked for internal operations must 177 * ensure that it does not create any new internal operatons that can 178 * cause the same plug-in to be re-invoked. 179 * 180 * @return Returns the "invoke-for-internal-operations" property definition. 181 */ 182 public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() { 183 return PluginCfgDefn.getInstance().getInvokeForInternalOperationsPropertyDefinition(); 184 } 185 186 187 188 /** 189 * Get the "java-class" property definition. 190 * <p> 191 * Specifies the fully-qualified name of the Java class that 192 * provides the plug-in implementation. 193 * 194 * @return Returns the "java-class" property definition. 195 */ 196 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 197 return PD_JAVA_CLASS; 198 } 199 200 201 202 /** 203 * Get the "plugin-type" property definition. 204 * <p> 205 * Specifies the set of plug-in types for the plug-in, which 206 * specifies the times at which the plug-in is invoked. 207 * 208 * @return Returns the "plugin-type" property definition. 209 */ 210 public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() { 211 return PD_PLUGIN_TYPE; 212 } 213 214 215 216 /** 217 * Managed object client implementation. 218 */ 219 private static class LastModPluginCfgClientImpl implements 220 LastModPluginCfgClient { 221 222 /** Private implementation. */ 223 private ManagedObject<? extends LastModPluginCfgClient> impl; 224 225 226 227 /** Private constructor. */ 228 private LastModPluginCfgClientImpl( 229 ManagedObject<? extends LastModPluginCfgClient> impl) { 230 this.impl = impl; 231 } 232 233 234 235 /** {@inheritDoc} */ 236 public Boolean isEnabled() { 237 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 238 } 239 240 241 242 /** {@inheritDoc} */ 243 public void setEnabled(boolean value) { 244 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 245 } 246 247 248 249 /** {@inheritDoc} */ 250 public boolean isInvokeForInternalOperations() { 251 return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition()); 252 } 253 254 255 256 /** {@inheritDoc} */ 257 public void setInvokeForInternalOperations(Boolean value) { 258 impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value); 259 } 260 261 262 263 /** {@inheritDoc} */ 264 public String getJavaClass() { 265 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 266 } 267 268 269 270 /** {@inheritDoc} */ 271 public void setJavaClass(String value) { 272 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 273 } 274 275 276 277 /** {@inheritDoc} */ 278 public SortedSet<PluginType> getPluginType() { 279 return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition()); 280 } 281 282 283 284 /** {@inheritDoc} */ 285 public void setPluginType(Collection<PluginType> values) { 286 impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values); 287 } 288 289 290 291 /** {@inheritDoc} */ 292 public ManagedObjectDefinition<? extends LastModPluginCfgClient, ? extends LastModPluginCfg> definition() { 293 return INSTANCE; 294 } 295 296 297 298 /** {@inheritDoc} */ 299 public PropertyProvider properties() { 300 return impl; 301 } 302 303 304 305 /** {@inheritDoc} */ 306 public void commit() throws ManagedObjectAlreadyExistsException, 307 MissingMandatoryPropertiesException, ConcurrentModificationException, 308 OperationRejectedException, LdapException { 309 impl.commit(); 310 } 311 312 313 314 /** {@inheritDoc} */ 315 public String toString() { 316 return impl.toString(); 317 } 318 } 319 320 321 322 /** 323 * Managed object server implementation. 324 */ 325 private static class LastModPluginCfgServerImpl implements 326 LastModPluginCfg { 327 328 /** Private implementation. */ 329 private ServerManagedObject<? extends LastModPluginCfg> impl; 330 331 /** The value of the "enabled" property. */ 332 private final boolean pEnabled; 333 334 /** The value of the "invoke-for-internal-operations" property. */ 335 private final boolean pInvokeForInternalOperations; 336 337 /** The value of the "java-class" property. */ 338 private final String pJavaClass; 339 340 /** The value of the "plugin-type" property. */ 341 private final SortedSet<PluginType> pPluginType; 342 343 344 345 /** Private constructor. */ 346 private LastModPluginCfgServerImpl(ServerManagedObject<? extends LastModPluginCfg> impl) { 347 this.impl = impl; 348 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 349 this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition()); 350 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 351 this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition()); 352 } 353 354 355 356 /** {@inheritDoc} */ 357 public void addLastModChangeListener( 358 ConfigurationChangeListener<LastModPluginCfg> listener) { 359 impl.registerChangeListener(listener); 360 } 361 362 363 364 /** {@inheritDoc} */ 365 public void removeLastModChangeListener( 366 ConfigurationChangeListener<LastModPluginCfg> listener) { 367 impl.deregisterChangeListener(listener); 368 } 369 /** {@inheritDoc} */ 370 public void addChangeListener( 371 ConfigurationChangeListener<PluginCfg> listener) { 372 impl.registerChangeListener(listener); 373 } 374 375 376 377 /** {@inheritDoc} */ 378 public void removeChangeListener( 379 ConfigurationChangeListener<PluginCfg> listener) { 380 impl.deregisterChangeListener(listener); 381 } 382 383 384 385 /** {@inheritDoc} */ 386 public boolean isEnabled() { 387 return pEnabled; 388 } 389 390 391 392 /** {@inheritDoc} */ 393 public boolean isInvokeForInternalOperations() { 394 return pInvokeForInternalOperations; 395 } 396 397 398 399 /** {@inheritDoc} */ 400 public String getJavaClass() { 401 return pJavaClass; 402 } 403 404 405 406 /** {@inheritDoc} */ 407 public SortedSet<PluginType> getPluginType() { 408 return pPluginType; 409 } 410 411 412 413 /** {@inheritDoc} */ 414 public Class<? extends LastModPluginCfg> configurationClass() { 415 return LastModPluginCfg.class; 416 } 417 418 419 420 /** {@inheritDoc} */ 421 public DN dn() { 422 return impl.getDN(); 423 } 424 425 426 427 /** {@inheritDoc} */ 428 public String toString() { 429 return impl.toString(); 430 } 431 } 432}