001: /*
002: * Copyright 2001-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: /*
018: * Modified by Nabh Information Systems, Inc. for Stringbeans Web Services
019: * Framework.
020: *
021: * Modifications (c) 2005 Nabh Information Systems, Inc.
022: */
023: package com.nabhinc.ws.soap;
024:
025: import java.io.IOException;
026: import java.util.ArrayList;
027: import java.util.List;
028: import java.util.StringTokenizer;
029: import java.util.Vector;
030:
031: import javax.xml.namespace.QName;
032:
033: import org.apache.axis.AxisEngine;
034: import org.apache.axis.ConfigurationException;
035: import org.apache.axis.Constants;
036: import org.apache.axis.EngineConfiguration;
037: import org.apache.axis.FaultableHandler;
038: import org.apache.axis.Handler;
039: import org.apache.axis.attachments.Attachments;
040: import org.apache.axis.attachments.AttachmentsImpl;
041: import org.apache.axis.constants.Style;
042: import org.apache.axis.constants.Use;
043: import org.apache.axis.deployment.wsdd.WSDDArrayMapping;
044: import org.apache.axis.deployment.wsdd.WSDDBeanMapping;
045: import org.apache.axis.deployment.wsdd.WSDDChain;
046: import org.apache.axis.deployment.wsdd.WSDDConstants;
047: import org.apache.axis.deployment.wsdd.WSDDDeployment;
048: import org.apache.axis.deployment.wsdd.WSDDDocumentation;
049: import org.apache.axis.deployment.wsdd.WSDDException;
050: import org.apache.axis.deployment.wsdd.WSDDFaultFlow;
051: import org.apache.axis.deployment.wsdd.WSDDJAXRPCHandlerInfoChain;
052: import org.apache.axis.deployment.wsdd.WSDDNonFatalException;
053: import org.apache.axis.deployment.wsdd.WSDDOperation;
054: import org.apache.axis.deployment.wsdd.WSDDTargetedChain;
055: import org.apache.axis.deployment.wsdd.WSDDTypeMapping;
056: import org.apache.axis.deployment.wsdd.WSDDTypeMappingContainer;
057: import org.apache.axis.description.ServiceDesc;
058: import org.apache.axis.encoding.DeserializerFactory;
059: import org.apache.axis.encoding.SerializationContext;
060: import org.apache.axis.encoding.SerializerFactory;
061: import org.apache.axis.encoding.TypeMapping;
062: import org.apache.axis.encoding.TypeMappingRegistry;
063: import org.apache.axis.encoding.TypeMappingRegistryImpl;
064: import org.apache.axis.encoding.ser.ArraySerializerFactory;
065: import org.apache.axis.encoding.ser.BaseDeserializerFactory;
066: import org.apache.axis.encoding.ser.BaseSerializerFactory;
067: import org.apache.axis.handlers.HandlerInfoChainFactory;
068: import org.apache.axis.handlers.soap.SOAPService;
069: import org.apache.axis.providers.java.JavaProvider;
070: import org.apache.axis.utils.Messages;
071: import org.apache.axis.utils.XMLUtils;
072: import org.w3c.dom.Element;
073: import org.xml.sax.helpers.AttributesImpl;
074:
075: import com.nabhinc.ws.core.WebServiceException;
076: import com.nabhinc.ws.server.WebService;
077:
078: /**
079: * A service represented in WSDD.
080: *
081: * @author Glen Daniels (gdaniels@apache.org)
082: */
083: public class WSDDService extends WSDDTargetedChain implements
084: WSDDTypeMappingContainer {
085: /**
086: * Comment for <code>serialVersionUID</code>
087: */
088: private static final long serialVersionUID = 3257282517827662640L;
089:
090: private TypeMappingRegistry tmr = null;
091:
092: private Vector faultFlows = new Vector();
093: private Vector typeMappings = new Vector();
094: private Vector operations = new Vector();
095:
096: /** Which namespaces should auto-dispatch to this service? */
097: private Vector namespaces = new Vector();
098:
099: /** Which roles does this service support? */
100: private List roles = new ArrayList();
101:
102: private String descriptionURL;
103:
104: /** Style - document, wrapped, message, or RPC (the default) */
105: private Style style = Style.DEFAULT;
106: /** Use - encoded (the default) or literal */
107: private Use use = Use.DEFAULT;
108:
109: private SOAPService cachedService = null;
110:
111: /**
112: * Our provider - used to figure out which Handler we use as a service
113: * pivot (see getInstance() below)
114: */
115: private QName providerQName;
116:
117: // private HandlerInfoChainFactory _hiChainFactory;
118: private WSDDJAXRPCHandlerInfoChain _wsddHIchain;
119:
120: JavaServiceDesc desc = new JavaServiceDesc();
121:
122: /**
123: * Is streaming (i.e. NO high-fidelity recording, deserialize on the fly)
124: * on for this service?
125: */
126: private boolean streaming = false;
127:
128: /**
129: * What attachment format should be used?
130: */
131: private int sendType = Attachments.SEND_TYPE_NOTSET;
132:
133: /**
134: * Default constructor
135: */
136: public WSDDService() {
137: }
138:
139: /**
140: *
141: * @param e (Element) XXX
142: * @throws WSDDException XXX
143: */
144: public WSDDService(Element e) throws WSDDException {
145: super (e);
146:
147: desc.setName(getQName().getLocalPart());
148:
149: String styleStr = e.getAttribute(ATTR_STYLE);
150: if (styleStr != null && !styleStr.equals("")) {
151: style = Style.getStyle(styleStr, Style.DEFAULT);
152: desc.setStyle(style);
153: providerQName = style.getProvider();
154: }
155:
156: String useStr = e.getAttribute(ATTR_USE);
157: if (useStr != null && !useStr.equals("")) {
158: use = Use.getUse(useStr, Use.DEFAULT);
159: desc.setUse(use);
160: } else {
161: if (style != Style.RPC) {
162: // Default to use=literal if not style=RPC
163: use = Use.LITERAL;
164: desc.setUse(use);
165: }
166: }
167:
168: String streamStr = e.getAttribute(ATTR_STREAMING);
169: if (streamStr != null && streamStr.equals("on")) {
170: streaming = true;
171: }
172:
173: String attachmentStr = e.getAttribute(ATTR_ATTACHMENT_FORMAT);
174: if (attachmentStr != null && !attachmentStr.equals("")) {
175: sendType = AttachmentsImpl.getSendType(attachmentStr);
176: }
177:
178: Element[] operationElements = getChildElements(e,
179: ELEM_WSDD_OPERATION);
180: for (int i = 0; i < operationElements.length; i++) {
181: WSDDOperation operation = new WSDDOperation(
182: operationElements[i], desc);
183: addOperation(operation);
184: }
185:
186: Element[] typeMappingElements = getChildElements(e,
187: ELEM_WSDD_TYPEMAPPING);
188: for (int i = 0; i < typeMappingElements.length; i++) {
189: WSDDTypeMapping mapping = new WSDDTypeMapping(
190: typeMappingElements[i]);
191: typeMappings.add(mapping);
192: }
193:
194: Element[] beanMappingElements = getChildElements(e,
195: ELEM_WSDD_BEANMAPPING);
196: for (int i = 0; i < beanMappingElements.length; i++) {
197: WSDDBeanMapping mapping = new WSDDBeanMapping(
198: beanMappingElements[i]);
199: typeMappings.add(mapping);
200: }
201:
202: Element[] arrayMappingElements = getChildElements(e,
203: ELEM_WSDD_ARRAYMAPPING);
204: for (int i = 0; i < arrayMappingElements.length; i++) {
205: WSDDArrayMapping mapping = new WSDDArrayMapping(
206: arrayMappingElements[i]);
207: typeMappings.add(mapping);
208: }
209:
210: Element[] namespaceElements = getChildElements(e,
211: ELEM_WSDD_NAMESPACE);
212: for (int i = 0; i < namespaceElements.length; i++) {
213: // Register a namespace for this service
214: String ns = XMLUtils
215: .getChildCharacterData(namespaceElements[i]);
216: namespaces.add(ns);
217: }
218: if (!namespaces.isEmpty())
219: desc.setNamespaceMappings(namespaces);
220:
221: Element[] roleElements = getChildElements(e, ELEM_WSDD_ROLE);
222: for (int i = 0; i < roleElements.length; i++) {
223: String role = XMLUtils
224: .getChildCharacterData(roleElements[i]);
225: roles.add(role);
226: }
227:
228: Element wsdlElem = getChildElement(e, ELEM_WSDD_WSDLFILE);
229: if (wsdlElem != null) {
230: String fileName = XMLUtils.getChildCharacterData(wsdlElem);
231: desc.setWSDLFile(fileName.trim());
232: }
233:
234: Element docElem = getChildElement(e, ELEM_WSDD_DOC);
235: if (docElem != null) {
236: WSDDDocumentation documentation = new WSDDDocumentation(
237: docElem);
238: desc.setDocumentation(documentation.getValue());
239: }
240:
241: Element urlElem = getChildElement(e, ELEM_WSDD_ENDPOINTURL);
242: if (urlElem != null) {
243: String endpointURL = XMLUtils
244: .getChildCharacterData(urlElem);
245: desc.setEndpointURL(endpointURL);
246: }
247:
248: String providerStr = e.getAttribute(ATTR_PROVIDER);
249: if (providerStr != null && !providerStr.equals("")) {
250: providerQName = XMLUtils.getQNameFromString(providerStr, e);
251: if (WSDDConstants.QNAME_JAVAMSG_PROVIDER
252: .equals(providerQName)) {
253: // Message style if message provider...
254: desc.setStyle(Style.MESSAGE);
255: }
256: }
257:
258: // Add in JAX-RPC support for HandlerInfo chains
259: Element hcEl = getChildElement(e, ELEM_WSDD_JAXRPC_CHAIN);
260: if (hcEl != null) {
261: _wsddHIchain = new WSDDJAXRPCHandlerInfoChain(hcEl);
262: }
263:
264: // Initialize TypeMappingRegistry
265: initTMR();
266:
267: // call to validate standard descriptors for this service
268: validateDescriptors();
269: }
270:
271: /**
272: * Initialize a TypeMappingRegistry with the
273: * WSDDTypeMappings.
274: * Note: Extensions of WSDDService may override
275: * initTMR to popluate the tmr with different
276: * type mappings.
277: */
278: protected void initTMR() throws WSDDException {
279: // If not created, construct a tmr
280: // and populate it with the type mappings.
281: if (tmr == null) {
282: createTMR();
283: for (int i = 0; i < typeMappings.size(); i++) {
284: deployTypeMapping((WSDDTypeMapping) typeMappings.get(i));
285: }
286: }
287: }
288:
289: private void createTMR() {
290: tmr = new TypeMappingRegistryImpl(false);
291: String version = getParameter("typeMappingVersion");
292: ((TypeMappingRegistryImpl) tmr).doRegisterFromVersion(version);
293: }
294:
295: /**
296: * This method can be used for dynamic deployment using new WSDDService()
297: * etc. It validates some standard parameters for some standard providers
298: * (if present). Do this before deployment.deployService().
299: */
300: public void validateDescriptors() throws WSDDException {
301: if (tmr == null) {
302: initTMR();
303: }
304: desc.setTypeMappingRegistry(tmr);
305: desc
306: .setTypeMapping(getTypeMapping(desc.getUse()
307: .getEncoding()));
308:
309: String allowedMethods = getParameter(JavaProvider.OPTION_ALLOWEDMETHODS);
310: if (allowedMethods != null && !"*".equals(allowedMethods)) {
311: ArrayList methodList = new ArrayList();
312: StringTokenizer tokenizer = new StringTokenizer(
313: allowedMethods, " ,");
314: while (tokenizer.hasMoreTokens()) {
315: methodList.add(tokenizer.nextToken());
316: }
317: desc.setAllowedMethods(methodList);
318: }
319: }
320:
321: /**
322: * Add a WSDDTypeMapping to the Service.
323: * @param mapping
324: **/
325: public void addTypeMapping(WSDDTypeMapping mapping) {
326: typeMappings.add(mapping);
327: }
328:
329: /**
330: * Add a WSDDOperation to the Service.
331: * @param operation the operation to add
332: **/
333: public void addOperation(WSDDOperation operation) {
334: operations.add(operation);
335: desc.addOperationDesc(operation.getOperationDesc());
336: }
337:
338: protected QName getElementName() {
339: return QNAME_SERVICE;
340: }
341:
342: /**
343: * Get any service description URL which might be associated with this
344: * service.
345: *
346: * @return a String containing a URL, or null.
347: */
348: public String getServiceDescriptionURL() {
349: return descriptionURL;
350: }
351:
352: /**
353: * Set the service description URL for this service.
354: *
355: * @param sdUrl a String containing a URL
356: */
357: public void setServiceDescriptionURL(String sdUrl) {
358: descriptionURL = sdUrl;
359: }
360:
361: public QName getProviderQName() {
362: return providerQName;
363: }
364:
365: public void setProviderQName(QName providerQName) {
366: this .providerQName = providerQName;
367: }
368:
369: public ServiceDesc getServiceDesc() {
370: return desc;
371: }
372:
373: /**
374: * Get the service style - document or RPC
375: */
376: public Style getStyle() {
377: return style;
378: }
379:
380: /**
381: * Set the service style - document or RPC
382: */
383: public void setStyle(Style style) {
384: this .style = style;
385: }
386:
387: /**
388: * Get the service use - literal or encoded
389: */
390: public Use getUse() {
391: return use;
392: }
393:
394: /**
395: * Set the service use - literal or encoded
396: */
397: public void setUse(Use use) {
398: this .use = use;
399: }
400:
401: /**
402: *
403: * @return XXX
404: */
405: public WSDDFaultFlow[] getFaultFlows() {
406: WSDDFaultFlow[] t = new WSDDFaultFlow[faultFlows.size()];
407: faultFlows.toArray(t);
408: return t;
409: }
410:
411: /**
412: * Obtain the list of namespaces registered for this service
413: * @return a Vector of namespaces (Strings) which should dispatch to
414: * this service
415: */
416: public Vector getNamespaces() {
417: return namespaces;
418: }
419:
420: /**
421: *
422: * @param name XXX
423: * @return XXX
424: */
425: public WSDDFaultFlow getFaultFlow(QName name) {
426: WSDDFaultFlow[] t = getFaultFlows();
427:
428: for (int n = 0; n < t.length; n++) {
429: if (t[n].getQName().equals(name)) {
430: return t[n];
431: }
432: }
433:
434: return null;
435: }
436:
437: /**
438: *
439: * @param registry XXX
440: * @return XXX
441: * @throws ConfigurationException XXX
442: * @throws WebServiceException
443: */
444: public Handler makeNewInstance(EngineConfiguration registry,
445: WebService webService, String wsClass)
446: throws ConfigurationException, WebServiceException {
447: if (cachedService != null) {
448: return cachedService;
449: }
450:
451: // Make sure tmr is initialized.
452: initTMR();
453:
454: //Handler reqHandler = null;
455: WSDDChain request = getRequestFlow();
456:
457: if (request != null) {
458: request.getInstance(registry);
459: }
460:
461: //Handler providerHandler = null;
462: // providerHandler = new RPCProvider();
463: /*
464: if (providerQName != null) {
465: try {
466: providerHandler = WSDDProvider.getInstance(providerQName,
467: this,
468: registry);
469: } catch (Exception e) {
470: throw new ConfigurationException(e);
471: }
472: if (providerHandler == null)
473: throw new WSDDException(
474: Messages.getMessage("couldntConstructProvider00"));
475: }
476: */
477: //Handler respHandler = null;
478: WSDDChain response = getResponseFlow();
479:
480: if (response != null) {
481: /* respHandler = */response.getInstance(registry);
482: }
483:
484: SOAPService service = new SOAPService(); // reqHandler, providerHandler,
485: // respHandler);
486: service.setStyle(style);
487: service.setUse(use);
488: service.setServiceDescription(desc);
489:
490: service.setHighFidelityRecording(!streaming);
491: service.setSendType(sendType);
492:
493: if (getQName() != null)
494: service.setName(getQName().getLocalPart());
495: service.setOptions(getParametersTable());
496:
497: service.setRoles(roles);
498:
499: // Changed by PDD
500: // service.setEngine(((WSDDDeployment)registry).getEngine());
501:
502: if (use != Use.ENCODED) {
503: // If not encoded, turn off multi-refs and prefer
504: // not to sent xsi:type and xsi:nil
505: service.setOption(AxisEngine.PROP_DOMULTIREFS,
506: Boolean.FALSE);
507: service.setOption(AxisEngine.PROP_SEND_XSI, Boolean.FALSE);
508: }
509:
510: // Set handlerInfoChain
511: if (_wsddHIchain != null) {
512: HandlerInfoChainFactory hiChainFactory = _wsddHIchain
513: .getHandlerChainFactory();
514:
515: service.setOption(Constants.ATTR_HANDLERINFOCHAIN,
516: hiChainFactory);
517: }
518:
519: AxisEngine.normaliseOptions(service);
520:
521: WSDDFaultFlow[] faultFlows = getFaultFlows();
522: if (faultFlows != null && faultFlows.length > 0) {
523: FaultableHandler wrapper = new FaultableHandler(service);
524: for (int i = 0; i < faultFlows.length; i++) {
525: WSDDFaultFlow flow = faultFlows[i];
526: Handler faultHandler = flow.getInstance(registry);
527: wrapper.setOption("fault-"
528: + flow.getQName().getLocalPart(), faultHandler);
529: }
530: }
531: /*
532: try {
533: service.getInitializedServiceDesc(MessageContext.getCurrentContext());
534: } catch (AxisFault axisFault) {
535: throw new ConfigurationException(axisFault);
536: }
537: */
538: populateServiceDescription(service, webService, wsClass);
539: cachedService = service;
540: return service;
541: }
542:
543: public void deployTypeMapping(WSDDTypeMapping mapping)
544: throws WSDDException {
545: if (!typeMappings.contains(mapping)) {
546: typeMappings.add(mapping);
547: }
548: if (tmr == null) {
549: createTMR();
550: }
551: try {
552: // Get the encoding style from the mapping, if it isn't set
553: // use the use of the service to map doc/lit or rpc/enc
554: String encodingStyle = mapping.getEncodingStyle();
555: if (encodingStyle == null) {
556: encodingStyle = use.getEncoding();
557: }
558: TypeMapping tm = tmr.getOrMakeTypeMapping(encodingStyle);
559: desc.setTypeMappingRegistry(tmr);
560: desc.setTypeMapping(tm);
561:
562: SerializerFactory ser = null;
563: DeserializerFactory deser = null;
564:
565: // Try to construct a serializerFactory by introspecting for the
566: // following:
567: // public static create(Class javaType, QName xmlType)
568: // public <constructor>(Class javaType, QName xmlType)
569: // public <constructor>()
570: //
571: // The BaseSerializerFactory createFactory() method is a utility
572: // that does this for us.
573: if (mapping.getSerializerName() != null
574: && !mapping.getSerializerName().equals("")) {
575: ser = BaseSerializerFactory.createFactory(mapping
576: .getSerializer(), mapping
577: .getLanguageSpecificType(), mapping.getQName());
578: }
579:
580: if (mapping instanceof WSDDArrayMapping
581: && ser instanceof ArraySerializerFactory) {
582: WSDDArrayMapping am = (WSDDArrayMapping) mapping;
583: ArraySerializerFactory factory = (ArraySerializerFactory) ser;
584: factory.setComponentType(am.getInnerType());
585: }
586:
587: if (mapping.getDeserializerName() != null
588: && !mapping.getDeserializerName().equals("")) {
589: deser = BaseDeserializerFactory.createFactory(mapping
590: .getDeserializer(), mapping
591: .getLanguageSpecificType(), mapping.getQName());
592: }
593: tm.register(mapping.getLanguageSpecificType(), mapping
594: .getQName(), ser, deser);
595: } catch (ClassNotFoundException e) {
596: log.error(Messages.getMessage(
597: "unabletoDeployTypemapping00", mapping.getQName()
598: .toString()), e);
599: throw new WSDDNonFatalException(e);
600: } catch (Exception e) {
601: throw new WSDDException(e);
602: }
603: }
604:
605: /**
606: * Write this element out to a SerializationContext
607: */
608: public void writeToContext(SerializationContext context)
609: throws IOException {
610: AttributesImpl attrs = new AttributesImpl();
611: QName name = getQName();
612: if (name != null) {
613: attrs.addAttribute("", ATTR_NAME, ATTR_NAME, "CDATA",
614: context.qName2String(name));
615: }
616: if (providerQName != null) {
617: attrs.addAttribute("", ATTR_PROVIDER, ATTR_PROVIDER,
618: "CDATA", context.qName2String(providerQName));
619: }
620: if (style != Style.DEFAULT) {
621: attrs.addAttribute("", ATTR_STYLE, ATTR_STYLE, "CDATA",
622: style.getName());
623: }
624:
625: if (use != Use.DEFAULT) {
626: attrs.addAttribute("", ATTR_USE, ATTR_USE, "CDATA", use
627: .getName());
628: }
629:
630: if (streaming) {
631: attrs.addAttribute("", ATTR_STREAMING, ATTR_STREAMING,
632: "CDATA", "on");
633: }
634:
635: if (sendType != Attachments.SEND_TYPE_NOTSET) {
636: attrs.addAttribute("", ATTR_ATTACHMENT_FORMAT,
637: ATTR_ATTACHMENT_FORMAT, "CDATA", AttachmentsImpl
638: .getSendTypeString(sendType));
639: }
640: context.startElement(WSDDConstants.QNAME_SERVICE, attrs);
641:
642: if (desc.getWSDLFile() != null) {
643: context.startElement(QNAME_WSDLFILE, null);
644: context.writeSafeString(desc.getWSDLFile());
645: context.endElement();
646: }
647:
648: if (desc.getDocumentation() != null) {
649: WSDDDocumentation documentation = new WSDDDocumentation(
650: desc.getDocumentation());
651: documentation.writeToContext(context);
652: }
653:
654: for (int i = 0; i < operations.size(); i++) {
655: WSDDOperation operation = (WSDDOperation) operations
656: .elementAt(i);
657: operation.writeToContext(context);
658: }
659: writeFlowsToContext(context);
660: writeParamsToContext(context);
661:
662: for (int i = 0; i < typeMappings.size(); i++) {
663: ((WSDDTypeMapping) typeMappings.elementAt(i))
664: .writeToContext(context);
665: }
666:
667: for (int i = 0; i < namespaces.size(); i++) {
668: context.startElement(QNAME_NAMESPACE, null);
669: context.writeString((String) namespaces.get(i));
670: context.endElement();
671: }
672:
673: String endpointURL = desc.getEndpointURL();
674: if (endpointURL != null) {
675: context.startElement(QNAME_ENDPOINTURL, null);
676: context.writeSafeString(endpointURL);
677: context.endElement();
678: }
679:
680: if (_wsddHIchain != null) {
681: _wsddHIchain.writeToContext(context);
682:
683: }
684:
685: context.endElement();
686:
687: }
688:
689: public void setCachedService(SOAPService service) {
690: cachedService = service;
691: }
692:
693: public Vector getTypeMappings() {
694: return typeMappings;
695: }
696:
697: public void setTypeMappings(Vector typeMappings) {
698: this .typeMappings = typeMappings;
699: }
700:
701: /*
702: public void deployToRegistry(WSDDDeployment registry)
703: {
704: registry.addService(this);
705:
706: // Register the name of the service as a valid namespace, just for
707: // backwards compatibility
708: registry.registerNamespaceForService(getQName().getLocalPart(), this);
709:
710: for (int i = 0; i < namespaces.size(); i++) {
711: String namespace = (String) namespaces.elementAt(i);
712: registry.registerNamespaceForService(namespace, this);
713: }
714:
715: super.deployToRegistry(registry);
716: }
717: */
718: public void removeNamespaceMappings(WSDDDeployment registry) {
719: for (int i = 0; i < namespaces.size(); i++) {
720: String namespace = (String) namespaces.elementAt(i);
721: registry.removeNamespaceMapping(namespace);
722: }
723: registry.removeNamespaceMapping(getQName().getLocalPart());
724: }
725:
726: public TypeMapping getTypeMapping(String encodingStyle) {
727: // If type mapping registry not initialized yet, return null.
728: if (tmr == null) {
729: return null;
730: }
731: return (TypeMapping) tmr.getOrMakeTypeMapping(encodingStyle);
732: }
733:
734: public WSDDJAXRPCHandlerInfoChain getHandlerInfoChain() {
735: return _wsddHIchain;
736: }
737:
738: public void setHandlerInfoChain(WSDDJAXRPCHandlerInfoChain hichain) {
739: _wsddHIchain = hichain;
740: }
741:
742: private void populateServiceDescription(SOAPService service,
743: WebService webService, String className)
744: throws WebServiceException {
745: Class cls = null;
746: try {
747: if (className != null)
748: cls = Class.forName(className);
749: } catch (ClassNotFoundException e) {
750: throw new WebServiceException(
751: "Invalid service impl class: " + className + ".", e);
752: }
753: // If the implementation class is not known, we can't really do the introspection.
754: if (cls == null)
755: return;
756: JavaServiceDesc serviceDescription = (JavaServiceDesc) service
757: .getServiceDescription();
758:
759: // And the allowed methods, if necessary
760: if (serviceDescription.getAllowedMethods() == null
761: && service != null) {
762: String allowedMethods = getAllowedMethods(service);
763: if (allowedMethods != null && !"*".equals(allowedMethods)) {
764: ArrayList methodList = new ArrayList();
765: StringTokenizer tokenizer = new StringTokenizer(
766: allowedMethods, " ,");
767: while (tokenizer.hasMoreTokens()) {
768: methodList.add(tokenizer.nextToken());
769: }
770: serviceDescription.setAllowedMethods(methodList);
771: }
772: }
773:
774: serviceDescription.loadServiceDescByIntrospection(cls);
775:
776: }
777:
778: private String getAllowedMethods(Handler service) {
779: String val = (String) service
780: .getOption(JavaProvider.OPTION_ALLOWEDMETHODS);
781: if (val == null || val.length() == 0) {
782: // Try the old option for backwards-compatibility
783: val = (String) service.getOption("methodName");
784: }
785: return val;
786: }
787:
788: }
|