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