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.BooleanPropertyDefinition; 023import org.opends.server.admin.ClassPropertyDefinition; 024import org.opends.server.admin.client.AuthorizationException; 025import org.opends.server.admin.client.CommunicationException; 026import org.opends.server.admin.client.ConcurrentModificationException; 027import org.opends.server.admin.client.ManagedObject; 028import org.opends.server.admin.client.MissingMandatoryPropertiesException; 029import org.opends.server.admin.client.OperationRejectedException; 030import org.opends.server.admin.ManagedObjectAlreadyExistsException; 031import org.opends.server.admin.ManagedObjectDefinition; 032import org.opends.server.admin.PropertyOption; 033import org.opends.server.admin.PropertyProvider; 034import org.opends.server.admin.server.ConfigurationChangeListener; 035import org.opends.server.admin.server.ServerManagedObject; 036import org.opends.server.admin.std.client.SchemaProviderCfgClient; 037import org.opends.server.admin.std.server.SchemaProviderCfg; 038import org.opends.server.admin.TopCfgDefn; 039import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 040 041 042 043/** 044 * An interface for querying the Schema Provider managed object 045 * definition meta information. 046 * <p> 047 * Schema Providers define the schema elements to load. 048 */ 049public final class SchemaProviderCfgDefn extends ManagedObjectDefinition<SchemaProviderCfgClient, SchemaProviderCfg> { 050 051 // The singleton configuration definition instance. 052 private static final SchemaProviderCfgDefn INSTANCE = new SchemaProviderCfgDefn(); 053 054 055 056 // The "enabled" property definition. 057 private static final BooleanPropertyDefinition PD_ENABLED; 058 059 060 061 // The "java-class" property definition. 062 private static final ClassPropertyDefinition PD_JAVA_CLASS; 063 064 065 066 // Build the "enabled" property definition. 067 static { 068 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled"); 069 builder.setOption(PropertyOption.MANDATORY); 070 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled")); 071 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 072 PD_ENABLED = builder.getInstance(); 073 INSTANCE.registerPropertyDefinition(PD_ENABLED); 074 } 075 076 077 078 // Build the "java-class" property definition. 079 static { 080 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 081 builder.setOption(PropertyOption.MANDATORY); 082 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 083 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 084 builder.addInstanceOf("org.opends.server.schema.SchemaProvider"); 085 PD_JAVA_CLASS = builder.getInstance(); 086 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 087 } 088 089 090 091 /** 092 * Get the Schema Provider configuration definition singleton. 093 * 094 * @return Returns the Schema Provider configuration definition 095 * singleton. 096 */ 097 public static SchemaProviderCfgDefn getInstance() { 098 return INSTANCE; 099 } 100 101 102 103 /** 104 * Private constructor. 105 */ 106 private SchemaProviderCfgDefn() { 107 super("schema-provider", TopCfgDefn.getInstance()); 108 } 109 110 111 112 /** 113 * {@inheritDoc} 114 */ 115 public SchemaProviderCfgClient createClientConfiguration( 116 ManagedObject<? extends SchemaProviderCfgClient> impl) { 117 return new SchemaProviderCfgClientImpl(impl); 118 } 119 120 121 122 /** 123 * {@inheritDoc} 124 */ 125 public SchemaProviderCfg createServerConfiguration( 126 ServerManagedObject<? extends SchemaProviderCfg> impl) { 127 return new SchemaProviderCfgServerImpl(impl); 128 } 129 130 131 132 /** 133 * {@inheritDoc} 134 */ 135 public Class<SchemaProviderCfg> getServerConfigurationClass() { 136 return SchemaProviderCfg.class; 137 } 138 139 140 141 /** 142 * Get the "enabled" property definition. 143 * <p> 144 * Indicates whether the Schema Provider is enabled for use. 145 * 146 * @return Returns the "enabled" property definition. 147 */ 148 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 149 return PD_ENABLED; 150 } 151 152 153 154 /** 155 * Get the "java-class" property definition. 156 * <p> 157 * Specifies the fully-qualified name of the Java class that 158 * provides the Schema Provider implementation. 159 * 160 * @return Returns the "java-class" property definition. 161 */ 162 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 163 return PD_JAVA_CLASS; 164 } 165 166 167 168 /** 169 * Managed object client implementation. 170 */ 171 private static class SchemaProviderCfgClientImpl implements 172 SchemaProviderCfgClient { 173 174 // Private implementation. 175 private ManagedObject<? extends SchemaProviderCfgClient> impl; 176 177 178 179 // Private constructor. 180 private SchemaProviderCfgClientImpl( 181 ManagedObject<? extends SchemaProviderCfgClient> impl) { 182 this.impl = impl; 183 } 184 185 186 187 /** 188 * {@inheritDoc} 189 */ 190 public Boolean isEnabled() { 191 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 192 } 193 194 195 196 /** 197 * {@inheritDoc} 198 */ 199 public void setEnabled(boolean value) { 200 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 201 } 202 203 204 205 /** 206 * {@inheritDoc} 207 */ 208 public String getJavaClass() { 209 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 210 } 211 212 213 214 /** 215 * {@inheritDoc} 216 */ 217 public void setJavaClass(String value) { 218 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 219 } 220 221 222 223 /** 224 * {@inheritDoc} 225 */ 226 public ManagedObjectDefinition<? extends SchemaProviderCfgClient, ? extends SchemaProviderCfg> definition() { 227 return INSTANCE; 228 } 229 230 231 232 /** 233 * {@inheritDoc} 234 */ 235 public PropertyProvider properties() { 236 return impl; 237 } 238 239 240 241 /** 242 * {@inheritDoc} 243 */ 244 public void commit() throws ManagedObjectAlreadyExistsException, 245 MissingMandatoryPropertiesException, ConcurrentModificationException, 246 OperationRejectedException, AuthorizationException, 247 CommunicationException { 248 impl.commit(); 249 } 250 251 252 253 /** {@inheritDoc} */ 254 public String toString() { 255 return impl.toString(); 256 } 257 } 258 259 260 261 /** 262 * Managed object server implementation. 263 */ 264 private static class SchemaProviderCfgServerImpl implements 265 SchemaProviderCfg { 266 267 // Private implementation. 268 private ServerManagedObject<? extends SchemaProviderCfg> impl; 269 270 // The value of the "enabled" property. 271 private final boolean pEnabled; 272 273 // The value of the "java-class" property. 274 private final String pJavaClass; 275 276 277 278 // Private constructor. 279 private SchemaProviderCfgServerImpl(ServerManagedObject<? extends SchemaProviderCfg> impl) { 280 this.impl = impl; 281 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 282 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 283 } 284 285 286 287 /** 288 * {@inheritDoc} 289 */ 290 public void addChangeListener( 291 ConfigurationChangeListener<SchemaProviderCfg> listener) { 292 impl.registerChangeListener(listener); 293 } 294 295 296 297 /** 298 * {@inheritDoc} 299 */ 300 public void removeChangeListener( 301 ConfigurationChangeListener<SchemaProviderCfg> listener) { 302 impl.deregisterChangeListener(listener); 303 } 304 305 306 307 /** 308 * {@inheritDoc} 309 */ 310 public boolean isEnabled() { 311 return pEnabled; 312 } 313 314 315 316 /** 317 * {@inheritDoc} 318 */ 319 public String getJavaClass() { 320 return pJavaClass; 321 } 322 323 324 325 /** 326 * {@inheritDoc} 327 */ 328 public Class<? extends SchemaProviderCfg> configurationClass() { 329 return SchemaProviderCfg.class; 330 } 331 332 333 334 /** 335 * {@inheritDoc} 336 */ 337 public DN dn() { 338 return impl.getDN(); 339 } 340 341 342 343 /** {@inheritDoc} */ 344 public String toString() { 345 return impl.toString(); 346 } 347 } 348}