KickJava   Java API By Example, From Geeks To Geeks.

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


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 SessionGenerateFromIntfVisitor implements MethodType.MethodTypeVisitor, AbstractMethodController.GenerateFromIntf {
35
36     private MethodModel implMethod;
37     private static final String JavaDoc TODO = "//TODO implement "; //NOI18N
38

39     public void getInterfaceMethodFromImpl(MethodType methodType) {
40         methodType.accept(this);
41     }
42     
43     public MethodModel getImplMethod() {
44         return implMethod;
45     }
46     
47     public MethodModel getSecondaryMethod() {
48         return null;
49     }
50     
51     public void visit(BusinessMethodType bmt) {
52         implMethod = bmt.getMethodElement();
53         String JavaDoc body = TODO + implMethod.getName() + EntityGenerateFromIntfVisitor.getReturnStatement(implMethod.getReturnType());
54         implMethod = MethodModel.create(
55                 implMethod.getName(),
56                 implMethod.getReturnType(),
57                 body,
58                 implMethod.getParameters(),
59                 implMethod.getExceptions(),
60                 Collections.singleton(Modifier.PUBLIC)
61                 );
62     }
63        
64     public void visit(CreateMethodType cmt) {
65         implMethod = cmt.getMethodElement();
66         String JavaDoc origName = implMethod.getName();
67         String JavaDoc newName = prependAndUpper(origName, "ejb"); //NOI18N
68
String JavaDoc body = TODO + newName;
69         implMethod = MethodModel.create(
70                 newName,
71                 "void",
72                 body,
73                 implMethod.getParameters(),
74                 implMethod.getExceptions(),
75                 Collections.singleton(Modifier.PUBLIC)
76                 );
77     }
78     
79     public void visit(HomeMethodType hmt) {
80         assert false: "session beans do not have home methods";
81     }
82     
83     public void visit(FinderMethodType fmt) {
84         assert false: "session beans do not have finder methods";
85     }
86     
87     private String JavaDoc prependAndUpper(String JavaDoc fullName, String JavaDoc prefix) {
88          StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(fullName);
89          buffer.setCharAt(0, Character.toUpperCase(buffer.charAt(0)));
90          return prefix+buffer.toString();
91     }
92 }
93
Popular Tags