KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > util > WSIFUtils


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "WSIF" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2001, 2002, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.apache.wsif.util;
59
60 import java.io.IOException JavaDoc;
61 import java.io.Reader JavaDoc;
62 import java.io.StringReader JavaDoc;
63 import java.io.Writer JavaDoc;
64 import java.lang.reflect.Method JavaDoc;
65 import java.net.MalformedURLException JavaDoc;
66 import java.net.URL JavaDoc;
67 import java.security.AccessController JavaDoc;
68 import java.security.PrivilegedAction JavaDoc;
69 import java.util.ArrayList JavaDoc;
70 import java.util.HashMap JavaDoc;
71 import java.util.Iterator JavaDoc;
72 import java.util.List JavaDoc;
73 import java.util.Map JavaDoc;
74 import java.util.Set JavaDoc;
75 import java.util.StringTokenizer JavaDoc;
76
77 import javax.wsdl.Binding;
78 import javax.wsdl.BindingOperation;
79 import javax.wsdl.Definition;
80 import javax.wsdl.Import;
81 import javax.wsdl.Message;
82 import javax.wsdl.Operation;
83 import javax.wsdl.Part;
84 import javax.wsdl.PortType;
85 import javax.wsdl.Service;
86 import javax.wsdl.WSDLException;
87 import javax.wsdl.extensions.ExtensibilityElement;
88 import javax.wsdl.extensions.ExtensionRegistry;
89 import javax.wsdl.factory.WSDLFactory;
90 import javax.wsdl.xml.WSDLReader;
91 import javax.wsdl.xml.WSDLWriter;
92 import javax.xml.namespace.QName JavaDoc;
93
94 import org.apache.wsif.WSIFConstants;
95 import org.apache.wsif.WSIFException;
96 import org.apache.wsif.WSIFService;
97 import org.apache.wsif.base.WSIFServiceImpl;
98 import org.apache.wsif.compiler.schema.tools.Schema2Java;
99 import org.apache.wsif.format.WSIFFormatHandler;
100 import org.apache.wsif.logging.MessageLogger;
101 import org.apache.wsif.logging.Trc;
102 import org.apache.wsif.schema.ComplexType;
103 import org.apache.wsif.schema.ElementType;
104 import org.apache.wsif.schema.Parser;
105 import org.apache.wsif.schema.SequenceElement;
106 import org.apache.wsif.wsdl.WSIFWSDLLocatorImpl;
107 import org.apache.wsif.wsdl.extensions.format.TypeMapping;
108 import org.w3c.dom.Document JavaDoc;
109 import org.w3c.dom.Element JavaDoc;
110 import org.xml.sax.InputSource JavaDoc;
111
112 import com.ibm.wsdl.Constants;
113 import com.ibm.wsdl.PartImpl;
114
115 /**
116  * This class provides utilities for WSIF runtime and generated stubs.
117  *
118  * @author Alekander Slominski
119  * @author Matthew J. Duftler
120  * @author Sanjiva Weerawarana
121  * @author Owen Burroughs <owenb@apache.org>
122  * @author Ant Elder <antelder@apache.org>
123  * @author Jeremy Hughes <hughesj@apache.org>
124  * @author Mark Whitlock <whitlock@apache.org>
125  * @author Piotr Przybylski
126  */

