001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008 Sun Microsystems, Inc.
015 */
016package org.opends.server.admin.std.meta;
017
018
019
020import java.util.Collection;
021import java.util.SortedSet;
022import org.forgerock.opendj.ldap.DN;
023import org.opends.server.admin.AdministratorAction;
024import org.opends.server.admin.BooleanPropertyDefinition;
025import org.opends.server.admin.ClassPropertyDefinition;
026import org.opends.server.admin.client.AuthorizationException;
027import org.opends.server.admin.client.CommunicationException;
028import org.opends.server.admin.client.ConcurrentModificationException;
029import org.opends.server.admin.client.ManagedObject;
030import org.opends.server.admin.client.MissingMandatoryPropertiesException;
031import org.opends.server.admin.client.OperationRejectedException;
032import org.opends.server.admin.DefaultBehaviorProvider;
033import org.opends.server.admin.DefinedDefaultBehaviorProvider;
034import org.opends.server.admin.DNPropertyDefinition;
035import org.opends.server.admin.EnumPropertyDefinition;
036import org.opends.server.admin.ManagedObjectAlreadyExistsException;
037import org.opends.server.admin.ManagedObjectDefinition;
038import org.opends.server.admin.ManagedObjectOption;
039import org.opends.server.admin.PropertyException;
040import org.opends.server.admin.PropertyOption;
041import org.opends.server.admin.PropertyProvider;
042import org.opends.server.admin.server.ConfigurationChangeListener;
043import org.opends.server.admin.server.ServerManagedObject;
044import org.opends.server.admin.std.client.ConfigFileHandlerBackendCfgClient;
045import org.opends.server.admin.std.meta.BackendCfgDefn.WritabilityMode;
046import org.opends.server.admin.std.server.BackendCfg;
047import org.opends.server.admin.std.server.ConfigFileHandlerBackendCfg;
048import org.opends.server.admin.StringPropertyDefinition;
049import org.opends.server.admin.Tag;
050
051
052
053/**
054 * An interface for querying the Config File Handler Backend managed
055 * object definition meta information.
056 * <p>
057 * The Config File Handler Backend allows clients to access the server
058 * configuration over protocol, and allow both read and write
059 * operations. Note: Modify DN operations are not supported for entries
060 * in the server configuration.
061 */
062public final class ConfigFileHandlerBackendCfgDefn extends ManagedObjectDefinition<ConfigFileHandlerBackendCfgClient, ConfigFileHandlerBackendCfg> {
063
064  // The singleton configuration definition instance.
065  private static final ConfigFileHandlerBackendCfgDefn INSTANCE = new ConfigFileHandlerBackendCfgDefn();
066
067
068
069  // The "java-class" property definition.
070  private static final ClassPropertyDefinition PD_JAVA_CLASS;
071
072
073
074  // The "writability-mode" property definition.
075  private static final EnumPropertyDefinition<WritabilityMode> PD_WRITABILITY_MODE;
076
077
078
079  // Build the "java-class" property definition.
080  static {
081      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
082      builder.setOption(PropertyOption.MANDATORY);
083      builder.setOption(PropertyOption.ADVANCED);
084      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
085      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.ConfigFileHandler");
086      builder.setDefaultBehaviorProvider(provider);
087      builder.addInstanceOf("org.opends.server.api.Backend");
088      PD_JAVA_CLASS = builder.getInstance();
089      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
090  }
091
092
093
094  // Build the "writability-mode" property definition.
095  static {
096      EnumPropertyDefinition.Builder<WritabilityMode> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "writability-mode");
097      builder.setOption(PropertyOption.MANDATORY);
098      builder.setOption(PropertyOption.ADVANCED);
099      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "writability-mode"));
100      DefaultBehaviorProvider<WritabilityMode> provider = new DefinedDefaultBehaviorProvider<WritabilityMode>("enabled");
101      builder.setDefaultBehaviorProvider(provider);
102      builder.setEnumClass(WritabilityMode.class);
103      PD_WRITABILITY_MODE = builder.getInstance();
104      INSTANCE.registerPropertyDefinition(PD_WRITABILITY_MODE);
105  }
106
107
108
109  // Register the options associated with this managed object definition.
110  static {
111    INSTANCE.registerOption(ManagedObjectOption.ADVANCED);
112  }
113
114
115
116  // Register the tags associated with this managed object definition.
117  static {
118    INSTANCE.registerTag(Tag.valueOf("database"));
119  }
120
121
122
123  /**
124   * Get the Config File Handler Backend configuration definition
125   * singleton.
126   *
127   * @return Returns the Config File Handler Backend configuration
128   *         definition singleton.
129   */
130  public static ConfigFileHandlerBackendCfgDefn getInstance() {
131    return INSTANCE;
132  }
133
134
135
136  /**
137   * Private constructor.
138   */
139  private ConfigFileHandlerBackendCfgDefn() {
140    super("config-file-handler-backend", BackendCfgDefn.getInstance());
141  }
142
143
144
145  /**
146   * {@inheritDoc}
147   */
148  public ConfigFileHandlerBackendCfgClient createClientConfiguration(
149      ManagedObject<? extends ConfigFileHandlerBackendCfgClient> impl) {
150    return new ConfigFileHandlerBackendCfgClientImpl(impl);
151  }
152
153
154
155  /**
156   * {@inheritDoc}
157   */
158  public ConfigFileHandlerBackendCfg createServerConfiguration(
159      ServerManagedObject<? extends ConfigFileHandlerBackendCfg> impl) {
160    return new ConfigFileHandlerBackendCfgServerImpl(impl);
161  }
162
163
164
165  /**
166   * {@inheritDoc}
167   */
168  public Class<ConfigFileHandlerBackendCfg> getServerConfigurationClass() {
169    return ConfigFileHandlerBackendCfg.class;
170  }
171
172
173
174  /**
175   * Get the "backend-id" property definition.
176   * <p>
177   * Specifies a name to identify the associated backend.
178   * <p>
179   * The name must be unique among all backends in the server. The
180   * backend ID may not be altered after the backend is created in the
181   * server.
182   *
183   * @return Returns the "backend-id" property definition.
184   */
185  public StringPropertyDefinition getBackendIdPropertyDefinition() {
186    return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition();
187  }
188
189
190
191  /**
192   * Get the "base-dn" property definition.
193   * <p>
194   * Specifies the base DN(s) for the data that the backend handles.
195   * <p>
196   * A single backend may be responsible for one or more base DNs.
197   * Note that no two backends may have the same base DN although one
198   * backend may have a base DN that is below a base DN provided by
199   * another backend (similar to the use of sub-suffixes in the Sun
200   * Java System Directory Server). If any of the base DNs is
201   * subordinate to a base DN for another backend, then all base DNs
202   * for that backend must be subordinate to that same base DN.
203   *
204   * @return Returns the "base-dn" property definition.
205   */
206  public DNPropertyDefinition getBaseDNPropertyDefinition() {
207    return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition();
208  }
209
210
211
212  /**
213   * Get the "enabled" property definition.
214   * <p>
215   * Indicates whether the backend is enabled in the server.
216   * <p>
217   * If a backend is not enabled, then its contents are not accessible
218   * when processing operations.
219   *
220   * @return Returns the "enabled" property definition.
221   */
222  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
223    return BackendCfgDefn.getInstance().getEnabledPropertyDefinition();
224  }
225
226
227
228  /**
229   * Get the "java-class" property definition.
230   * <p>
231   * Specifies the fully-qualified name of the Java class that
232   * provides the backend implementation.
233   *
234   * @return Returns the "java-class" property definition.
235   */
236  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
237    return PD_JAVA_CLASS;
238  }
239
240
241
242  /**
243   * Get the "writability-mode" property definition.
244   * <p>
245   * Specifies the behavior that the backend should use when
246   * processing write operations.
247   *
248   * @return Returns the "writability-mode" property definition.
249   */
250  public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() {
251    return PD_WRITABILITY_MODE;
252  }
253
254
255
256  /**
257   * Managed object client implementation.
258   */
259  private static class ConfigFileHandlerBackendCfgClientImpl implements
260    ConfigFileHandlerBackendCfgClient {
261
262    // Private implementation.
263    private ManagedObject<? extends ConfigFileHandlerBackendCfgClient> impl;
264
265
266
267    // Private constructor.
268    private ConfigFileHandlerBackendCfgClientImpl(
269        ManagedObject<? extends ConfigFileHandlerBackendCfgClient> impl) {
270      this.impl = impl;
271    }
272
273
274
275    /**
276     * {@inheritDoc}
277     */
278    public String getBackendId() {
279      return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
280    }
281
282
283
284    /**
285     * {@inheritDoc}
286     */
287    public void setBackendId(String value) throws PropertyException {
288      impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value);
289    }
290
291
292
293    /**
294     * {@inheritDoc}
295     */
296    public SortedSet<DN> getBaseDN() {
297      return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
298    }
299
300
301
302    /**
303     * {@inheritDoc}
304     */
305    public void setBaseDN(Collection<DN> values) {
306      impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values);
307    }
308
309
310
311    /**
312     * {@inheritDoc}
313     */
314    public Boolean isEnabled() {
315      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
316    }
317
318
319
320    /**
321     * {@inheritDoc}
322     */
323    public void setEnabled(boolean value) {
324      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
325    }
326
327
328
329    /**
330     * {@inheritDoc}
331     */
332    public String getJavaClass() {
333      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
334    }
335
336
337
338    /**
339     * {@inheritDoc}
340     */
341    public void setJavaClass(String value) {
342      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
343    }
344
345
346
347    /**
348     * {@inheritDoc}
349     */
350    public WritabilityMode getWritabilityMode() {
351      return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
352    }
353
354
355
356    /**
357     * {@inheritDoc}
358     */
359    public void setWritabilityMode(WritabilityMode value) {
360      impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value);
361    }
362
363
364
365    /**
366     * {@inheritDoc}
367     */
368    public ManagedObjectDefinition<? extends ConfigFileHandlerBackendCfgClient, ? extends ConfigFileHandlerBackendCfg> definition() {
369      return INSTANCE;
370    }
371
372
373
374    /**
375     * {@inheritDoc}
376     */
377    public PropertyProvider properties() {
378      return impl;
379    }
380
381
382
383    /**
384     * {@inheritDoc}
385     */
386    public void commit() throws ManagedObjectAlreadyExistsException,
387        MissingMandatoryPropertiesException, ConcurrentModificationException,
388        OperationRejectedException, AuthorizationException,
389        CommunicationException {
390      impl.commit();
391    }
392
393
394
395    /** {@inheritDoc} */
396    public String toString() {
397      return impl.toString();
398    }
399  }
400
401
402
403  /**
404   * Managed object server implementation.
405   */
406  private static class ConfigFileHandlerBackendCfgServerImpl implements
407    ConfigFileHandlerBackendCfg {
408
409    // Private implementation.
410    private ServerManagedObject<? extends ConfigFileHandlerBackendCfg> impl;
411
412    // The value of the "backend-id" property.
413    private final String pBackendId;
414
415    // The value of the "base-dn" property.
416    private final SortedSet<DN> pBaseDN;
417
418    // The value of the "enabled" property.
419    private final boolean pEnabled;
420
421    // The value of the "java-class" property.
422    private final String pJavaClass;
423
424    // The value of the "writability-mode" property.
425    private final WritabilityMode pWritabilityMode;
426
427
428
429    // Private constructor.
430    private ConfigFileHandlerBackendCfgServerImpl(ServerManagedObject<? extends ConfigFileHandlerBackendCfg> impl) {
431      this.impl = impl;
432      this.pBackendId = impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
433      this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
434      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
435      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
436      this.pWritabilityMode = impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
437    }
438
439
440
441    /**
442     * {@inheritDoc}
443     */
444    public void addConfigFileHandlerChangeListener(
445        ConfigurationChangeListener<ConfigFileHandlerBackendCfg> listener) {
446      impl.registerChangeListener(listener);
447    }
448
449
450
451    /**
452     * {@inheritDoc}
453     */
454    public void removeConfigFileHandlerChangeListener(
455        ConfigurationChangeListener<ConfigFileHandlerBackendCfg> listener) {
456      impl.deregisterChangeListener(listener);
457    }
458    /**
459     * {@inheritDoc}
460     */
461    public void addChangeListener(
462        ConfigurationChangeListener<BackendCfg> listener) {
463      impl.registerChangeListener(listener);
464    }
465
466
467
468    /**
469     * {@inheritDoc}
470     */
471    public void removeChangeListener(
472        ConfigurationChangeListener<BackendCfg> listener) {
473      impl.deregisterChangeListener(listener);
474    }
475
476
477
478    /**
479     * {@inheritDoc}
480     */
481    public String getBackendId() {
482      return pBackendId;
483    }
484
485
486
487    /**
488     * {@inheritDoc}
489     */
490    public SortedSet<DN> getBaseDN() {
491      return pBaseDN;
492    }
493
494
495
496    /**
497     * {@inheritDoc}
498     */
499    public boolean isEnabled() {
500      return pEnabled;
501    }
502
503
504
505    /**
506     * {@inheritDoc}
507     */
508    public String getJavaClass() {
509      return pJavaClass;
510    }
511
512
513
514    /**
515     * {@inheritDoc}
516     */
517    public WritabilityMode getWritabilityMode() {
518      return pWritabilityMode;
519    }
520
521
522
523    /**
524     * {@inheritDoc}
525     */
526    public Class<? extends ConfigFileHandlerBackendCfg> configurationClass() {
527      return ConfigFileHandlerBackendCfg.class;
528    }
529
530
531
532    /**
533     * {@inheritDoc}
534     */
535    public DN dn() {
536      return impl.getDN();
537    }
538
539
540
541    /** {@inheritDoc} */
542    public String toString() {
543      return impl.toString();
544    }
545  }
546}