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