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