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