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