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