KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collections JavaDoc;
22 import javax.lang.model.element.Modifier;
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 final class SessionGenerateFromImplVisitor 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 void getInterfaceMethodFromImpl(MethodType methodType, String JavaDoc home, String JavaDoc component) {
42         this.home = home;
43         this.component = component;
44         methodType.accept(this);
45     }
46     
47     public MethodModel getInterfaceMethod() {
48         return intfMethod;
49     }
50     
51     public String JavaDoc getDestinationInterface() {
52         return destination;
53     }
54     
55     public void visit(BusinessMethodType bmt) {
56         intfMethod = bmt.getMethodElement();
57         destination = component;
58     }
59        
60     public void visit(CreateMethodType cmt) {
61         intfMethod = cmt.getMethodElement();
62         String JavaDoc origName = intfMethod.getName();
63         String JavaDoc newName = chopAndUpper(origName,"ejb"); //NOI18N
64
intfMethod = MethodModel.create(
65                 newName,
66                 home,
67                 intfMethod.getBody(),
68                 intfMethod.getParameters(),
69                 intfMethod.getExceptions(),
70                 Collections.singleton(Modifier.PUBLIC)
71                 );
72         destination = home;
73     }
74     
75     public void visit(HomeMethodType hmt) {
76         assert false: "session beans do not have home methods";
77     }
78     
79     public void visit(FinderMethodType fmt) {
80         assert false: "session beans do not have finder methods";
81     }
82     
83     private String JavaDoc chopAndUpper(String JavaDoc fullName, String JavaDoc chop) {
84          StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(fullName);
85          buffer.delete(0, chop.length());
86          buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0)));
87          return buffer.toString();
88     }
89     
90 }
91
Popular Tags