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