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