001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * EjbInfo.java
044: *
045: * Created on April 28, 2004, 4:58 PM
046: */
047:
048: package org.netbeans.modules.visualweb.ejb.datamodel;
049:
050: import java.util.*;
051:
052: /**
053: * This class is to encapsulate the information Rave needs to know about an EJB
054: *
055: * @author cao
056: */
057: public class EjbInfo implements java.lang.Cloneable, Comparable {
058: public final static int STATELESS_SESSION_BEAN = 1;
059: public final static int STATEFUL_SESSION_BEAN = 2;
060: public final static int ENTITY_BEAN = 3;
061: public final static int MESSAGE_DRIVEN_BEAN = 4;
062:
063: private int beanType; // Must be one of the types listed above
064: private String jndiName;
065: private String ejbName;
066: private String beanId; // Can be null for SunAppServer and weblogic. But needed for websphere
067: private String homeInterfaceName;
068: private String compInterfaceName;
069: private String webEjbRef; // the ejb ref name used in web.xml/sun-web.xml
070:
071: private String beanWrapperName;
072: private String beanInfoWrapperName;
073:
074: // A collection of business method - MethodInfo
075: private ArrayList methodInfos = new ArrayList();
076:
077: /**
078: * Creates a session bean info
079: */
080: public EjbInfo(String jndiName, String ejbName,
081: String homeInterface, String compInterface) {
082: this .beanType = STATELESS_SESSION_BEAN;
083: this .jndiName = jndiName;
084: this .ejbName = ejbName;
085: this .homeInterfaceName = homeInterface;
086: this .compInterfaceName = compInterface;
087: }
088:
089: public EjbInfo() {
090: };
091:
092: public void setBeanType(int type) {
093: if (type != STATELESS_SESSION_BEAN
094: && type != STATEFUL_SESSION_BEAN && type != ENTITY_BEAN
095: && type != MESSAGE_DRIVEN_BEAN)
096: throw new java.lang.IllegalArgumentException(
097: "Invalid EJB type: " + type);
098:
099: beanType = type;
100: }
101:
102: public void setBeanId(String id) {
103: this .beanId = id;
104: }
105:
106: public void setEjbName(String name) {
107: this .ejbName = name;
108: }
109:
110: public void setJNDIName(String jndiName) {
111: this .jndiName = jndiName;
112: }
113:
114: public void setHomeInterfaceName(String interfaceName) {
115: this .homeInterfaceName = interfaceName;
116: }
117:
118: public void setCompInterfaceName(String interfaceName) {
119: this .compInterfaceName = interfaceName;
120: }
121:
122: public void setMethods(ArrayList methods) {
123: this .methodInfos = methods;
124: }
125:
126: public void addMethod(MethodInfo method) {
127: if (methodInfos == null)
128: methodInfos = new ArrayList();
129:
130: methodInfos.add(method);
131: }
132:
133: public void setWebEjbRef(String webRef) {
134: this .webEjbRef = webRef;
135: }
136:
137: public void setBeanWrapperName(String name) {
138: this .beanWrapperName = name;
139: }
140:
141: public void setBeanInfoWrapperName(String name) {
142: this .beanInfoWrapperName = name;
143: }
144:
145: public boolean isStatelessSessionBean() {
146: if (this .beanType == STATELESS_SESSION_BEAN)
147: return true;
148: else
149: return false;
150: }
151:
152: public int getBeanType() {
153: return this .beanType;
154: }
155:
156: public String getJNDIName() {
157: return this .jndiName;
158: }
159:
160: public String getEjbName() {
161: return this .ejbName;
162: }
163:
164: public String getBeanId() {
165: return this .beanId;
166: }
167:
168: public String getHomeInterfaceName() {
169: return this .homeInterfaceName;
170: }
171:
172: public String getCompInterfaceName() {
173: return this .compInterfaceName;
174: }
175:
176: public String getWebEjbRef() {
177: return this .webEjbRef;
178: }
179:
180: public ArrayList getMethods() {
181: // Sort it first
182: ArrayList methods = new ArrayList(this .methodInfos);
183: Collections.sort(methods);
184: return methods;
185: }
186:
187: public boolean hasAnyMethodWithCollectionReturn() {
188: for (Iterator iter = methodInfos.iterator(); iter.hasNext();) {
189: MethodInfo m = (MethodInfo) iter.next();
190: if (m.getReturnType().isCollection())
191: return true;
192: }
193:
194: // Didn't find any
195: return false;
196: }
197:
198: public boolean hasAnyConfigurableMethod() {
199: for (Iterator iter = methodInfos.iterator(); iter.hasNext();) {
200: MethodInfo m = (MethodInfo) iter.next();
201: if (m.isMethodConfigurable())
202: return true;
203: }
204:
205: // Didn't find any
206: return false;
207: }
208:
209: public String getBeanTypeName() {
210: // NOI18N
211: switch (this .beanType) {
212: case STATELESS_SESSION_BEAN:
213: case STATEFUL_SESSION_BEAN:
214: return "Session"; // NOI18N
215: case ENTITY_BEAN:
216: return "Entity"; // NOI18N
217: case MESSAGE_DRIVEN_BEAN:
218: return "Message Driven Bean"; // NOI18N
219: default:
220: return "Session"; // NOI18N
221: }
222: }
223:
224: public String getBeanWrapperName() {
225: return this .beanWrapperName;
226: }
227:
228: public String getBeanInfoWrapperName() {
229: return this .beanInfoWrapperName;
230: }
231:
232: /**
233: * The EJB can be auto be auto init() if it only has one init() and
234: * it takes no arguments
235: */
236: public boolean canBeAutoInit() {
237: int numCreateMethods = 0;
238: boolean foundNonArgCreateMethod = false;
239: for (Iterator iter = methodInfos.iterator(); iter.hasNext();) {
240: MethodInfo method = (MethodInfo) iter.next();
241: if (!method.isBusinessMethod()) {
242: // Found a create method
243: numCreateMethods++;
244:
245: // And found a create method w/o arguemnt
246: if (method.hasNoParameters())
247: foundNonArgCreateMethod = true;
248: }
249: }
250:
251: if (numCreateMethods == 1 && foundNonArgCreateMethod)
252: return true;
253: else
254: return false;
255: }
256:
257: public String toString() {
258: // NOI18N
259: StringBuffer buf = new StringBuffer();
260: buf.append("Type: " + getBeanType() + "\n");
261: buf.append("JNDI name: " + getJNDIName() + "\n");
262: buf.append("EJB name: " + getEjbName() + "\n");
263: buf.append("EJB name: " + getBeanId() + "\n");
264: buf.append("Home Interface: " + getHomeInterfaceName() + "\n");
265: buf.append("Component Interface: " + getCompInterfaceName()
266: + "\n");
267: buf.append("Web EJB Ref: " + getWebEjbRef() + "\n");
268: buf.append("Wrapper Bean Name: " + getBeanWrapperName() + "\n");
269: buf.append("Wrapper Bean Info Name: "
270: + getBeanInfoWrapperName() + "\n");
271: if (getMethods() != null) {
272: buf.append("Num of methods: " + getMethods().size() + "\n");
273: buf.append(getMethods().toString());
274: }
275:
276: return buf.toString();
277: }
278:
279: public Collection getMethodNames() {
280: ArrayList mNames = new ArrayList();
281:
282: for (Iterator iter = methodInfos.iterator(); iter.hasNext();) {
283: MethodInfo mInfo = (MethodInfo) iter.next();
284: mNames.add(mInfo.getName());
285: }
286:
287: return mNames;
288: }
289:
290: public MethodInfo getMethod(String name) {
291: for (Iterator iter = methodInfos.iterator(); iter.hasNext();) {
292: MethodInfo mInfo = (MethodInfo) iter.next();
293: if (mInfo.getName().equals(name))
294: return mInfo;
295: }
296:
297: return null;
298: }
299:
300: public Object clone() {
301: try {
302: EjbInfo ejbCopy = (EjbInfo) super .clone();
303:
304: // Methods
305: if (this .methodInfos != null) {
306: ArrayList mdCopy = new ArrayList();
307:
308: for (Iterator iter = this .methodInfos.iterator(); iter
309: .hasNext();) {
310: mdCopy.add(((MethodInfo) iter.next()).clone());
311: }
312:
313: ejbCopy.setMethods(mdCopy);
314: }
315:
316: return ejbCopy;
317: } catch (java.lang.CloneNotSupportedException e) {
318: return null;
319: }
320: }
321:
322: // Implementing Comparable
323: public int compareTo(Object o) {
324:
325: if (o == null || !(o instanceof EjbInfo))
326: return 0;
327:
328: String theOtherName = ((EjbInfo) o).getJNDIName();
329:
330: if (this .getJNDIName() == null || theOtherName == null)
331: return 0;
332:
333: return this.getJNDIName().compareTo(theOtherName);
334: }
335:
336: }
|