127 public class WSIFUtils {
128     private static Class JavaDoc initContextClass;
129     private static final String JavaDoc SLASH = "/";
130     private static final String JavaDoc DOT = ".";
131     private static final String JavaDoc FORMAT_HANDLER = "FormatHandler";
132     private static final String JavaDoc ELEMENT_FORMAT_HANDLER = "ElementFormatHandler";
133     private static final String JavaDoc PHYSICALREP = "physicalrep/";
134     private static final String JavaDoc FORMATBINDING = "formatbinding/";
135     private static final String JavaDoc XMLSEPARATORS =
136         "\u002D\u002E\u003A\u00B7\u0387\u06DD\u06DE\u30FB";
137     private static final String JavaDoc XMLSEPARATORS_NODOT =
138         "\u002D\u003A\u00B7\u0387\u06DD\u06DE";
139     private static final String JavaDoc UNDERSCORE = "_";
140     private static final String JavaDoc WWW = "www";
141     private static final String JavaDoc lookupPrefix = "java:comp/env/";
142     private static final String JavaDoc emptyString = "";
143     
144     private static Boolean JavaDoc providersInitialized = new Boolean JavaDoc(false);
145     private static Boolean JavaDoc simpleTypesMapCreated = new Boolean JavaDoc(false);
146     private static HashMap JavaDoc simpleTypesMap = new HashMap JavaDoc();
147     private static HashMap JavaDoc keywordMap = null;
148     
149     /**
150      * This checks whether JNDI classes are available at runtime.
151      * If the return value is true, then generated stubs should
152      * invoke lookupFactoryFromJNDI to get the WSIFService.
153      * If not, then there's no need to do so.
154      */

155     public static boolean isJNDIAvailable() {
156         Trc.entry(null);
157         initContextClass =
158             (Class JavaDoc) AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
159             public Object JavaDoc run() {
160                 try {
161                     return Class.forName(
162                         "javax.naming.InitialContext",
163                         true,
164                         Thread.currentThread().getContextClassLoader());
165                 } catch (Throwable JavaDoc ignored) {
166                     Trc.ignoredException(ignored);
167                 }
168                 return null;
169             }
170         });
171
172         boolean b = true;
173         if (initContextClass == null)
174             b = false;
175         Trc.exit(b);
176         return b;
177     }
178
179     /**
180      * Given the service and portType identification, return a factory
181      * that can produce WSIFPorts for that service/portType combination.
182      */

