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.forgerock.opendj.server.config.meta;
017
018
019
020import java.util.Collection;
021import java.util.SortedSet;
022import org.forgerock.opendj.config.AdministratorAction;
023import org.forgerock.opendj.config.AliasDefaultBehaviorProvider;
024import org.forgerock.opendj.config.BooleanPropertyDefinition;
025import org.forgerock.opendj.config.ClassPropertyDefinition;
026import org.forgerock.opendj.config.client.ConcurrentModificationException;
027import org.forgerock.opendj.config.client.ManagedObject;
028import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
029import org.forgerock.opendj.config.client.OperationRejectedException;
030import org.forgerock.opendj.config.DefaultBehaviorProvider;
031import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
032import org.forgerock.opendj.config.EnumPropertyDefinition;
033import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
034import org.forgerock.opendj.config.ManagedObjectDefinition;
035import org.forgerock.opendj.config.PropertyOption;
036import org.forgerock.opendj.config.PropertyProvider;
037import org.forgerock.opendj.config.server.ConfigurationChangeListener;
038import org.forgerock.opendj.config.server.ServerManagedObject;
039import org.forgerock.opendj.config.StringPropertyDefinition;
040import org.forgerock.opendj.config.Tag;
041import org.forgerock.opendj.ldap.DN;
042import org.forgerock.opendj.ldap.LdapException;
043import org.forgerock.opendj.server.config.client.ErrorLogPublisherCfgClient;
044import org.forgerock.opendj.server.config.server.ErrorLogPublisherCfg;
045import org.forgerock.opendj.server.config.server.LogPublisherCfg;
046
047
048
049/**
050 * An interface for querying the Error Log Publisher managed object
051 * definition meta information.
052 * <p>
053 * Error Log Publishers are responsible for distributing error log
054 * messages from the error logger to a destination.
055 */
056public final class ErrorLogPublisherCfgDefn extends ManagedObjectDefinition<ErrorLogPublisherCfgClient, ErrorLogPublisherCfg> {
057
058  /** The singleton configuration definition instance. */
059  private static final ErrorLogPublisherCfgDefn INSTANCE = new ErrorLogPublisherCfgDefn();
060
061
062
063  /**
064   * Defines the set of permissable values for the "default-severity" property.
065   * <p>
066   * Specifies the default severity levels for the logger.
067   */
068  public static enum DefaultSeverity {
069
070    /**
071     * Messages of all severity levels are logged.
072     */
073    ALL("all"),
074
075
076
077    /**
078     * The error log severity that is used for messages that provide
079     * debugging information triggered during processing.
080     */
081    DEBUG("debug"),
082
083
084
085    /**
086     * The error log severity that is used for messages that provide
087     * information about errors which may force the server to shut down
088     * or operate in a significantly degraded state.
089     */
090    ERROR("error"),
091
092
093
094    /**
095     * The error log severity that is used for messages that provide
096     * information about significant events within the server that are
097     * not warnings or errors.
098     */
099    INFO("info"),
100
101
102
103    /**
104     * No messages of any severity are logged by default. This value
105     * is intended to be used in conjunction with the override-severity
106     * property to define an error logger that will publish no error
107     * message beside the errors of a given category.
108     */
109    NONE("none"),
110
111
112
113    /**
114     * The error log severity that is used for the most important
115     * informational messages (i.e., information that should almost
116     * always be logged but is not associated with a warning or error
117     * condition).
118     */
119    NOTICE("notice"),
120
121
122
123    /**
124     * The error log severity that is used for messages that provide
125     * information about warnings triggered during processing.
126     */
127    WARNING("warning");
128
129
130
131    /** String representation of the value. */
132    private final String name;
133
134
135
136    /** Private constructor. */
137    private DefaultSeverity(String name) { this.name = name; }
138
139
140
141    /** {@inheritDoc} */
142    public String toString() { return name; }
143
144  }
145
146
147
148  /** The "default-severity" property definition. */
149  private static final EnumPropertyDefinition<DefaultSeverity> PD_DEFAULT_SEVERITY;
150
151
152
153  /** The "java-class" property definition. */
154  private static final ClassPropertyDefinition PD_JAVA_CLASS;
155
156
157
158  /** The "override-severity" property definition. */
159  private static final StringPropertyDefinition PD_OVERRIDE_SEVERITY;
160
161
162
163  /** Build the "default-severity" property definition. */
164  static {
165      EnumPropertyDefinition.Builder<DefaultSeverity> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "default-severity");
166      builder.setOption(PropertyOption.MULTI_VALUED);
167      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "default-severity"));
168      DefaultBehaviorProvider<DefaultSeverity> provider = new DefinedDefaultBehaviorProvider<DefaultSeverity>("error", "warning");
169      builder.setDefaultBehaviorProvider(provider);
170      builder.setEnumClass(DefaultSeverity.class);
171      PD_DEFAULT_SEVERITY = builder.getInstance();
172      INSTANCE.registerPropertyDefinition(PD_DEFAULT_SEVERITY);
173  }
174
175
176
177  /** Build the "java-class" property definition. */
178  static {
179      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
180      builder.setOption(PropertyOption.MANDATORY);
181      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
182      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.loggers.ErrorLogPublisher");
183      builder.setDefaultBehaviorProvider(provider);
184      builder.addInstanceOf("org.opends.server.loggers.LogPublisher");
185      PD_JAVA_CLASS = builder.getInstance();
186      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
187  }
188
189
190
191  /** Build the "override-severity" property definition. */
192  static {
193      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "override-severity");
194      builder.setOption(PropertyOption.MULTI_VALUED);
195      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "override-severity"));
196      builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "override-severity"));
197      builder.setPattern(".*", "STRING");
198      PD_OVERRIDE_SEVERITY = builder.getInstance();
199      INSTANCE.registerPropertyDefinition(PD_OVERRIDE_SEVERITY);
200  }
201
202
203
204  // Register the tags associated with this managed object definition.
205  static {
206    INSTANCE.registerTag(Tag.valueOf("logging"));
207  }
208
209
210
211  /**
212   * Get the Error Log Publisher configuration definition singleton.
213   *
214   * @return Returns the Error Log Publisher configuration definition
215   *         singleton.
216   */
217  public static ErrorLogPublisherCfgDefn getInstance() {
218    return INSTANCE;
219  }
220
221
222
223  /**
224   * Private constructor.
225   */
226  private ErrorLogPublisherCfgDefn() {
227    super("error-log-publisher", LogPublisherCfgDefn.getInstance());
228  }
229
230
231
232  /** {@inheritDoc} */
233  public ErrorLogPublisherCfgClient createClientConfiguration(
234      ManagedObject<? extends ErrorLogPublisherCfgClient> impl) {
235    return new ErrorLogPublisherCfgClientImpl(impl);
236  }
237
238
239
240  /** {@inheritDoc} */
241  public ErrorLogPublisherCfg createServerConfiguration(
242      ServerManagedObject<? extends ErrorLogPublisherCfg> impl) {
243    return new ErrorLogPublisherCfgServerImpl(impl);
244  }
245
246
247
248  /** {@inheritDoc} */
249  public Class<ErrorLogPublisherCfg> getServerConfigurationClass() {
250    return ErrorLogPublisherCfg.class;
251  }
252
253
254
255  /**
256   * Get the "default-severity" property definition.
257   * <p>
258   * Specifies the default severity levels for the logger.
259   *
260   * @return Returns the "default-severity" property definition.
261   */
262  public EnumPropertyDefinition<DefaultSeverity> getDefaultSeverityPropertyDefinition() {
263    return PD_DEFAULT_SEVERITY;
264  }
265
266
267
268  /**
269   * Get the "enabled" property definition.
270   * <p>
271   * Indicates whether the Error Log Publisher is enabled for use.
272   *
273   * @return Returns the "enabled" property definition.
274   */
275  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
276    return LogPublisherCfgDefn.getInstance().getEnabledPropertyDefinition();
277  }
278
279
280
281  /**
282   * Get the "java-class" property definition.
283   * <p>
284   * The fully-qualified name of the Java class that provides the
285   * Error Log Publisher implementation.
286   *
287   * @return Returns the "java-class" property definition.
288   */
289  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
290    return PD_JAVA_CLASS;
291  }
292
293
294
295  /**
296   * Get the "override-severity" property definition.
297   * <p>
298   * Specifies the override severity levels for the logger based on
299   * the category of the messages.
300   * <p>
301   * Each override severity level should include the category and the
302   * severity levels to log for that category, for example,
303   * core=error,info,warning. Valid categories are: core, extensions,
304   * protocol, config, log, util, schema, plugin, jeb, backend, tools,
305   * task, access-control, admin, sync, version, quicksetup,
306   * admin-tool, dsconfig, user-defined. Valid severities are: all,
307   * error, info, warning, notice, debug.
308   *
309   * @return Returns the "override-severity" property definition.
310   */
311  public StringPropertyDefinition getOverrideSeverityPropertyDefinition() {
312    return PD_OVERRIDE_SEVERITY;
313  }
314
315
316
317  /**
318   * Managed object client implementation.
319   */
320  private static class ErrorLogPublisherCfgClientImpl implements
321    ErrorLogPublisherCfgClient {
322
323    /** Private implementation. */
324    private ManagedObject<? extends ErrorLogPublisherCfgClient> impl;
325
326
327
328    /** Private constructor. */
329    private ErrorLogPublisherCfgClientImpl(
330        ManagedObject<? extends ErrorLogPublisherCfgClient> impl) {
331      this.impl = impl;
332    }
333
334
335
336    /** {@inheritDoc} */
337    public SortedSet<DefaultSeverity> getDefaultSeverity() {
338      return impl.getPropertyValues(INSTANCE.getDefaultSeverityPropertyDefinition());
339    }
340
341
342
343    /** {@inheritDoc} */
344    public void setDefaultSeverity(Collection<DefaultSeverity> values) {
345      impl.setPropertyValues(INSTANCE.getDefaultSeverityPropertyDefinition(), values);
346    }
347
348
349
350    /** {@inheritDoc} */
351    public Boolean isEnabled() {
352      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
353    }
354
355
356
357    /** {@inheritDoc} */
358    public void setEnabled(boolean value) {
359      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
360    }
361
362
363
364    /** {@inheritDoc} */
365    public String getJavaClass() {
366      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
367    }
368
369
370
371    /** {@inheritDoc} */
372    public void setJavaClass(String value) {
373      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
374    }
375
376
377
378    /** {@inheritDoc} */
379    public SortedSet<String> getOverrideSeverity() {
380      return impl.getPropertyValues(INSTANCE.getOverrideSeverityPropertyDefinition());
381    }
382
383
384
385    /** {@inheritDoc} */
386    public void setOverrideSeverity(Collection<String> values) {
387      impl.setPropertyValues(INSTANCE.getOverrideSeverityPropertyDefinition(), values);
388    }
389
390
391
392    /** {@inheritDoc} */
393    public ManagedObjectDefinition<? extends ErrorLogPublisherCfgClient, ? extends ErrorLogPublisherCfg> definition() {
394      return INSTANCE;
395    }
396
397
398
399    /** {@inheritDoc} */
400    public PropertyProvider properties() {
401      return impl;
402    }
403
404
405
406    /** {@inheritDoc} */
407    public void commit() throws ManagedObjectAlreadyExistsException,
408        MissingMandatoryPropertiesException, ConcurrentModificationException,
409        OperationRejectedException, LdapException {
410      impl.commit();
411    }
412
413
414
415    /** {@inheritDoc} */
416    public String toString() {
417      return impl.toString();
418    }
419  }
420
421
422
423  /**
424   * Managed object server implementation.
425   */
426  private static class ErrorLogPublisherCfgServerImpl implements
427    ErrorLogPublisherCfg {
428
429    /** Private implementation. */
430    private ServerManagedObject<? extends ErrorLogPublisherCfg> impl;
431
432    /** The value of the "default-severity" property. */
433    private final SortedSet<DefaultSeverity> pDefaultSeverity;
434
435    /** The value of the "enabled" property. */
436    private final boolean pEnabled;
437
438    /** The value of the "java-class" property. */
439    private final String pJavaClass;
440
441    /** The value of the "override-severity" property. */
442    private final SortedSet<String> pOverrideSeverity;
443
444
445
446    /** Private constructor. */
447    private ErrorLogPublisherCfgServerImpl(ServerManagedObject<? extends ErrorLogPublisherCfg> impl) {
448      this.impl = impl;
449      this.pDefaultSeverity = impl.getPropertyValues(INSTANCE.getDefaultSeverityPropertyDefinition());
450      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
451      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
452      this.pOverrideSeverity = impl.getPropertyValues(INSTANCE.getOverrideSeverityPropertyDefinition());
453    }
454
455
456
457    /** {@inheritDoc} */
458    public void addErrorChangeListener(
459        ConfigurationChangeListener<ErrorLogPublisherCfg> listener) {
460      impl.registerChangeListener(listener);
461    }
462
463
464
465    /** {@inheritDoc} */
466    public void removeErrorChangeListener(
467        ConfigurationChangeListener<ErrorLogPublisherCfg> listener) {
468      impl.deregisterChangeListener(listener);
469    }
470    /** {@inheritDoc} */
471    public void addChangeListener(
472        ConfigurationChangeListener<LogPublisherCfg> listener) {
473      impl.registerChangeListener(listener);
474    }
475
476
477
478    /** {@inheritDoc} */
479    public void removeChangeListener(
480        ConfigurationChangeListener<LogPublisherCfg> listener) {
481      impl.deregisterChangeListener(listener);
482    }
483
484
485
486    /** {@inheritDoc} */
487    public SortedSet<DefaultSeverity> getDefaultSeverity() {
488      return pDefaultSeverity;
489    }
490
491
492
493    /** {@inheritDoc} */
494    public boolean isEnabled() {
495      return pEnabled;
496    }
497
498
499
500    /** {@inheritDoc} */
501    public String getJavaClass() {
502      return pJavaClass;
503    }
504
505
506
507    /** {@inheritDoc} */
508    public SortedSet<String> getOverrideSeverity() {
509      return pOverrideSeverity;
510    }
511
512
513
514    /** {@inheritDoc} */
515    public Class<? extends ErrorLogPublisherCfg> configurationClass() {
516      return ErrorLogPublisherCfg.class;
517    }
518
519
520
521    /** {@inheritDoc} */
522    public DN dn() {
523      return impl.getDN();
524    }
525
526
527
528    /** {@inheritDoc} */
529    public String toString() {
530      return impl.toString();
531    }
532  }
533}