001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial Developer : Delplanque Xavier & Sauthier Guillaume
022: * --------------------------------------------------------------------------
023: * $Id: PortComponentDesc.java 7320 2005-09-05 13:33:44Z sauthieg $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas_ws.deployment.api;
026:
027: import java.net.URL;
028: import java.util.Iterator;
029: import java.util.List;
030: import java.util.Vector;
031:
032: import javax.xml.namespace.QName;
033:
034: import org.objectweb.jonas_lib.I18n;
035: import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
036: import org.objectweb.jonas_lib.deployment.api.HandlerDesc;
037: import org.objectweb.jonas_lib.deployment.xml.Handler;
038:
039: import org.objectweb.jonas_ws.deployment.xml.JonasPortComponent;
040: import org.objectweb.jonas_ws.deployment.xml.PortComponent;
041:
042: /**
043: * This class provides methodes to manipulate portComponent's attributes.
044: *
045: * @author Guillaume Sauthier
046: * @author Xavier Delplanque
047: */
048:
049: public abstract class PortComponentDesc {
050:
051: /**
052: * Internationalization
053: */
054: private static I18n i18n = I18n
055: .getInstance(PortComponentDesc.class);
056:
057: /**
058: * The name of the Port (must be unique)
059: */
060: private String name;
061:
062: /**
063: * The interface of the endpoint/port
064: */
065: private Class sei;
066:
067: /**
068: * the sib link, can be ejb or servlet link
069: */
070: private String sibLink;
071:
072: /**
073: * The classname of bean implementing the service
074: */
075: private String sib;
076:
077: /**
078: * The list of Handlers the Port will run
079: */
080: private List handlers = new Vector();
081:
082: /**
083: * The QName of the WSDL port
084: */
085: private QName portQName;
086:
087: /**
088: * The URL where to access the port-component (null before resolving)
089: */
090: private URL endpoint = null;
091:
092: /**
093: * parent container service
094: */
095: private ServiceDesc parent = null;
096:
097: /**
098: * User specified endpoint URI
099: */
100: private String endpointURI = null;
101:
102: /**
103: * url-pattern computed from endpoint-uri
104: */
105: private String mapping = null;
106:
107: /**
108: * service name computed from endpoint-uri
109: */
110: private String serviceName = null;
111:
112: /**
113: * Creates a new PortComponentDesc object.
114: *
115: * @param jarCL the module (ejbjar or war) classloader.
116: * @param pc webservices port-component element
117: * @param jpc webservices jonas-port-component element
118: * @param parent ServiceDesc containing the PortComponent
119: *
120: * @throws WSDeploymentDescException When construction fails.
121: */
122: protected PortComponentDesc(ClassLoader jarCL, PortComponent pc,
123: JonasPortComponent jpc, ServiceDesc parent)
124: throws WSDeploymentDescException {
125:
126: this .parent = parent;
127:
128: // set name
129: name = pc.getPortComponentName();
130: if ("".equals(name)) { //$NON-NLS-1$
131: String err = getI18n().getMessage(
132: "PortComponentDesc.noPCName"); //$NON-NLS-1$
133: throw new WSDeploymentDescException(err);
134: }
135:
136: // set sei
137: String seiClassName = pc.getServiceEndpointInterface();
138: if ("".equals(seiClassName)) { //$NON-NLS-1$
139: String err = getI18n().getMessage(
140: "PortComponentDesc.noInterfaceName"); //$NON-NLS-1$
141: throw new WSDeploymentDescException(err);
142: }
143:
144: try {
145: sei = jarCL.loadClass(seiClassName);
146: } catch (ClassNotFoundException e) {
147: String err = getI18n().getMessage(
148: "PortComponentDesc.loadError", seiClassName); //$NON-NLS-1$
149: throw new WSDeploymentDescException(err, e);
150: }
151:
152: // set and init handlers
153: List hl = pc.getHandlerList();
154: Handler h = null;
155:
156: for (int i = 0; i < hl.size(); i++) {
157: // for each reference, build and add a HandlerDesc Object
158: if (hl.get(i) != null) {
159: // get the standard dd handler
160: h = (Handler) hl.get(i);
161: // build and add a new handler
162: try {
163: handlers.add(new HandlerDesc(jarCL, h));
164: } catch (DeploymentDescException dde) {
165: throw new WSDeploymentDescException(dde);
166: }
167: }
168: }
169:
170: // set portQName
171: portQName = pc.getWsdlPort().getQName();
172:
173: // we have jonas specific infos
174: if (jpc != null) {
175: // endpoint URI
176: endpointURI = jpc.getEndpointURI();
177: if (endpointURI != null) {
178:
179: // uri doesn't start with '/'
180: if (!endpointURI.startsWith("/")) {
181: // create service-name
182: serviceName = endpointURI;
183: endpointURI += "/" + endpointURI;
184: } else {
185: // remove the first / for the service name
186: serviceName = endpointURI.substring(1);
187: }
188:
189: // serviceName shouldn't be empty
190: if ("".equals(serviceName)) {
191: String err = getI18n()
192: .getMessage(
193: "PortComponentDesc.invalidEndpointURI", this .name); //$NON-NLS-1$
194: throw new WSDeploymentDescException(err);
195: }
196:
197: }
198: } else {
199: // TODO Check this
200: serviceName = portQName.getLocalPart();
201: }
202:
203: }
204:
205: /**
206: * Return the parent ServiceDesc of the PortComponent.
207: *
208: * @return the parent ServiceDesc of the PortComponent.
209: */
210: public ServiceDesc getServiceDesc() {
211: return parent;
212: }
213:
214: /**
215: * Return the name of the PortComponent.
216: *
217: * @return the name of the PortComponent.
218: */
219: public String getName() {
220: return name;
221: }
222:
223: /**
224: * Return the Service Endpoint Interface name.
225: *
226: * @return the Service Endpoint Interface name.
227: */
228: public Class getServiceEndpointInterface() {
229: return sei;
230: }
231:
232: /**
233: * Return the implementation bean. It's the bean classname
234: * which do the real work.
235: *
236: * @return the implementation bean classname.
237: */
238: public String getSIBClassname() {
239: return sib;
240: }
241:
242: /**
243: * Set the sib class name.
244: *
245: * @param sibClassName the sib class name.
246: *
247: * @deprecated sib class set with the setSessionStatelessDesc
248: * or setWebDesc methods.
249: */
250: protected void setSIBClassname(String sibClassName) {
251: this .sib = sibClassName;
252: }
253:
254: /**
255: * Return the WSDL's Port QName, the PortComponent is asssociated with.
256: *
257: * @return the port's QName
258: */
259: public QName getQName() {
260: return portQName;
261: }
262:
263: /**
264: * Return the list of Handlers the PortComponent is associated with.
265: *
266: * @return the list of Handlers the PortComponent is associated with.
267: */
268: public List getHandlers() {
269: return handlers;
270: }
271:
272: /**
273: * Return the service-impl-bean value. the sib can be an ejb or a servlet.
274: *
275: * @return the sib name.
276: */
277: public String getSibLink() {
278: return sibLink;
279: }
280:
281: /**
282: * Return true if the Service Impl Bean is an EJB.
283: *
284: * @return true if the Service Impl Bean is an EJB.
285: */
286: public abstract boolean hasBeanImpl();
287:
288: /**
289: * Return true if the Service Impl Bean is a JaxRpc component.
290: *
291: * @return true if the Service Impl Bean is a JaxRpc component.
292: */
293: public abstract boolean hasJaxRpcImpl();
294:
295: /**
296: * Return the URL where the port-component can be accessed.
297: *
298: * @return the URL where the port-component can be accessed.
299: */
300: public URL getEndpointURL() {
301: return endpoint;
302: }
303:
304: /**
305: * Set the Endpoint URL of the port-component.
306: *
307: * @param url the resolved endpoint URL.
308: */
309: public void setEndpointURL(URL url) {
310: endpoint = url;
311: }
312:
313: /**
314: * @return Returns the mapping.
315: */
316: public String getMapping() {
317: return mapping;
318: }
319:
320: /**
321: * @return Returns the serviceName.
322: */
323: public String getServiceName() {
324: return serviceName;
325: }
326:
327: /**
328: * Setter method for J2EE component linking.
329: * @param desc the descriptor of the component implementing the endpoint.
330: * @throws WSDeploymentDescException when desc is an unknown type.
331: */
332: public abstract void setDesc(Object desc)
333: throws WSDeploymentDescException;
334:
335: /**
336: * @return Returns a String representation of the PortComponent
337: */
338: public String toString() {
339:
340: StringBuffer sb = new StringBuffer();
341:
342: sb.append("\n" + getClass().getName()); //$NON-NLS-1$
343: sb.append("\ngetName()=" + getName()); //$NON-NLS-1$
344: sb
345: .append("\ngetServiceEndpointInterface()=" + getServiceEndpointInterface()); //$NON-NLS-1$
346: sb.append("\ngetSibLink()=" + getSibLink()); //$NON-NLS-1$
347: sb.append("\ngetSIBClassname()=" + getSIBClassname()); //$NON-NLS-1$
348: sb.append("\ngetQName()=" + getQName()); //$NON-NLS-1$
349:
350: for (Iterator i = getHandlers().iterator(); i.hasNext();) {
351: sb
352: .append("\ngetHandlers()=" + ((Handler) i.next()).toString()); //$NON-NLS-1$
353: }
354:
355: return sb.toString();
356:
357: }
358:
359: /**
360: * @return Returns the sib.
361: */
362: public String getSib() {
363: return sib;
364: }
365:
366: /**
367: * @param sib The sib to set.
368: */
369: public void setSib(String sib) {
370: this .sib = sib;
371: }
372:
373: /**
374: * @param sibLink The sibLink to set.
375: */
376: public void setSibLink(String sibLink) {
377: this .sibLink = sibLink;
378: }
379:
380: /**
381: * @return Returns the i18n.
382: */
383: public static I18n getI18n() {
384: return i18n;
385: }
386:
387: /**
388: * @return Returns the endpointURI.
389: */
390: public String getEndpointURI() {
391: return endpointURI;
392: }
393: }
|