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