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 /** {@inheritDoc} */ 281 public String toString() { 282 return impl.toString(); 283 } 284 } 285 286 287 288 /** 289 * Managed object server implementation. 290 */ 291 private static class FixedTimeLogRotationPolicyCfgServerImpl implements 292 FixedTimeLogRotationPolicyCfg { 293 294 // Private implementation. 295 private ServerManagedObject<? extends FixedTimeLogRotationPolicyCfg> impl; 296 297 // The value of the "java-class" property. 298 private final String pJavaClass; 299 300 // The value of the "time-of-day" property. 301 private final SortedSet<String> pTimeOfDay; 302 303 304 305 // Private constructor. 306 private FixedTimeLogRotationPolicyCfgServerImpl(ServerManagedObject<? extends FixedTimeLogRotationPolicyCfg> impl) { 307 this.impl = impl; 308 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 309 this.pTimeOfDay = impl.getPropertyValues(INSTANCE.getTimeOfDayPropertyDefinition()); 310 } 311 312 313 314 /** 315 * {@inheritDoc} 316 */ 317 public void addFixedTimeChangeListener( 318 ConfigurationChangeListener<FixedTimeLogRotationPolicyCfg> listener) { 319 impl.registerChangeListener(listener); 320 } 321 322 323 324 /** 325 * {@inheritDoc} 326 */ 327 public void removeFixedTimeChangeListener( 328 ConfigurationChangeListener<FixedTimeLogRotationPolicyCfg> listener) { 329 impl.deregisterChangeListener(listener); 330 } 331 /** 332 * {@inheritDoc} 333 */ 334 public void addChangeListener( 335 ConfigurationChangeListener<LogRotationPolicyCfg> listener) { 336 impl.registerChangeListener(listener); 337 } 338 339 340 341 /** 342 * {@inheritDoc} 343 */ 344 public void removeChangeListener( 345 ConfigurationChangeListener<LogRotationPolicyCfg> listener) { 346 impl.deregisterChangeListener(listener); 347 } 348 349 350 351 /** 352 * {@inheritDoc} 353 */ 354 public String getJavaClass() { 355 return pJavaClass; 356 } 357 358 359 360 /** 361 * {@inheritDoc} 362 */ 363 public SortedSet<String> getTimeOfDay() { 364 return pTimeOfDay; 365 } 366 367 368 369 /** 370 * {@inheritDoc} 371 */ 372 public Class<? extends FixedTimeLogRotationPolicyCfg> configurationClass() { 373 return FixedTimeLogRotationPolicyCfg.class; 374 } 375 376 377 378 /** 379 * {@inheritDoc} 380 */ 381 public DN dn() { 382 return impl.getDN(); 383 } 384 385 386 387 /** {@inheritDoc} */ 388 public String toString() { 389 return impl.toString(); 390 } 391 } 392}