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 java.util.Collection;
031import java.util.SortedSet;
032import org.opends.server.admin.AdministratorAction;
033import org.opends.server.admin.ClassPropertyDefinition;
034import org.opends.server.admin.client.AuthorizationException;
035import org.opends.server.admin.client.CommunicationException;
036import org.opends.server.admin.client.ConcurrentModificationException;
037import org.opends.server.admin.client.ManagedObject;
038import org.opends.server.admin.client.MissingMandatoryPropertiesException;
039import org.opends.server.admin.client.OperationRejectedException;
040import org.opends.server.admin.DefaultBehaviorProvider;
041import org.opends.server.admin.DefinedDefaultBehaviorProvider;
042import org.opends.server.admin.ManagedObjectAlreadyExistsException;
043import org.opends.server.admin.ManagedObjectDefinition;
044import org.opends.server.admin.PropertyOption;
045import org.opends.server.admin.PropertyProvider;
046import org.opends.server.admin.server.ConfigurationChangeListener;
047import org.opends.server.admin.server.ServerManagedObject;
048import org.opends.server.admin.std.client.FixedTimeLogRotationPolicyCfgClient;
049import org.opends.server.admin.std.server.FixedTimeLogRotationPolicyCfg;
050import org.opends.server.admin.std.server.LogRotationPolicyCfg;
051import org.opends.server.admin.StringPropertyDefinition;
052import org.opends.server.admin.Tag;
053import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
054import org.opends.server.types.DN;
055
056
057
058/**
059 * An interface for querying the Fixed Time Log Rotation Policy
060 * managed object definition meta information.
061 * <p>
062 * Rotation policy based on a fixed time of day.
063 */
064public final class FixedTimeLogRotationPolicyCfgDefn extends ManagedObjectDefinition<FixedTimeLogRotationPolicyCfgClient, FixedTimeLogRotationPolicyCfg> {
065
066  // The singleton configuration definition instance.
067  private static final FixedTimeLogRotationPolicyCfgDefn INSTANCE = new FixedTimeLogRotationPolicyCfgDefn();
068
069
070
071  // The "java-class" property definition.
072  private static final ClassPropertyDefinition PD_JAVA_CLASS;
073
074
075
076  // The "time-of-day" property definition.
077  private static final StringPropertyDefinition PD_TIME_OF_DAY;
078
079
080
081  // Build the "java-class" property definition.
082  static {
083      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
084      builder.setOption(PropertyOption.MANDATORY);
085      builder.setOption(PropertyOption.ADVANCED);
086      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
087      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.loggers.FixedTimeRotationPolicy");
088      builder.setDefaultBehaviorProvider(provider);
089      builder.addInstanceOf("org.opends.server.loggers.RotationPolicy");
090      PD_JAVA_CLASS = builder.getInstance();
091      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
092  }
093
094
095
096  // Build the "time-of-day" property definition.
097  static {
098      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "time-of-day");
099      builder.setOption(PropertyOption.MULTI_VALUED);
100      builder.setOption(PropertyOption.MANDATORY);
101      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "time-of-day"));
102      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
103      builder.setPattern("^(([0-1][0-9])|([2][0-3]))([0-5][0-9])$", "HHmm");
104      PD_TIME_OF_DAY = builder.getInstance();
105      INSTANCE.registerPropertyDefinition(PD_TIME_OF_DAY);
106  }
107
108
109
110  // Register the tags associated with this managed object definition.
111  static {
112    INSTANCE.registerTag(Tag.valueOf("logging"));
113  }
114
115
116
117  /**
118   * Get the Fixed Time Log Rotation Policy configuration definition
119   * singleton.
120   *
121   * @return Returns the Fixed Time Log Rotation Policy configuration
122   *         definition singleton.
123   */
124  public static FixedTimeLogRotationPolicyCfgDefn getInstance() {
125    return INSTANCE;
126  }
127
128
129
130  /**
131   * Private constructor.
132   */
133  private FixedTimeLogRotationPolicyCfgDefn() {
134    super("fixed-time-log-rotation-policy", LogRotationPolicyCfgDefn.getInstance());
135  }
136
137
138
139  /**
140   * {@inheritDoc}
141   */
142  public FixedTimeLogRotationPolicyCfgClient createClientConfiguration(
143      ManagedObject<? extends FixedTimeLogRotationPolicyCfgClient> impl) {
144    return new FixedTimeLogRotationPolicyCfgClientImpl(impl);
145  }
146
147
148
149  /**
150   * {@inheritDoc}
151   */
152  public FixedTimeLogRotationPolicyCfg createServerConfiguration(
153      ServerManagedObject<? extends FixedTimeLogRotationPolicyCfg> impl) {
154    return new FixedTimeLogRotationPolicyCfgServerImpl(impl);
155  }
156
157
158
159  /**
160   * {@inheritDoc}
161   */
162  public Class<FixedTimeLogRotationPolicyCfg> getServerConfigurationClass() {
163    return FixedTimeLogRotationPolicyCfg.class;
164  }
165
166
167
168  /**
169   * Get the "java-class" property definition.
170   * <p>
171   * Specifies the fully-qualified name of the Java class that
172   * provides the Fixed Time Log Rotation Policy implementation.
173   *
174   * @return Returns the "java-class" property definition.
175   */
176  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
177    return PD_JAVA_CLASS;
178  }
179
180
181
182  /**
183   * Get the "time-of-day" property definition.
184   * <p>
185   * Specifies the time of day at which log rotation should occur.
186   *
187   * @return Returns the "time-of-day" property definition.
188   */
189  public StringPropertyDefinition getTimeOfDayPropertyDefinition() {
190    return PD_TIME_OF_DAY;
191  }
192
193
194
195  /**
196   * Managed object client implementation.
197   */
198  private static class FixedTimeLogRotationPolicyCfgClientImpl implements
199    FixedTimeLogRotationPolicyCfgClient {
200
201    // Private implementation.
202    private ManagedObject<? extends FixedTimeLogRotationPolicyCfgClient> impl;
203
204
205
206    // Private constructor.
207    private FixedTimeLogRotationPolicyCfgClientImpl(
208        ManagedObject<? extends FixedTimeLogRotationPolicyCfgClient> impl) {
209      this.impl = impl;
210    }
211
212
213
214    /**
215     * {@inheritDoc}
216     */
217    public String getJavaClass() {
218      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
219    }
220
221
222
223    /**
224     * {@inheritDoc}
225     */
226    public void setJavaClass(String value) {
227      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
228    }
229
230
231
232    /**
233     * {@inheritDoc}
234     */
235    public SortedSet<String> getTimeOfDay() {
236      return impl.getPropertyValues(INSTANCE.getTimeOfDayPropertyDefinition());
237    }
238
239
240
241    /**
242     * {@inheritDoc}
243     */
244    public void setTimeOfDay(Collection<String> values) {
245      impl.setPropertyValues(INSTANCE.getTimeOfDayPropertyDefinition(), values);
246    }
247
248
249
250    /**
251     * {@inheritDoc}
252     */
253    public ManagedObjectDefinition<? extends FixedTimeLogRotationPolicyCfgClient, ? extends FixedTimeLogRotationPolicyCfg> definition() {
254      return INSTANCE;
255    }
256
257
258
259    /**
260     * {@inheritDoc}
261     */
262    public PropertyProvider properties() {
263      return impl;
264    }
265
266
267
268    /**
269     * {@inheritDoc}
270     */
271    public void commit() throws ManagedObjectAlreadyExistsException,
272        MissingMandatoryPropertiesException, ConcurrentModificationException,
273        OperationRejectedException, AuthorizationException,
274        CommunicationException {
275      impl.commit();
276    }
277
278  }
279
280
281
282  /**
283   * Managed object server implementation.
284   */
285  private static class FixedTimeLogRotationPolicyCfgServerImpl implements
286    FixedTimeLogRotationPolicyCfg {
287
288    // Private implementation.
289    private ServerManagedObject<? extends FixedTimeLogRotationPolicyCfg> impl;
290
291    // The value of the "java-class" property.
292    private final String pJavaClass;
293
294    // The value of the "time-of-day" property.
295    private final SortedSet<String> pTimeOfDay;
296
297
298
299    // Private constructor.
300    private FixedTimeLogRotationPolicyCfgServerImpl(ServerManagedObject<? extends FixedTimeLogRotationPolicyCfg> impl) {
301      this.impl = impl;
302      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
303      this.pTimeOfDay = impl.getPropertyValues(INSTANCE.getTimeOfDayPropertyDefinition());
304    }
305
306
307
308    /**
309     * {@inheritDoc}
310     */
311    public void addFixedTimeChangeListener(
312        ConfigurationChangeListener<FixedTimeLogRotationPolicyCfg> listener) {
313      impl.registerChangeListener(listener);
314    }
315
316
317
318    /**
319     * {@inheritDoc}
320     */
321    public void removeFixedTimeChangeListener(
322        ConfigurationChangeListener<FixedTimeLogRotationPolicyCfg> listener) {
323      impl.deregisterChangeListener(listener);
324    }
325    /**
326     * {@inheritDoc}
327     */
328    public void addChangeListener(
329        ConfigurationChangeListener<LogRotationPolicyCfg> listener) {
330      impl.registerChangeListener(listener);
331    }
332
333
334
335    /**
336     * {@inheritDoc}
337     */
338    public void removeChangeListener(
339        ConfigurationChangeListener<LogRotationPolicyCfg> listener) {
340      impl.deregisterChangeListener(listener);
341    }
342
343
344
345    /**
346     * {@inheritDoc}
347     */
348    public String getJavaClass() {
349      return pJavaClass;
350    }
351
352
353
354    /**
355     * {@inheritDoc}
356     */
357    public SortedSet<String> getTimeOfDay() {
358      return pTimeOfDay;
359    }
360
361
362
363    /**
364     * {@inheritDoc}
365     */
366    public Class<? extends FixedTimeLogRotationPolicyCfg> configurationClass() {
367      return FixedTimeLogRotationPolicyCfg.class;
368    }
369
370
371
372    /**
373     * {@inheritDoc}
374     */
375    public DN dn() {
376      return impl.getDN();
377    }
378
379  }
380}