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