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