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 java.util.Collection;
032 import java.util.SortedSet;
033 import org.opends.server.admin.AdministratorAction;
034 import org.opends.server.admin.BooleanPropertyDefinition;
035 import org.opends.server.admin.ClassPropertyDefinition;
036 import org.opends.server.admin.client.AuthorizationException;
037 import org.opends.server.admin.client.CommunicationException;
038 import org.opends.server.admin.client.ConcurrentModificationException;
039 import org.opends.server.admin.client.ManagedObject;
040 import org.opends.server.admin.client.MissingMandatoryPropertiesException;
041 import org.opends.server.admin.client.OperationRejectedException;
042 import org.opends.server.admin.DefaultBehaviorProvider;
043 import org.opends.server.admin.DefinedDefaultBehaviorProvider;
044 import org.opends.server.admin.DNPropertyDefinition;
045 import org.opends.server.admin.EnumPropertyDefinition;
046 import org.opends.server.admin.ManagedObjectAlreadyExistsException;
047 import org.opends.server.admin.ManagedObjectDefinition;
048 import org.opends.server.admin.ManagedObjectOption;
049 import org.opends.server.admin.PropertyIsReadOnlyException;
050 import org.opends.server.admin.PropertyOption;
051 import org.opends.server.admin.PropertyProvider;
052 import org.opends.server.admin.server.ConfigurationChangeListener;
053 import org.opends.server.admin.server.ServerManagedObject;
054 import org.opends.server.admin.std.client.ConfigFileHandlerBackendCfgClient;
055 import org.opends.server.admin.std.meta.BackendCfgDefn.WritabilityMode;
056 import org.opends.server.admin.std.server.BackendCfg;
057 import org.opends.server.admin.std.server.ConfigFileHandlerBackendCfg;
058 import org.opends.server.admin.StringPropertyDefinition;
059 import org.opends.server.admin.Tag;
060 import org.opends.server.types.DN;
061
062
063
064 /**
065 * An interface for querying the Config File Handler Backend managed
066 * object definition meta information.
067 * <p>
068 * The Config File Handler Backend allows clients to access the server
069 * configuration over protocol, and allow both read and write
070 * operations. Note: Modify DN operations are not supported for entries
071 * in the server configuration.
072 */
073 public final class ConfigFileHandlerBackendCfgDefn extends ManagedObjectDefinition<ConfigFileHandlerBackendCfgClient, ConfigFileHandlerBackendCfg> {
074
075 // The singleton configuration definition instance.
076 private static final ConfigFileHandlerBackendCfgDefn INSTANCE = new ConfigFileHandlerBackendCfgDefn();
077
078
079
080 // The "java-class" property definition.
081 private static final ClassPropertyDefinition PD_JAVA_CLASS;
082
083
084
085 // The "writability-mode" property definition.
086 private static final EnumPropertyDefinition<WritabilityMode> PD_WRITABILITY_MODE;
087
088
089
090 // Build the "java-class" property definition.
091 static {
092 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
093 builder.setOption(PropertyOption.MANDATORY);
094 builder.setOption(PropertyOption.ADVANCED);
095 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
096 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.ConfigFileHandler");
097 builder.setDefaultBehaviorProvider(provider);
098 builder.addInstanceOf("org.opends.server.api.Backend");
099 PD_JAVA_CLASS = builder.getInstance();
100 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
101 }
102
103
104
105 // Build the "writability-mode" property definition.
106 static {
107 EnumPropertyDefinition.Builder<WritabilityMode> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "writability-mode");
108 builder.setOption(PropertyOption.MANDATORY);
109 builder.setOption(PropertyOption.ADVANCED);
110 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "writability-mode"));
111 DefaultBehaviorProvider<WritabilityMode> provider = new DefinedDefaultBehaviorProvider<WritabilityMode>("enabled");
112 builder.setDefaultBehaviorProvider(provider);
113 builder.setEnumClass(WritabilityMode.class);
114 PD_WRITABILITY_MODE = builder.getInstance();
115 INSTANCE.registerPropertyDefinition(PD_WRITABILITY_MODE);
116 }
117
118
119
120 // Register the options associated with this managed object definition.
121 static {
122 INSTANCE.registerOption(ManagedObjectOption.ADVANCED);
123 }
124
125
126
127 // Register the tags associated with this managed object definition.
128 static {
129 INSTANCE.registerTag(Tag.valueOf("database"));
130 }
131
132
133
134 /**
135 * Get the Config File Handler Backend configuration definition
136 * singleton.
137 *
138 * @return Returns the Config File Handler Backend configuration
139 * definition singleton.
140 */
141 public static ConfigFileHandlerBackendCfgDefn getInstance() {
142 return INSTANCE;
143 }
144
145
146
147 /**
148 * Private constructor.
149 */
150 private ConfigFileHandlerBackendCfgDefn() {
151 super("config-file-handler-backend", BackendCfgDefn.getInstance());
152 }
153
154
155
156 /**
157 * {@inheritDoc}
158 */
159 public ConfigFileHandlerBackendCfgClient createClientConfiguration(
160 ManagedObject<? extends ConfigFileHandlerBackendCfgClient> impl) {
161 return new ConfigFileHandlerBackendCfgClientImpl(impl);
162 }
163
164
165
166 /**
167 * {@inheritDoc}
168 */
169 public ConfigFileHandlerBackendCfg createServerConfiguration(
170 ServerManagedObject<? extends ConfigFileHandlerBackendCfg> impl) {
171 return new ConfigFileHandlerBackendCfgServerImpl(impl);
172 }
173
174
175
176 /**
177 * {@inheritDoc}
178 */
179 public Class<ConfigFileHandlerBackendCfg> getServerConfigurationClass() {
180 return ConfigFileHandlerBackendCfg.class;
181 }
182
183
184
185 /**
186 * Get the "backend-id" property definition.
187 * <p>
188 * Specifies a name to identify the associated backend.
189 * <p>
190 * The name must be unique among all backends in the server. The
191 * backend ID may not be altered after the backend is created in the
192 * server.
193 *
194 * @return Returns the "backend-id" property definition.
195 */
196 public StringPropertyDefinition getBackendIdPropertyDefinition() {
197 return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition();
198 }
199
200
201
202 /**
203 * Get the "base-dn" property definition.
204 * <p>
205 * Specifies the base DN(s) for the data that the backend handles.
206 * <p>
207 * A single backend may be responsible for one or more base DNs.
208 * Note that no two backends may have the same base DN although one
209 * backend may have a base DN that is below a base DN provided by
210 * another backend (similar to the use of sub-suffixes in the Sun
211 * Java System Directory Server). If any of the base DNs is
212 * subordinate to a base DN for another backend, then all base DNs
213 * for that backend must be subordinate to that same base DN.
214 *
215 * @return Returns the "base-dn" property definition.
216 */
217 public DNPropertyDefinition getBaseDNPropertyDefinition() {
218 return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition();
219 }
220
221
222
223 /**
224 * Get the "enabled" property definition.
225 * <p>
226 * Indicates whether the backend is enabled in the server.
227 * <p>
228 * If a backend is not enabled, then its contents are not accessible
229 * when processing operations.
230 *
231 * @return Returns the "enabled" property definition.
232 */
233 public BooleanPropertyDefinition getEnabledPropertyDefinition() {
234 return BackendCfgDefn.getInstance().getEnabledPropertyDefinition();
235 }
236
237
238
239 /**
240 * Get the "java-class" property definition.
241 * <p>
242 * Specifies the fully-qualified name of the Java class that
243 * provides the backend implementation.
244 *
245 * @return Returns the "java-class" property definition.
246 */
247 public ClassPropertyDefinition getJavaClassPropertyDefinition() {
248 return PD_JAVA_CLASS;
249 }
250
251
252
253 /**
254 * Get the "writability-mode" property definition.
255 * <p>
256 * Specifies the behavior that the backend should use when
257 * processing write operations.
258 *
259 * @return Returns the "writability-mode" property definition.
260 */
261 public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() {
262 return PD_WRITABILITY_MODE;
263 }
264
265
266
267 /**
268 * Managed object client implementation.
269 */
270 private static class ConfigFileHandlerBackendCfgClientImpl implements
271 ConfigFileHandlerBackendCfgClient {
272
273 // Private implementation.
274 private ManagedObject<? extends ConfigFileHandlerBackendCfgClient> impl;
275
276
277
278 // Private constructor.
279 private ConfigFileHandlerBackendCfgClientImpl(
280 ManagedObject<? extends ConfigFileHandlerBackendCfgClient> impl) {
281 this.impl = impl;
282 }
283
284
285
286 /**
287 * {@inheritDoc}
288 */
289 public String getBackendId() {
290 return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
291 }
292
293
294
295 /**
296 * {@inheritDoc}
297 */
298 public void setBackendId(String value) throws PropertyIsReadOnlyException {
299 impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value);
300 }
301
302
303
304 /**
305 * {@inheritDoc}
306 */
307 public SortedSet<DN> getBaseDN() {
308 return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
309 }
310
311
312
313 /**
314 * {@inheritDoc}
315 */
316 public void setBaseDN(Collection<DN> values) {
317 impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values);
318 }
319
320
321
322 /**
323 * {@inheritDoc}
324 */
325 public Boolean isEnabled() {
326 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
327 }
328
329
330
331 /**
332 * {@inheritDoc}
333 */
334 public void setEnabled(boolean value) {
335 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
336 }
337
338
339
340 /**
341 * {@inheritDoc}
342 */
343 public String getJavaClass() {
344 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
345 }
346
347
348
349 /**
350 * {@inheritDoc}
351 */
352 public void setJavaClass(String value) {
353 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
354 }
355
356
357
358 /**
359 * {@inheritDoc}
360 */
361 public WritabilityMode getWritabilityMode() {
362 return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
363 }
364
365
366
367 /**
368 * {@inheritDoc}
369 */
370 public void setWritabilityMode(WritabilityMode value) {
371 impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value);
372 }
373
374
375
376 /**
377 * {@inheritDoc}
378 */
379 public ManagedObjectDefinition<? extends ConfigFileHandlerBackendCfgClient, ? extends ConfigFileHandlerBackendCfg> definition() {
380 return INSTANCE;
381 }
382
383
384
385 /**
386 * {@inheritDoc}
387 */
388 public PropertyProvider properties() {
389 return impl;
390 }
391
392
393
394 /**
395 * {@inheritDoc}
396 */
397 public void commit() throws ManagedObjectAlreadyExistsException,
398 MissingMandatoryPropertiesException, ConcurrentModificationException,
399 OperationRejectedException, AuthorizationException,
400 CommunicationException {
401 impl.commit();
402 }
403
404 }
405
406
407
408 /**
409 * Managed object server implementation.
410 */
411 private static class ConfigFileHandlerBackendCfgServerImpl implements
412 ConfigFileHandlerBackendCfg {
413
414 // Private implementation.
415 private ServerManagedObject<? extends ConfigFileHandlerBackendCfg> impl;
416
417 // The value of the "backend-id" property.
418 private final String pBackendId;
419
420 // The value of the "base-dn" property.
421 private final SortedSet<DN> pBaseDN;
422
423 // The value of the "enabled" property.
424 private final boolean pEnabled;
425
426 // The value of the "java-class" property.
427 private final String pJavaClass;
428
429 // The value of the "writability-mode" property.
430 private final WritabilityMode pWritabilityMode;
431
432
433
434 // Private constructor.
435 private ConfigFileHandlerBackendCfgServerImpl(ServerManagedObject<? extends ConfigFileHandlerBackendCfg> impl) {
436 this.impl = impl;
437 this.pBackendId = impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
438 this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
439 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
440 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
441 this.pWritabilityMode = impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
442 }
443
444
445
446 /**
447 * {@inheritDoc}
448 */
449 public void addConfigFileHandlerChangeListener(
450 ConfigurationChangeListener<ConfigFileHandlerBackendCfg> listener) {
451 impl.registerChangeListener(listener);
452 }
453
454
455
456 /**
457 * {@inheritDoc}
458 */
459 public void removeConfigFileHandlerChangeListener(
460 ConfigurationChangeListener<ConfigFileHandlerBackendCfg> listener) {
461 impl.deregisterChangeListener(listener);
462 }
463 /**
464 * {@inheritDoc}
465 */
466 public void addChangeListener(
467 ConfigurationChangeListener<BackendCfg> listener) {
468 impl.registerChangeListener(listener);
469 }
470
471
472
473 /**
474 * {@inheritDoc}
475 */
476 public void removeChangeListener(
477 ConfigurationChangeListener<BackendCfg> listener) {
478 impl.deregisterChangeListener(listener);
479 }
480
481
482
483 /**
484 * {@inheritDoc}
485 */
486 public String getBackendId() {
487 return pBackendId;
488 }
489
490
491
492 /**
493 * {@inheritDoc}
494 */
495 public SortedSet<DN> getBaseDN() {
496 return pBaseDN;
497 }
498
499
500
501 /**
502 * {@inheritDoc}
503 */
504 public boolean isEnabled() {
505 return pEnabled;
506 }
507
508
509
510 /**
511 * {@inheritDoc}
512 */
513 public String getJavaClass() {
514 return pJavaClass;
515 }
516
517
518
519 /**
520 * {@inheritDoc}
521 */
522 public WritabilityMode getWritabilityMode() {
523 return pWritabilityMode;
524 }
525
526
527
528 /**
529 * {@inheritDoc}
530 */
531 public Class<? extends ConfigFileHandlerBackendCfg> configurationClass() {
532 return ConfigFileHandlerBackendCfg.class;
533 }
534
535
536
537 /**
538 * {@inheritDoc}
539 */
540 public DN dn() {
541 return impl.getDN();
542 }
543
544 }
545 }