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 org.forgerock.opendj.config.AdministratorAction;
031import org.forgerock.opendj.config.ClassPropertyDefinition;
032import org.forgerock.opendj.config.client.ConcurrentModificationException;
033import org.forgerock.opendj.config.client.ManagedObject;
034import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
035import org.forgerock.opendj.config.client.OperationRejectedException;
036import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
037import org.forgerock.opendj.config.ManagedObjectDefinition;
038import org.forgerock.opendj.config.PropertyOption;
039import org.forgerock.opendj.config.PropertyProvider;
040import org.forgerock.opendj.config.server.ConfigurationChangeListener;
041import org.forgerock.opendj.config.server.ServerManagedObject;
042import org.forgerock.opendj.config.Tag;
043import org.forgerock.opendj.config.TopCfgDefn;
044import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
045import org.forgerock.opendj.ldap.DN;
046import org.forgerock.opendj.ldap.LdapException;
047import org.forgerock.opendj.server.config.client.LogRetentionPolicyCfgClient;
048import org.forgerock.opendj.server.config.server.LogRetentionPolicyCfg;
049
050
051
052/**
053 * An interface for querying the Log Retention Policy managed object
054 * definition meta information.
055 * <p>
056 * Log Retention Policies are used to specify when log files should be
057 * cleaned.
058 */
059public final class LogRetentionPolicyCfgDefn extends ManagedObjectDefinition<LogRetentionPolicyCfgClient, LogRetentionPolicyCfg> {
060
061  /** The singleton configuration definition instance. */
062  private static final LogRetentionPolicyCfgDefn INSTANCE = new LogRetentionPolicyCfgDefn();
063
064
065
066  /** The "java-class" property definition. */
067  private static final ClassPropertyDefinition PD_JAVA_CLASS;
068
069
070
071  /** Build the "java-class" property definition. */
072  static {
073      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
074      builder.setOption(PropertyOption.MANDATORY);
075      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
076      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
077      builder.addInstanceOf("org.opends.server.loggers.RetentionPolicy");
078      PD_JAVA_CLASS = builder.getInstance();
079      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
080  }
081
082
083
084  // Register the tags associated with this managed object definition.
085  static {
086    INSTANCE.registerTag(Tag.valueOf("logging"));
087  }
088
089
090
091  /**
092   * Get the Log Retention Policy configuration definition singleton.
093   *
094   * @return Returns the Log Retention Policy configuration definition
095   *         singleton.
096   */
097  public static LogRetentionPolicyCfgDefn getInstance() {
098    return INSTANCE;
099  }
100
101
102
103  /**
104   * Private constructor.
105   */
106  private LogRetentionPolicyCfgDefn() {
107    super("log-retention-policy", TopCfgDefn.getInstance());
108  }
109
110
111
112  /** {@inheritDoc} */
113  public LogRetentionPolicyCfgClient createClientConfiguration(
114      ManagedObject<? extends LogRetentionPolicyCfgClient> impl) {
115    return new LogRetentionPolicyCfgClientImpl(impl);
116  }
117
118
119
120  /** {@inheritDoc} */
121  public LogRetentionPolicyCfg createServerConfiguration(
122      ServerManagedObject<? extends LogRetentionPolicyCfg> impl) {
123    return new LogRetentionPolicyCfgServerImpl(impl);
124  }
125
126
127
128  /** {@inheritDoc} */
129  public Class<LogRetentionPolicyCfg> getServerConfigurationClass() {
130    return LogRetentionPolicyCfg.class;
131  }
132
133
134
135  /**
136   * Get the "java-class" property definition.
137   * <p>
138   * Specifies the fully-qualified name of the Java class that
139   * provides the Log Retention Policy implementation.
140   *
141   * @return Returns the "java-class" property definition.
142   */
143  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
144    return PD_JAVA_CLASS;
145  }
146
147
148
149  /**
150   * Managed object client implementation.
151   */
152  private static class LogRetentionPolicyCfgClientImpl implements
153    LogRetentionPolicyCfgClient {
154
155    /** Private implementation. */
156    private ManagedObject<? extends LogRetentionPolicyCfgClient> impl;
157
158
159
160    /** Private constructor. */
161    private LogRetentionPolicyCfgClientImpl(
162        ManagedObject<? extends LogRetentionPolicyCfgClient> impl) {
163      this.impl = impl;
164    }
165
166
167
168    /** {@inheritDoc} */
169    public String getJavaClass() {
170      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
171    }
172
173
174
175    /** {@inheritDoc} */
176    public void setJavaClass(String value) {
177      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
178    }
179
180
181
182    /** {@inheritDoc} */
183    public ManagedObjectDefinition<? extends LogRetentionPolicyCfgClient, ? extends LogRetentionPolicyCfg> definition() {
184      return INSTANCE;
185    }
186
187
188
189    /** {@inheritDoc} */
190    public PropertyProvider properties() {
191      return impl;
192    }
193
194
195
196    /** {@inheritDoc} */
197    public void commit() throws ManagedObjectAlreadyExistsException,
198        MissingMandatoryPropertiesException, ConcurrentModificationException,
199        OperationRejectedException, LdapException {
200      impl.commit();
201    }
202
203
204
205    /** {@inheritDoc} */
206    public String toString() {
207      return impl.toString();
208    }
209  }
210
211
212
213  /**
214   * Managed object server implementation.
215   */
216  private static class LogRetentionPolicyCfgServerImpl implements
217    LogRetentionPolicyCfg {
218
219    /** Private implementation. */
220    private ServerManagedObject<? extends LogRetentionPolicyCfg> impl;
221
222    /** The value of the "java-class" property. */
223    private final String pJavaClass;
224
225
226
227    /** Private constructor. */
228    private LogRetentionPolicyCfgServerImpl(ServerManagedObject<? extends LogRetentionPolicyCfg> impl) {
229      this.impl = impl;
230      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
231    }
232
233
234
235    /** {@inheritDoc} */
236    public void addChangeListener(
237        ConfigurationChangeListener<LogRetentionPolicyCfg> listener) {
238      impl.registerChangeListener(listener);
239    }
240
241
242
243    /** {@inheritDoc} */
244    public void removeChangeListener(
245        ConfigurationChangeListener<LogRetentionPolicyCfg> listener) {
246      impl.deregisterChangeListener(listener);
247    }
248
249
250
251    /** {@inheritDoc} */
252    public String getJavaClass() {
253      return pJavaClass;
254    }
255
256
257
258    /** {@inheritDoc} */
259    public Class<? extends LogRetentionPolicyCfg> configurationClass() {
260      return LogRetentionPolicyCfg.class;
261    }
262
263
264
265    /** {@inheritDoc} */
266    public DN dn() {
267      return impl.getDN();
268    }
269
270
271
272    /** {@inheritDoc} */
273    public String toString() {
274      return impl.toString();
275    }
276  }
277}