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.opends.server.admin.std.meta; 017 018 019 020import java.util.Collection; 021import java.util.SortedSet; 022import org.forgerock.opendj.ldap.DN; 023import org.opends.server.admin.AdministratorAction; 024import org.opends.server.admin.AliasDefaultBehaviorProvider; 025import org.opends.server.admin.BooleanPropertyDefinition; 026import org.opends.server.admin.ClassPropertyDefinition; 027import org.opends.server.admin.client.AuthorizationException; 028import org.opends.server.admin.client.CommunicationException; 029import org.opends.server.admin.client.ConcurrentModificationException; 030import org.opends.server.admin.client.ManagedObject; 031import org.opends.server.admin.client.MissingMandatoryPropertiesException; 032import org.opends.server.admin.client.OperationRejectedException; 033import org.opends.server.admin.DefaultBehaviorProvider; 034import org.opends.server.admin.DefinedDefaultBehaviorProvider; 035import org.opends.server.admin.EnumPropertyDefinition; 036import org.opends.server.admin.ManagedObjectAlreadyExistsException; 037import org.opends.server.admin.ManagedObjectDefinition; 038import org.opends.server.admin.PropertyOption; 039import org.opends.server.admin.PropertyProvider; 040import org.opends.server.admin.server.ConfigurationChangeListener; 041import org.opends.server.admin.server.ServerManagedObject; 042import org.opends.server.admin.std.client.AttributeCleanupPluginCfgClient; 043import org.opends.server.admin.std.meta.PluginCfgDefn.PluginType; 044import org.opends.server.admin.std.server.AttributeCleanupPluginCfg; 045import org.opends.server.admin.std.server.PluginCfg; 046import org.opends.server.admin.StringPropertyDefinition; 047import org.opends.server.admin.Tag; 048 049 050 051/** 052 * An interface for querying the Attribute Cleanup Plugin managed 053 * object definition meta information. 054 * <p> 055 * A pre-parse plugin which can be used to remove and rename 056 * attributes in ADD and MODIFY requests before being processed. 057 */ 058public final class AttributeCleanupPluginCfgDefn extends ManagedObjectDefinition<AttributeCleanupPluginCfgClient, AttributeCleanupPluginCfg> { 059 060 // The singleton configuration definition instance. 061 private static final AttributeCleanupPluginCfgDefn INSTANCE = new AttributeCleanupPluginCfgDefn(); 062 063 064 065 // The "invoke-for-internal-operations" property definition. 066 private static final BooleanPropertyDefinition PD_INVOKE_FOR_INTERNAL_OPERATIONS; 067 068 069 070 // The "java-class" property definition. 071 private static final ClassPropertyDefinition PD_JAVA_CLASS; 072 073 074 075 // The "plugin-type" property definition. 076 private static final EnumPropertyDefinition<PluginType> PD_PLUGIN_TYPE; 077 078 079 080 // The "remove-inbound-attributes" property definition. 081 private static final StringPropertyDefinition PD_REMOVE_INBOUND_ATTRIBUTES; 082 083 084 085 // The "rename-inbound-attributes" property definition. 086 private static final StringPropertyDefinition PD_RENAME_INBOUND_ATTRIBUTES; 087 088 089 090 // Build the "invoke-for-internal-operations" property definition. 091 static { 092 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "invoke-for-internal-operations"); 093 builder.setOption(PropertyOption.ADVANCED); 094 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "invoke-for-internal-operations")); 095 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false"); 096 builder.setDefaultBehaviorProvider(provider); 097 PD_INVOKE_FOR_INTERNAL_OPERATIONS = builder.getInstance(); 098 INSTANCE.registerPropertyDefinition(PD_INVOKE_FOR_INTERNAL_OPERATIONS); 099 } 100 101 102 103 // Build the "java-class" property definition. 104 static { 105 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 106 builder.setOption(PropertyOption.MANDATORY); 107 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 108 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.plugins.AttributeCleanupPlugin"); 109 builder.setDefaultBehaviorProvider(provider); 110 builder.addInstanceOf("org.opends.server.api.plugin.DirectoryServerPlugin"); 111 PD_JAVA_CLASS = builder.getInstance(); 112 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 113 } 114 115 116 117 // Build the "plugin-type" property definition. 118 static { 119 EnumPropertyDefinition.Builder<PluginType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "plugin-type"); 120 builder.setOption(PropertyOption.MULTI_VALUED); 121 builder.setOption(PropertyOption.MANDATORY); 122 builder.setOption(PropertyOption.ADVANCED); 123 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "plugin-type")); 124 DefaultBehaviorProvider<PluginType> provider = new DefinedDefaultBehaviorProvider<PluginType>("preparseadd", "preparsemodify"); 125 builder.setDefaultBehaviorProvider(provider); 126 builder.setEnumClass(PluginType.class); 127 PD_PLUGIN_TYPE = builder.getInstance(); 128 INSTANCE.registerPropertyDefinition(PD_PLUGIN_TYPE); 129 } 130 131 132 133 // Build the "remove-inbound-attributes" property definition. 134 static { 135 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "remove-inbound-attributes"); 136 builder.setOption(PropertyOption.MULTI_VALUED); 137 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "remove-inbound-attributes")); 138 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "remove-inbound-attributes")); 139 PD_REMOVE_INBOUND_ATTRIBUTES = builder.getInstance(); 140 INSTANCE.registerPropertyDefinition(PD_REMOVE_INBOUND_ATTRIBUTES); 141 } 142 143 144 145 // Build the "rename-inbound-attributes" property definition. 146 static { 147 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "rename-inbound-attributes"); 148 builder.setOption(PropertyOption.MULTI_VALUED); 149 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "rename-inbound-attributes")); 150 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "rename-inbound-attributes")); 151 builder.setPattern("^[^:]+:[^:]+$", "FROM:TO"); 152 PD_RENAME_INBOUND_ATTRIBUTES = builder.getInstance(); 153 INSTANCE.registerPropertyDefinition(PD_RENAME_INBOUND_ATTRIBUTES); 154 } 155 156 157 158 // Register the tags associated with this managed object definition. 159 static { 160 INSTANCE.registerTag(Tag.valueOf("core-server")); 161 } 162 163 164 165 /** 166 * Get the Attribute Cleanup Plugin configuration definition 167 * singleton. 168 * 169 * @return Returns the Attribute Cleanup Plugin configuration 170 * definition singleton. 171 */ 172 public static AttributeCleanupPluginCfgDefn getInstance() { 173 return INSTANCE; 174 } 175 176 177 178 /** 179 * Private constructor. 180 */ 181 private AttributeCleanupPluginCfgDefn() { 182 super("attribute-cleanup-plugin", PluginCfgDefn.getInstance()); 183 } 184 185 186 187 /** 188 * {@inheritDoc} 189 */ 190 public AttributeCleanupPluginCfgClient createClientConfiguration( 191 ManagedObject<? extends AttributeCleanupPluginCfgClient> impl) { 192 return new AttributeCleanupPluginCfgClientImpl(impl); 193 } 194 195 196 197 /** 198 * {@inheritDoc} 199 */ 200 public AttributeCleanupPluginCfg createServerConfiguration( 201 ServerManagedObject<? extends AttributeCleanupPluginCfg> impl) { 202 return new AttributeCleanupPluginCfgServerImpl(impl); 203 } 204 205 206 207 /** 208 * {@inheritDoc} 209 */ 210 public Class<AttributeCleanupPluginCfg> getServerConfigurationClass() { 211 return AttributeCleanupPluginCfg.class; 212 } 213 214 215 216 /** 217 * Get the "enabled" property definition. 218 * <p> 219 * Indicates whether the plug-in is enabled for use. 220 * 221 * @return Returns the "enabled" property definition. 222 */ 223 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 224 return PluginCfgDefn.getInstance().getEnabledPropertyDefinition(); 225 } 226 227 228 229 /** 230 * Get the "invoke-for-internal-operations" property definition. 231 * <p> 232 * Indicates whether the plug-in should be invoked for internal 233 * operations. 234 * <p> 235 * Any plug-in that can be invoked for internal operations must 236 * ensure that it does not create any new internal operatons that can 237 * cause the same plug-in to be re-invoked. 238 * 239 * @return Returns the "invoke-for-internal-operations" property definition. 240 */ 241 public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() { 242 return PD_INVOKE_FOR_INTERNAL_OPERATIONS; 243 } 244 245 246 247 /** 248 * Get the "java-class" property definition. 249 * <p> 250 * Specifies the fully-qualified name of the Java class that 251 * provides the plug-in implementation. 252 * 253 * @return Returns the "java-class" property definition. 254 */ 255 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 256 return PD_JAVA_CLASS; 257 } 258 259 260 261 /** 262 * Get the "plugin-type" property definition. 263 * <p> 264 * Specifies the set of plug-in types for the plug-in, which 265 * specifies the times at which the plug-in is invoked. 266 * 267 * @return Returns the "plugin-type" property definition. 268 */ 269 public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() { 270 return PD_PLUGIN_TYPE; 271 } 272 273 274 275 /** 276 * Get the "remove-inbound-attributes" property definition. 277 * <p> 278 * A list of attributes which should be removed from incoming add or 279 * modify requests. 280 * 281 * @return Returns the "remove-inbound-attributes" property definition. 282 */ 283 public StringPropertyDefinition getRemoveInboundAttributesPropertyDefinition() { 284 return PD_REMOVE_INBOUND_ATTRIBUTES; 285 } 286 287 288 289 /** 290 * Get the "rename-inbound-attributes" property definition. 291 * <p> 292 * A list of attributes which should be renamed in incoming add or 293 * modify requests. 294 * 295 * @return Returns the "rename-inbound-attributes" property definition. 296 */ 297 public StringPropertyDefinition getRenameInboundAttributesPropertyDefinition() { 298 return PD_RENAME_INBOUND_ATTRIBUTES; 299 } 300 301 302 303 /** 304 * Managed object client implementation. 305 */ 306 private static class AttributeCleanupPluginCfgClientImpl implements 307 AttributeCleanupPluginCfgClient { 308 309 // Private implementation. 310 private ManagedObject<? extends AttributeCleanupPluginCfgClient> impl; 311 312 313 314 // Private constructor. 315 private AttributeCleanupPluginCfgClientImpl( 316 ManagedObject<? extends AttributeCleanupPluginCfgClient> impl) { 317 this.impl = impl; 318 } 319 320 321 322 /** 323 * {@inheritDoc} 324 */ 325 public Boolean isEnabled() { 326 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 327 } 328 329 330 331 /** 332 * {@inheritDoc} 333 */ 334 public void setEnabled(boolean value) { 335 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 336 } 337 338 339 340 /** 341 * {@inheritDoc} 342 */ 343 public boolean isInvokeForInternalOperations() { 344 return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition()); 345 } 346 347 348 349 /** 350 * {@inheritDoc} 351 */ 352 public void setInvokeForInternalOperations(Boolean value) { 353 impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value); 354 } 355 356 357 358 /** 359 * {@inheritDoc} 360 */ 361 public String getJavaClass() { 362 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 363 } 364 365 366 367 /** 368 * {@inheritDoc} 369 */ 370 public void setJavaClass(String value) { 371 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 372 } 373 374 375 376 /** 377 * {@inheritDoc} 378 */ 379 public SortedSet<PluginType> getPluginType() { 380 return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition()); 381 } 382 383 384 385 /** 386 * {@inheritDoc} 387 */ 388 public void setPluginType(Collection<PluginType> values) { 389 impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values); 390 } 391 392 393 394 /** 395 * {@inheritDoc} 396 */ 397 public SortedSet<String> getRemoveInboundAttributes() { 398 return impl.getPropertyValues(INSTANCE.getRemoveInboundAttributesPropertyDefinition()); 399 } 400 401 402 403 /** 404 * {@inheritDoc} 405 */ 406 public void setRemoveInboundAttributes(Collection<String> values) { 407 impl.setPropertyValues(INSTANCE.getRemoveInboundAttributesPropertyDefinition(), values); 408 } 409 410 411 412 /** 413 * {@inheritDoc} 414 */ 415 public SortedSet<String> getRenameInboundAttributes() { 416 return impl.getPropertyValues(INSTANCE.getRenameInboundAttributesPropertyDefinition()); 417 } 418 419 420 421 /** 422 * {@inheritDoc} 423 */ 424 public void setRenameInboundAttributes(Collection<String> values) { 425 impl.setPropertyValues(INSTANCE.getRenameInboundAttributesPropertyDefinition(), values); 426 } 427 428 429 430 /** 431 * {@inheritDoc} 432 */ 433 public ManagedObjectDefinition<? extends AttributeCleanupPluginCfgClient, ? extends AttributeCleanupPluginCfg> definition() { 434 return INSTANCE; 435 } 436 437 438 439 /** 440 * {@inheritDoc} 441 */ 442 public PropertyProvider properties() { 443 return impl; 444 } 445 446 447 448 /** 449 * {@inheritDoc} 450 */ 451 public void commit() throws ManagedObjectAlreadyExistsException, 452 MissingMandatoryPropertiesException, ConcurrentModificationException, 453 OperationRejectedException, AuthorizationException, 454 CommunicationException { 455 impl.commit(); 456 } 457 458 459 460 /** {@inheritDoc} */ 461 public String toString() { 462 return impl.toString(); 463 } 464 } 465 466 467 468 /** 469 * Managed object server implementation. 470 */ 471 private static class AttributeCleanupPluginCfgServerImpl implements 472 AttributeCleanupPluginCfg { 473 474 // Private implementation. 475 private ServerManagedObject<? extends AttributeCleanupPluginCfg> impl; 476 477 // The value of the "enabled" property. 478 private final boolean pEnabled; 479 480 // The value of the "invoke-for-internal-operations" property. 481 private final boolean pInvokeForInternalOperations; 482 483 // The value of the "java-class" property. 484 private final String pJavaClass; 485 486 // The value of the "plugin-type" property. 487 private final SortedSet<PluginType> pPluginType; 488 489 // The value of the "remove-inbound-attributes" property. 490 private final SortedSet<String> pRemoveInboundAttributes; 491 492 // The value of the "rename-inbound-attributes" property. 493 private final SortedSet<String> pRenameInboundAttributes; 494 495 496 497 // Private constructor. 498 private AttributeCleanupPluginCfgServerImpl(ServerManagedObject<? extends AttributeCleanupPluginCfg> impl) { 499 this.impl = impl; 500 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 501 this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition()); 502 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 503 this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition()); 504 this.pRemoveInboundAttributes = impl.getPropertyValues(INSTANCE.getRemoveInboundAttributesPropertyDefinition()); 505 this.pRenameInboundAttributes = impl.getPropertyValues(INSTANCE.getRenameInboundAttributesPropertyDefinition()); 506 } 507 508 509 510 /** 511 * {@inheritDoc} 512 */ 513 public void addAttributeCleanupChangeListener( 514 ConfigurationChangeListener<AttributeCleanupPluginCfg> listener) { 515 impl.registerChangeListener(listener); 516 } 517 518 519 520 /** 521 * {@inheritDoc} 522 */ 523 public void removeAttributeCleanupChangeListener( 524 ConfigurationChangeListener<AttributeCleanupPluginCfg> listener) { 525 impl.deregisterChangeListener(listener); 526 } 527 /** 528 * {@inheritDoc} 529 */ 530 public void addChangeListener( 531 ConfigurationChangeListener<PluginCfg> listener) { 532 impl.registerChangeListener(listener); 533 } 534 535 536 537 /** 538 * {@inheritDoc} 539 */ 540 public void removeChangeListener( 541 ConfigurationChangeListener<PluginCfg> listener) { 542 impl.deregisterChangeListener(listener); 543 } 544 545 546 547 /** 548 * {@inheritDoc} 549 */ 550 public boolean isEnabled() { 551 return pEnabled; 552 } 553 554 555 556 /** 557 * {@inheritDoc} 558 */ 559 public boolean isInvokeForInternalOperations() { 560 return pInvokeForInternalOperations; 561 } 562 563 564 565 /** 566 * {@inheritDoc} 567 */ 568 public String getJavaClass() { 569 return pJavaClass; 570 } 571 572 573 574 /** 575 * {@inheritDoc} 576 */ 577 public SortedSet<PluginType> getPluginType() { 578 return pPluginType; 579 } 580 581 582 583 /** 584 * {@inheritDoc} 585 */ 586 public SortedSet<String> getRemoveInboundAttributes() { 587 return pRemoveInboundAttributes; 588 } 589 590 591 592 /** 593 * {@inheritDoc} 594 */ 595 public SortedSet<String> getRenameInboundAttributes() { 596 return pRenameInboundAttributes; 597 } 598 599 600 601 /** 602 * {@inheritDoc} 603 */ 604 public Class<? extends AttributeCleanupPluginCfg> configurationClass() { 605 return AttributeCleanupPluginCfg.class; 606 } 607 608 609 610 /** 611 * {@inheritDoc} 612 */ 613 public DN dn() { 614 return impl.getDN(); 615 } 616 617 618 619 /** {@inheritDoc} */ 620 public String toString() { 621 return impl.toString(); 622 } 623 } 624}