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.forgerock.opendj.server.config.meta; 017 018 019 020import org.forgerock.opendj.config.AdministratorAction; 021import org.forgerock.opendj.config.BooleanPropertyDefinition; 022import org.forgerock.opendj.config.ClassPropertyDefinition; 023import org.forgerock.opendj.config.client.ConcurrentModificationException; 024import org.forgerock.opendj.config.client.ManagedObject; 025import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 026import org.forgerock.opendj.config.client.OperationRejectedException; 027import org.forgerock.opendj.config.DefaultBehaviorProvider; 028import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 029import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 030import org.forgerock.opendj.config.ManagedObjectDefinition; 031import org.forgerock.opendj.config.PropertyOption; 032import org.forgerock.opendj.config.PropertyProvider; 033import org.forgerock.opendj.config.server.ConfigurationChangeListener; 034import org.forgerock.opendj.config.server.ServerManagedObject; 035import org.forgerock.opendj.config.Tag; 036import org.forgerock.opendj.ldap.DN; 037import org.forgerock.opendj.ldap.LdapException; 038import org.forgerock.opendj.server.config.client.HTTPAccessLogPublisherCfgClient; 039import org.forgerock.opendj.server.config.server.HTTPAccessLogPublisherCfg; 040import org.forgerock.opendj.server.config.server.LogPublisherCfg; 041 042 043 044/** 045 * An interface for querying the HTTP Access Log Publisher managed 046 * object definition meta information. 047 * <p> 048 * HTTP Access Log Publishers are responsible for distributing HTTP 049 * access log messages from the HTTP access logger to a destination. 050 */ 051public final class HTTPAccessLogPublisherCfgDefn extends ManagedObjectDefinition<HTTPAccessLogPublisherCfgClient, HTTPAccessLogPublisherCfg> { 052 053 /** The singleton configuration definition instance. */ 054 private static final HTTPAccessLogPublisherCfgDefn INSTANCE = new HTTPAccessLogPublisherCfgDefn(); 055 056 057 058 /** The "java-class" property definition. */ 059 private static final ClassPropertyDefinition PD_JAVA_CLASS; 060 061 062 063 /** Build the "java-class" property definition. */ 064 static { 065 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 066 builder.setOption(PropertyOption.MANDATORY); 067 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 068 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.loggers.HTTPAccessLogPublisher"); 069 builder.setDefaultBehaviorProvider(provider); 070 builder.addInstanceOf("org.opends.server.loggers.LogPublisher"); 071 PD_JAVA_CLASS = builder.getInstance(); 072 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 073 } 074 075 076 077 // Register the tags associated with this managed object definition. 078 static { 079 INSTANCE.registerTag(Tag.valueOf("logging")); 080 } 081 082 083 084 /** 085 * Get the HTTP Access Log Publisher configuration definition 086 * singleton. 087 * 088 * @return Returns the HTTP Access Log Publisher configuration 089 * definition singleton. 090 */ 091 public static HTTPAccessLogPublisherCfgDefn getInstance() { 092 return INSTANCE; 093 } 094 095 096 097 /** 098 * Private constructor. 099 */ 100 private HTTPAccessLogPublisherCfgDefn() { 101 super("http-access-log-publisher", LogPublisherCfgDefn.getInstance()); 102 } 103 104 105 106 /** {@inheritDoc} */ 107 public HTTPAccessLogPublisherCfgClient createClientConfiguration( 108 ManagedObject<? extends HTTPAccessLogPublisherCfgClient> impl) { 109 return new HTTPAccessLogPublisherCfgClientImpl(impl); 110 } 111 112 113 114 /** {@inheritDoc} */ 115 public HTTPAccessLogPublisherCfg createServerConfiguration( 116 ServerManagedObject<? extends HTTPAccessLogPublisherCfg> impl) { 117 return new HTTPAccessLogPublisherCfgServerImpl(impl); 118 } 119 120 121 122 /** {@inheritDoc} */ 123 public Class<HTTPAccessLogPublisherCfg> getServerConfigurationClass() { 124 return HTTPAccessLogPublisherCfg.class; 125 } 126 127 128 129 /** 130 * Get the "enabled" property definition. 131 * <p> 132 * Indicates whether the HTTP Access Log Publisher is enabled for 133 * use. 134 * 135 * @return Returns the "enabled" property definition. 136 */ 137 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 138 return LogPublisherCfgDefn.getInstance().getEnabledPropertyDefinition(); 139 } 140 141 142 143 /** 144 * Get the "java-class" property definition. 145 * <p> 146 * The fully-qualified name of the Java class that provides the HTTP 147 * Access Log Publisher 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 HTTPAccessLogPublisherCfgClientImpl implements 161 HTTPAccessLogPublisherCfgClient { 162 163 /** Private implementation. */ 164 private ManagedObject<? extends HTTPAccessLogPublisherCfgClient> impl; 165 166 167 168 /** Private constructor. */ 169 private HTTPAccessLogPublisherCfgClientImpl( 170 ManagedObject<? extends HTTPAccessLogPublisherCfgClient> impl) { 171 this.impl = impl; 172 } 173 174 175 176 /** {@inheritDoc} */ 177 public Boolean isEnabled() { 178 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 179 } 180 181 182 183 /** {@inheritDoc} */ 184 public void setEnabled(boolean value) { 185 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 186 } 187 188 189 190 /** {@inheritDoc} */ 191 public String getJavaClass() { 192 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 193 } 194 195 196 197 /** {@inheritDoc} */ 198 public void setJavaClass(String value) { 199 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 200 } 201 202 203 204 /** {@inheritDoc} */ 205 public ManagedObjectDefinition<? extends HTTPAccessLogPublisherCfgClient, ? extends HTTPAccessLogPublisherCfg> definition() { 206 return INSTANCE; 207 } 208 209 210 211 /** {@inheritDoc} */ 212 public PropertyProvider properties() { 213 return impl; 214 } 215 216 217 218 /** {@inheritDoc} */ 219 public void commit() throws ManagedObjectAlreadyExistsException, 220 MissingMandatoryPropertiesException, ConcurrentModificationException, 221 OperationRejectedException, LdapException { 222 impl.commit(); 223 } 224 225 226 227 /** {@inheritDoc} */ 228 public String toString() { 229 return impl.toString(); 230 } 231 } 232 233 234 235 /** 236 * Managed object server implementation. 237 */ 238 private static class HTTPAccessLogPublisherCfgServerImpl implements 239 HTTPAccessLogPublisherCfg { 240 241 /** Private implementation. */ 242 private ServerManagedObject<? extends HTTPAccessLogPublisherCfg> impl; 243 244 /** The value of the "enabled" property. */ 245 private final boolean pEnabled; 246 247 /** The value of the "java-class" property. */ 248 private final String pJavaClass; 249 250 251 252 /** Private constructor. */ 253 private HTTPAccessLogPublisherCfgServerImpl(ServerManagedObject<? extends HTTPAccessLogPublisherCfg> impl) { 254 this.impl = impl; 255 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 256 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 257 } 258 259 260 261 /** {@inheritDoc} */ 262 public void addHTTPAccessChangeListener( 263 ConfigurationChangeListener<HTTPAccessLogPublisherCfg> listener) { 264 impl.registerChangeListener(listener); 265 } 266 267 268 269 /** {@inheritDoc} */ 270 public void removeHTTPAccessChangeListener( 271 ConfigurationChangeListener<HTTPAccessLogPublisherCfg> listener) { 272 impl.deregisterChangeListener(listener); 273 } 274 /** {@inheritDoc} */ 275 public void addChangeListener( 276 ConfigurationChangeListener<LogPublisherCfg> listener) { 277 impl.registerChangeListener(listener); 278 } 279 280 281 282 /** {@inheritDoc} */ 283 public void removeChangeListener( 284 ConfigurationChangeListener<LogPublisherCfg> listener) { 285 impl.deregisterChangeListener(listener); 286 } 287 288 289 290 /** {@inheritDoc} */ 291 public boolean isEnabled() { 292 return pEnabled; 293 } 294 295 296 297 /** {@inheritDoc} */ 298 public String getJavaClass() { 299 return pJavaClass; 300 } 301 302 303 304 /** {@inheritDoc} */ 305 public Class<? extends HTTPAccessLogPublisherCfg> configurationClass() { 306 return HTTPAccessLogPublisherCfg.class; 307 } 308 309 310 311 /** {@inheritDoc} */ 312 public DN dn() { 313 return impl.getDN(); 314 } 315 316 317 318 /** {@inheritDoc} */ 319 public String toString() { 320 return impl.toString(); 321 } 322 } 323}