KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > interop > generator > JSwitchStatement


1 /**
2  *
3  * Copyright 2004-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.geronimo.interop.generator;
19
20 import java.util.Vector JavaDoc;
21
22 public class JSwitchStatement extends JStatement {
23     private JExpression switchExpr;
24     private Vector JavaDoc caseStatements;
25
26     public JSwitchStatement(JExpression e) {
27         switchExpr = e;
28         caseStatements = new Vector JavaDoc();
29     }
30
31     public void setVariable(JExpression e) {
32         switchExpr = e;
33     }
34
35     public JExpression getExpression() {
36         return switchExpr;
37     }
38
39     public JCaseStatement getCase(JExpression e) {
40         JCaseStatement rc = null;
41         int index = caseStatements.indexOf(e);
42
43         if (index >= 0) {
44             rc = (JCaseStatement) caseStatements.get(index);
45         }
46
47         return rc;
48     }
49
50     public JCaseStatement newCase(JExpression e) {
51         JCaseStatement rc = getCase(e);
52
53         if (rc == null) {
54             rc = new JCaseStatement(e);
55             caseStatements.add(rc);
56         }
57
58         return rc;
59     }
60
61     public void addCaseStatement(JExpression e, JStatement s) {
62         JCaseStatement cs = getCase(e);
63
64         if (cs == null) {
65             cs = newCase(e);
66         }
67
68         cs.addStatement(s);
69     }
70
71     public Vector JavaDoc getCases() {
72         return caseStatements;
73     }
74 }
75
Popular Tags