KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.modules.j2ee.common.method.MethodModel;
26 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
27 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb;
28 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
29 import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
30 import org.netbeans.modules.j2ee.dd.api.ejb.Entity;
31 import org.netbeans.modules.j2ee.dd.api.ejb.Session;
32 import org.openide.ErrorManager;
33 import org.openide.filesystems.FileObject;
34
35 /**
36  * This class encapsulates functionality required for working with EJB methods.
37  * @author Chris Webster
38  * @author Martin Adamek
39  */

40 public abstract class EjbMethodController {
41     
42     public static EjbMethodController createFromClass(FileObject ejbClassFO, String JavaDoc className) {
43         org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbModule = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(ejbClassFO);
44         if (ejbModule == null) {
45             return null;
46         }
47         DDProvider provider = DDProvider.getDefault();
48         EjbJar ejbJar = null;
49         EjbMethodController controller = null;
50         try {
51             ejbJar = provider.getMergedDDRoot(ejbModule.getMetadataUnit());
52             if (ejbJar != null) {
53                 EnterpriseBeans beans = ejbJar.getEnterpriseBeans();
54                 if (beans != null) {
55                     Session session = (Session) beans.findBeanByName(EnterpriseBeans.SESSION, Ejb.EJB_CLASS, className);
56                     if (session != null) {
57                         controller = new SessionMethodController(ejbClassFO, session);
58                         // TODO EJB3: on Java EE 5.0 this always sets controller to null
59
if (!controller.hasLocal() && !controller.hasRemote()) {
60                             // this is either an error or a web service
61
controller = null;
62                         }
63                     } else {
64                         Entity entity = (Entity) beans.findBeanByName(EnterpriseBeans.ENTITY, Ejb.EJB_CLASS, className);
65                         if (entity != null) {
66                             controller = new EntityMethodController(ejbClassFO, entity, ejbJar);
67                         }
68                     }
69                 }
70             }
71         } catch (IOException JavaDoc ioe) {
72             ErrorManager.getDefault().notify(ioe);
73         }
74         return controller;
75     }
76     
77     /**
78      * Find the implementation methods
79      * @return MethodElement representing the implementation method or null.
80      */

81     public abstract List JavaDoc getImplementation(MethodModel intfView);
82     public abstract MethodModel getPrimaryImplementation(MethodModel intfView);
83     /**
84      * @return true if intfView has a java implementation.
85      */

86     public abstract boolean hasJavaImplementation(MethodModel intfView);
87     public abstract boolean hasJavaImplementation(MethodType methodType);
88     
89     /**
90      * return interface method in the requested interface.
91      * @param beanImpl implementation method
92      * @param local true if local method should be returned false otherwise
93      */

94     public abstract ClassMethodPair getInterface(MethodModel beanImpl, boolean local);
95     
96     /** Return if the passed method is implementation of method defined
97      * in local or remote interface.
98      * @param m Method from bean class.
99      * @param methodType Type of method to define the search algorithm
100      * @param local If <code>true</code> the local interface is searched,
101      * if <code>false</code> the remote interface is searched.
102      */

103     public abstract boolean hasMethodInInterface(MethodModel method, MethodType methodType, boolean local);
104     
105     /**
106      * @param clientView of the method
107      */

108     public abstract MethodType getMethodTypeFromInterface(MethodModel clientView);
109     public abstract MethodType getMethodTypeFromImpl(MethodModel implView);
110     
111     public abstract String JavaDoc getBeanClass();
112     public abstract String JavaDoc getLocal();
113     public abstract String JavaDoc getRemote();
114     public abstract Collection JavaDoc<String JavaDoc> getLocalInterfaces();
115     public abstract Collection JavaDoc<String JavaDoc> getRemoteInterfaces();
116     public abstract boolean hasLocal();
117     public abstract boolean hasRemote();
118     public void addEjbQl(MethodModel clientView, String JavaDoc ejbql, FileObject ddFileObject) throws IOException JavaDoc {
119         assert false: "ejbql not supported for this bean type";
120     }
121     
122     public String JavaDoc createDefaultQL(MethodModel methodModel) {
123         return null;
124     }
125     
126     /**
127      * create interface signature based on the given implementation
128      */

129     public abstract void createAndAddInterface(MethodModel beanImpl, boolean local);
130     
131     /**
132      * create implementation methods based on the client method.
133      * @param clientView method which will be inserted into an interface
134      * @param intf interface where element will be inserted. This can be the
135      * use the business interface pattern.
136      */

137     public abstract void createAndAddImpl(MethodModel clientView);
138     
139     public abstract void delete(MethodModel interfaceMethod, boolean local);
140     
141     /** Checks if given method type is supported by controller.
142      * @param type One of <code>METHOD_</code> constants in @link{MethodType}
143      */

144     public abstract boolean supportsMethodType(MethodType.Kind type);
145     public abstract MethodModel createAndAdd(MethodModel clientView, boolean local, boolean component);
146     
147     
148     /** Immutable type representing method and its enclosing class */
149     protected static final class ClassMethodPair {
150         
151         private final String JavaDoc className;
152         private final MethodModel methodModel;
153         
154         public ClassMethodPair(String JavaDoc className, MethodModel methodModel) {
155             this.className = className;
156             this.methodModel = methodModel;
157         }
158         
159         public String JavaDoc getClassName() {
160             return className;
161         }
162         
163         public MethodModel getMethodModel() {
164             return methodModel;
165         }
166         
167     }
168 }
169
Popular Tags