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.EnumPropertyDefinition;
045 import org.opends.server.admin.ManagedObjectAlreadyExistsException;
046 import org.opends.server.admin.ManagedObjectDefinition;
047 import org.opends.server.admin.PropertyOption;
048 import org.opends.server.admin.PropertyProvider;
049 import org.opends.server.admin.server.ConfigurationChangeListener;
050 import org.opends.server.admin.server.ServerManagedObject;
051 import org.opends.server.admin.std.client.PluginCfgClient;
052 import org.opends.server.admin.std.server.PluginCfg;
053 import org.opends.server.admin.Tag;
054 import org.opends.server.admin.TopCfgDefn;
055 import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
056 import org.opends.server.types.DN;
057
058
059
060 /**
061 * An interface for querying the Plugin managed object definition meta
062 * information.
063 * <p>
064 * Plugins provide a mechanism for executing custom code at specified
065 * points in operation processing and in the course of other events
066 * like connection establishment and termination, server startup and
067 * shutdown, and LDIF import and export.
068 */
069 public final class PluginCfgDefn extends ManagedObjectDefinition<PluginCfgClient, PluginCfg> {
070
071 // The singleton configuration definition instance.
072 private static final PluginCfgDefn INSTANCE = new PluginCfgDefn();
073
074
075
076 /**
077 * Defines the set of permissable values for the "plugin-type" property.
078 * <p>
079 * Specifies the set of plug-in types for the plug-in, which
080 * specifies the times at which the plug-in is invoked.
081 */
082 public static enum PluginType {
083
084 /**
085 * Invoked before sending an intermediate repsonse message to the
086 * client.
087 */
088 INTERMEDIATERESPONSE("intermediateresponse"),
089
090
091
092 /**
093 * Invoked for each operation to be written during an LDIF export.
094 */
095 LDIFEXPORT("ldifexport"),
096
097
098
099 /**
100 * Invoked for each entry read during an LDIF import.
101 */
102 LDIFIMPORT("ldifimport"),
103
104
105
106 /**
107 * Invoked whenever a new connection is established to the server.
108 */
109 POSTCONNECT("postconnect"),
110
111
112
113 /**
114 * Invoked whenever an existing connection is terminated (by
115 * either the client or the server).
116 */
117 POSTDISCONNECT("postdisconnect"),
118
119
120
121 /**
122 * Invoked after completing the abandon processing.
123 */
124 POSTOPERATIONABANDON("postoperationabandon"),
125
126
127
128 /**
129 * Invoked after completing the core add processing but before
130 * sending the response to the client.
131 */
132 POSTOPERATIONADD("postoperationadd"),
133
134
135
136 /**
137 * Invoked after completing the core bind processing but before
138 * sending the response to the client.
139 */
140 POSTOPERATIONBIND("postoperationbind"),
141
142
143
144 /**
145 * Invoked after completing the core compare processing but before
146 * sending the response to the client.
147 */
148 POSTOPERATIONCOMPARE("postoperationcompare"),
149
150
151
152 /**
153 * Invoked after completing the core delete processing but before
154 * sending the response to the client.
155 */
156 POSTOPERATIONDELETE("postoperationdelete"),
157
158
159
160 /**
161 * Invoked after completing the core extended processing but
162 * before sending the response to the client.
163 */
164 POSTOPERATIONEXTENDED("postoperationextended"),
165
166
167
168 /**
169 * Invoked after completing the core modify processing but before
170 * sending the response to the client.
171 */
172 POSTOPERATIONMODIFY("postoperationmodify"),
173
174
175
176 /**
177 * Invoked after completing the core modify DN processing but
178 * before sending the response to the client.
179 */
180 POSTOPERATIONMODIFYDN("postoperationmodifydn"),
181
182
183
184 /**
185 * Invoked after completing the core search processing but before
186 * sending the response to the client.
187 */
188 POSTOPERATIONSEARCH("postoperationsearch"),
189
190
191
192 /**
193 * Invoked after completing the unbind processing.
194 */
195 POSTOPERATIONUNBIND("postoperationunbind"),
196
197
198
199 /**
200 * Invoked after sending the add response to the client.
201 */
202 POSTRESPONSEADD("postresponseadd"),
203
204
205
206 /**
207 * Invoked after sending the bind response to the client.
208 */
209 POSTRESPONSEBIND("postresponsebind"),
210
211
212
213 /**
214 * Invoked after sending the compare response to the client.
215 */
216 POSTRESPONSECOMPARE("postresponsecompare"),
217
218
219
220 /**
221 * Invoked after sending the delete response to the client.
222 */
223 POSTRESPONSEDELETE("postresponsedelete"),
224
225
226
227 /**
228 * Invoked after sending the extended response to the client.
229 */
230 POSTRESPONSEEXTENDED("postresponseextended"),
231
232
233
234 /**
235 * Invoked after sending the modify response to the client.
236 */
237 POSTRESPONSEMODIFY("postresponsemodify"),
238
239
240
241 /**
242 * Invoked after sending the modify DN response to the client.
243 */
244 POSTRESPONSEMODIFYDN("postresponsemodifydn"),
245
246
247
248 /**
249 * Invoked after sending the search result done message to the
250 * client.
251 */
252 POSTRESPONSESEARCH("postresponsesearch"),
253
254
255
256 /**
257 * Invoked after completing post-synchronization processing for an
258 * add operation.
259 */
260 POSTSYNCHRONIZATIONADD("postsynchronizationadd"),
261
262
263
264 /**
265 * Invoked after completing post-synchronization processing for a
266 * delete operation.
267 */
268 POSTSYNCHRONIZATIONDELETE("postsynchronizationdelete"),
269
270
271
272 /**
273 * Invoked after completing post-synchronization processing for a
274 * modify operation.
275 */
276 POSTSYNCHRONIZATIONMODIFY("postsynchronizationmodify"),
277
278
279
280 /**
281 * Invoked after completing post-synchronization processing for a
282 * modify DN operation.
283 */
284 POSTSYNCHRONIZATIONMODIFYDN("postsynchronizationmodifydn"),
285
286
287
288 /**
289 * Invoked prior to performing the core add processing.
290 */
291 PREOPERATIONADD("preoperationadd"),
292
293
294
295 /**
296 * Invoked prior to performing the core bind processing.
297 */
298 PREOPERATIONBIND("preoperationbind"),
299
300
301
302 /**
303 * Invoked prior to performing the core compare processing.
304 */
305 PREOPERATIONCOMPARE("preoperationcompare"),
306
307
308
309 /**
310 * Invoked prior to performing the core delete processing.
311 */
312 PREOPERATIONDELETE("preoperationdelete"),
313
314
315
316 /**
317 * Invoked prior to performing the core extended processing.
318 */
319 PREOPERATIONEXTENDED("preoperationextended"),
320
321
322
323 /**
324 * Invoked prior to performing the core modify processing.
325 */
326 PREOPERATIONMODIFY("preoperationmodify"),
327
328
329
330 /**
331 * Invoked prior to performing the core modify DN processing.
332 */
333 PREOPERATIONMODIFYDN("preoperationmodifydn"),
334
335
336
337 /**
338 * Invoked prior to performing the core search processing.
339 */
340 PREOPERATIONSEARCH("preoperationsearch"),
341
342
343
344 /**
345 * Invoked prior to parsing an abandon request.
346 */
347 PREPARSEABANDON("preparseabandon"),
348
349
350
351 /**
352 * Invoked prior to parsing an add request.
353 */
354 PREPARSEADD("preparseadd"),
355
356
357
358 /**
359 * Invoked prior to parsing a bind request.
360 */
361 PREPARSEBIND("preparsebind"),
362
363
364
365 /**
366 * Invoked prior to parsing a compare request.
367 */
368 PREPARSECOMPARE("preparsecompare"),
369
370
371
372 /**
373 * Invoked prior to parsing a delete request.
374 */
375 PREPARSEDELETE("preparsedelete"),
376
377
378
379 /**
380 * Invoked prior to parsing an extended request.
381 */
382 PREPARSEEXTENDED("preparseextended"),
383
384
385
386 /**
387 * Invoked prior to parsing a modify request.
388 */
389 PREPARSEMODIFY("preparsemodify"),
390
391
392
393 /**
394 * Invoked prior to parsing a modify DN request.
395 */
396 PREPARSEMODIFYDN("preparsemodifydn"),
397
398
399
400 /**
401 * Invoked prior to parsing a search request.
402 */
403 PREPARSESEARCH("preparsesearch"),
404
405
406
407 /**
408 * Invoked prior to parsing an unbind request.
409 */
410 PREPARSEUNBIND("preparseunbind"),
411
412
413
414 /**
415 * Invoked before sending a search result entry to the client.
416 */
417 SEARCHRESULTENTRY("searchresultentry"),
418
419
420
421 /**
422 * Invoked before sending a search result reference to the client.
423 */
424 SEARCHRESULTREFERENCE("searchresultreference"),
425
426
427
428 /**
429 * Invoked during a graceful Directory Server shutdown.
430 */
431 SHUTDOWN("shutdown"),
432
433
434
435 /**
436 * Invoked during the Directory Server startup process.
437 */
438 STARTUP("startup"),
439
440
441
442 /**
443 * Invoked in the course of moving or renaming an entry
444 * subordinate to the target of a modify DN operation.
445 */
446 SUBORDINATEMODIFYDN("subordinatemodifydn");
447
448
449
450 // String representation of the value.
451 private final String name;
452
453
454
455 // Private constructor.
456 private PluginType(String name) { this.name = name; }
457
458
459
460 /**
461 * {@inheritDoc}
462 */
463 public String toString() { return name; }
464
465 }
466
467
468
469 // The "enabled" property definition.
470 private static final BooleanPropertyDefinition PD_ENABLED;
471
472
473
474 // The "invoke-for-internal-operations" property definition.
475 private static final BooleanPropertyDefinition PD_INVOKE_FOR_INTERNAL_OPERATIONS;
476
477
478
479 // The "java-class" property definition.
480 private static final ClassPropertyDefinition PD_JAVA_CLASS;
481
482
483
484 // The "plugin-type" property definition.
485 private static final EnumPropertyDefinition<PluginType> PD_PLUGIN_TYPE;
486
487
488
489 // Build the "enabled" property definition.
490 static {
491 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
492 builder.setOption(PropertyOption.MANDATORY);
493 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
494 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
495 PD_ENABLED = builder.getInstance();
496 INSTANCE.registerPropertyDefinition(PD_ENABLED);
497 }
498
499
500
501 // Build the "invoke-for-internal-operations" property definition.
502 static {
503 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "invoke-for-internal-operations");
504 builder.setOption(PropertyOption.ADVANCED);
505 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "invoke-for-internal-operations"));
506 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("true");
507 builder.setDefaultBehaviorProvider(provider);
508 PD_INVOKE_FOR_INTERNAL_OPERATIONS = builder.getInstance();
509 INSTANCE.registerPropertyDefinition(PD_INVOKE_FOR_INTERNAL_OPERATIONS);
510 }
511
512
513
514 // Build the "java-class" property definition.
515 static {
516 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
517 builder.setOption(PropertyOption.MANDATORY);
518 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
519 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
520 builder.addInstanceOf("org.opends.server.api.plugin.DirectoryServerPlugin");
521 PD_JAVA_CLASS = builder.getInstance();
522 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
523 }
524
525
526
527 // Build the "plugin-type" property definition.
528 static {
529 EnumPropertyDefinition.Builder<PluginType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "plugin-type");
530 builder.setOption(PropertyOption.MULTI_VALUED);
531 builder.setOption(PropertyOption.MANDATORY);
532 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "plugin-type"));
533 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<PluginType>());
534 builder.setEnumClass(PluginType.class);
535 PD_PLUGIN_TYPE = builder.getInstance();
536 INSTANCE.registerPropertyDefinition(PD_PLUGIN_TYPE);
537 }
538
539
540
541 // Register the tags associated with this managed object definition.
542 static {
543 INSTANCE.registerTag(Tag.valueOf("core-server"));
544 }
545
546
547
548 /**
549 * Get the Plugin configuration definition singleton.
550 *
551 * @return Returns the Plugin configuration definition singleton.
552 */
553 public static PluginCfgDefn getInstance() {
554 return INSTANCE;
555 }
556
557
558
559 /**
560 * Private constructor.
561 */
562 private PluginCfgDefn() {
563 super("plugin", TopCfgDefn.getInstance());
564 }
565
566
567
568 /**
569 * {@inheritDoc}
570 */
571 public PluginCfgClient createClientConfiguration(
572 ManagedObject<? extends PluginCfgClient> impl) {
573 return new PluginCfgClientImpl(impl);
574 }
575
576
577
578 /**
579 * {@inheritDoc}
580 */
581 public PluginCfg createServerConfiguration(
582 ServerManagedObject<? extends PluginCfg> impl) {
583 return new PluginCfgServerImpl(impl);
584 }
585
586
587
588 /**
589 * {@inheritDoc}
590 */
591 public Class<PluginCfg> getServerConfigurationClass() {
592 return PluginCfg.class;
593 }
594
595
596
597 /**
598 * Get the "enabled" property definition.
599 * <p>
600 * Indicates whether the plug-in is enabled for use.
601 *
602 * @return Returns the "enabled" property definition.
603 */
604 public BooleanPropertyDefinition getEnabledPropertyDefinition() {
605 return PD_ENABLED;
606 }
607
608
609
610 /**
611 * Get the "invoke-for-internal-operations" property definition.
612 * <p>
613 * Indicates whether the plug-in should be invoked for internal
614 * operations.
615 * <p>
616 * Any plug-in that can be invoked for internal operations must
617 * ensure that it does not create any new internal operatons that can
618 * cause the same plug-in to be re-invoked.
619 *
620 * @return Returns the "invoke-for-internal-operations" property definition.
621 */
622 public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() {
623 return PD_INVOKE_FOR_INTERNAL_OPERATIONS;
624 }
625
626
627
628 /**
629 * Get the "java-class" property definition.
630 * <p>
631 * Specifies the fully-qualified name of the Java class that
632 * provides the plug-in implementation.
633 *
634 * @return Returns the "java-class" property definition.
635 */
636 public ClassPropertyDefinition getJavaClassPropertyDefinition() {
637 return PD_JAVA_CLASS;
638 }
639
640
641
642 /**
643 * Get the "plugin-type" property definition.
644 * <p>
645 * Specifies the set of plug-in types for the plug-in, which
646 * specifies the times at which the plug-in is invoked.
647 *
648 * @return Returns the "plugin-type" property definition.
649 */
650 public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() {
651 return PD_PLUGIN_TYPE;
652 }
653
654
655
656 /**
657 * Managed object client implementation.
658 */
659 private static class PluginCfgClientImpl implements
660 PluginCfgClient {
661
662 // Private implementation.
663 private ManagedObject<? extends PluginCfgClient> impl;
664
665
666
667 // Private constructor.
668 private PluginCfgClientImpl(
669 ManagedObject<? extends PluginCfgClient> impl) {
670 this.impl = impl;
671 }
672
673
674
675 /**
676 * {@inheritDoc}
677 */
678 public Boolean isEnabled() {
679 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
680 }
681
682
683
684 /**
685 * {@inheritDoc}
686 */
687 public void setEnabled(boolean value) {
688 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
689 }
690
691
692
693 /**
694 * {@inheritDoc}
695 */
696 public boolean isInvokeForInternalOperations() {
697 return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
698 }
699
700
701
702 /**
703 * {@inheritDoc}
704 */
705 public void setInvokeForInternalOperations(Boolean value) {
706 impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value);
707 }
708
709
710
711 /**
712 * {@inheritDoc}
713 */
714 public String getJavaClass() {
715 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
716 }
717
718
719
720 /**
721 * {@inheritDoc}
722 */
723 public void setJavaClass(String value) {
724 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
725 }
726
727
728
729 /**
730 * {@inheritDoc}
731 */
732 public SortedSet<PluginType> getPluginType() {
733 return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
734 }
735
736
737
738 /**
739 * {@inheritDoc}
740 */
741 public void setPluginType(Collection<PluginType> values) {
742 impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values);
743 }
744
745
746
747 /**
748 * {@inheritDoc}
749 */
750 public ManagedObjectDefinition<? extends PluginCfgClient, ? extends PluginCfg> definition() {
751 return INSTANCE;
752 }
753
754
755
756 /**
757 * {@inheritDoc}
758 */
759 public PropertyProvider properties() {
760 return impl;
761 }
762
763
764
765 /**
766 * {@inheritDoc}
767 */
768 public void commit() throws ManagedObjectAlreadyExistsException,
769 MissingMandatoryPropertiesException, ConcurrentModificationException,
770 OperationRejectedException, AuthorizationException,
771 CommunicationException {
772 impl.commit();
773 }
774
775 }
776
777
778
779 /**
780 * Managed object server implementation.
781 */
782 private static class PluginCfgServerImpl implements
783 PluginCfg {
784
785 // Private implementation.
786 private ServerManagedObject<? extends PluginCfg> impl;
787
788 // The value of the "enabled" property.
789 private final boolean pEnabled;
790
791 // The value of the "invoke-for-internal-operations" property.
792 private final boolean pInvokeForInternalOperations;
793
794 // The value of the "java-class" property.
795 private final String pJavaClass;
796
797 // The value of the "plugin-type" property.
798 private final SortedSet<PluginType> pPluginType;
799
800
801
802 // Private constructor.
803 private PluginCfgServerImpl(ServerManagedObject<? extends PluginCfg> impl) {
804 this.impl = impl;
805 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
806 this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
807 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
808 this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
809 }
810
811
812
813 /**
814 * {@inheritDoc}
815 */
816 public void addChangeListener(
817 ConfigurationChangeListener<PluginCfg> listener) {
818 impl.registerChangeListener(listener);
819 }
820
821
822
823 /**
824 * {@inheritDoc}
825 */
826 public void removeChangeListener(
827 ConfigurationChangeListener<PluginCfg> listener) {
828 impl.deregisterChangeListener(listener);
829 }
830
831
832
833 /**
834 * {@inheritDoc}
835 */
836 public boolean isEnabled() {
837 return pEnabled;
838 }
839
840
841
842 /**
843 * {@inheritDoc}
844 */
845 public boolean isInvokeForInternalOperations() {
846 return pInvokeForInternalOperations;
847 }
848
849
850
851 /**
852 * {@inheritDoc}
853 */
854 public String getJavaClass() {
855 return pJavaClass;
856 }
857
858
859
860 /**
861 * {@inheritDoc}
862 */
863 public SortedSet<PluginType> getPluginType() {
864 return pPluginType;
865 }
866
867
868
869 /**
870 * {@inheritDoc}
871 */
872 public Class<? extends PluginCfg> configurationClass() {
873 return PluginCfg.class;
874 }
875
876
877
878 /**
879 * {@inheritDoc}
880 */
881 public DN dn() {
882 return impl.getDN();
883 }
884
885 }
886 }