183     public static WSIFService lookupFactoryFromJNDI(
184         String JavaDoc serviceNS,
185         String JavaDoc serviceName,
186         String JavaDoc portTypeNS,
187         String JavaDoc portTypeName)
188         throws WSIFException {
189         Trc.entry(null, serviceNS, serviceName, portTypeNS, portTypeName);
190         if (serviceNS == null)
191             throw new IllegalArgumentException JavaDoc("service namespace can not be null");
192         if (serviceName == null)
193             throw new IllegalArgumentException JavaDoc("service name can not be null");
194         if (portTypeNS == null)
195             throw new IllegalArgumentException JavaDoc("port type namespace can not be null");
196         if (portTypeName == null)
197             throw new IllegalArgumentException JavaDoc("port type name can not be null");
198
199         WSIFService ws = null;
200         try {
201             if (initContextClass == null) {
202                 initContextClass =
203                     Class.forName(
204                         "javax.naming.InitialContext",
205                         true,
206                         WSIFUtils.class.getClassLoader());
207             }
208             Object JavaDoc ic = initContextClass.newInstance();
209             Class JavaDoc[] lookupSig = new Class JavaDoc[] { String JavaDoc.class };
210             Object JavaDoc[] lookupArgs =
211                 new String JavaDoc[] {
212                     serviceNS
213                         + "::"
214                         + serviceName
215                         + "::"
216                         + portTypeNS
217                         + "::"
218                         + portTypeName };
219             Method JavaDoc m = initContextClass.getMethod("lookup", lookupSig);
220             ws = (WSIFService) m.invoke(ic, lookupArgs);
221         } catch (Exception JavaDoc e) {
222             Trc.exception(e);
223             throw new WSIFException(
224                 "Exception while looking up JNDI factory: " + e.getMessage(),
225                 e);
226         }
227         Trc.exit(ws);
228         return ws;
229     }
230
231     public static Service selectService(
232         Definition def,
233         String JavaDoc serviceNS,
234         String JavaDoc serviceName)
235         throws WSIFException {
236         Trc.entry(null, def, serviceNS, serviceName);
237         Map JavaDoc services = getAllItems(def, "Service");
238         QName JavaDoc serviceQName =
239             ((serviceNS != null && serviceName != null)
240                 ? new QName JavaDoc(serviceNS, serviceName)
241                 : null);
242         Service service =
243             (Service) getNamedItem(services, serviceQName, "Service");
244
245         Trc.exit(service);
246         return service;
247     }
248
249     public static PortType selectPortType(
250         Definition def,
251         String JavaDoc portTypeNS,
252         String JavaDoc portTypeName)
253         throws WSIFException {
254         Trc.entry(null, def, portTypeNS, portTypeName);
255         Map JavaDoc portTypes = getAllItems(def, "PortType");
256         QName JavaDoc portTypeQName =
257             ((portTypeNS != null && portTypeName != null)
258                 ? new QName JavaDoc(portTypeNS, portTypeName)
259                 : null);
260         PortType portType =
261             (PortType) getNamedItem(portTypes, portTypeQName, "PortType");
262
263         Trc.exit(portType);
264         return portType;
265     }
266
267     public static void addDefinedItems(
268         Map JavaDoc fromItems,
269         String JavaDoc itemType,
270         Map JavaDoc toItems) {
271         Trc.entry(null, fromItems, itemType, toItems);
272
273         if (fromItems != null) {
274             Iterator JavaDoc entryIterator = fromItems.entrySet().iterator();
275
276             if (itemType.equals("Message")) {
277                 while (entryIterator.hasNext()) {
278                     Map.Entry JavaDoc entry = (Map.Entry JavaDoc) entryIterator.next();
279                     Message message = (Message) entry.getValue();
280
281                     if (!message.isUndefined()) {
282                         toItems.put(entry.getKey(), message);
283                     }
284                 }
285             } else if (itemType.equals("Operation")) {
286                 while (entryIterator.hasNext()) {
287                     Map.Entry JavaDoc entry = (Map.Entry JavaDoc) entryIterator.next();
288                     Operation operation = (Operation) entry.getValue();
289
290                     if (!operation.isUndefined()) {
291                         toItems.put(entry.getKey(), operation);
292                     }
293                 }
294             } else if (itemType.equals("PortType")) {
295                 while (entryIterator.hasNext()) {
296                     Map.Entry JavaDoc entry = (Map.Entry JavaDoc) entryIterator.next();
297                     PortType portType = (PortType) entry.getValue();
298
299                     if (!portType.isUndefined()) {
300                         toItems.put(entry.getKey(), portType);
301                     }
302                 }
303             } else if (itemType.equals("Binding")) {
304                 while (entryIterator.hasNext()) {
305                     Map.Entry JavaDoc entry = (Map.Entry JavaDoc) entryIterator.next();
306                     Binding binding = (Binding) entry.getValue();
307
308                     if (!binding.isUndefined()) {
309                         toItems.put(entry.getKey(), binding);
310                     }
311                 }
312             } else if (itemType.equals("Service")) {
313                 while (entryIterator.hasNext()) {
314                     Map.Entry JavaDoc entry = (Map.Entry JavaDoc) entryIterator.next();
315                     Service service = (Service) entry.getValue();
316
317                     toItems.put(entry.getKey(), service);
318                 }
319             }
320         }
321         Trc.exit();
322     }
323
324     private static void getAllItems(
325         Definition def,
326         String JavaDoc itemType,
327         Map JavaDoc toItems) {
328         Trc.entry(null, def, itemType, toItems);
329         Map JavaDoc items = null;
330
331         if (itemType.equals("PortType")) {
332             items = def.getPortTypes();
333         } else if (itemType.equals("Service")) {
334             items = def.getServices();
335         } else {
336             throw new IllegalArgumentException JavaDoc(
337                 "Don't know how to find all " + itemType + "s.");
338         }
339
340         addDefinedItems(items, itemType, toItems);
341
342         Map JavaDoc imports = def.getImports();
343
344         if (imports != null) {
345             Iterator JavaDoc valueIterator = imports.values().iterator();
346
347             while (valueIterator.hasNext()) {
348                 List JavaDoc importList = (List JavaDoc) valueIterator.next();
349
350                 if (importList != null) {
351                     Iterator JavaDoc importIterator = importList.iterator();
352
353                     while (importIterator.hasNext()) {
354                         Import tempImport = (Import) importIterator.next();
355
356                         if (tempImport != null) {
357                             Definition importedDef = tempImport.getDefinition();
358
359                             if (importedDef != null) {
360                                 getAllItems(importedDef, itemType, toItems);
361                             }
362                         }
363                     }
364                 }
365             }
366         }
367         Trc.exit();
368     }
369
370     public static Map JavaDoc getAllItems(Definition def, String JavaDoc itemType) {
371         Trc.entry(null, def, itemType);
372         Map JavaDoc ret = new HashMap JavaDoc();
373
374         getAllItems(def, itemType, ret);
375
376         Trc.exit(ret);
377         return ret;
378     }
379
380     public static Object JavaDoc getNamedItem(Map JavaDoc items, QName JavaDoc qname, String JavaDoc itemType)
381         throws WSIFException {
382         Trc.entry(null, items, qname, itemType);
383         if (qname != null) {
384             Object JavaDoc item = items.get(qname);
385
386             if (item != null) {
387                 Trc.exit(item);
388                 return item;
389             } else {
390                 throw new WSIFException(
391                     itemType
392                         + " '"
393                         + qname
394                         + "' not found. Choices are: "
395                         + getCommaListFromQNameMap(items));
396             }
397         } else {
398             int size = items.size();
399
400             if (size == 1) {
401                 Iterator JavaDoc valueIterator = items.values().iterator();
402
403                 Object JavaDoc o = valueIterator.next();
404                 Trc.exit(o);
405                 return o;
406             } else if (size == 0) {
407                 throw new WSIFException(
408                     "WSDL document contains no " + itemType + "s.");
409             } else {
410                 throw new WSIFException(
411                     "Please specify a "
412                         + itemType
413                         + ". Choices are: "
414                         + getCommaListFromQNameMap(items));
415             }
416         }
417     }
418
419     private static String JavaDoc getCommaListFromQNameMap(Map JavaDoc qnameMap) {
420         StringBuffer JavaDoc strBuf = new StringBuffer JavaDoc("{");
421         Set JavaDoc keySet = qnameMap.keySet();
422         Iterator JavaDoc keyIterator = keySet.iterator();
423         int index = 0;
424
425         while (keyIterator.hasNext()) {
426             QName JavaDoc key = (QName JavaDoc) keyIterator.next();
427
428             strBuf.append((index > 0 ? ", " : "") + key);
429             index++;
430         }
431
432         strBuf.append("}");
433
434         return strBuf.toString();
435     }
436
437     /**
438      * Read WSDL - it is different from standard readWSDL method as it is
439      * using extensibility elements that were registered for dynamic port
440      * factory.
441      */

