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 org.opends.server.admin.AdministratorAction; 032 import org.opends.server.admin.ClassPropertyDefinition; 033 import org.opends.server.admin.client.AuthorizationException; 034 import org.opends.server.admin.client.CommunicationException; 035 import org.opends.server.admin.client.ConcurrentModificationException; 036 import org.opends.server.admin.client.ManagedObject; 037 import org.opends.server.admin.client.MissingMandatoryPropertiesException; 038 import org.opends.server.admin.client.OperationRejectedException; 039 import org.opends.server.admin.ManagedObjectAlreadyExistsException; 040 import org.opends.server.admin.ManagedObjectDefinition; 041 import org.opends.server.admin.PropertyOption; 042 import org.opends.server.admin.PropertyProvider; 043 import org.opends.server.admin.server.ConfigurationChangeListener; 044 import org.opends.server.admin.server.ServerManagedObject; 045 import org.opends.server.admin.std.client.LogRotationPolicyCfgClient; 046 import org.opends.server.admin.std.server.LogRotationPolicyCfg; 047 import org.opends.server.admin.Tag; 048 import org.opends.server.admin.TopCfgDefn; 049 import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 050 import org.opends.server.types.DN; 051 052 053 054 /** 055 * An interface for querying the Log Rotation Policy managed object 056 * definition meta information. 057 * <p> 058 * Log Rotation Policies are used to specify when log files should be 059 * rotated. 060 */ 061 public final class LogRotationPolicyCfgDefn extends ManagedObjectDefinition<LogRotationPolicyCfgClient, LogRotationPolicyCfg> { 062 063 // The singleton configuration definition instance. 064 private static final LogRotationPolicyCfgDefn INSTANCE = new LogRotationPolicyCfgDefn(); 065 066 067 068 // The "java-class" property definition. 069 private static final ClassPropertyDefinition PD_JAVA_CLASS; 070 071 072 073 // Build the "java-class" property definition. 074 static { 075 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 076 builder.setOption(PropertyOption.MANDATORY); 077 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 078 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 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 // Register the tags associated with this managed object definition. 087 static { 088 INSTANCE.registerTag(Tag.valueOf("logging")); 089 } 090 091 092 093 /** 094 * Get the Log Rotation Policy configuration definition singleton. 095 * 096 * @return Returns the Log Rotation Policy configuration definition 097 * singleton. 098 */ 099 public static LogRotationPolicyCfgDefn getInstance() { 100 return INSTANCE; 101 } 102 103 104 105 /** 106 * Private constructor. 107 */ 108 private LogRotationPolicyCfgDefn() { 109 super("log-rotation-policy", TopCfgDefn.getInstance()); 110 } 111 112 113 114 /** 115 * {@inheritDoc} 116 */ 117 public LogRotationPolicyCfgClient createClientConfiguration( 118 ManagedObject<? extends LogRotationPolicyCfgClient> impl) { 119 return new LogRotationPolicyCfgClientImpl(impl); 120 } 121 122 123 124 /** 125 * {@inheritDoc} 126 */ 127 public LogRotationPolicyCfg createServerConfiguration( 128 ServerManagedObject<? extends LogRotationPolicyCfg> impl) { 129 return new LogRotationPolicyCfgServerImpl(impl); 130 } 131 132 133 134 /** 135 * {@inheritDoc} 136 */ 137 public Class<LogRotationPolicyCfg> getServerConfigurationClass() { 138 return LogRotationPolicyCfg.class; 139 } 140 141 142 143 /** 144 * Get the "java-class" property definition. 145 * <p> 146 * Specifies the fully-qualified name of the Java class that 147 * provides the Log Rotation Policy implementation. 148 * 149 * @return Returns the "java-class" property definition. 150 */ 151 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 152 return PD_JAVA_CLASS; 153 } 154 155 156 157 /** 158 * Managed object client implementation. 159 */ 160 private static class LogRotationPolicyCfgClientImpl implements 161 LogRotationPolicyCfgClient { 162 163 // Private implementation. 164 private ManagedObject<? extends LogRotationPolicyCfgClient> impl; 165 166 167 168 // Private constructor. 169 private LogRotationPolicyCfgClientImpl( 170 ManagedObject<? extends LogRotationPolicyCfgClient> impl) { 171 this.impl = impl; 172 } 173 174 175 176 /** 177 * {@inheritDoc} 178 */ 179 public String getJavaClass() { 180 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 181 } 182 183 184 185 /** 186 * {@inheritDoc} 187 */ 188 public void setJavaClass(String value) { 189 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 190 } 191 192 193 194 /** 195 * {@inheritDoc} 196 */ 197 public ManagedObjectDefinition<? extends LogRotationPolicyCfgClient, ? extends LogRotationPolicyCfg> definition() { 198 return INSTANCE; 199 } 200 201 202 203 /** 204 * {@inheritDoc} 205 */ 206 public PropertyProvider properties() { 207 return impl; 208 } 209 210 211 212 /** 213 * {@inheritDoc} 214 */ 215 public void commit() throws ManagedObjectAlreadyExistsException, 216 MissingMandatoryPropertiesException, ConcurrentModificationException, 217 OperationRejectedException, AuthorizationException, 218 CommunicationException { 219 impl.commit(); 220 } 221 222 } 223 224 225 226 /** 227 * Managed object server implementation. 228 */ 229 private static class LogRotationPolicyCfgServerImpl implements 230 LogRotationPolicyCfg { 231 232 // Private implementation. 233 private ServerManagedObject<? extends LogRotationPolicyCfg> impl; 234 235 // The value of the "java-class" property. 236 private final String pJavaClass; 237 238 239 240 // Private constructor. 241 private LogRotationPolicyCfgServerImpl(ServerManagedObject<? extends LogRotationPolicyCfg> impl) { 242 this.impl = impl; 243 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 244 } 245 246 247 248 /** 249 * {@inheritDoc} 250 */ 251 public void addChangeListener( 252 ConfigurationChangeListener<LogRotationPolicyCfg> listener) { 253 impl.registerChangeListener(listener); 254 } 255 256 257 258 /** 259 * {@inheritDoc} 260 */ 261 public void removeChangeListener( 262 ConfigurationChangeListener<LogRotationPolicyCfg> listener) { 263 impl.deregisterChangeListener(listener); 264 } 265 266 267 268 /** 269 * {@inheritDoc} 270 */ 271 public String getJavaClass() { 272 return pJavaClass; 273 } 274 275 276 277 /** 278 * {@inheritDoc} 279 */ 280 public Class<? extends LogRotationPolicyCfg> configurationClass() { 281 return LogRotationPolicyCfg.class; 282 } 283 284 285 286 /** 287 * {@inheritDoc} 288 */ 289 public DN dn() { 290 return impl.getDN(); 291 } 292 293 } 294 }