KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ws > deployment > api > PortComponentDesc


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial Developer : Delplanque Xavier & Sauthier Guillaume
22  * --------------------------------------------------------------------------
23  * $Id: PortComponentDesc.java,v 1.13 2004/11/19 09:23:00 sauthieg Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_ws.deployment.api;
28
29 import java.net.URL JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Vector JavaDoc;
33
34 import javax.xml.namespace.QName JavaDoc;
35
36 import org.objectweb.jonas_lib.I18n;
37 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
38 import org.objectweb.jonas_lib.deployment.api.HandlerDesc;
39 import org.objectweb.jonas_lib.deployment.xml.Handler;
40
41 import org.objectweb.jonas_ws.deployment.xml.JonasPortComponent;
42 import org.objectweb.jonas_ws.deployment.xml.PortComponent;
43
44
45
46 /**
47  * This class provides methodes to manipulate portComponent's attributes.
48  *
49  * @author Guillaume Sauthier
50  * @author Xavier Delplanque
51  */

52
53 public abstract class PortComponentDesc {
54
55     /**
56      * Internationalization
57      */

58     private static I18n i18n = I18n.getInstance(PortComponentDesc.class);
59
60     /**
61      * The name of the Port (must be unique)
62      */

63     private String JavaDoc name;
64
65     /**
66      * The interface of the endpoint/port
67      */

68     private Class JavaDoc sei;
69
70     /**
71      * the sib link, can be ejb or servlet link
72      */

73     private String JavaDoc sibLink;
74
75     /**
76      * The classname of bean implementing the service
77      */

78     private String JavaDoc sib;
79
80     /**
81      * The list of Handlers the Port will run
82      */

83     private List JavaDoc handlers = new Vector JavaDoc();
84
85     /**
86      * The QName of the WSDL port
87      */

88     private QName JavaDoc portQName;
89
90     /**
91      * The URL where to access the port-component (null before resolving)
92      */

93     private URL JavaDoc endpoint = null;
94
95     /**
96      * parent container service
97      */

98     private ServiceDesc parent = null;
99
100     /**
101      * User specified endpoint URI
102      */

103     private String JavaDoc endpointURI = null;
104
105     /**
106      * url-pattern computed from endpoint-uri
107      */

108     private String JavaDoc mapping = null;
109
110     /**
111      * service name computed from endpoint-uri
112      */

113     private String JavaDoc serviceName = null;
114
115     /**
116      * Creates a new PortComponentDesc object.
117      *
118      * @param jarCL the module (ejbjar or war) classloader.
119      * @param pc webservices port-component element
120      * @param jpc webservices jonas-port-component element
121      * @param parent ServiceDesc containing the PortComponent
122      *
123      * @throws WSDeploymentDescException When construction fails.
124      */

125     protected PortComponentDesc(ClassLoader JavaDoc jarCL,
126                                 PortComponent pc,
127                                 JonasPortComponent jpc,
128                                 ServiceDesc parent)
129         throws WSDeploymentDescException {
130
131         this.parent = parent;
132
133         // set name
134
name = pc.getPortComponentName();
135         if ("".equals(name)) { //$NON-NLS-1$
136
String JavaDoc err = getI18n().getMessage("PortComponentDesc.noPCName"); //$NON-NLS-1$
137
throw new WSDeploymentDescException(err);
138         }
139
140         // set sei
141
String JavaDoc seiClassName = pc.getServiceEndpointInterface();
142         if ("".equals(seiClassName)) { //$NON-NLS-1$
143
String JavaDoc err = getI18n().getMessage("PortComponentDesc.noInterfaceName"); //$NON-NLS-1$
144
throw new WSDeploymentDescException(err);
145         }
146
147         try {
148             sei = jarCL.loadClass(seiClassName);
149         } catch (ClassNotFoundException JavaDoc e) {
150             String JavaDoc err = getI18n().getMessage("PortComponentDesc.loadError", seiClassName); //$NON-NLS-1$
151
System.out.println("***** used ClassLoader : " + jarCL);
152             throw new WSDeploymentDescException(err, e);
153         }
154
155         // set and init handlers
156
List JavaDoc hl = pc.getHandlerList();
157         Handler h = null;
158
159         for (int i = 0; i < hl.size(); i++) {
160             // for each reference, build and add a HandlerDesc Object
161
if (hl.get(i) != null) {
162                 // get the standard dd handler
163
h = (Handler) hl.get(i);
164                 // build and add a new handler
165
try {
166                     handlers.add(new HandlerDesc(jarCL, h));
167                 } catch (DeploymentDescException dde) {
168                     throw new WSDeploymentDescException(dde);
169                 }
170             }
171         }
172
173         // set portQName
174
portQName = pc.getWsdlPort().getQName();
175
176         // we have jonas specific infos
177
if (jpc != null) {
178             // endpoint URI
179
endpointURI = jpc.getEndpointURI();
180
181             int lastSlash = endpointURI.lastIndexOf("/"); //$NON-NLS-1$
182
// create /<mapping>/*
183
mapping = endpointURI.substring(0, lastSlash + 1) + "*"; //$NON-NLS-1$
184

185             String JavaDoc[] parts = endpointURI.split("/"); //$NON-NLS-1$
186
// create service-name
187
serviceName = parts[parts.length - 1];
188         } else {
189             // TODO Check this
190
serviceName = portQName.getLocalPart();
191         }
192
193
194     }
195
196     /**
197      * Return the parent ServiceDesc of the PortComponent.
198      *
199      * @return the parent ServiceDesc of the PortComponent.
200      */

201     public ServiceDesc getServiceDesc() {
202         return parent;
203     }
204
205     /**
206      * Return the name of the PortComponent.
207      *
208      * @return the name of the PortComponent.
209      */

210     public String JavaDoc getName() {
211         return name;
212     }
213
214     /**
215      * Return the Service Endpoint Interface name.
216      *
217      * @return the Service Endpoint Interface name.
218      */

219     public Class JavaDoc getServiceEndpointInterface() {
220         return sei;
221     }
222
223     /**
224      * Return the implementation bean. It's the bean classname
225      * which do the real work.
226      *
227      * @return the implementation bean classname.
228      */

229     public String JavaDoc getSIBClassname() {
230         return sib;
231     }
232
233     /**
234      * Set the sib class name.
235      *
236      * @param sibClassName the sib class name.
237      *
238      * @deprecated sib class set with the setSessionStatelessDesc
239      * or setWebDesc methods.
240      */

241     protected void setSIBClassname(String JavaDoc sibClassName) {
242         this.sib = sibClassName;
243     }
244
245     /**
246      * Return the WSDL's Port QName, the PortComponent is asssociated with.
247      *
248      * @return the port's QName
249      */

250     public QName JavaDoc getQName() {
251         return portQName;
252     }
253
254     /**
255      * Return the list of Handlers the PortComponent is associated with.
256      *
257      * @return the list of Handlers the PortComponent is associated with.
258      */

259     public List JavaDoc getHandlers() {
260         return handlers;
261     }
262
263     /**
264      * Return the service-impl-bean value. the sib can be an ejb or a servlet.
265      *
266      * @return the sib name.
267      */

268     public String JavaDoc getSibLink() {
269         return sibLink;
270     }
271
272     /**
273      * Return true if the Service Impl Bean is an EJB.
274      *
275      * @return true if the Service Impl Bean is an EJB.
276      */

277     public abstract boolean hasBeanImpl();
278
279     /**
280      * Return true if the Service Impl Bean is a JaxRpc component.
281      *
282      * @return true if the Service Impl Bean is a JaxRpc component.
283      */

284     public abstract boolean hasJaxRpcImpl();
285
286     /**
287      * Return the URL where the port-component can be accessed.
288      *
289      * @return the URL where the port-component can be accessed.
290      */

291     public URL JavaDoc getEndpointURL() {
292         return endpoint;
293     }
294
295     /**
296      * Set the Endpoint URL of the port-component.
297      *
298      * @param url the resolved endpoint URL.
299      */

300     public void setEndpointURL(URL JavaDoc url) {
301         endpoint = url;
302     }
303
304     /**
305      * @return Returns the mapping.
306      */

307     public String JavaDoc getMapping() {
308         return mapping;
309     }
310
311     /**
312      * @return Returns the serviceName.
313      */

314     public String JavaDoc getServiceName() {
315         return serviceName;
316     }
317
318     /**
319      * Setter method for J2EE component linking.
320      * @param desc the descriptor of the component implementing the endpoint.
321      * @throws WSDeploymentDescException when desc is an unknown type.
322      */

323     public abstract void setDesc(Object JavaDoc desc) throws WSDeploymentDescException;
324
325     /**
326      * @return Returns a String representation of the PortComponent
327      */

328     public String JavaDoc toString() {
329
330         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
331
332         sb.append("\n" + getClass().getName()); //$NON-NLS-1$
333
sb.append("\ngetName()=" + getName()); //$NON-NLS-1$
334
sb.append("\ngetServiceEndpointInterface()=" + getServiceEndpointInterface()); //$NON-NLS-1$
335
sb.append("\ngetSibLink()=" + getSibLink()); //$NON-NLS-1$
336
sb.append("\ngetSIBClassname()=" + getSIBClassname()); //$NON-NLS-1$
337
sb.append("\ngetQName()=" + getQName()); //$NON-NLS-1$
338

339         for (Iterator JavaDoc i = getHandlers().iterator(); i.hasNext();) {
340             sb.append("\ngetHandlers()=" + ((Handler) i.next()).toString()); //$NON-NLS-1$
341
}
342
343         return sb.toString();
344
345     }
346
347     /**
348      * @return Returns the sib.
349      */

350     public String JavaDoc getSib() {
351         return sib;
352     }
353
354     /**
355      * @param sib The sib to set.
356      */

357     public void setSib(String JavaDoc sib) {
358         this.sib = sib;
359     }
360
361     /**
362      * @param sibLink The sibLink to set.
363      */

364     public void setSibLink(String JavaDoc sibLink) {
365         this.sibLink = sibLink;
366     }
367
368     /**
369      * @return Returns the i18n.
370      */

371     public static I18n getI18n() {
372         return i18n;
373     }
374
375     /**
376      * @return Returns the endpointURI.
377      */

378     public String JavaDoc getEndpointURI() {
379         return endpointURI;
380     }
381 }
382
Popular Tags