442     public static Definition readWSDL(String JavaDoc contextURL, String JavaDoc wsdlLoc)
443         throws WSDLException {
444         Trc.entry(null, contextURL, wsdlLoc);
445
446         initializeProviders();
447
448         WSDLFactory factory = WSDLFactory.newInstance(
449             WSIFConstants.WSIF_WSDLFACTORY);
450         WSDLReader wsdlReader = factory.newWSDLReader();
451         wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
452         try {
453             Definition def = wsdlReader.readWSDL(contextURL, wsdlLoc);
454             Trc.exitExpandWsdl(def);
455             return def;
456         } catch (WSDLException e) {
457             Trc.exception(e);
458             MessageLogger.log("WSIF.0002E", wsdlLoc);
459             throw e;
460         }
461     }
462
463     /**
464      * Read WSDL - it is different from standard readWSDL method as it is
465      * using extensibility elements that were registered for dynamic port
466      * factory. It also uses the accompanying class loader to load imported WSDL
467      * resources.
468      */

469     public static Definition readWSDL(
470         URL JavaDoc documentBase,
471         Reader JavaDoc reader,
472         ClassLoader JavaDoc cl)
473         throws WSDLException {
474         String JavaDoc base = (documentBase == null) ? null : documentBase.toString();
475         return readWSDL(base, reader, cl);
476     }
477
478     /**
479      * Read WSDL - it is different from standard readWSDL method as it is
480      * using extensibility elements that were registered for dynamic port
481      * factory. It also uses the accompanying class loader to load imported WSDL
482      * resources.
483      */

484     public static Definition readWSDL(
485         String JavaDoc documentBase,
486         Reader JavaDoc reader,
487         ClassLoader JavaDoc cl)
488         throws WSDLException {
489         Trc.entry(null, documentBase, reader, cl);
490
491         initializeProviders();
492
493         WSDLFactory factory = WSDLFactory.newInstance(
494             WSIFConstants.WSIF_WSDLFACTORY);
495         WSDLReader wsdlReader = factory.newWSDLReader();
496         wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
497         WSIFWSDLLocatorImpl lo = null;
498         try {
499             lo = new WSIFWSDLLocatorImpl(documentBase, reader, cl);
500             Definition def = wsdlReader.readWSDL(lo);
501             Trc.exitExpandWsdl(def);
502             return def;
503         } catch (WSDLException e) {
504             Trc.exception(e);
505             MessageLogger.log("WSIF.0002E", documentBase);
506             throw e;
507         } finally {
508             try {
509                 if (lo != null) lo.close();
510             } catch (IOException JavaDoc ioe) {
511                 //ignore
512
Trc.ignoredException(ioe);
513             }
514         }
515     }
516
517     /**
518      * Read WSDL - it is different from standard readWSDL method as it is
519      * using extensibility elements that were registered for dynamic port
520      * factory. It also uses the accompanying class loader to load imported WSDL
521      * resources.
522      */

