KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.j2ee.ejbcore.api.methodcontroller;
20
21 import java.util.Collection JavaDoc;
22 import java.util.Set JavaDoc;
23 import org.netbeans.modules.j2ee.common.method.MethodModel;
24 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.MethodType.BusinessMethodType;
25 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.MethodType.CreateMethodType;
26 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.MethodType.FinderMethodType;
27 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.MethodType.HomeMethodType;
28
29 /**
30  *
31  * @author Chris Webster
32  * @author Martin Adamek
33  */

34 class EntityGenerateFromImplVisitor implements MethodType.MethodTypeVisitor, AbstractMethodController.GenerateFromImpl {
35     
36     private MethodModel intfMethod;
37     private String JavaDoc destination;
38     private String JavaDoc home;
39     private String JavaDoc component;
40     
41     public EntityGenerateFromImplVisitor() {
42     }
43     
44     public void getInterfaceMethodFromImpl(MethodType methodType, String JavaDoc home, String JavaDoc component) {
45         this.home = home;
46         this.component = component;
47         methodType.accept(this);
48     }
49     
50     public MethodModel getInterfaceMethod() {
51         return intfMethod;
52     }
53     
54     public String JavaDoc getDestinationInterface() {
55         return destination;
56     }
57     
58     public void visit(BusinessMethodType bmt) {
59         intfMethod = bmt.getMethodElement();
60         destination = component;
61     }
62     
63     public void visit(CreateMethodType cmt) {
64         intfMethod = cmt.getMethodElement();
65         String JavaDoc origName = intfMethod.getName();
66         String JavaDoc newName = null;
67         if (origName.startsWith("ejbPostCreate")) {
68             newName = chopAndUpper(origName,"ejbPost"); //NOI18N
69
} else {
70             newName = chopAndUpper(origName,"ejb"); //NOI18N
71
}
72         intfMethod = MethodModel.create(
73                 newName,
74                 intfMethod.getReturnType(),
75                 intfMethod.getBody(),
76                 intfMethod.getParameters(),
77                 intfMethod.getExceptions(),
78                 intfMethod.getModifiers()
79                 );
80         destination = home;
81     }
82     
83     public void visit(HomeMethodType hmt) {
84         intfMethod = hmt.getMethodElement();
85         String JavaDoc origName = intfMethod.getName();
86         String JavaDoc newName = chopAndUpper(origName,"ejbHome"); //NOI18N
87
intfMethod = MethodModel.create(
88                 newName,
89                 intfMethod.getReturnType(),
90                 intfMethod.getBody(),
91                 intfMethod.getParameters(),
92                 intfMethod.getExceptions(),
93                 intfMethod.getModifiers()
94                 );
95         destination = home;
96     }
97     
98     public void visit(FinderMethodType fmt) {
99         intfMethod = fmt.getMethodElement();
100         String JavaDoc origName = intfMethod.getName();
101         String JavaDoc newName = chopAndUpper(origName,"ejb"); //NOI18N
102
String JavaDoc fqn = intfMethod.getReturnType();
103         boolean changeType = false;
104         if (!fqn.equals(Collection JavaDoc.class.getName()) || !fqn.equals(Set JavaDoc.class.getName())) {
105             changeType = true;
106         }
107         intfMethod = MethodModel.create(
108                 newName,
109                 changeType ? component : intfMethod.getReturnType(),
110                 intfMethod.getBody(),
111                 intfMethod.getParameters(),
112                 intfMethod.getExceptions(),
113                 intfMethod.getModifiers()
114                 );
115         //TODO: RETOUCHE need to empty the body?
116
// intfMethod.setBody(null);
117
destination = home;
118     }
119     
120     private String JavaDoc chopAndUpper(String JavaDoc fullName, String JavaDoc chop) {
121         StringBuffer JavaDoc stringBuffer = new StringBuffer JavaDoc(fullName);
122         stringBuffer.delete(0, chop.length());
123         stringBuffer.setCharAt(0, Character.toLowerCase(stringBuffer.charAt(0)));
124         return stringBuffer.toString();
125     }
126 }
127
Popular Tags