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