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