KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > api > methodcontroller > MethodType


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ejbcore.api.methodcontroller;
21
22 import org.netbeans.modules.j2ee.common.method.MethodModel;
23
24 /**
25  * Provide simple instance of the visitor pattern to use for code generation.
26  * @author Chris Webster
27  */

28 public abstract class MethodType {
29
30     public enum Kind {BUSINESS, SELECT, CREATE, FINDER, HOME}
31     
32     private final MethodModel methodHandle;
33     
34     public MethodType(MethodModel methodHandle) {
35         this.methodHandle = methodHandle;
36     }
37     
38     public abstract void accept(MethodTypeVisitor visitor);
39     
40     public abstract Kind getKind();
41     
42     public final MethodModel getMethodElement() {
43         return methodHandle;
44     }
45     
46     public interface MethodTypeVisitor {
47         void visit(BusinessMethodType bmt);
48         void visit(CreateMethodType cmt);
49         void visit(HomeMethodType hmt);
50         void visit(FinderMethodType fmt);
51     }
52     
53     public static class BusinessMethodType extends MethodType {
54         public BusinessMethodType(MethodModel methodHandle) {
55             super(methodHandle);
56         }
57         
58         public void accept(MethodTypeVisitor visitor) {
59             visitor.visit(this);
60         }
61         
62         public Kind getKind() {
63             return Kind.BUSINESS;
64         }
65     }
66     
67     public static class SelectMethodType extends MethodType {
68         public SelectMethodType(MethodModel methodHandle) {
69             super(methodHandle);
70         }
71         
72         public void accept(MethodTypeVisitor visitor) {
73             assert false:"select methods are not intended to be visited";
74         }
75         
76         public Kind getKind() {
77             return Kind.SELECT;
78         }
79     }
80     
81     public static class CreateMethodType extends MethodType {
82         public CreateMethodType(MethodModel methodHandle) {
83             super(methodHandle);
84         }
85         
86         public void accept(MethodTypeVisitor visitor) {
87             visitor.visit(this);
88         }
89
90         public Kind getKind() {
91             return Kind.CREATE;
92         }
93     }
94     
95     public static class HomeMethodType extends MethodType {
96         public HomeMethodType(MethodModel methodHandle) {
97             super(methodHandle);
98         }
99         
100         public void accept(MethodTypeVisitor visitor) {
101             visitor.visit(this);
102         }
103
104         public Kind getKind() {
105             return Kind.HOME;
106         }
107     }
108     
109     public static class FinderMethodType extends MethodType {
110         public FinderMethodType(MethodModel methodHandle) {
111             super(methodHandle);
112         }
113         
114         public void accept(MethodTypeVisitor visitor) {
115             visitor.visit(this);
116         }
117         
118         public Kind getKind() {
119             return Kind.FINDER;
120         }
121     }
122 }
123
Popular Tags