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.forgerock.opendj.server.config.meta;
027
028
029
030import java.util.Collection;
031import java.util.SortedSet;
032import org.forgerock.opendj.config.AdministratorAction;
033import org.forgerock.opendj.config.AttributeTypePropertyDefinition;
034import org.forgerock.opendj.config.BooleanPropertyDefinition;
035import org.forgerock.opendj.config.ClassPropertyDefinition;
036import org.forgerock.opendj.config.client.ConcurrentModificationException;
037import org.forgerock.opendj.config.client.ManagedObject;
038import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
039import org.forgerock.opendj.config.client.OperationRejectedException;
040import org.forgerock.opendj.config.DefaultBehaviorProvider;
041import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
042import org.forgerock.opendj.config.DNPropertyDefinition;
043import org.forgerock.opendj.config.EnumPropertyDefinition;
044import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
045import org.forgerock.opendj.config.ManagedObjectDefinition;
046import org.forgerock.opendj.config.PropertyOption;
047import org.forgerock.opendj.config.PropertyProvider;
048import org.forgerock.opendj.config.server.ConfigurationChangeListener;
049import org.forgerock.opendj.config.server.ServerManagedObject;
050import org.forgerock.opendj.config.StringPropertyDefinition;
051import org.forgerock.opendj.config.Tag;
052import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
053import org.forgerock.opendj.ldap.DN;
054import org.forgerock.opendj.ldap.LdapException;
055import org.forgerock.opendj.ldap.schema.AttributeType;
056import org.forgerock.opendj.server.config.client.UserDefinedVirtualAttributeCfgClient;
057import org.forgerock.opendj.server.config.meta.VirtualAttributeCfgDefn.ConflictBehavior;
058import org.forgerock.opendj.server.config.meta.VirtualAttributeCfgDefn.Scope;
059import org.forgerock.opendj.server.config.server.UserDefinedVirtualAttributeCfg;
060import org.forgerock.opendj.server.config.server.VirtualAttributeCfg;
061
062
063
064/**
065 * An interface for querying the User Defined Virtual Attribute
066 * managed object definition meta information.
067 * <p>
068 * The User Defined Virtual Attribute creates virtual attributes with
069 * user-defined values in entries that match the criteria defined in
070 * the plug-in's configuration.
071 */
072public final class UserDefinedVirtualAttributeCfgDefn extends ManagedObjectDefinition<UserDefinedVirtualAttributeCfgClient, UserDefinedVirtualAttributeCfg> {
073
074  /** The singleton configuration definition instance. */
075  private static final UserDefinedVirtualAttributeCfgDefn INSTANCE = new UserDefinedVirtualAttributeCfgDefn();
076
077
078
079  /** The "java-class" property definition. */
080  private static final ClassPropertyDefinition PD_JAVA_CLASS;
081
082
083
084  /** The "value" property definition. */
085  private static final StringPropertyDefinition PD_VALUE;
086
087
088
089  /** Build the "java-class" property definition. */
090  static {
091      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
092      builder.setOption(PropertyOption.MANDATORY);
093      builder.setOption(PropertyOption.ADVANCED);
094      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
095      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
096      builder.setDefaultBehaviorProvider(provider);
097      builder.addInstanceOf("org.opends.server.api.VirtualAttributeProvider");
098      PD_JAVA_CLASS = builder.getInstance();
099      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
100  }
101
102
103
104  /** Build the "value" property definition. */
105  static {
106      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "value");
107      builder.setOption(PropertyOption.MULTI_VALUED);
108      builder.setOption(PropertyOption.MANDATORY);
109      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "value"));
110      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
111      PD_VALUE = builder.getInstance();
112      INSTANCE.registerPropertyDefinition(PD_VALUE);
113  }
114
115
116
117  // Register the tags associated with this managed object definition.
118  static {
119    INSTANCE.registerTag(Tag.valueOf("core-server"));
120  }
121
122
123
124  /**
125   * Get the User Defined Virtual Attribute configuration definition
126   * singleton.
127   *
128   * @return Returns the User Defined Virtual Attribute configuration
129   *         definition singleton.
130   */
131  public static UserDefinedVirtualAttributeCfgDefn getInstance() {
132    return INSTANCE;
133  }
134
135
136
137  /**
138   * Private constructor.
139   */
140  private UserDefinedVirtualAttributeCfgDefn() {
141    super("user-defined-virtual-attribute", VirtualAttributeCfgDefn.getInstance());
142  }
143
144
145
146  /** {@inheritDoc} */
147  public UserDefinedVirtualAttributeCfgClient createClientConfiguration(
148      ManagedObject<? extends UserDefinedVirtualAttributeCfgClient> impl) {
149    return new UserDefinedVirtualAttributeCfgClientImpl(impl);
150  }
151
152
153
154  /** {@inheritDoc} */
155  public UserDefinedVirtualAttributeCfg createServerConfiguration(
156      ServerManagedObject<? extends UserDefinedVirtualAttributeCfg> impl) {
157    return new UserDefinedVirtualAttributeCfgServerImpl(impl);
158  }
159
160
161
162  /** {@inheritDoc} */
163  public Class<UserDefinedVirtualAttributeCfg> getServerConfigurationClass() {
164    return UserDefinedVirtualAttributeCfg.class;
165  }
166
167
168
169  /**
170   * Get the "attribute-type" property definition.
171   * <p>
172   * Specifies the attribute type for the attribute whose values are
173   * to be dynamically assigned by the virtual attribute.
174   *
175   * @return Returns the "attribute-type" property definition.
176   */
177  public AttributeTypePropertyDefinition getAttributeTypePropertyDefinition() {
178    return VirtualAttributeCfgDefn.getInstance().getAttributeTypePropertyDefinition();
179  }
180
181
182
183  /**
184   * Get the "base-dn" property definition.
185   * <p>
186   * Specifies the base DNs for the branches containing entries that
187   * are eligible to use this virtual attribute.
188   * <p>
189   * If no values are given, then the server generates virtual
190   * attributes anywhere in the server.
191   *
192   * @return Returns the "base-dn" property definition.
193   */
194  public DNPropertyDefinition getBaseDNPropertyDefinition() {
195    return VirtualAttributeCfgDefn.getInstance().getBaseDNPropertyDefinition();
196  }
197
198
199
200  /**
201   * Get the "conflict-behavior" property definition.
202   * <p>
203   * Specifies the behavior that the server is to exhibit for entries
204   * that already contain one or more real values for the associated
205   * attribute.
206   *
207   * @return Returns the "conflict-behavior" property definition.
208   */
209  public EnumPropertyDefinition<ConflictBehavior> getConflictBehaviorPropertyDefinition() {
210    return VirtualAttributeCfgDefn.getInstance().getConflictBehaviorPropertyDefinition();
211  }
212
213
214
215  /**
216   * Get the "enabled" property definition.
217   * <p>
218   * Indicates whether the User Defined Virtual Attribute is enabled
219   * for use.
220   *
221   * @return Returns the "enabled" property definition.
222   */
223  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
224    return VirtualAttributeCfgDefn.getInstance().getEnabledPropertyDefinition();
225  }
226
227
228
229  /**
230   * Get the "filter" property definition.
231   * <p>
232   * Specifies the search filters to be applied against entries to
233   * determine if the virtual attribute is to be generated for those
234   * entries.
235   * <p>
236   * If no values are given, then any entry is eligible to have the
237   * value generated. If one or more filters are specified, then only
238   * entries that match at least one of those filters are allowed to
239   * have the virtual attribute.
240   *
241   * @return Returns the "filter" property definition.
242   */
243  public StringPropertyDefinition getFilterPropertyDefinition() {
244    return VirtualAttributeCfgDefn.getInstance().getFilterPropertyDefinition();
245  }
246
247
248
249  /**
250   * Get the "group-dn" property definition.
251   * <p>
252   * Specifies the DNs of the groups whose members can be eligible to
253   * use this virtual attribute.
254   * <p>
255   * If no values are given, then group membership is not taken into
256   * account when generating the virtual attribute. If one or more
257   * group DNs are specified, then only members of those groups are
258   * allowed to have the virtual attribute.
259   *
260   * @return Returns the "group-dn" property definition.
261   */
262  public DNPropertyDefinition getGroupDNPropertyDefinition() {
263    return VirtualAttributeCfgDefn.getInstance().getGroupDNPropertyDefinition();
264  }
265
266
267
268  /**
269   * Get the "java-class" property definition.
270   * <p>
271   * Specifies the fully-qualified name of the virtual attribute
272   * provider class that generates the attribute values.
273   *
274   * @return Returns the "java-class" property definition.
275   */
276  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
277    return PD_JAVA_CLASS;
278  }
279
280
281
282  /**
283   * Get the "scope" property definition.
284   * <p>
285   * Specifies the LDAP scope associated with base DNs for entries
286   * that are eligible to use this virtual attribute.
287   *
288   * @return Returns the "scope" property definition.
289   */
290  public EnumPropertyDefinition<Scope> getScopePropertyDefinition() {
291    return VirtualAttributeCfgDefn.getInstance().getScopePropertyDefinition();
292  }
293
294
295
296  /**
297   * Get the "value" property definition.
298   * <p>
299   * Specifies the values to be included in the virtual attribute.
300   *
301   * @return Returns the "value" property definition.
302   */
303  public StringPropertyDefinition getValuePropertyDefinition() {
304    return PD_VALUE;
305  }
306
307
308
309  /**
310   * Managed object client implementation.
311   */
312  private static class UserDefinedVirtualAttributeCfgClientImpl implements
313    UserDefinedVirtualAttributeCfgClient {
314
315    /** Private implementation. */
316    private ManagedObject<? extends UserDefinedVirtualAttributeCfgClient> impl;
317
318
319
320    /** Private constructor. */
321    private UserDefinedVirtualAttributeCfgClientImpl(
322        ManagedObject<? extends UserDefinedVirtualAttributeCfgClient> impl) {
323      this.impl = impl;
324    }
325
326
327
328    /** {@inheritDoc} */
329    public AttributeType getAttributeType() {
330      return impl.getPropertyValue(INSTANCE.getAttributeTypePropertyDefinition());
331    }
332
333
334
335    /** {@inheritDoc} */
336    public void setAttributeType(AttributeType value) {
337      impl.setPropertyValue(INSTANCE.getAttributeTypePropertyDefinition(), value);
338    }
339
340
341
342    /** {@inheritDoc} */
343    public SortedSet<DN> getBaseDN() {
344      return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
345    }
346
347
348
349    /** {@inheritDoc} */
350    public void setBaseDN(Collection<DN> values) {
351      impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values);
352    }
353
354
355
356    /** {@inheritDoc} */
357    public ConflictBehavior getConflictBehavior() {
358      return impl.getPropertyValue(INSTANCE.getConflictBehaviorPropertyDefinition());
359    }
360
361
362
363    /** {@inheritDoc} */
364    public void setConflictBehavior(ConflictBehavior value) {
365      impl.setPropertyValue(INSTANCE.getConflictBehaviorPropertyDefinition(), value);
366    }
367
368
369
370    /** {@inheritDoc} */
371    public Boolean isEnabled() {
372      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
373    }
374
375
376
377    /** {@inheritDoc} */
378    public void setEnabled(boolean value) {
379      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
380    }
381
382
383
384    /** {@inheritDoc} */
385    public SortedSet<String> getFilter() {
386      return impl.getPropertyValues(INSTANCE.getFilterPropertyDefinition());
387    }
388
389
390
391    /** {@inheritDoc} */
392    public void setFilter(Collection<String> values) {
393      impl.setPropertyValues(INSTANCE.getFilterPropertyDefinition(), values);
394    }
395
396
397
398    /** {@inheritDoc} */
399    public SortedSet<DN> getGroupDN() {
400      return impl.getPropertyValues(INSTANCE.getGroupDNPropertyDefinition());
401    }
402
403
404
405    /** {@inheritDoc} */
406    public void setGroupDN(Collection<DN> values) {
407      impl.setPropertyValues(INSTANCE.getGroupDNPropertyDefinition(), values);
408    }
409
410
411
412    /** {@inheritDoc} */
413    public String getJavaClass() {
414      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
415    }
416
417
418
419    /** {@inheritDoc} */
420    public void setJavaClass(String value) {
421      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
422    }
423
424
425
426    /** {@inheritDoc} */
427    public Scope getScope() {
428      return impl.getPropertyValue(INSTANCE.getScopePropertyDefinition());
429    }
430
431
432
433    /** {@inheritDoc} */
434    public void setScope(Scope value) {
435      impl.setPropertyValue(INSTANCE.getScopePropertyDefinition(), value);
436    }
437
438
439
440    /** {@inheritDoc} */
441    public SortedSet<String> getValue() {
442      return impl.getPropertyValues(INSTANCE.getValuePropertyDefinition());
443    }
444
445
446
447    /** {@inheritDoc} */
448    public void setValue(Collection<String> values) {
449      impl.setPropertyValues(INSTANCE.getValuePropertyDefinition(), values);
450    }
451
452
453
454    /** {@inheritDoc} */
455    public ManagedObjectDefinition<? extends UserDefinedVirtualAttributeCfgClient, ? extends UserDefinedVirtualAttributeCfg> definition() {
456      return INSTANCE;
457    }
458
459
460
461    /** {@inheritDoc} */
462    public PropertyProvider properties() {
463      return impl;
464    }
465
466
467
468    /** {@inheritDoc} */
469    public void commit() throws ManagedObjectAlreadyExistsException,
470        MissingMandatoryPropertiesException, ConcurrentModificationException,
471        OperationRejectedException, LdapException {
472      impl.commit();
473    }
474
475
476
477    /** {@inheritDoc} */
478    public String toString() {
479      return impl.toString();
480    }
481  }
482
483
484
485  /**
486   * Managed object server implementation.
487   */
488  private static class UserDefinedVirtualAttributeCfgServerImpl implements
489    UserDefinedVirtualAttributeCfg {
490
491    /** Private implementation. */
492    private ServerManagedObject<? extends UserDefinedVirtualAttributeCfg> impl;
493
494    /** The value of the "attribute-type" property. */
495    private final AttributeType pAttributeType;
496
497    /** The value of the "base-dn" property. */
498    private final SortedSet<DN> pBaseDN;
499
500    /** The value of the "conflict-behavior" property. */
501    private final ConflictBehavior pConflictBehavior;
502
503    /** The value of the "enabled" property. */
504    private final boolean pEnabled;
505
506    /** The value of the "filter" property. */
507    private final SortedSet<String> pFilter;
508
509    /** The value of the "group-dn" property. */
510    private final SortedSet<DN> pGroupDN;
511
512    /** The value of the "java-class" property. */
513    private final String pJavaClass;
514
515    /** The value of the "scope" property. */
516    private final Scope pScope;
517
518    /** The value of the "value" property. */
519    private final SortedSet<String> pValue;
520
521
522
523    /** Private constructor. */
524    private UserDefinedVirtualAttributeCfgServerImpl(ServerManagedObject<? extends UserDefinedVirtualAttributeCfg> impl) {
525      this.impl = impl;
526      this.pAttributeType = impl.getPropertyValue(INSTANCE.getAttributeTypePropertyDefinition());
527      this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
528      this.pConflictBehavior = impl.getPropertyValue(INSTANCE.getConflictBehaviorPropertyDefinition());
529      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
530      this.pFilter = impl.getPropertyValues(INSTANCE.getFilterPropertyDefinition());
531      this.pGroupDN = impl.getPropertyValues(INSTANCE.getGroupDNPropertyDefinition());
532      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
533      this.pScope = impl.getPropertyValue(INSTANCE.getScopePropertyDefinition());
534      this.pValue = impl.getPropertyValues(INSTANCE.getValuePropertyDefinition());
535    }
536
537
538
539    /** {@inheritDoc} */
540    public void addUserDefinedChangeListener(
541        ConfigurationChangeListener<UserDefinedVirtualAttributeCfg> listener) {
542      impl.registerChangeListener(listener);
543    }
544
545
546
547    /** {@inheritDoc} */
548    public void removeUserDefinedChangeListener(
549        ConfigurationChangeListener<UserDefinedVirtualAttributeCfg> listener) {
550      impl.deregisterChangeListener(listener);
551    }
552    /** {@inheritDoc} */
553    public void addChangeListener(
554        ConfigurationChangeListener<VirtualAttributeCfg> listener) {
555      impl.registerChangeListener(listener);
556    }
557
558
559
560    /** {@inheritDoc} */
561    public void removeChangeListener(
562        ConfigurationChangeListener<VirtualAttributeCfg> listener) {
563      impl.deregisterChangeListener(listener);
564    }
565
566
567
568    /** {@inheritDoc} */
569    public AttributeType getAttributeType() {
570      return pAttributeType;
571    }
572
573
574
575    /** {@inheritDoc} */
576    public SortedSet<DN> getBaseDN() {
577      return pBaseDN;
578    }
579
580
581
582    /** {@inheritDoc} */
583    public ConflictBehavior getConflictBehavior() {
584      return pConflictBehavior;
585    }
586
587
588
589    /** {@inheritDoc} */
590    public boolean isEnabled() {
591      return pEnabled;
592    }
593
594
595
596    /** {@inheritDoc} */
597    public SortedSet<String> getFilter() {
598      return pFilter;
599    }
600
601
602
603    /** {@inheritDoc} */
604    public SortedSet<DN> getGroupDN() {
605      return pGroupDN;
606    }
607
608
609
610    /** {@inheritDoc} */
611    public String getJavaClass() {
612      return pJavaClass;
613    }
614
615
616
617    /** {@inheritDoc} */
618    public Scope getScope() {
619      return pScope;
620    }
621
622
623
624    /** {@inheritDoc} */
625    public SortedSet<String> getValue() {
626      return pValue;
627    }
628
629
630
631    /** {@inheritDoc} */
632    public Class<? extends UserDefinedVirtualAttributeCfg> configurationClass() {
633      return UserDefinedVirtualAttributeCfg.class;
634    }
635
636
637
638    /** {@inheritDoc} */
639    public DN dn() {
640      return impl.getDN();
641    }
642
643
644
645    /** {@inheritDoc} */
646    public String toString() {
647      return impl.toString();
648    }
649  }
650}