523     public static Definition readWSDL(
524         URL JavaDoc contextURL,
525         String JavaDoc wsdlLoc,
526         ClassLoader JavaDoc cl)
527         throws WSDLException {
528         Trc.entry(null, contextURL, wsdlLoc, cl);
529
530         initializeProviders();
531
532         WSDLFactory factory = WSDLFactory.newInstance(
533             WSIFConstants.WSIF_WSDLFACTORY);
534         WSDLReader wsdlReader = factory.newWSDLReader();
535         wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
536         WSIFWSDLLocatorImpl lo = null;
537
538         try {
539             String JavaDoc url = (contextURL == null) ? null : contextURL.toString();
540             lo = new WSIFWSDLLocatorImpl(url, wsdlLoc, cl);
541             Definition def = wsdlReader.readWSDL(lo);
542             Trc.exitExpandWsdl(def);
543             return def;
544         } catch (WSDLException e) {
545             Trc.exception(e);
546             MessageLogger.log("WSIF.0002E", wsdlLoc);
547             throw e;
548         } finally {
549             try {
550                 if (lo != null) lo.close();
551             } catch (IOException JavaDoc ioe) {
552                 //ignore
553
Trc.ignoredException(ioe);
554             }
555         }
556     }
557
558     /**
559      * Read WSDL - it is different from standard readWSDL method as it is
560      * using extensibility elements that were registered for dynamic port
561      * factory.
562      */

563     public static Definition readWSDL(String JavaDoc contextURL, Reader JavaDoc reader)
564         throws WSDLException {
565         Trc.entry(null, contextURL, reader);
566
567         initializeProviders();
568
569         WSDLFactory factory = WSDLFactory.newInstance(
570             WSIFConstants.WSIF_WSDLFACTORY);
571         WSDLReader wsdlReader = factory.newWSDLReader();
572         wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
573         Definition def =
574             wsdlReader.readWSDL(contextURL, new InputSource JavaDoc(reader));
575         Trc.exitExpandWsdl(def);
576         return def;
577     }
578
579     /**
580      * Read WSDL - it is different from standard readWSDL method as it is
581      * using extensibility elements that were registered for dynamic port
582      * factory.
583      */

584     public static Definition readWSDL(String JavaDoc contextURL, Document JavaDoc wsdlDocument)
585         throws WSDLException {
586         Trc.entry(null, contextURL, wsdlDocument);
587
588         initializeProviders();
589
590         WSDLFactory factory = WSDLFactory.newInstance(
591             WSIFConstants.WSIF_WSDLFACTORY);
592         WSDLReader wsdlReader = factory.newWSDLReader();
593         wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
594         Definition def = wsdlReader.readWSDL(contextURL, wsdlDocument);
595
596         Trc.exitExpandWsdl(def);
597         return def;
598     }
599
600     /**
601      * Read WSDL - it is different from standard readWSDL method as it is
602      * using extensibility elements that were registered for dynamic port
603      * factory.
604      */

605     public static Definition readWSDL(
606         String JavaDoc contextURL,
607         Element wsdlServicesElement)
608         throws WSDLException {
609         Trc.entry(null, contextURL, wsdlServicesElement);
610
611         initializeProviders();
612
613         WSDLFactory factory = WSDLFactory.newInstance(
614             WSIFConstants.WSIF_WSDLFACTORY);
615         WSDLReader wsdlReader = factory.newWSDLReader();
616         wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
617         Definition def = wsdlReader.readWSDL(contextURL, wsdlServicesElement);
618
619         Trc.exitExpandWsdl(def);
620         return def;
621     }
622
623     /**
624      * Write WSDL - it is different from standard writeWSDL method as it is
625      * using extensibility elements that were registered for dynamic port
626      * factory.
627      */

