001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.jee;
018:
019: import javax.xml.bind.annotation.XmlAccessType;
020: import javax.xml.bind.annotation.XmlAccessorType;
021: import javax.xml.bind.annotation.XmlAttribute;
022: import javax.xml.bind.annotation.XmlElement;
023: import javax.xml.bind.annotation.XmlID;
024: import javax.xml.bind.annotation.XmlType;
025: import javax.xml.bind.annotation.XmlTransient;
026: import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
027: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
028:
029: /**
030: * The methodType is used to denote a method of an enterprise
031: * bean's business, home, component, and/or web service endpoint
032: * interface, or, in the case of a message-driven bean, the
033: * bean's message listener method, or a set of such
034: * methods. The ejb-name element must be the name of one of the
035: * enterprise beans declared in the deployment descriptor; the
036: * optional method-intf element allows to distinguish between a
037: * method with the same signature that is multiply defined
038: * across the business, home, component, and/or web service
039: * endpoint nterfaces; the method-name element specifies the
040: * method name; and the optional method-params elements identify
041: * a single method among multiple methods with an overloaded
042: * method name.
043: * <p/>
044: * There are three possible styles of using methodType element
045: * within a method element:
046: * <p/>
047: * 1.
048: * <method>
049: * <ejb-name>EJBNAME</ejb-name>
050: * <method-name>*</method-name>
051: * </method>
052: * <p/>
053: * This style is used to refer to all the methods of the
054: * specified enterprise bean's business, home, component,
055: * and/or web service endpoint interfaces.
056: * <p/>
057: * 2.
058: * <method>
059: * <ejb-name>EJBNAME</ejb-name>
060: * <method-name>METHOD</method-name>
061: * </method>
062: * <p/>
063: * This style is used to refer to the specified method of
064: * the specified enterprise bean. If there are multiple
065: * methods with the same overloaded name, the element of
066: * this style refers to all the methods with the overloaded
067: * name.
068: * <p/>
069: * 3.
070: * <method>
071: * <ejb-name>EJBNAME</ejb-name>
072: * <method-name>METHOD</method-name>
073: * <method-params>
074: * <method-param>PARAM-1</method-param>
075: * <method-param>PARAM-2</method-param>
076: * ...
077: * <method-param>PARAM-n</method-param>
078: * </method-params>
079: * </method>
080: * <p/>
081: * This style is used to refer to a single method within a
082: * set of methods with an overloaded name. PARAM-1 through
083: * PARAM-n are the fully-qualified Java types of the
084: * method's input parameters (if the method has no input
085: * arguments, the method-params element contains no
086: * method-param elements). Arrays are specified by the
087: * array element's type, followed by one or more pair of
088: * square brackets (e.g. int[][]). If there are multiple
089: * methods with the same overloaded name, this style refers
090: * to all of the overloaded methods.
091: * <p/>
092: * Examples:
093: * <p/>
094: * Style 1: The following method element refers to all the
095: * methods of the EmployeeService bean's business, home,
096: * component, and/or web service endpoint interfaces:
097: * <p/>
098: * <method>
099: * <ejb-name>EmployeeService</ejb-name>
100: * <method-name>*</method-name>
101: * </method>
102: * <p/>
103: * Style 2: The following method element refers to all the
104: * create methods of the EmployeeService bean's home
105: * interface(s).
106: * <p/>
107: * <method>
108: * <ejb-name>EmployeeService</ejb-name>
109: * <method-name>create</method-name>
110: * </method>
111: * <p/>
112: * Style 3: The following method element refers to the
113: * create(String firstName, String LastName) method of the
114: * EmployeeService bean's home interface(s).
115: * <p/>
116: * <method>
117: * <ejb-name>EmployeeService</ejb-name>
118: * <method-name>create</method-name>
119: * <method-params>
120: * <method-param>String</method-param>
121: * <method-param>String</method-param>
122: * </method-params>
123: * </method>
124: * <p/>
125: * The following example illustrates a Style 3 element with
126: * more complex parameter types. The method
127: * foobar(char s, int i, int[] iar, mypackage.MyClass mycl,
128: * mypackage.MyClass[][] myclaar) would be specified as:
129: * <p/>
130: * <method>
131: * <ejb-name>EmployeeService</ejb-name>
132: * <method-name>foobar</method-name>
133: * <method-params>
134: * <method-param>char</method-param>
135: * <method-param>int</method-param>
136: * <method-param>int[]</method-param>
137: * <method-param>mypackage.MyClass</method-param>
138: * <method-param>mypackage.MyClass[][]</method-param>
139: * </method-params>
140: * </method>
141: * <p/>
142: * The optional method-intf element can be used when it becomes
143: * necessary to differentiate between a method that is multiply
144: * defined across the enterprise bean's business, home, component,
145: * and/or web service endpoint interfaces with the same name and
146: * signature. However, if the same method is a method of both the
147: * local business interface, and the local component interface,
148: * the same attribute applies to the method for both interfaces.
149: * Likewise, if the same method is a method of both the remote
150: * business interface and the remote component interface, the same
151: * attribute applies to the method for both interfaces.
152: * <p/>
153: * For example, the method element
154: * <p/>
155: * <method>
156: * <ejb-name>EmployeeService</ejb-name>
157: * <method-intf>Remote</method-intf>
158: * <method-name>create</method-name>
159: * <method-params>
160: * <method-param>String</method-param>
161: * <method-param>String</method-param>
162: * </method-params>
163: * </method>
164: * <p/>
165: * can be used to differentiate the create(String, String)
166: * method defined in the remote interface from the
167: * create(String, String) method defined in the remote home
168: * interface, which would be defined as
169: * <p/>
170: * <method>
171: * <ejb-name>EmployeeService</ejb-name>
172: * <method-intf>Home</method-intf>
173: * <method-name>create</method-name>
174: * <method-params>
175: * <method-param>String</method-param>
176: * <method-param>String</method-param>
177: * </method-params>
178: * </method>
179: * <p/>
180: * and the create method that is defined in the local home
181: * interface which would be defined as
182: * <p/>
183: * <method>
184: * <ejb-name>EmployeeService</ejb-name>
185: * <method-intf>LocalHome</method-intf>
186: * <method-name>create</method-name>
187: * <method-params>
188: * <method-param>String</method-param>
189: * <method-param>String</method-param>
190: * </method-params>
191: * </method>
192: * <p/>
193: * The method-intf element can be used with all three Styles
194: * of the method element usage. For example, the following
195: * method element example could be used to refer to all the
196: * methods of the EmployeeService bean's remote home interface
197: * and the remote business interface.
198: * <p/>
199: * <method>
200: * <ejb-name>EmployeeService</ejb-name>
201: * <method-intf>Home</method-intf>
202: * <method-name>*</method-name>
203: * </method>
204: */
205: @XmlAccessorType(XmlAccessType.FIELD)
206: @XmlType(name="methodType",propOrder={"descriptions","ejbName","methodIntf","methodName","methodParams"})
207: public class Method {
208:
209: @XmlElement(name="ejb-name",required=true)
210: protected String ejbName;
211:
212: @XmlTransient
213: protected String className;
214:
215: @XmlElement(name="method-intf")
216: protected MethodIntf methodIntf;
217: @XmlElement(name="method-name",required=true)
218: protected String methodName;
219: @XmlElement(name="method-params")
220: protected MethodParams methodParams;
221: @XmlAttribute
222: @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
223: @XmlID
224: protected String id;
225:
226: @XmlTransient
227: protected TextMap description = new TextMap();
228:
229: public Method(String ejbName, java.lang.reflect.Method method) {
230: this .ejbName = ejbName;
231: this .methodName = method.getName();
232: this .className = method.getDeclaringClass().getName();
233: MethodParams methodParams = new MethodParams();
234: for (Class<?> type : method.getParameterTypes()) {
235: methodParams.getMethodParam().add(type.getCanonicalName());
236: }
237: this .methodParams = methodParams;
238: }
239:
240: public Method(String ejbName, String methodName,
241: String... parameters) {
242: this (ejbName, null, methodName, parameters);
243: }
244:
245: public Method(String ejbName, String className, String methodName,
246: String... parameters) {
247: this .ejbName = ejbName;
248: this .methodName = methodName;
249: this .className = className;
250:
251: if (parameters.length > 0) {
252: MethodParams params = new MethodParams();
253: for (String paramName : parameters) {
254: params.getMethodParam().add(paramName);
255: }
256: this .methodParams = params;
257: }
258: }
259:
260: public Method() {
261: }
262:
263: public Method(String ejbName, String methodName) {
264: this (ejbName, null, methodName);
265: }
266:
267: public Method(String ejbName, String className, String methodName) {
268: this .ejbName = ejbName;
269: this .methodName = methodName;
270: this .className = className;
271: }
272:
273: public String getClassName() {
274: return className;
275: }
276:
277: @XmlElement(name="description",required=true)
278: public Text[] getDescriptions() {
279: return description.toArray();
280: }
281:
282: public void setDescriptions(Text[] text) {
283: description.set(text);
284: }
285:
286: public String getDescription() {
287: return description.get();
288: }
289:
290: public String getEjbName() {
291: return ejbName;
292: }
293:
294: /**
295: * The ejb-nameType specifies an enterprise bean's name. It is
296: * used by ejb-name elements. This name is assigned by the
297: * ejb-jar file producer to name the enterprise bean in the
298: * ejb-jar file's deployment descriptor. The name must be
299: * unique among the names of the enterprise beans in the same
300: * ejb-jar file.
301: * <p/>
302: * There is no architected relationship between the used
303: * ejb-name in the deployment descriptor and the JNDI name that
304: * the Deployer will assign to the enterprise bean's home.
305: * <p/>
306: * The name for an entity bean must conform to the lexical
307: * rules for an NMTOKEN.
308: * <p/>
309: * Example:
310: * <p/>
311: * <ejb-name>EmployeeService</ejb-name>
312: */
313: public void setEjbName(String value) {
314: this .ejbName = value;
315: }
316:
317: public MethodIntf getMethodIntf() {
318: return methodIntf;
319: }
320:
321: public void setMethodIntf(MethodIntf value) {
322: this .methodIntf = value;
323: }
324:
325: public String getMethodName() {
326: return methodName;
327: }
328:
329: /**
330: * contains a name of an enterprise
331: * bean method or the asterisk (*) character. The asterisk is
332: * used when the element denotes all the methods of an
333: * enterprise bean's client view interfaces.
334: */
335: public void setMethodName(String value) {
336: this .methodName = value;
337: }
338:
339: public MethodParams getMethodParams() {
340: return methodParams;
341: }
342:
343: public void setMethodParams(MethodParams value) {
344: this .methodParams = value;
345: }
346:
347: public String getId() {
348: return id;
349: }
350:
351: public void setId(String value) {
352: this.id = value;
353: }
354:
355: }
|