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