628     public static void writeWSDL(Definition def, Writer JavaDoc sink)
629         throws WSDLException {
630         Trc.entry(null, def, sink);
631
632         WSDLFactory factory = WSDLFactory.newInstance(
633             WSIFConstants.WSIF_WSDLFACTORY);
634         WSDLWriter wsdlWriter = factory.newWSDLWriter();
635         wsdlWriter.writeWSDL(def, sink);
636
637         Trc.exit();
638     }
639
640     public static Definition getDefinitionFromLocation(
641         String JavaDoc contextURL,
642         String JavaDoc location)
643         throws WSIFException {
644         Trc.entry(null, contextURL, location);
645
646         if (location == null) {
647             throw new WSIFException("WSDL location must not be null.");
648         }
649
650         Definition def = null;
651         try {
652             def = WSIFUtils.readWSDL(contextURL, location);
653         } catch (WSDLException e) {
654             Trc.exception(e);
655             throw new WSIFException("Problem reading WSDL document.", e);
656         }
657         Trc.exitExpandWsdl(def);
658         return def;
659     }
660
661     public static Definition getDefinitionFromContent(
662         String JavaDoc contextURL,
663         String JavaDoc content)
664         throws WSIFException {
665         Trc.entry(null, contextURL, content);
666         if (content == null) {
667             throw new WSIFException("WSDL content must not be null.");
668         }
669
670         Definition def = null;
671         try {
672             def = WSIFUtils.readWSDL(contextURL, new StringReader JavaDoc(content));
673         } catch (WSDLException e) {
674             Trc.exception(e);
675             throw new WSIFException("Problem reading WSDL document.", e);
676         }
677         Trc.exitExpandWsdl(def);
678         return def;
679     }
680
681     /**
682      * Initialize the WSIF providers. Each provider initializes its WSDL
683      * extension registries. This has no effect if AutoLoad providers has
684      * been turned off on WSIFServiceImpl ... in that case it is the
685      * responsibility of the application to initialize providers.
686      */

687     public static void initializeProviders() {
688         synchronized (providersInitialized) {
689             if (!providersInitialized.booleanValue()) {
690                 WSIFPluggableProviders.getProvider("/");
691                 providersInitialized = new Boolean JavaDoc(true);
692             }
693         }
694     }
695
696     /**
697      * Create a map of all schema simple types and there Java equivalents.
698      */

699     public static void createSimpleTypesMap() {
700         synchronized (simpleTypesMapCreated) {
701             if (!simpleTypesMapCreated.booleanValue()) {
702                 new Schema2Java(
703                     WSIFConstants.NS_URI_1999_SCHEMA_XSD).getRegistry(
704                     simpleTypesMap);
705                 new Schema2Java(
706                     WSIFConstants.NS_URI_2000_SCHEMA_XSD).getRegistry(
707                     simpleTypesMap);
708                 new Schema2Java(
709                     WSIFConstants.NS_URI_2001_SCHEMA_XSD).getRegistry(
710                     simpleTypesMap);
711                 simpleTypesMapCreated = new Boolean JavaDoc(true);
712             }
713         }
714     }
715
716     /**
717      * Get a map of all schema simple types and there Java equivalents.
718      * @return The map of simple types
719      */

720     public static Map JavaDoc getSimpleTypesMap() {
721         if (!simpleTypesMapCreated.booleanValue()) {
722             createSimpleTypesMap();
723         }
724         return simpleTypesMap;
725     }
726
727     // the following code copied from JCAUtils
728
public static WSIFFormatHandler getFormatHandler(
729         Part part,
730         Definition definition,
731         javax.wsdl.Binding binding)
732         throws
733             java.lang.InstantiationException JavaDoc,
734             java.lang.IllegalAccessException JavaDoc,
735             java.lang.ClassNotFoundException JavaDoc {
736         Trc.entry(null, part, definition, binding);
737         WSIFFormatHandler formatHandler = null;
738         javax.xml.namespace.QName JavaDoc partTypeQName = part.getTypeName();
739         if (partTypeQName == null)
740             partTypeQName = part.getElementName();
741         if (partTypeQName == null)
742             throw new ClassNotFoundException JavaDoc(part.getName());
743
744         String JavaDoc typePackageName =
745             getPackageNameFromNamespaceURI(partTypeQName.getNamespaceURI());
746         String JavaDoc formatHandlerName = typePackageName;
747
748         String JavaDoc bindingShortName =
749             getPackageNameFromXMLName(
750                 definition.getPrefix(getBindingNamespace(binding)));
751         if (bindingShortName != null)