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.AttributeTypePropertyDefinition;
035    import org.opends.server.admin.BooleanPropertyDefinition;
036    import org.opends.server.admin.ClassPropertyDefinition;
037    import org.opends.server.admin.client.AuthorizationException;
038    import org.opends.server.admin.client.CommunicationException;
039    import org.opends.server.admin.client.ConcurrentModificationException;
040    import org.opends.server.admin.client.ManagedObject;
041    import org.opends.server.admin.client.MissingMandatoryPropertiesException;
042    import org.opends.server.admin.client.OperationRejectedException;
043    import org.opends.server.admin.DefaultBehaviorProvider;
044    import org.opends.server.admin.DefinedDefaultBehaviorProvider;
045    import org.opends.server.admin.DNPropertyDefinition;
046    import org.opends.server.admin.EnumPropertyDefinition;
047    import org.opends.server.admin.ManagedObjectAlreadyExistsException;
048    import org.opends.server.admin.ManagedObjectDefinition;
049    import org.opends.server.admin.PropertyOption;
050    import org.opends.server.admin.PropertyProvider;
051    import org.opends.server.admin.server.ConfigurationChangeListener;
052    import org.opends.server.admin.server.ServerManagedObject;
053    import org.opends.server.admin.std.client.UserDefinedVirtualAttributeCfgClient;
054    import org.opends.server.admin.std.meta.VirtualAttributeCfgDefn.ConflictBehavior;
055    import org.opends.server.admin.std.server.UserDefinedVirtualAttributeCfg;
056    import org.opends.server.admin.std.server.VirtualAttributeCfg;
057    import org.opends.server.admin.StringPropertyDefinition;
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 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     */
073    public 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 "value" property definition.
291       * <p>
292       * Specifies the values to be included in the virtual attribute.
293       *
294       * @return Returns the "value" property definition.
295       */
296      public StringPropertyDefinition getValuePropertyDefinition() {
297        return PD_VALUE;
298      }
299    
300    
301    
302      /**
303       * Managed object client implementation.
304       */
305      private static class UserDefinedVirtualAttributeCfgClientImpl implements
306        UserDefinedVirtualAttributeCfgClient {
307    
308        // Private implementation.
309        private ManagedObject<? extends UserDefinedVirtualAttributeCfgClient> impl;
310    
311    
312    
313        // Private constructor.
314        private UserDefinedVirtualAttributeCfgClientImpl(
315            ManagedObject<? extends UserDefinedVirtualAttributeCfgClient> impl) {
316          this.impl = impl;
317        }
318    
319    
320    
321        /**
322         * {@inheritDoc}
323         */
324        public AttributeType getAttributeType() {
325          return impl.getPropertyValue(INSTANCE.getAttributeTypePropertyDefinition());
326        }
327    
328    
329    
330        /**
331         * {@inheritDoc}
332         */
333        public void setAttributeType(AttributeType value) {
334          impl.setPropertyValue(INSTANCE.getAttributeTypePropertyDefinition(), value);
335        }
336    
337    
338    
339        /**
340         * {@inheritDoc}
341         */
342        public SortedSet<DN> getBaseDN() {
343          return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
344        }
345    
346    
347    
348        /**
349         * {@inheritDoc}
350         */
351        public void setBaseDN(Collection<DN> values) {
352          impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values);
353        }
354    
355    
356    
357        /**
358         * {@inheritDoc}
359         */
360        public ConflictBehavior getConflictBehavior() {
361          return impl.getPropertyValue(INSTANCE.getConflictBehaviorPropertyDefinition());
362        }
363    
364    
365    
366        /**
367         * {@inheritDoc}
368         */
369        public void setConflictBehavior(ConflictBehavior value) {
370          impl.setPropertyValue(INSTANCE.getConflictBehaviorPropertyDefinition(), value);
371        }
372    
373    
374    
375        /**
376         * {@inheritDoc}
377         */
378        public Boolean isEnabled() {
379          return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
380        }
381    
382    
383    
384        /**
385         * {@inheritDoc}
386         */
387        public void setEnabled(boolean value) {
388          impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
389        }
390    
391    
392    
393        /**
394         * {@inheritDoc}
395         */
396        public SortedSet<String> getFilter() {
397          return impl.getPropertyValues(INSTANCE.getFilterPropertyDefinition());
398        }
399    
400    
401    
402        /**
403         * {@inheritDoc}
404         */
405        public void setFilter(Collection<String> values) {
406          impl.setPropertyValues(INSTANCE.getFilterPropertyDefinition(), values);
407        }
408    
409    
410    
411        /**
412         * {@inheritDoc}
413         */
414        public SortedSet<DN> getGroupDN() {
415          return impl.getPropertyValues(INSTANCE.getGroupDNPropertyDefinition());
416        }
417    
418    
419    
420        /**
421         * {@inheritDoc}
422         */
423        public void setGroupDN(Collection<DN> values) {
424          impl.setPropertyValues(INSTANCE.getGroupDNPropertyDefinition(), values);
425        }
426    
427    
428    
429        /**
430         * {@inheritDoc}
431         */
432        public String getJavaClass() {
433          return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
434        }
435    
436    
437    
438        /**
439         * {@inheritDoc}
440         */
441        public void setJavaClass(String value) {
442          impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
443        }
444    
445    
446    
447        /**
448         * {@inheritDoc}
449         */
450        public SortedSet<String> getValue() {
451          return impl.getPropertyValues(INSTANCE.getValuePropertyDefinition());
452        }
453    
454    
455    
456        /**
457         * {@inheritDoc}
458         */
459        public void setValue(Collection<String> values) {
460          impl.setPropertyValues(INSTANCE.getValuePropertyDefinition(), values);
461        }
462    
463    
464    
465        /**
466         * {@inheritDoc}
467         */
468        public ManagedObjectDefinition<? extends UserDefinedVirtualAttributeCfgClient, ? extends UserDefinedVirtualAttributeCfg> definition() {
469          return INSTANCE;
470        }
471    
472    
473    
474        /**
475         * {@inheritDoc}
476         */
477        public PropertyProvider properties() {
478          return impl;
479        }
480    
481    
482    
483        /**
484         * {@inheritDoc}
485         */
486        public void commit() throws ManagedObjectAlreadyExistsException,
487            MissingMandatoryPropertiesException, ConcurrentModificationException,
488            OperationRejectedException, AuthorizationException,
489            CommunicationException {
490          impl.commit();
491        }
492    
493      }
494    
495    
496    
497      /**
498       * Managed object server implementation.
499       */
500      private static class UserDefinedVirtualAttributeCfgServerImpl implements
501        UserDefinedVirtualAttributeCfg {
502    
503        // Private implementation.
504        private ServerManagedObject<? extends UserDefinedVirtualAttributeCfg> impl;
505    
506        // The value of the "attribute-type" property.
507        private final AttributeType pAttributeType;
508    
509        // The value of the "base-dn" property.
510        private final SortedSet<DN> pBaseDN;
511    
512        // The value of the "conflict-behavior" property.
513        private final ConflictBehavior pConflictBehavior;
514    
515        // The value of the "enabled" property.
516        private final boolean pEnabled;
517    
518        // The value of the "filter" property.
519        private final SortedSet<String> pFilter;
520    
521        // The value of the "group-dn" property.
522        private final SortedSet<DN> pGroupDN;
523    
524        // The value of the "java-class" property.
525        private final String pJavaClass;
526    
527        // The value of the "value" property.
528        private final SortedSet<String> pValue;
529    
530    
531    
532        // Private constructor.
533        private UserDefinedVirtualAttributeCfgServerImpl(ServerManagedObject<? extends UserDefinedVirtualAttributeCfg> impl) {
534          this.impl = impl;
535          this.pAttributeType = impl.getPropertyValue(INSTANCE.getAttributeTypePropertyDefinition());
536          this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
537          this.pConflictBehavior = impl.getPropertyValue(INSTANCE.getConflictBehaviorPropertyDefinition());
538          this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
539          this.pFilter = impl.getPropertyValues(INSTANCE.getFilterPropertyDefinition());
540          this.pGroupDN = impl.getPropertyValues(INSTANCE.getGroupDNPropertyDefinition());
541          this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
542          this.pValue = impl.getPropertyValues(INSTANCE.getValuePropertyDefinition());
543        }
544    
545    
546    
547        /**
548         * {@inheritDoc}
549         */
550        public void addUserDefinedChangeListener(
551            ConfigurationChangeListener<UserDefinedVirtualAttributeCfg> listener) {
552          impl.registerChangeListener(listener);
553        }
554    
555    
556    
557        /**
558         * {@inheritDoc}
559         */
560        public void removeUserDefinedChangeListener(
561            ConfigurationChangeListener<UserDefinedVirtualAttributeCfg> listener) {
562          impl.deregisterChangeListener(listener);
563        }
564        /**
565         * {@inheritDoc}
566         */
567        public void addChangeListener(
568            ConfigurationChangeListener<VirtualAttributeCfg> listener) {
569          impl.registerChangeListener(listener);
570        }
571    
572    
573    
574        /**
575         * {@inheritDoc}
576         */
577        public void removeChangeListener(
578            ConfigurationChangeListener<VirtualAttributeCfg> listener) {
579          impl.deregisterChangeListener(listener);
580        }
581    
582    
583    
584        /**
585         * {@inheritDoc}
586         */
587        public AttributeType getAttributeType() {
588          return pAttributeType;
589        }
590    
591    
592    
593        /**
594         * {@inheritDoc}
595         */
596        public SortedSet<DN> getBaseDN() {
597          return pBaseDN;
598        }
599    
600    
601    
602        /**
603         * {@inheritDoc}
604         */
605        public ConflictBehavior getConflictBehavior() {
606          return pConflictBehavior;
607        }
608    
609    
610    
611        /**
612         * {@inheritDoc}
613         */
614        public boolean isEnabled() {
615          return pEnabled;
616        }
617    
618    
619    
620        /**
621         * {@inheritDoc}
622         */
623        public SortedSet<String> getFilter() {
624          return pFilter;
625        }
626    
627    
628    
629        /**
630         * {@inheritDoc}
631         */
632        public SortedSet<DN> getGroupDN() {
633          return pGroupDN;
634        }
635    
636    
637    
638        /**
639         * {@inheritDoc}
640         */
641        public String getJavaClass() {
642          return pJavaClass;
643        }
644    
645    
646    
647        /**
648         * {@inheritDoc}
649         */
650        public SortedSet<String> getValue() {
651          return pValue;
652        }
653    
654    
655    
656        /**
657         * {@inheritDoc}
658         */
659        public Class<? extends UserDefinedVirtualAttributeCfg> configurationClass() {
660          return UserDefinedVirtualAttributeCfg.class;
661        }
662    
663    
664    
665        /**
666         * {@inheritDoc}
667         */
668        public DN dn() {
669          return impl.getDN();
670        }
671    
672      }
673    }