KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > actionflow > config > ExceptionLink


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.controller.actionflow.config;
8
9
10 /**
11  * This class is a Link that handles exceptions that are thrown
12  * from a Node that has just been executed. This Link will handle
13  * all Exceptions of the type given during construction and all
14  * of its sub-classes.
15  *
16  * @author Brian Pontarelli
17  * @since 2.0
18  * @version 2.0
19  */

20 public class ExceptionLink extends BaseLink {
21
22     private Exception JavaDoc exception;
23
24
25     /**
26      * Constructs a new <code>ExceptionLink</code> with the given exception,
27      * origin Node and destination Node. The Exception given denotes the highest
28      * parent that this Link will accept. That means this Link accepts the
29      * given Exception and all of its sub-classes
30      *
31      * @param exception The Exception of the Link
32      * @param origin The origin Node
33      * @param destination The destination Node
34      */

35     public ExceptionLink(Exception JavaDoc exception, Node origin, Node destination) {
36         super(origin, destination);
37         assert (exception != null) : "exception == null";
38         this.exception = exception;
39     }
40
41
42     /**
43      * Returns the Exception of this Link
44      *
45      * @return The Exception of this Link
46      */

47     public Exception JavaDoc getException() {
48         return exception;
49     }
50
51     /**
52      * Returns the value of the link, which is the toString of the exception.
53      *
54      * @return The value of the link
55      */

56     public String JavaDoc getValue() {
57         return exception.toString();
58     }
59
60     /**
61      * Returns whether this Link accepts the given action. This returns true if
62      * the given action is an Exception and is assignable to the Exception for
63      * this Link.
64      *
65      * @param action The action to check for acceptance
66      * @return True if the given action is assignable to the Exception of this
67      * Link
68      */

69     public boolean acceptAction(Object JavaDoc action) {
70         assert (action != null) : "action == null";
71         assert (action instanceof Exception JavaDoc) : "action must be a String";
72
73         return getClass().isAssignableFrom(action.getClass());
74     }
75     
76     /**
77      * Returns a String representation of this link suitable for debugging
78      */

79     public String JavaDoc toString() {
80         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
81         buf.append(getOrigin().getName()).append(" --(");
82         buf.append(exception.getClass().getName()).append(")--> ");
83         buf.append(getDestination().getName());
84         return buf.toString();
85     }
86 }
87
88
Popular Tags