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