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