KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > runtime > common > MessageDescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment.runtime.common;
25
26 import java.lang.reflect.Method JavaDoc;
27 import java.util.ArrayList JavaDoc;
28
29 import com.sun.enterprise.deployment.MethodDescriptor;
30 import com.sun.enterprise.deployment.runtime.RuntimeDescriptor;
31 import com.sun.enterprise.deployment.ServiceRefPortInfo;
32 import com.sun.enterprise.deployment.WebServiceEndpoint;
33 import com.sun.enterprise.deployment.BundleDescriptor;
34
35 public class MessageDescriptor extends RuntimeDescriptor {
36     public static final String JavaDoc JAVA_METHOD = "JavaMethod";
37     public static final String JavaDoc OPERATION_NAME = "OperationName";
38
39     private static final String JavaDoc ALL_METHODS = "*";
40
41     private String JavaDoc operationName = null;
42     private MethodDescriptor methodDescriptor = null;
43     private ArrayList JavaDoc convertedMethodDescs = new ArrayList JavaDoc();
44
45     // when this message is defined from client side
46
private ServiceRefPortInfo portInfo = null;
47
48     // when this message is defined from server side
49
private WebServiceEndpoint endPoint = null;
50
51     private BundleDescriptor bundleDesc = null;
52
53     private boolean isConverted = false;
54
55     public MessageDescriptor() {}
56
57     public void setOperationName(String JavaDoc operationName) {
58         this.operationName = operationName;
59     }
60     
61     public String JavaDoc getOperationName() {
62         return operationName;
63     }
64
65     public void setMethodDescriptor(MethodDescriptor methodDescriptor) {
66         this.methodDescriptor = methodDescriptor;
67     }
68
69     public MethodDescriptor getMethodDescriptor() {
70         return methodDescriptor;
71     }
72     
73     public void setServiceRefPortInfo(ServiceRefPortInfo portInfo) {
74         this.portInfo = portInfo;
75     }
76
77     public ServiceRefPortInfo getServiceRefPortInfo() {
78         return portInfo;
79     }
80
81     public void setWebServiceEndpoint(WebServiceEndpoint endPoint){
82         this.endPoint = endPoint;
83     }
84
85     public WebServiceEndpoint getWebServiceEndpoint() {
86         return endPoint;
87     }
88
89     public void setBundleDescriptor(BundleDescriptor bundleDesc){
90         this.bundleDesc = bundleDesc;
91     }
92         
93     public BundleDescriptor getBundleDescriptor() {
94         return bundleDesc;
95     }
96
97     /**
98      * Return all methods defined in this message.
99      *
100      * In the case of an empty message, it will return all methods
101      * defined in the SEI.
102      *
103      * In the case of methods overloading, it will return all methods
104      * defined in the SEI that match with the specified method name.
105      *
106      * In the case of DII, i.e the client doesn't have the SEI info,
107      * it will return an empty list for client side defined message.
108      *
109      **/

110     public ArrayList JavaDoc getAllDefinedMethodsInMessage() {
111        // only do the conversion if it hasn't done it yet
112
if (!isConverted) {
113            doStyleConversion();
114        }
115        return convertedMethodDescs;
116     }
117
118     private void doStyleConversion() {
119         if (operationName == null && methodDescriptor == null) {
120             // this is the empty message case
121
// and we need to expand to all methods
122
convertedMethodDescs = getAllSEIMethodsOf(ALL_METHODS);
123         } else if (methodDescriptor != null) {
124             if (methodDescriptor.getName() != null &&
125                 methodDescriptor.getParameterClassNames() != null) {
126                 // this is the exact case, so no conversion needed
127
convertedMethodDescs.add(methodDescriptor);
128             } else if (methodDescriptor.getName() != null &&
129                 methodDescriptor.getParameterClassNames() == null) {
130                 // we need to check for overloading methods
131
convertedMethodDescs =
132                     getAllSEIMethodsOf(methodDescriptor.getName());
133             }
134         }
135         isConverted = true;
136     }
137
138     private ArrayList JavaDoc getAllSEIMethodsOf(String JavaDoc methodName) {
139         String JavaDoc serviceInterfaceName = null;
140         ArrayList JavaDoc allMethodsInSEI = new ArrayList JavaDoc();
141
142         // this is a server side message
143
if (endPoint != null) {
144             serviceInterfaceName = endPoint.getServiceEndpointInterface();
145         // this is a client side message
146
} else if (portInfo != null) {
147             serviceInterfaceName = portInfo.getServiceEndpointInterface();
148         }
149         
150         // In the case of DII, client doesn't know the SEI name
151
// return an empty list
152
if (serviceInterfaceName == null) {
153             return allMethodsInSEI;
154         }
155
156         ClassLoader JavaDoc classLoader = null;
157         if (bundleDesc != null) {
158             classLoader = bundleDesc.getClassLoader();
159         }
160
161         // return an empty list if class loader is not set
162
if (classLoader == null) {
163             return allMethodsInSEI;
164         }
165
166         try {
167             Class JavaDoc c = classLoader.loadClass(serviceInterfaceName);
168             Method JavaDoc[] methods = c.getMethods();
169             for (int i = 0; i < methods.length; i++) {
170                 // empty message or message name is *
171
if (methodName.equals(ALL_METHODS)) {
172                     allMethodsInSEI.add(new MethodDescriptor(methods[i]));
173                 // overloading methods with same method name
174
} else if (methodName.equals(methods[i].getName())) {
175                     allMethodsInSEI.add(new MethodDescriptor(methods[i]));
176                 }
177             }
178         } catch (Exception JavaDoc e) {
179             e.printStackTrace();
180             // if there is exception in the class loading
181
// then we just return the empty list
182
}
183         return allMethodsInSEI;
184     }
185 }
186
Popular Tags