KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jruby > exceptions > JumpException


1 /***** BEGIN LICENSE BLOCK *****
2  * Version: CPL 1.0/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Common Public
5  * License Version 1.0 (the "License"); you may not use this file
6  * except in compliance with the License. You may obtain a copy of
7  * the License at http://www.eclipse.org/legal/cpl-v10.html
8  *
9  * Software distributed under the License is distributed on an "AS
10  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11  * implied. See the License for the specific language governing
12  * rights and limitations under the License.
13  *
14  * Copyright (C) 2002 Anders Bengtsson <ndrsbngtssn@yahoo.se>
15  * Copyright (C) 2002 Jan Arne Petersen <jpetersen@uni-bonn.de>
16  * Copyright (C) 2005 Charles O Nutter <headius@headius.com>
17  * Copyright (C) 2007 Thomas E Enebo <enebo@acm.org>
18  * Copyright (C) 2007 Miguel Covarrubias <mlcovarrubias@gmail.com>
19  *
20  * Alternatively, the contents of this file may be used under the terms of
21  * either of the GNU General Public License Version 2 or later (the "GPL"),
22  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
23  * in which case the provisions of the GPL or the LGPL are applicable instead
24  * of those above. If you wish to allow use of your version of this file only
25  * under the terms of either the GPL or the LGPL, and not to allow others to
26  * use your version of this file under the terms of the CPL, indicate your
27  * decision by deleting the provisions above and replace them with the notice
28  * and other provisions required by the GPL or the LGPL. If you do not delete
29  * the provisions above, a recipient may use your version of this file under
30  * the terms of any one of the CPL, the GPL or the LGPL.
31  ***** END LICENSE BLOCK *****/

32 package org.jruby.exceptions;
33
34 /**
35  * This class should be used for performance reasons if the
36  * Exception don't need a stack trace.
37  *
38  * @author jpetersen
39  */

40 public class JumpException extends RuntimeException JavaDoc {
41     private static final long serialVersionUID = -228162532535826617L;
42
43     public static final class JumpType {
44         public static final int BREAK = 0;
45         public static final int NEXT = 1;
46         public static final int REDO = 2;
47         public static final int RETRY = 3;
48         public static final int RETURN = 4;
49         public static final int THROW = 5;
50         public static final int RAISE = 6;
51         
52         public static final JumpType BreakJump = new JumpType(BREAK);
53         public static final JumpType NextJump = new JumpType(NEXT);
54         public static final JumpType RedoJump = new JumpType(REDO);
55         public static final JumpType RetryJump = new JumpType(RETRY);
56         public static final JumpType ReturnJump = new JumpType(RETURN);
57         public static final JumpType ThrowJump = new JumpType(THROW);
58         public static final JumpType RaiseJump = new JumpType(RAISE);
59         
60         private final int typeId;
61         private JumpType(int typeId) {
62             this.typeId = typeId;
63         }
64         public int getTypeId() {
65             return typeId;
66         }
67     }
68     
69     private JumpType jumpType;
70     private Object JavaDoc target;
71     private Object JavaDoc value;
72
73     // FIXME: Remove inKernelLoop from this and come up with something more general
74
// Hack to detect a break in Kernel#loop
75
private boolean inKernelLoop = false;
76
77     /**
78      * Constructor for JumpException.
79      */

80     public JumpException(JumpType jumpType) {
81         super();
82         this.jumpType = jumpType;
83     }
84
85     /**
86      * Constructor for JumpException.
87      * @param msg
88      */

89     public JumpException(String JavaDoc msg, JumpType jumpType) {
90         super(msg);
91         this.jumpType = jumpType;
92     }
93
94     public JumpException(String JavaDoc msg, Throwable JavaDoc cause, JumpType jumpType) {
95         super(msg, cause);
96         this.jumpType = jumpType;
97     }
98     
99     /** This method don't do anything for performance reasons.
100      *
101      * @see Throwable#fillInStackTrace()
102      */

103     public Throwable JavaDoc fillInStackTrace() {
104         return this;
105     }
106
107     protected Throwable JavaDoc originalFillInStackTrace() {
108         return super.fillInStackTrace();
109     }
110     
111     public JumpType getJumpType() {
112         return jumpType;
113     }
114     
115     /**
116      * @return Returns the target.
117      */

118     public Object JavaDoc getTarget() {
119         return target;
120     }
121     
122     /**
123      * @param target The target (destination) of the jump.
124      */

125     public void setTarget(Object JavaDoc target) {
126         this.target = target;
127     }
128     
129     /**
130      * Get the value that will returned when the jump reaches its destination
131      *
132      * @return Returns the return value.
133      */

134     public Object JavaDoc getValue() {
135         return value;
136     }
137     
138     /**
139      * Set the value that will be returned when the jump reaches its destination
140      *
141      * @param value the value to be returned.
142      */

143     public void setValue(Object JavaDoc value) {
144         this.value = value;
145     }
146
147     
148     public void setBreakInKernelLoop(boolean inKernelLoop) {
149         this.inKernelLoop = inKernelLoop;
150     }
151
152     public boolean isBreakInKernelLoop() {
153         return inKernelLoop;
154     }
155 }
156
Popular Tags