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  /**
113   * {@inheritDoc}
114   */
115  public LogRetentionPolicyCfgClient createClientConfiguration(
116      ManagedObject<? extends LogRetentionPolicyCfgClient> impl) {
117    return new LogRetentionPolicyCfgClientImpl(impl);
118  }
119
120
121
122  /**
123   * {@inheritDoc}
124   */
125  public LogRetentionPolicyCfg createServerConfiguration(
126      ServerManagedObject<? extends LogRetentionPolicyCfg> impl) {
127    return new LogRetentionPolicyCfgServerImpl(impl);
128  }
129
130
131
132  /**
133   * {@inheritDoc}
134   */
135  public Class<LogRetentionPolicyCfg> getServerConfigurationClass() {
136    return LogRetentionPolicyCfg.class;
137  }
138
139
140
141  /**
142   * Get the "java-class" property definition.
143   * <p>
144   * Specifies the fully-qualified name of the Java class that
145   * provides the Log Retention Policy implementation.
146   *
147   * @return Returns the "java-class" property definition.
148   */
149  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
150    return PD_JAVA_CLASS;
151  }
152
153
154
155  /**
156   * Managed object client implementation.
157   */
158  private static class LogRetentionPolicyCfgClientImpl implements
159    LogRetentionPolicyCfgClient {
160
161    // Private implementation.
162    private ManagedObject<? extends LogRetentionPolicyCfgClient> impl;
163
164
165
166    // Private constructor.
167    private LogRetentionPolicyCfgClientImpl(
168        ManagedObject<? extends LogRetentionPolicyCfgClient> impl) {
169      this.impl = impl;
170    }
171
172
173
174    /**
175     * {@inheritDoc}
176     */
177    public String getJavaClass() {
178      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
179    }
180
181
182
183    /**
184     * {@inheritDoc}
185     */
186    public void setJavaClass(String value) {
187      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
188    }
189
190
191
192    /**
193     * {@inheritDoc}
194     */
195    public ManagedObjectDefinition<? extends LogRetentionPolicyCfgClient, ? extends LogRetentionPolicyCfg> definition() {
196      return INSTANCE;
197    }
198
199
200
201    /**
202     * {@inheritDoc}
203     */
204    public PropertyProvider properties() {
205      return impl;
206    }
207
208
209
210    /**
211     * {@inheritDoc}
212     */
213    public void commit() throws ManagedObjectAlreadyExistsException,
214        MissingMandatoryPropertiesException, ConcurrentModificationException,
215        OperationRejectedException, LdapException {
216      impl.commit();
217    }
218
219  }
220
221
222
223  /**
224   * Managed object server implementation.
225   */
226  private static class LogRetentionPolicyCfgServerImpl implements
227    LogRetentionPolicyCfg {
228
229    // Private implementation.
230    private ServerManagedObject<? extends LogRetentionPolicyCfg> impl;
231
232    // The value of the "java-class" property.
233    private final String pJavaClass;
234
235
236
237    // Private constructor.
238    private LogRetentionPolicyCfgServerImpl(ServerManagedObject<? extends LogRetentionPolicyCfg> impl) {
239      this.impl = impl;
240      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
241    }
242
243
244
245    /**
246     * {@inheritDoc}
247     */
248    public void addChangeListener(
249        ConfigurationChangeListener<LogRetentionPolicyCfg> listener) {
250      impl.registerChangeListener(listener);
251    }
252
253
254
255    /**
256     * {@inheritDoc}
257     */
258    public void removeChangeListener(
259        ConfigurationChangeListener<LogRetentionPolicyCfg> listener) {
260      impl.deregisterChangeListener(listener);
261    }
262
263
264
265    /**
266     * {@inheritDoc}
267     */
268    public String getJavaClass() {
269      return pJavaClass;
270    }
271
272
273
274    /**
275     * {@inheritDoc}
276     */
277    public Class<? extends LogRetentionPolicyCfg> configurationClass() {
278      return LogRetentionPolicyCfg.class;
279    }
280
281
282
283    /**
284     * {@inheritDoc}
285     */
286    public DN dn() {
287      return impl.getDN();
288    }
289
290  }
291}