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.SchemaBackendCfgClient;
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.SchemaBackendCfg;
058 import org.opends.server.admin.StringPropertyDefinition;
059 import org.opends.server.admin.Tag;
060 import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
061 import org.opends.server.types.DN;
062
063
064
065 /**
066 * An interface for querying the Schema Backend managed object
067 * definition meta information.
068 * <p>
069 * The Schema Backend provides access to the Directory Server schema
070 * information, including the attribute types, object classes,
071 * attribute syntaxes, matching rules, matching rule uses, DIT content
072 * rules, and DIT structure rules that it contains.
073 */
074 public final class SchemaBackendCfgDefn extends ManagedObjectDefinition<SchemaBackendCfgClient, SchemaBackendCfg> {
075
076 // The singleton configuration definition instance.
077 private static final SchemaBackendCfgDefn INSTANCE = new SchemaBackendCfgDefn();
078
079
080
081 // The "java-class" property definition.
082 private static final ClassPropertyDefinition PD_JAVA_CLASS;
083
084
085
086 // The "schema-entry-dn" property definition.
087 private static final DNPropertyDefinition PD_SCHEMA_ENTRY_DN;
088
089
090
091 // The "show-all-attributes" property definition.
092 private static final BooleanPropertyDefinition PD_SHOW_ALL_ATTRIBUTES;
093
094
095
096 // The "writability-mode" property definition.
097 private static final EnumPropertyDefinition<WritabilityMode> PD_WRITABILITY_MODE;
098
099
100
101 // Build the "java-class" property definition.
102 static {
103 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
104 builder.setOption(PropertyOption.MANDATORY);
105 builder.setOption(PropertyOption.ADVANCED);
106 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
107 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.backends.SchemaBackend");
108 builder.setDefaultBehaviorProvider(provider);
109 builder.addInstanceOf("org.opends.server.api.Backend");
110 PD_JAVA_CLASS = builder.getInstance();
111 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
112 }
113
114
115
116 // Build the "schema-entry-dn" property definition.
117 static {
118 DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "schema-entry-dn");
119 builder.setOption(PropertyOption.MULTI_VALUED);
120 builder.setOption(PropertyOption.ADVANCED);
121 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "schema-entry-dn"));
122 DefaultBehaviorProvider<DN> provider = new DefinedDefaultBehaviorProvider<DN>("cn=schema");
123 builder.setDefaultBehaviorProvider(provider);
124 PD_SCHEMA_ENTRY_DN = builder.getInstance();
125 INSTANCE.registerPropertyDefinition(PD_SCHEMA_ENTRY_DN);
126 }
127
128
129
130 // Build the "show-all-attributes" property definition.
131 static {
132 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "show-all-attributes");
133 builder.setOption(PropertyOption.MANDATORY);
134 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "show-all-attributes"));
135 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
136 PD_SHOW_ALL_ATTRIBUTES = builder.getInstance();
137 INSTANCE.registerPropertyDefinition(PD_SHOW_ALL_ATTRIBUTES);
138 }
139
140
141
142 // Build the "writability-mode" property definition.
143 static {
144 EnumPropertyDefinition.Builder<WritabilityMode> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "writability-mode");
145 builder.setOption(PropertyOption.MANDATORY);
146 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "writability-mode"));
147 DefaultBehaviorProvider<WritabilityMode> provider = new DefinedDefaultBehaviorProvider<WritabilityMode>("enabled");
148 builder.setDefaultBehaviorProvider(provider);
149 builder.setEnumClass(WritabilityMode.class);
150 PD_WRITABILITY_MODE = builder.getInstance();
151 INSTANCE.registerPropertyDefinition(PD_WRITABILITY_MODE);
152 }
153
154
155
156 // Register the options associated with this managed object definition.
157 static {
158 INSTANCE.registerOption(ManagedObjectOption.ADVANCED);
159 }
160
161
162
163 // Register the tags associated with this managed object definition.
164 static {
165 INSTANCE.registerTag(Tag.valueOf("database"));
166 }
167
168
169
170 /**
171 * Get the Schema Backend configuration definition singleton.
172 *
173 * @return Returns the Schema Backend configuration definition
174 * singleton.
175 */
176 public static SchemaBackendCfgDefn getInstance() {
177 return INSTANCE;
178 }
179
180
181
182 /**
183 * Private constructor.
184 */
185 private SchemaBackendCfgDefn() {
186 super("schema-backend", BackendCfgDefn.getInstance());
187 }
188
189
190
191 /**
192 * {@inheritDoc}
193 */
194 public SchemaBackendCfgClient createClientConfiguration(
195 ManagedObject<? extends SchemaBackendCfgClient> impl) {
196 return new SchemaBackendCfgClientImpl(impl);
197 }
198
199
200
201 /**
202 * {@inheritDoc}
203 */
204 public SchemaBackendCfg createServerConfiguration(
205 ServerManagedObject<? extends SchemaBackendCfg> impl) {
206 return new SchemaBackendCfgServerImpl(impl);
207 }
208
209
210
211 /**
212 * {@inheritDoc}
213 */
214 public Class<SchemaBackendCfg> getServerConfigurationClass() {
215 return SchemaBackendCfg.class;
216 }
217
218
219
220 /**
221 * Get the "backend-id" property definition.
222 * <p>
223 * Specifies a name to identify the associated backend.
224 * <p>
225 * The name must be unique among all backends in the server. The
226 * backend ID may not be altered after the backend is created in the
227 * server.
228 *
229 * @return Returns the "backend-id" property definition.
230 */
231 public StringPropertyDefinition getBackendIdPropertyDefinition() {
232 return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition();
233 }
234
235
236
237 /**
238 * Get the "base-dn" property definition.
239 * <p>
240 * Specifies the base DN(s) for the data that the backend handles.
241 * <p>
242 * A single backend may be responsible for one or more base DNs.
243 * Note that no two backends may have the same base DN although one
244 * backend may have a base DN that is below a base DN provided by
245 * another backend (similar to the use of sub-suffixes in the Sun
246 * Java System Directory Server). If any of the base DNs is
247 * subordinate to a base DN for another backend, then all base DNs
248 * for that backend must be subordinate to that same base DN.
249 *
250 * @return Returns the "base-dn" property definition.
251 */
252 public DNPropertyDefinition getBaseDNPropertyDefinition() {
253 return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition();
254 }
255
256
257
258 /**
259 * Get the "enabled" property definition.
260 * <p>
261 * Indicates whether the backend is enabled in the server.
262 * <p>
263 * If a backend is not enabled, then its contents are not accessible
264 * when processing operations.
265 *
266 * @return Returns the "enabled" property definition.
267 */
268 public BooleanPropertyDefinition getEnabledPropertyDefinition() {
269 return BackendCfgDefn.getInstance().getEnabledPropertyDefinition();
270 }
271
272
273
274 /**
275 * Get the "java-class" property definition.
276 * <p>
277 * Specifies the fully-qualified name of the Java class that
278 * provides the backend implementation.
279 *
280 * @return Returns the "java-class" property definition.
281 */
282 public ClassPropertyDefinition getJavaClassPropertyDefinition() {
283 return PD_JAVA_CLASS;
284 }
285
286
287
288 /**
289 * Get the "schema-entry-dn" property definition.
290 * <p>
291 * Defines the base DNs of the subtrees in which the schema
292 * information is published in addition to the value included in the
293 * base-dn property.
294 * <p>
295 * The value provided in the base-dn property is the only one that
296 * appears in the subschemaSubentry operational attribute of the
297 * server's root DSE (which is necessary because that is a
298 * single-valued attribute) and as a virtual attribute in other
299 * entries. The schema-entry-dn attribute may be used to make the
300 * schema information available in other locations to accommodate
301 * certain client applications that have been hard-coded to expect
302 * the schema to reside in a specific location.
303 *
304 * @return Returns the "schema-entry-dn" property definition.
305 */
306 public DNPropertyDefinition getSchemaEntryDNPropertyDefinition() {
307 return PD_SCHEMA_ENTRY_DN;
308 }
309
310
311
312 /**
313 * Get the "show-all-attributes" property definition.
314 * <p>
315 * Indicates whether to treat all attributes in the schema entry as
316 * if they were user attributes regardless of their configuration.
317 * <p>
318 * This may provide compatibility with some applications that expect
319 * schema attributes like attributeTypes and objectClasses to be
320 * included by default even if they are not requested. Note that the
321 * ldapSyntaxes attribute is always treated as operational in order
322 * to avoid problems with attempts to modify the schema over
323 * protocol.
324 *
325 * @return Returns the "show-all-attributes" property definition.
326 */
327 public BooleanPropertyDefinition getShowAllAttributesPropertyDefinition() {
328 return PD_SHOW_ALL_ATTRIBUTES;
329 }
330
331
332
333 /**
334 * Get the "writability-mode" property definition.
335 * <p>
336 * Specifies the behavior that the backend should use when
337 * processing write operations.
338 *
339 * @return Returns the "writability-mode" property definition.
340 */
341 public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() {
342 return PD_WRITABILITY_MODE;
343 }
344
345
346
347 /**
348 * Managed object client implementation.
349 */
350 private static class SchemaBackendCfgClientImpl implements
351 SchemaBackendCfgClient {
352
353 // Private implementation.
354 private ManagedObject<? extends SchemaBackendCfgClient> impl;
355
356
357
358 // Private constructor.
359 private SchemaBackendCfgClientImpl(
360 ManagedObject<? extends SchemaBackendCfgClient> impl) {
361 this.impl = impl;
362 }
363
364
365
366 /**
367 * {@inheritDoc}
368 */
369 public String getBackendId() {
370 return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
371 }
372
373
374
375 /**
376 * {@inheritDoc}
377 */
378 public void setBackendId(String value) throws PropertyIsReadOnlyException {
379 impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value);
380 }
381
382
383
384 /**
385 * {@inheritDoc}
386 */
387 public SortedSet<DN> getBaseDN() {
388 return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
389 }
390
391
392
393 /**
394 * {@inheritDoc}
395 */
396 public void setBaseDN(Collection<DN> values) {
397 impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values);
398 }
399
400
401
402 /**
403 * {@inheritDoc}
404 */
405 public Boolean isEnabled() {
406 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
407 }
408
409
410
411 /**
412 * {@inheritDoc}
413 */
414 public void setEnabled(boolean value) {
415 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
416 }
417
418
419
420 /**
421 * {@inheritDoc}
422 */
423 public String getJavaClass() {
424 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
425 }
426
427
428
429 /**
430 * {@inheritDoc}
431 */
432 public void setJavaClass(String value) {
433 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
434 }
435
436
437
438 /**
439 * {@inheritDoc}
440 */
441 public SortedSet<DN> getSchemaEntryDN() {
442 return impl.getPropertyValues(INSTANCE.getSchemaEntryDNPropertyDefinition());
443 }
444
445
446
447 /**
448 * {@inheritDoc}
449 */
450 public void setSchemaEntryDN(Collection<DN> values) {
451 impl.setPropertyValues(INSTANCE.getSchemaEntryDNPropertyDefinition(), values);
452 }
453
454
455
456 /**
457 * {@inheritDoc}
458 */
459 public Boolean isShowAllAttributes() {
460 return impl.getPropertyValue(INSTANCE.getShowAllAttributesPropertyDefinition());
461 }
462
463
464
465 /**
466 * {@inheritDoc}
467 */
468 public void setShowAllAttributes(boolean value) {
469 impl.setPropertyValue(INSTANCE.getShowAllAttributesPropertyDefinition(), value);
470 }
471
472
473
474 /**
475 * {@inheritDoc}
476 */
477 public WritabilityMode getWritabilityMode() {
478 return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
479 }
480
481
482
483 /**
484 * {@inheritDoc}
485 */
486 public void setWritabilityMode(WritabilityMode value) {
487 impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value);
488 }
489
490
491
492 /**
493 * {@inheritDoc}
494 */
495 public ManagedObjectDefinition<? extends SchemaBackendCfgClient, ? extends SchemaBackendCfg> definition() {
496 return INSTANCE;
497 }
498
499
500
501 /**
502 * {@inheritDoc}
503 */
504 public PropertyProvider properties() {
505 return impl;
506 }
507
508
509
510 /**
511 * {@inheritDoc}
512 */
513 public void commit() throws ManagedObjectAlreadyExistsException,
514 MissingMandatoryPropertiesException, ConcurrentModificationException,
515 OperationRejectedException, AuthorizationException,
516 CommunicationException {
517 impl.commit();
518 }
519
520 }
521
522
523
524 /**
525 * Managed object server implementation.
526 */
527 private static class SchemaBackendCfgServerImpl implements
528 SchemaBackendCfg {
529
530 // Private implementation.
531 private ServerManagedObject<? extends SchemaBackendCfg> impl;
532
533 // The value of the "backend-id" property.
534 private final String pBackendId;
535
536 // The value of the "base-dn" property.
537 private final SortedSet<DN> pBaseDN;
538
539 // The value of the "enabled" property.
540 private final boolean pEnabled;
541
542 // The value of the "java-class" property.
543 private final String pJavaClass;
544
545 // The value of the "schema-entry-dn" property.
546 private final SortedSet<DN> pSchemaEntryDN;
547
548 // The value of the "show-all-attributes" property.
549 private final boolean pShowAllAttributes;
550
551 // The value of the "writability-mode" property.
552 private final WritabilityMode pWritabilityMode;
553
554
555
556 // Private constructor.
557 private SchemaBackendCfgServerImpl(ServerManagedObject<? extends SchemaBackendCfg> impl) {
558 this.impl = impl;
559 this.pBackendId = impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
560 this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
561 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
562 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
563 this.pSchemaEntryDN = impl.getPropertyValues(INSTANCE.getSchemaEntryDNPropertyDefinition());
564 this.pShowAllAttributes = impl.getPropertyValue(INSTANCE.getShowAllAttributesPropertyDefinition());
565 this.pWritabilityMode = impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
566 }
567
568
569
570 /**
571 * {@inheritDoc}
572 */
573 public void addSchemaChangeListener(
574 ConfigurationChangeListener<SchemaBackendCfg> listener) {
575 impl.registerChangeListener(listener);
576 }
577
578
579
580 /**
581 * {@inheritDoc}
582 */
583 public void removeSchemaChangeListener(
584 ConfigurationChangeListener<SchemaBackendCfg> listener) {
585 impl.deregisterChangeListener(listener);
586 }
587 /**
588 * {@inheritDoc}
589 */
590 public void addChangeListener(
591 ConfigurationChangeListener<BackendCfg> listener) {
592 impl.registerChangeListener(listener);
593 }
594
595
596
597 /**
598 * {@inheritDoc}
599 */
600 public void removeChangeListener(
601 ConfigurationChangeListener<BackendCfg> listener) {
602 impl.deregisterChangeListener(listener);
603 }
604
605
606
607 /**
608 * {@inheritDoc}
609 */
610 public String getBackendId() {
611 return pBackendId;
612 }
613
614
615
616 /**
617 * {@inheritDoc}
618 */
619 public SortedSet<DN> getBaseDN() {
620 return pBaseDN;
621 }
622
623
624
625 /**
626 * {@inheritDoc}
627 */
628 public boolean isEnabled() {
629 return pEnabled;
630 }
631
632
633
634 /**
635 * {@inheritDoc}
636 */
637 public String getJavaClass() {
638 return pJavaClass;
639 }
640
641
642
643 /**
644 * {@inheritDoc}
645 */
646 public SortedSet<DN> getSchemaEntryDN() {
647 return pSchemaEntryDN;
648 }
649
650
651
652 /**
653 * {@inheritDoc}
654 */
655 public boolean isShowAllAttributes() {
656 return pShowAllAttributes;
657 }
658
659
660
661 /**
662 * {@inheritDoc}
663 */
664 public WritabilityMode getWritabilityMode() {
665 return pWritabilityMode;
666 }
667
668
669
670 /**
671 * {@inheritDoc}
672 */
673 public Class<? extends SchemaBackendCfg> configurationClass() {
674 return SchemaBackendCfg.class;
675 }
676
677
678
679 /**
680 * {@inheritDoc}
681 */
682 public DN dn() {
683 return impl.getDN();
684 }
685
686 }
687 }