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 legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2010 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027package org.opends.server.api.plugin;
028
029import org.forgerock.i18n.LocalizableMessage;
030import org.forgerock.opendj.ldap.ResultCode;
031import org.opends.server.types.DN;
032import org.opends.server.types.DisconnectReason;
033
034import java.util.List;
035
036/**
037 * This class defines a data structure that holds information about
038 * the result of processing by a plugin.
039 */
040@org.opends.server.types.PublicAPI(
041    stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
042    mayInstantiate=true,
043    mayExtend=false,
044    mayInvoke=true)
045public final class PluginResult
046{
047  /** Contract for operation results. */
048  public static interface OperationResult
049  {
050    /**
051     * Indicates whether processing on the associated operation should continue.
052     *
053     * @return {@code true} if processing on the associated operation should continue, or
054     *         {@code false} if it should stop.
055     */
056    boolean continueProcessing();
057
058    /**
059     * Retrieves the error message if {@link #continueProcessing()} returned {@code false}.
060     *
061     * @return An error message explaining why processing should stop or {@code null} if none is
062     *         provided.
063     */
064    LocalizableMessage getErrorMessage();
065
066    /**
067     * Retrieves the result code for the operation if {@link #continueProcessing()} returned
068     * {@code false}.
069     *
070     * @return the result code for the operation or {@code null} if none is provided.
071     */
072    ResultCode getResultCode();
073
074    /**
075     * Retrieves the matched DN for the operation if {@link #continueProcessing()} returned
076     * {@code false}.
077     *
078     * @return the matched DN for the operation or {@code null} if none is provided.
079     */
080    DN getMatchedDN();
081
082    /**
083     * Retrieves the referral URLs for the operation if {@link #continueProcessing()} returned
084     * {@code false}.
085     *
086     * @return the referral URLs for the operation or {@code null} if none is provided.
087     */
088    List<String> getReferralURLs();
089  }
090
091  /**
092   * Defines a startup plugin result consisting of either continue
093   * skip further plugins, or stop startup with an error message.
094   */
095  public static final class Startup
096  {
097    /** Whether to continue startup. */
098    private final boolean continueProcessing;
099
100    /** Whether to invoke the rest of the plugins. */
101    private final boolean continuePluginProcessing;
102
103    /** An message explaining why startup should stop. */
104    private final LocalizableMessage errorMessage;
105
106    private static Startup DEFAULT_RESULT =
107        new Startup(true, true, null);
108
109    /**
110     * Constructs a new startup plugin result.
111     *
112     * @param continueProcessing Whether to continue startup.
113     * @param continuePluginProcessing Whether to invoke the rest
114     * of the plugins.
115     * @param errorMessage An message explaining why startup should stop.
116     */
117    private Startup(boolean continueProcessing,
118                    boolean continuePluginProcessing,
119                    LocalizableMessage errorMessage)
120    {
121      this.continueProcessing = continueProcessing;
122      this.errorMessage = errorMessage;
123      this.continuePluginProcessing = continuePluginProcessing;
124    }
125
126    /**
127     * Defines a continue processing startup plugin result.
128     *
129     * @return a continue processing startup plugin result.
130     */
131    public static Startup continueStartup()
132    {
133      return DEFAULT_RESULT;
134    }
135
136    /**
137     * Defines a skip further plugin processing startup plugin result.
138     *
139     * @return  a skip further plugin processing startup plugin result.
140     */
141    public static Startup skipFurtherPluginProcesssing()
142    {
143      return new Startup(true, false, null);
144    }
145
146    /**
147     * Defines a new stop processing startup plugin result.
148     *
149     * @param errorMessage An message explaining why processing
150     * should stop for the given entry.
151     *
152     * @return a new stop processing startup plugin result.
153     */
154    public static Startup stopStartup(LocalizableMessage errorMessage)
155    {
156      return new Startup(false, false, errorMessage);
157    }
158
159    /**
160     * Whether to continue startup.
161     *
162     * @return {@code true} if processing should continue
163     * or {@code false} otherwise.
164     */
165    public boolean continueProcessing()
166    {
167      return continueProcessing;
168    }
169
170    /**
171     * Whether to invoke the rest of the plugins.
172     *
173     * @return {@code true} if the rest of the plugins should
174     * be invoked for {@code false} to skip the rest of the plugins.
175     */
176    public boolean continuePluginProcessing()
177    {
178      return continuePluginProcessing;
179    }
180
181    /**
182     * Retrieves the error message if {@link #continueProcessing()}
183     * returned {@code false}.
184     *
185     * @return An error message explaining why processing should
186     * stop or {@code null} if none is provided.
187     */
188    public LocalizableMessage getErrorMessage()
189    {
190      return errorMessage;
191    }
192  }
193
194  /**
195   * Defines a pre parse plugin result for core server operation
196   * processing consisting of either continue, skip further
197   * plugins, or stop operation processing with a result code,
198   * matched DN, referral URLs, and error message.
199   */
200  public static final class PreParse implements OperationResult
201  {
202    /** Whether to continue operation processing. */
203    private final boolean continueProcessing;
204
205    /** Whether to invoke the rest of the plugins. */
206    private final boolean continuePluginProcessing;
207
208    /** An message explaining why processing should stop. */
209    private final LocalizableMessage errorMessage;
210
211    /** The matched DN for this result. */
212    private final DN matchedDN;
213
214    /** The set of referral URLs for this result. */
215    private final List<String> referralURLs;
216
217    /** The result code for this result. */
218    private final ResultCode resultCode;
219
220    private static PreParse DEFAULT_RESULT =
221        new PreParse(true, true, null, null, null, null);
222
223    /**
224     * Constructs a new pre parse plugin result.
225     *
226     * @param continueProcessing Whether to continue startup.
227     * @param continuePluginProcessing Whether to invoke the rest
228     * of the plugins.
229     * @param errorMessage An message explaining why processing should stop.
230     * @param resultCode The result code for this result.
231     * @param matchedDN The matched DN for this result.
232     * @param referralURLs The set of referral URLs for this result.
233     */
234    private PreParse (boolean continueProcessing,
235                      boolean continuePluginProcessing,
236                      LocalizableMessage errorMessage,
237                      ResultCode resultCode, DN matchedDN,
238                      List<String> referralURLs)
239    {
240      this.continueProcessing = continueProcessing;
241      this.errorMessage = errorMessage;
242      this.continuePluginProcessing = continuePluginProcessing;
243      this.resultCode = resultCode;
244      this.matchedDN = matchedDN;
245      this.referralURLs = referralURLs;
246    }
247
248    /**
249     * Defines a continue processing pre parse plugin result.
250     *
251     * @return a continue processing pre parse plugin result.
252     */
253    public static PreParse continueOperationProcessing()
254    {
255      return DEFAULT_RESULT;
256    }
257
258    /**
259     * Defines a skip further plugin processing pre parse plugin result.
260     *
261     * @return  a skip further plugin processing pre parse plugin result.
262     */
263    public static PreParse skipFurtherPluginProcesssing()
264    {
265      return new PreParse(true, false, null, null, null, null);
266    }
267
268    /**
269     * Defines a new stop processing pre parse plugin result.
270     *
271     * @param resultCode The result code for this result.
272     * @param errorMessage An message explaining why processing should stop.
273     * @param matchedDN The matched DN for this result.
274     * @param referralURLs The set of referral URLs for this result.
275     *
276     * @return a new stop processing pre parse plugin result.
277     */
278    public static PreParse stopProcessing(ResultCode resultCode,
279                                          LocalizableMessage errorMessage,
280                                          DN matchedDN,
281                                          List<String> referralURLs)
282    {
283      return new PreParse(false, false, errorMessage, resultCode,
284          matchedDN, referralURLs);
285    }
286
287    /**
288     * Constructs a new stop processing pre parse plugin result.
289     *
290     * @param resultCode The result code for this result.
291     * @param errorMessage An message explaining why processing should stop.
292     *
293     * @return a new stop processing pre parse plugin result.
294     */
295    public static PreParse stopProcessing(ResultCode resultCode,
296                                          LocalizableMessage errorMessage)
297    {
298      return new PreParse(false, false, errorMessage, resultCode,
299          null, null);
300    }
301
302    @Override
303    public boolean continueProcessing()
304    {
305      return continueProcessing;
306    }
307
308    /**
309     * Whether to invoke the rest of the plugins.
310     *
311     * @return {@code true} if the rest of the plugins should
312     * be invoked for {@code false} to skip the rest of the plugins.
313     */
314    public boolean continuePluginProcessing()
315    {
316      return continuePluginProcessing;
317    }
318
319    @Override
320    public LocalizableMessage getErrorMessage()
321    {
322      return errorMessage;
323    }
324
325    @Override
326    public ResultCode getResultCode()
327    {
328      return resultCode;
329    }
330
331    @Override
332    public DN getMatchedDN()
333    {
334      return matchedDN;
335    }
336
337    @Override
338    public List<String> getReferralURLs()
339    {
340      return referralURLs;
341    }
342  }
343
344  /**
345   * Defines a pre operation plugin result for core server operation
346   * processing consisting of either continue, skip further
347   * plugins, or stop operation processing with a result code,
348   * matched DN, referral URLs, and error message.
349   */
350  public static final class PreOperation implements OperationResult
351  {
352    /** Whether to continue operation processing. */
353    private final boolean continueProcessing;
354
355    /** Whether to invoke the rest of the plugins. */
356    private final boolean continuePluginProcessing;
357
358    /** An message explaining why processing should stop. */
359    private final LocalizableMessage errorMessage;
360
361    /** The matched DN for this result. */
362    private final DN matchedDN;
363
364    /** The set of referral URLs for this result. */
365    private final List<String> referralURLs;
366
367    /** The result code for this result. */
368    private final ResultCode resultCode;
369
370    private static PreOperation DEFAULT_RESULT =
371        new PreOperation(true, true, null, null, null, null);
372
373    /**
374     * Constructs a new pre operation plugin result.
375     *
376     * @param continueProcessing Whether to continue startup.
377     * @param continuePluginProcessing Whether to invoke the rest
378     * of the plugins.
379     * @param errorMessage An message explaining why processing should stop.
380     * @param resultCode The result code for this result.
381     * @param matchedDN The matched DN for this result.
382     * @param referralURLs The set of referral URLs for this result.
383     */
384    private PreOperation (boolean continueProcessing,
385                          boolean continuePluginProcessing,
386                          LocalizableMessage errorMessage,
387                          ResultCode resultCode, DN matchedDN,
388                          List<String> referralURLs)
389    {
390      this.continueProcessing = continueProcessing;
391      this.errorMessage = errorMessage;
392      this.continuePluginProcessing = continuePluginProcessing;
393      this.resultCode = resultCode;
394      this.matchedDN = matchedDN;
395      this.referralURLs = referralURLs;
396    }
397
398    /**
399     * Defines a continue processing pre operation plugin result.
400     *
401     * @return a continue processing pre operation plugin result.
402     */
403    public static PreOperation continueOperationProcessing()
404    {
405      return DEFAULT_RESULT;
406    }
407
408    /**
409     * Defines a skip further plugin processing pre operation plugin result.
410     *
411     * @return  a skip further plugin processing pre operation plugin result.
412     */
413    public static PreOperation skipFurtherPluginProcesssing()
414    {
415      return new PreOperation(true, false, null, null, null, null);
416    }
417
418    /**
419     * Defines a new stop processing pre operation plugin result.
420     *
421     * @param resultCode The result code for this result.
422     * @param errorMessage An message explaining why processing should stop.
423     * @param matchedDN The matched DN for this result.
424     * @param referralURLs The set of referral URLs for this result.
425     *
426     * @return a new stop processing pre operation plugin result.
427     */
428    public static PreOperation stopProcessing(
429        ResultCode resultCode, LocalizableMessage errorMessage, DN matchedDN,
430        List<String> referralURLs)
431    {
432      return new PreOperation(false, false, errorMessage, resultCode,
433          matchedDN, referralURLs);
434    }
435
436    /**
437     * Constructs a new stop processing pre operation plugin result.
438     *
439     * @param resultCode The result code for this result.
440     * @param errorMessage An message explaining why processing should stop.
441     *
442     * @return a new stop processing pre operation plugin result.
443     */
444    public static PreOperation stopProcessing(ResultCode resultCode,
445                                              LocalizableMessage errorMessage)
446    {
447      return new PreOperation(false, false, errorMessage, resultCode,
448          null, null);
449    }
450
451    @Override
452    public boolean continueProcessing()
453    {
454      return continueProcessing;
455    }
456
457    /**
458     * Whether to invoke the rest of the plugins.
459     *
460     * @return {@code true} if the rest of the plugins should
461     * be invoked for {@code false} to skip the rest of the plugins.
462     */
463    public boolean continuePluginProcessing()
464    {
465      return continuePluginProcessing;
466    }
467
468    @Override
469    public LocalizableMessage getErrorMessage()
470    {
471      return errorMessage;
472    }
473
474    @Override
475    public ResultCode getResultCode()
476    {
477      return resultCode;
478    }
479
480    @Override
481    public DN getMatchedDN()
482    {
483      return matchedDN;
484    }
485
486    @Override
487    public List<String> getReferralURLs()
488    {
489      return referralURLs;
490    }
491  }
492
493  /**
494   * Defines a post operation plugin result for core server operation
495   * processing consisting of either continue, skip further
496   * plugins, or stop operation processing with a result code,
497   * matched DN, referral URLs, and error message.
498   */
499  public static final class PostOperation implements OperationResult
500  {
501    /** Whether to continue operation processing. */
502    private final boolean continueProcessing;
503
504    /** An message explaining why processing should stop. */
505    private final LocalizableMessage errorMessage;
506
507    /** The matched DN for this result. */
508    private final DN matchedDN;
509
510    /** The set of referral URLs for this result. */
511    private final List<String> referralURLs;
512
513    /** The result code for this result. */
514    private final ResultCode resultCode;
515
516    private static PostOperation DEFAULT_RESULT =
517        new PostOperation(true, null, null, null, null);
518
519    /**
520     * Constructs a new post operation plugin result.
521     *
522     * @param continueProcessing Whether to continue startup.
523     * @param errorMessage An message explaining why processing should stop.
524     * @param resultCode The result code for this result.
525     * @param matchedDN The matched DN for this result.
526     * @param referralURLs The set of referral URLs for this result.
527     */
528    private PostOperation(boolean continueProcessing,
529                          LocalizableMessage errorMessage,
530                          ResultCode resultCode, DN matchedDN,
531                          List<String> referralURLs)
532    {
533      this.continueProcessing = continueProcessing;
534      this.errorMessage = errorMessage;
535      this.resultCode = resultCode;
536      this.matchedDN = matchedDN;
537      this.referralURLs = referralURLs;
538    }
539
540    /**
541     * Defines a continue processing post operation plugin result.
542     *
543     * @return a continue processing post operation plugin result.
544     */
545    public static PostOperation continueOperationProcessing()
546    {
547      return DEFAULT_RESULT;
548    }
549
550    /**
551     * Defines a new stop processing post operation plugin result.
552     *
553     * @param resultCode The result code for this result.
554     * @param errorMessage An message explaining why processing should stop.
555     * @param matchedDN The matched DN for this result.
556     * @param referralURLs The set of referral URLs for this result.
557     *
558     * @return a new stop processing post operation plugin result.
559     */
560    public static PostOperation stopProcessing(
561        ResultCode resultCode, LocalizableMessage errorMessage, DN matchedDN,
562        List<String> referralURLs)
563    {
564      return new PostOperation(false, errorMessage, resultCode,
565          matchedDN, referralURLs);
566    }
567
568    /**
569     * Constructs a new stop processing post operation plugin result.
570     *
571     * @param resultCode The result code for this result.
572     * @param errorMessage An message explaining why processing should stop.
573     *
574     * @return a new stop processing post operation plugin result.
575     */
576    public static PostOperation stopProcessing(ResultCode resultCode,
577                                               LocalizableMessage errorMessage)
578    {
579      return new PostOperation(false, errorMessage, resultCode, null,
580          null);
581    }
582
583    @Override
584    public boolean continueProcessing()
585    {
586      return continueProcessing;
587    }
588
589    @Override
590    public LocalizableMessage getErrorMessage()
591    {
592      return errorMessage;
593    }
594
595    @Override
596    public ResultCode getResultCode()
597    {
598      return resultCode;
599    }
600
601    @Override
602    public DN getMatchedDN()
603    {
604      return matchedDN;
605    }
606
607    @Override
608    public List<String> getReferralURLs()
609    {
610      return referralURLs;
611    }
612  }
613
614
615  /**
616   * Defines a post response plugin result for core server operation
617   * processing consisting of either continue or skip further plugins.
618   */
619  public static final class PostResponse
620  {
621    /** Whether to invoke the rest of the plugins. */
622    private final boolean continuePluginProcessing;
623
624    private static PostResponse DEFAULT_RESULT =
625        new PostResponse(true);
626
627    /**
628     * Constructs a new post response plugin result.
629     *
630     * @param continuePluginProcessing Whether to invoke the rest
631     * of the plugins.
632     */
633    private PostResponse (boolean continuePluginProcessing)
634    {
635      this.continuePluginProcessing = continuePluginProcessing;
636    }
637
638    /**
639     * Defines a continue processing post response plugin result.
640     *
641     * @return a continue processing post response plugin result.
642     */
643    public static PostResponse continueOperationProcessing()
644    {
645      return DEFAULT_RESULT;
646    }
647
648    /**
649     * Defines a skip further plugin processing post response plugin result.
650     *
651     * @return  a skip further plugin processing post response plugin result.
652     */
653    public static PostResponse skipFurtherPluginProcesssing()
654    {
655      return new PostResponse(false);
656    }
657
658    /**
659     * Whether to invoke the rest of the plugins.
660     *
661     * @return {@code true} if the rest of the plugins should
662     * be invoked for {@code false} to skip the rest of the plugins.
663     */
664    public boolean continuePluginProcessing()
665    {
666      return continuePluginProcessing;
667    }
668  }
669
670  /**
671   * Defines a LDIF plugin result for import from LDIF
672   * processing consisting of either continue, skip further
673   * plugins, or stop processing with an error message.
674   */
675  public static final class ImportLDIF
676  {
677    /** Whether to continue operation processing. */
678    private final boolean continueProcessing;
679
680    /** Whether to invoke the rest of the plugins. */
681    private final boolean continuePluginProcessing;
682
683    /** An message explaining why processing should stop. */
684    private final LocalizableMessage errorMessage;
685
686    private static ImportLDIF DEFAULT_RESULT =
687        new ImportLDIF(true, true, null);
688
689    /**
690     * Constructs a new import LDIF plugin result.
691     *
692     * @param continueProcessing Whether to continue startup.
693     * @param continuePluginProcessing Whether to invoke the rest
694     * of the plugins.
695     * @param errorMessage An message explaining why startup should stop.
696     */
697    private ImportLDIF(boolean continueProcessing,
698                       boolean continuePluginProcessing,
699                       LocalizableMessage errorMessage)
700    {
701      this.continueProcessing = continueProcessing;
702      this.errorMessage = errorMessage;
703      this.continuePluginProcessing = continuePluginProcessing;
704    }
705
706    /**
707     * Defines a continue processing LDIF import plugin result.
708     *
709     * @return a continue processing LDIF import plugin result.
710     */
711    public static ImportLDIF continueEntryProcessing()
712    {
713      return DEFAULT_RESULT;
714    }
715
716    /**
717     * Defines a skip further plugin processing LDIF import plugin result.
718     *
719     * @return  a skip further plugin processing LDIF import plugin result.
720     */
721    public static ImportLDIF skipFurtherPluginProcesssing()
722    {
723      return new ImportLDIF(true, false, null);
724    }
725
726    /**
727     * Defines a new stop processing LDIF import plugin result.
728     *
729     * @param errorMessage An message explaining why processing
730     * should stop for the given entry.
731     *
732     * @return a new stop processing LDIF import plugin result.
733     */
734    public static ImportLDIF stopEntryProcessing(LocalizableMessage errorMessage)
735    {
736      return new ImportLDIF(false, false, errorMessage);
737    }
738
739    /**
740     * Whether to continue operation processing.
741     *
742     * @return {@code true} if processing should continue
743     * or {@code false} otherwise.
744     */
745    public boolean continueProcessing()
746    {
747      return continueProcessing;
748    }
749
750    /**
751     * Whether to invoke the rest of the plugins.
752     *
753     * @return {@code true} if the rest of the plugins should
754     * be invoked for {@code false} to skip the rest of the plugins.
755     */
756    public boolean continuePluginProcessing()
757    {
758      return continuePluginProcessing;
759    }
760
761    /**
762     * Retrieves the error message if {@link #continueProcessing()}
763     * returned {@code false}.
764     *
765     * @return An error message explaining why processing should
766     * stop or {@code null} if none is provided.
767     */
768    public LocalizableMessage getErrorMessage()
769    {
770      return errorMessage;
771    }
772  }
773
774  /**
775   * Defines a subordinate modify DN plugin result for core server
776   * operation processing consisting of either continue, skip further
777   * plugins, or stop operation processing with a result code,
778   * matched DN, referral URLs, and error message.
779   */
780  public static final class SubordinateModifyDN implements OperationResult
781  {
782    /** Whether to continue operation processing. */
783    private final boolean continueProcessing;
784
785    /** Whether to invoke the rest of the plugins. */
786    private final boolean continuePluginProcessing;
787
788    /** An message explaining why processing should stop. */
789    private final LocalizableMessage errorMessage;
790
791    /** The matched DN for this result. */
792    private final DN matchedDN;
793
794    /** The set of referral URLs for this result. */
795    private final List<String> referralURLs;
796
797    /** The result code for this result. */
798    private final ResultCode resultCode;
799
800    private static SubordinateModifyDN DEFAULT_RESULT =
801        new SubordinateModifyDN(true, true, null, null, null, null);
802
803    /**
804     * Constructs a new subordinate modify DN plugin result.
805     *
806     * @param continueProcessing Whether to continue startup.
807     * @param continuePluginProcessing Whether to invoke the rest
808     * of the plugins.
809     * @param errorMessage An message explaining why processing should stop.
810     * @param resultCode The result code for this result.
811     * @param matchedDN The matched DN for this result.
812     * @param referralURLs The set of referral URLs for this result.
813     */
814    private SubordinateModifyDN(boolean continueProcessing,
815                                boolean continuePluginProcessing,
816                                LocalizableMessage errorMessage,
817                                ResultCode resultCode, DN matchedDN,
818                                List<String> referralURLs)
819    {
820      this.continueProcessing = continueProcessing;
821      this.errorMessage = errorMessage;
822      this.continuePluginProcessing = continuePluginProcessing;
823      this.resultCode = resultCode;
824      this.matchedDN = matchedDN;
825      this.referralURLs = referralURLs;
826    }
827
828    /**
829     * Defines a continue processing subordinate modify DN plugin result.
830     *
831     * @return a continue processing subordinate modify DN plugin result.
832     */
833    public static SubordinateModifyDN continueOperationProcessing()
834    {
835      return DEFAULT_RESULT;
836    }
837
838    /**
839     * Defines a skip further plugin processing subordinate modify DN
840     * plugin result.
841     *
842     * @return  a skip further plugin processing subordinate modify DN
843     * plugin result.
844     */
845    public static SubordinateModifyDN skipFurtherPluginProcesssing()
846    {
847      return new SubordinateModifyDN(true, false, null, null, null,
848          null);
849    }
850
851    /**
852     * Defines a new stop processing subordinate modify DN plugin result.
853     *
854     * @param resultCode The result code for this result.
855     * @param errorMessage An message explaining why processing should stop.
856     * @param matchedDN The matched DN for this result.
857     * @param referralURLs The set of referral URLs for this result.
858     *
859     * @return a new stop processing subordinate modify DN plugin result.
860     */
861    public static SubordinateModifyDN stopProcessing(
862        ResultCode resultCode, LocalizableMessage errorMessage, DN matchedDN,
863        List<String> referralURLs)
864    {
865      return new SubordinateModifyDN(false, false, errorMessage,
866          resultCode, matchedDN, referralURLs);
867    }
868
869    /**
870     * Constructs a new stop processing subordinate modify DN plugin result.
871     *
872     * @param resultCode The result code for this result.
873     * @param errorMessage An message explaining why processing should stop.
874     * @return a new stop processing subordinate modify DN plugin result.
875     */
876    public static SubordinateModifyDN stopProcessing(
877        ResultCode resultCode, LocalizableMessage errorMessage)
878    {
879      return new SubordinateModifyDN(false, false, errorMessage,
880          resultCode, null, null);
881    }
882
883    @Override
884    public boolean continueProcessing()
885    {
886      return continueProcessing;
887    }
888
889    /**
890     * Whether to invoke the rest of the plugins.
891     *
892     * @return {@code true} if the rest of the plugins should
893     * be invoked for {@code false} to skip the rest of the plugins.
894     */
895    public boolean continuePluginProcessing()
896    {
897      return continuePluginProcessing;
898    }
899
900    @Override
901    public LocalizableMessage getErrorMessage()
902    {
903      return errorMessage;
904    }
905
906    @Override
907    public ResultCode getResultCode()
908    {
909      return resultCode;
910    }
911
912    @Override
913    public DN getMatchedDN()
914    {
915      return matchedDN;
916    }
917
918    @Override
919    public List<String> getReferralURLs()
920    {
921      return referralURLs;
922    }
923  }
924
925  /**
926   * Defines a subordinate delete plugin result for core server
927   * operation processing consisting of either continue, skip
928   * further plugins, or stop operation processing with a result
929   * code, matched DN, referral URLs, and error message.
930   */
931  public static final class SubordinateDelete implements OperationResult
932  {
933    /** Whether to continue operation processing. */
934    private final boolean continueProcessing;
935
936    /** Whether to invoke the rest of the plugins. */
937    private final boolean continuePluginProcessing;
938
939    /** An message explaining why processing should stop. */
940    private final LocalizableMessage errorMessage;
941
942    /** The matched DN for this result. */
943    private final DN matchedDN;
944
945    /** The set of referral URLs for this result. */
946    private final List<String> referralURLs;
947
948    /** The result code for this result. */
949    private final ResultCode resultCode;
950
951    private static SubordinateDelete DEFAULT_RESULT =
952        new SubordinateDelete(true, true, null, null, null, null);
953
954    /**
955     * Constructs a new subordinate delete plugin result.
956     *
957     * @param continueProcessing Whether to continue startup.
958     * @param continuePluginProcessing Whether to invoke the rest of the plugins.
959     * @param errorMessage An message explaining why processing should stop.
960     * @param resultCode The result code for this result.
961     * @param matchedDN The matched DN for this result.
962     * @param referralURLs The set of referral URLs for this result.
963     */
964    private SubordinateDelete(boolean continueProcessing,
965                              boolean continuePluginProcessing,
966                              LocalizableMessage errorMessage,
967                              ResultCode resultCode, DN matchedDN,
968                              List<String> referralURLs)
969    {
970      this.continueProcessing = continueProcessing;
971      this.errorMessage = errorMessage;
972      this.continuePluginProcessing = continuePluginProcessing;
973      this.resultCode = resultCode;
974      this.matchedDN = matchedDN;
975      this.referralURLs = referralURLs;
976    }
977
978    /**
979     * Defines a continue processing subordinate delete plugin result.
980     *
981     * @return a continue processing subordinate delete plugin result.
982     */
983    public static SubordinateDelete continueOperationProcessing()
984    {
985      return DEFAULT_RESULT;
986    }
987
988    /**
989     * Defines a skip further plugin processing subordinate delete
990     * plugin result.
991     *
992     * @return  a skip further plugin processing subordinate delete
993     * plugin result.
994     */
995    public static SubordinateDelete skipFurtherPluginProcesssing()
996    {
997      return new SubordinateDelete(true, false, null, null, null,
998          null);
999    }
1000
1001    /**
1002     * Defines a new stop processing subordinate delete plugin result.
1003     *
1004     * @param resultCode The result code for this result.
1005     * @param errorMessage An message explaining why processing should stop.
1006     * @param matchedDN The matched DN for this result.
1007     * @param referralURLs The set of referral URLs for this result.
1008     *
1009     * @return a new stop processing subordinate delete plugin result.
1010     */
1011    public static SubordinateDelete stopProcessing(
1012        ResultCode resultCode, LocalizableMessage errorMessage, DN matchedDN,
1013        List<String> referralURLs)
1014    {
1015      return new SubordinateDelete(false, false, errorMessage,
1016          resultCode, matchedDN, referralURLs);
1017    }
1018
1019    /**
1020     * Constructs a new stop processing subordinate delete plugin result.
1021     *
1022     * @param resultCode The result code for this result.
1023     * @param errorMessage An message explaining why processing should stop.
1024     * @return a new stop processing subordinate delete plugin result.
1025     */
1026    public static SubordinateDelete stopProcessing(
1027        ResultCode resultCode, LocalizableMessage errorMessage)
1028    {
1029      return new SubordinateDelete(false, false, errorMessage,
1030          resultCode, null, null);
1031    }
1032
1033    @Override
1034    public boolean continueProcessing()
1035    {
1036      return continueProcessing;
1037    }
1038
1039    /**
1040     * Whether to invoke the rest of the plugins.
1041     *
1042     * @return {@code true} if the rest of the plugins should
1043     * be invoked for {@code false} to skip the rest of the plugins.
1044     */
1045    public boolean continuePluginProcessing()
1046    {
1047      return continuePluginProcessing;
1048    }
1049
1050    @Override
1051    public LocalizableMessage getErrorMessage()
1052    {
1053      return errorMessage;
1054    }
1055
1056    @Override
1057    public ResultCode getResultCode()
1058    {
1059      return resultCode;
1060    }
1061
1062    @Override
1063    public DN getMatchedDN()
1064    {
1065      return matchedDN;
1066    }
1067
1068    @Override
1069    public List<String> getReferralURLs()
1070    {
1071      return referralURLs;
1072    }
1073  }
1074
1075  /**
1076   * Defines an intermediate response plugin result for core server
1077   *  operation processing consisting of either continue, skip further
1078   * plugins, or stop operation processing with a result code,
1079   * matched DN, referral URLs, and error message.
1080   */
1081  public static final class IntermediateResponse implements OperationResult
1082  {
1083    /** Whether to continue operation processing. */
1084    private final boolean continueProcessing;
1085
1086    /** Whether to invoke the rest of the plugins. */
1087    private final boolean continuePluginProcessing;
1088
1089    /** Whether to send the intermediate response to the client. */
1090    private final boolean sendResponse;
1091
1092    /** An message explaining why processing should stop. */
1093    private final LocalizableMessage errorMessage;
1094
1095    /** The matched DN for this result. */
1096    private final DN matchedDN;
1097
1098    /** The set of referral URLs for this result. */
1099    private final List<String> referralURLs;
1100
1101    /** The result code for this result. */
1102    private final ResultCode resultCode;
1103
1104    private static IntermediateResponse DEFAULT_RESULT =
1105        new IntermediateResponse(true, true, true, null, null, null,
1106            null);
1107
1108    /**
1109     * Constructs a new intermediate response plugin result.
1110     *
1111     * @param continueProcessing Whether to continue startup.
1112     * @param continuePluginProcessing Whether to invoke the rest
1113     * of the plugins.
1114     * @param sendResponse Whether to send the intermediate response
1115     * to the client.
1116     * @param errorMessage An message explaining why processing should stop.
1117     * @param resultCode The result code for this result.
1118     * @param matchedDN The matched DN for this result.
1119     * @param referralURLs The set of referral URLs for this result.
1120     */
1121    private IntermediateResponse(boolean continueProcessing,
1122                                 boolean continuePluginProcessing,
1123                                 boolean sendResponse,
1124                                 LocalizableMessage errorMessage,
1125                                 ResultCode resultCode, DN matchedDN,
1126                                 List<String> referralURLs)
1127    {
1128      this.continueProcessing = continueProcessing;
1129      this.errorMessage = errorMessage;
1130      this.continuePluginProcessing = continuePluginProcessing;
1131      this.resultCode = resultCode;
1132      this.matchedDN = matchedDN;
1133      this.referralURLs = referralURLs;
1134      this.sendResponse = sendResponse;
1135    }
1136
1137    /**
1138     * Defines a continue processing intermediate response plugin result.
1139     *
1140     * @param sendResponse Whether to send the intermediate response
1141     * to the client.
1142     * @return a continue processing intermediate response plugin result.
1143     */
1144    public static IntermediateResponse
1145    continueOperationProcessing(boolean sendResponse)
1146    {
1147      if(sendResponse)
1148      {
1149        return DEFAULT_RESULT;
1150      }
1151      else
1152      {
1153        return new IntermediateResponse(true, true, sendResponse,
1154            null, null, null, null);
1155      }
1156    }
1157
1158    /**
1159     * Defines a skip further plugin processing intermediate response
1160     * plugin result.
1161     *
1162     * @param sendResponse Whether to send the intermediate response
1163     * to the client.
1164     *
1165     * @return  a skip further plugin processing intermediate response
1166     * plugin result.
1167     */
1168    public static IntermediateResponse
1169    skipFurtherPluginProcesssing(boolean sendResponse)
1170    {
1171      return new IntermediateResponse(true, false, sendResponse,
1172          null, null, null, null);
1173    }
1174
1175    /**
1176     * Defines a new stop processing intermediate response plugin result.
1177     *
1178     * @param sendResponse Whether to send the intermediate response
1179     * to the client.
1180     * @param resultCode The result code for this result.
1181     * @param errorMessage An message explaining why processing should stop.
1182     * @param matchedDN The matched DN for this result.
1183     * @param referralURLs The set of referral URLs for this result.
1184     *
1185     * @return a new stop processing intermediate response plugin result.
1186     */
1187    public static IntermediateResponse stopProcessing(
1188        boolean sendResponse, ResultCode resultCode,
1189        LocalizableMessage errorMessage, DN matchedDN, List<String> referralURLs)
1190    {
1191      return new IntermediateResponse(false, false, sendResponse,
1192          errorMessage, resultCode, matchedDN, referralURLs);
1193    }
1194
1195    /**
1196     * Constructs a new stop processing intermediate response plugin result.
1197     *
1198     * @param sendResponse Whether to send the intermediate response
1199     * to the client.
1200     * @param resultCode The result code for this result.
1201     * @param errorMessage An message explaining why processing should stop.
1202     *
1203     * @return a new stop processing intermediate response plugin result.
1204     */
1205    public static IntermediateResponse stopProcessing(
1206        boolean sendResponse, ResultCode resultCode,
1207        LocalizableMessage errorMessage)
1208    {
1209      return new IntermediateResponse(false, false, sendResponse,
1210          errorMessage, resultCode, null, null);
1211    }
1212
1213    @Override
1214    public boolean continueProcessing()
1215    {
1216      return continueProcessing;
1217    }
1218
1219    /**
1220     * Whether to invoke the rest of the plugins.
1221     *
1222     * @return {@code true} if the rest of the plugins should
1223     * be invoked for {@code false} to skip the rest of the plugins.
1224     */
1225    public boolean continuePluginProcessing()
1226    {
1227      return continuePluginProcessing;
1228    }
1229
1230    /**
1231     * Whether to send the intermediate response to the client.
1232     *
1233     * @return {@code true} if the intermediate response should
1234     * be sent to the client or {@code false} otherwise.
1235     */
1236    public boolean sendResponse()
1237    {
1238      return sendResponse;
1239    }
1240
1241    @Override
1242    public LocalizableMessage getErrorMessage()
1243    {
1244      return errorMessage;
1245    }
1246
1247    @Override
1248    public ResultCode getResultCode()
1249    {
1250      return resultCode;
1251    }
1252
1253    @Override
1254    public DN getMatchedDN()
1255    {
1256      return matchedDN;
1257    }
1258
1259    @Override
1260    public List<String> getReferralURLs()
1261    {
1262      return referralURLs;
1263    }
1264  }
1265
1266  /**
1267   * Defines a post connect plugin result for client connection
1268   * processing consisting of either continue, skip further
1269   * plugins, or stop.
1270   */
1271  public static final class PostConnect
1272  {
1273    /** Whether to continue connection processing. */
1274    private final boolean continueProcessing;
1275
1276    /** Whether to invoke the rest of the plugins. */
1277    private final boolean continuePluginProcessing;
1278
1279    /** An message explaining why processing should stop. */
1280    private final LocalizableMessage errorMessage;
1281
1282    /** The disconnect reason that provides the generic cause for the disconnect. */
1283    private final DisconnectReason disconnectReason;
1284
1285    /** Whether to send a disconnect notification to the client. */
1286    private final boolean sendDisconnectNotification;
1287
1288    private static PostConnect DEFAULT_RESULT =
1289        new PostConnect(true, true, null, null, false);
1290
1291    /**
1292     * Constructs a new post connect plugin result.
1293     *
1294     * @param continueProcessing Whether to continue startup.
1295     * @param continuePluginProcessing Whether to invoke the rest
1296     * of the plugins.
1297     * @param errorMessage An message explaining why processing should stop.
1298     * @param disconnectReason The generic cause for the disconnect.
1299     * @param sendDisconnectNotification Whether to send a disconnect
1300     * notification to the client.
1301     */
1302    private PostConnect(boolean continueProcessing,
1303                        boolean continuePluginProcessing,
1304                        LocalizableMessage errorMessage,
1305                        DisconnectReason disconnectReason,
1306                        boolean sendDisconnectNotification)
1307    {
1308      this.continueProcessing = continueProcessing;
1309      this.errorMessage = errorMessage;
1310      this.continuePluginProcessing = continuePluginProcessing;
1311      this.disconnectReason = disconnectReason;
1312      this.sendDisconnectNotification = sendDisconnectNotification;
1313    }
1314
1315    /**
1316     * Defines a continue processing post connect plugin result.
1317     *
1318     * @return a continue processing post connect plugin result.
1319     */
1320    public static PostConnect continueConnectProcessing()
1321    {
1322      return DEFAULT_RESULT;
1323    }
1324
1325    /**
1326     * Defines a skip further plugin processing post connect plugin result.
1327     *
1328     * @return  a skip further plugin processing post connect plugin result.
1329     */
1330    public static PostConnect skipFurtherPluginProcesssing()
1331    {
1332      return new PostConnect(true, false, null, null, false);
1333    }
1334
1335    /**
1336     * Defines a new stop processing post connect plugin result.
1337     *
1338     * @param disconnectReason The generic cause for the disconnect.
1339     * @param sendDisconnectNotification Whether to send a disconnect
1340     * notification to the client.
1341     * @param errorMessage An message explaining why processing
1342     * should stop for the given entry.
1343     *
1344     * @return a new stop processing post connect plugin result.
1345     */
1346    public static PostConnect disconnectClient(
1347        DisconnectReason disconnectReason,
1348        boolean sendDisconnectNotification, LocalizableMessage errorMessage)
1349    {
1350      return new PostConnect(false, false, errorMessage,
1351          disconnectReason, sendDisconnectNotification);
1352    }
1353
1354    /**
1355     * Whether to continue operation processing.
1356     *
1357     * @return {@code true} if processing should continue
1358     * or {@code false} otherwise.
1359     */
1360    public boolean continueProcessing()
1361    {
1362      return continueProcessing;
1363    }
1364
1365    /**
1366     * Whether to invoke the rest of the plugins.
1367     *
1368     * @return {@code true} if the rest of the plugins should
1369     * be invoked for {@code false} to skip the rest of the plugins.
1370     */
1371    public boolean continuePluginProcessing()
1372    {
1373      return continuePluginProcessing;
1374    }
1375
1376    /**
1377     * Retrieves the error message if {@link #continueProcessing()}
1378     * returned {@code false}.
1379     *
1380     * @return An error message explaining why processing should
1381     * stop or {@code null} if none is provided.
1382     */
1383    public LocalizableMessage getErrorMessage()
1384    {
1385      return errorMessage;
1386    }
1387
1388    /**
1389     * The disconnect reason that provides the generic cause for the
1390     * disconnect.
1391     *
1392     * @return the generic cause for the disconnect.
1393     */
1394    public DisconnectReason getDisconnectReason()
1395    {
1396      return disconnectReason;
1397    }
1398
1399    /**
1400     * Indicates whether to try to provide notification to the client
1401     * that the connection will be closed.
1402     *
1403     * @return {@code true} if notification should be provided or
1404     * {@code false} otherwise.
1405     */
1406    public boolean sendDisconnectNotification()
1407    {
1408      return sendDisconnectNotification;
1409    }
1410  }
1411
1412  /**
1413   * Defines a post disconnect plugin result for client connection
1414   * processing consisting of either continue or skip further plugins.
1415   */
1416  public static final class PostDisconnect
1417  {
1418    /** Whether to invoke the rest of the plugins. */
1419    private final boolean continuePluginProcessing;
1420
1421    private static PostDisconnect DEFAULT_RESULT =
1422        new PostDisconnect(true);
1423
1424    /**
1425     * Constructs a new post disconnect plugin result.
1426     *
1427     * @param continuePluginProcessing Whether to invoke the rest
1428     * of the plugins.
1429     */
1430    private PostDisconnect(boolean continuePluginProcessing)
1431    {
1432      this.continuePluginProcessing = continuePluginProcessing;
1433    }
1434
1435    /**
1436     * Defines a continue processing post disconnect plugin result.
1437     *
1438     * @return a continue processing post disconnect plugin result.
1439     */
1440    public static PostDisconnect continueDisconnectProcessing()
1441    {
1442      return DEFAULT_RESULT;
1443    }
1444
1445    /**
1446     * Defines a skip further plugin processing post disconnect
1447     * plugin result.
1448     *
1449     * @return  a skip further plugin processing post disconnect
1450     * plugin result.
1451     */
1452    public static PostDisconnect skipFurtherPluginProcesssing()
1453    {
1454      return new PostDisconnect(false);
1455    }
1456
1457    /**
1458     * Whether to invoke the rest of the plugins.
1459     *
1460     * @return {@code true} if the rest of the plugins should
1461     * be invoked for {@code false} to skip the rest of the plugins.
1462     */
1463    public boolean continuePluginProcessing()
1464    {
1465      return continuePluginProcessing;
1466    }
1467  }
1468}