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