Source Code Cross Referenced for WSIFUtils.java in  » Web-Services » wsif » org » apache » wsif » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services » wsif » org.apache.wsif.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * The Apache Software License, Version 1.1
0003:         *
0004:         *
0005:         * Copyright (c) 2002 The Apache Software Foundation.  All rights 
0006:         * reserved.
0007:         *
0008:         * Redistribution and use in source and binary forms, with or without
0009:         * modification, are permitted provided that the following conditions
0010:         * are met:
0011:         *
0012:         * 1. Redistributions of source code must retain the above copyright
0013:         *    notice, this list of conditions and the following disclaimer. 
0014:         *
0015:         * 2. Redistributions in binary form must reproduce the above copyright
0016:         *    notice, this list of conditions and the following disclaimer in
0017:         *    the documentation and/or other materials provided with the
0018:         *    distribution.
0019:         *
0020:         * 3. The end-user documentation included with the redistribution,
0021:         *    if any, must include the following acknowledgment:  
0022:         *       "This product includes software developed by the
0023:         *        Apache Software Foundation (http://www.apache.org/)."
0024:         *    Alternately, this acknowledgment may appear in the software itself,
0025:         *    if and wherever such third-party acknowledgments normally appear.
0026:         *
0027:         * 4. The names "WSIF" and "Apache Software Foundation" must
0028:         *    not be used to endorse or promote products derived from this
0029:         *    software without prior written permission. For written 
0030:         *    permission, please contact apache@apache.org.
0031:         *
0032:         * 5. Products derived from this software may not be called "Apache",
0033:         *    nor may "Apache" appear in their name, without prior written
0034:         *    permission of the Apache Software Foundation.
0035:         *
0036:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0037:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0038:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0039:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0040:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0041:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0042:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
0043:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0044:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0045:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0046:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0047:         * SUCH DAMAGE.
0048:         * ====================================================================
0049:         *
0050:         * This software consists of voluntary contributions made by many
0051:         * individuals on behalf of the Apache Software Foundation and was
0052:         * originally based on software copyright (c) 2001, 2002, International
0053:         * Business Machines, Inc., http://www.apache.org.  For more
0054:         * information on the Apache Software Foundation, please see
0055:         * <http://www.apache.org/>.
0056:         */
0057:
0058:        package org.apache.wsif.util;
0059:
0060:        import java.io.IOException;
0061:        import java.io.Reader;
0062:        import java.io.StringReader;
0063:        import java.io.Writer;
0064:        import java.lang.reflect.Method;
0065:        import java.net.MalformedURLException;
0066:        import java.net.URL;
0067:        import java.security.AccessController;
0068:        import java.security.PrivilegedAction;
0069:        import java.util.ArrayList;
0070:        import java.util.HashMap;
0071:        import java.util.Iterator;
0072:        import java.util.List;
0073:        import java.util.Map;
0074:        import java.util.Set;
0075:        import java.util.StringTokenizer;
0076:
0077:        import javax.wsdl.Binding;
0078:        import javax.wsdl.BindingOperation;
0079:        import javax.wsdl.Definition;
0080:        import javax.wsdl.Import;
0081:        import javax.wsdl.Message;
0082:        import javax.wsdl.Operation;
0083:        import javax.wsdl.Part;
0084:        import javax.wsdl.PortType;
0085:        import javax.wsdl.Service;
0086:        import javax.wsdl.WSDLException;
0087:        import javax.wsdl.extensions.ExtensibilityElement;
0088:        import javax.wsdl.extensions.ExtensionRegistry;
0089:        import javax.wsdl.factory.WSDLFactory;
0090:        import javax.wsdl.xml.WSDLReader;
0091:        import javax.wsdl.xml.WSDLWriter;
0092:        import javax.xml.namespace.QName;
0093:
0094:        import org.apache.wsif.WSIFConstants;
0095:        import org.apache.wsif.WSIFException;
0096:        import org.apache.wsif.WSIFService;
0097:        import org.apache.wsif.base.WSIFServiceImpl;
0098:        import org.apache.wsif.compiler.schema.tools.Schema2Java;
0099:        import org.apache.wsif.format.WSIFFormatHandler;
0100:        import org.apache.wsif.logging.MessageLogger;
0101:        import org.apache.wsif.logging.Trc;
0102:        import org.apache.wsif.schema.ComplexType;
0103:        import org.apache.wsif.schema.ElementType;
0104:        import org.apache.wsif.schema.Parser;
0105:        import org.apache.wsif.schema.SequenceElement;
0106:        import org.apache.wsif.wsdl.WSIFWSDLLocatorImpl;
0107:        import org.apache.wsif.wsdl.extensions.format.TypeMapping;
0108:        import org.w3c.dom.Document;
0109:        import org.w3c.dom.Element;
0110:        import org.xml.sax.InputSource;
0111:
0112:        import com.ibm.wsdl.Constants;
0113:        import com.ibm.wsdl.PartImpl;
0114:
0115:        /**
0116:         * This class provides utilities for WSIF runtime and generated stubs.
0117:         *
0118:         * @author Alekander Slominski
0119:         * @author Matthew J. Duftler
0120:         * @author Sanjiva Weerawarana
0121:         * @author Owen Burroughs <owenb@apache.org>
0122:         * @author Ant Elder <antelder@apache.org>
0123:         * @author Jeremy Hughes <hughesj@apache.org>
0124:         * @author Mark Whitlock <whitlock@apache.org>
0125:         * @author Piotr Przybylski
0126:         */
0127:        public class WSIFUtils {
0128:            private static Class initContextClass;
0129:            private static final String SLASH = "/";
0130:            private static final String DOT = ".";
0131:            private static final String FORMAT_HANDLER = "FormatHandler";
0132:            private static final String ELEMENT_FORMAT_HANDLER = "ElementFormatHandler";
0133:            private static final String PHYSICALREP = "physicalrep/";
0134:            private static final String FORMATBINDING = "formatbinding/";
0135:            private static final String XMLSEPARATORS = "\u002D\u002E\u003A\u00B7\u0387\u06DD\u06DE\u30FB";
0136:            private static final String XMLSEPARATORS_NODOT = "\u002D\u003A\u00B7\u0387\u06DD\u06DE";
0137:            private static final String UNDERSCORE = "_";
0138:            private static final String WWW = "www";
0139:            private static final String lookupPrefix = "java:comp/env/";
0140:            private static final String emptyString = "";
0141:
0142:            private static Boolean providersInitialized = new Boolean(false);
0143:            private static Boolean simpleTypesMapCreated = new Boolean(false);
0144:            private static HashMap simpleTypesMap = new HashMap();
0145:            private static HashMap keywordMap = null;
0146:
0147:            /**
0148:             * This checks whether JNDI classes are available at runtime.
0149:             * If the return value is true, then generated stubs should
0150:             * invoke lookupFactoryFromJNDI to get the WSIFService.
0151:             * If not, then there's no need to do so.
0152:             */
0153:            public static boolean isJNDIAvailable() {
0154:                Trc.entry(null);
0155:                initContextClass = (Class) AccessController
0156:                        .doPrivileged(new PrivilegedAction() {
0157:                            public Object run() {
0158:                                try {
0159:                                    return Class.forName(
0160:                                            "javax.naming.InitialContext",
0161:                                            true, Thread.currentThread()
0162:                                                    .getContextClassLoader());
0163:                                } catch (Throwable ignored) {
0164:                                    Trc.ignoredException(ignored);
0165:                                }
0166:                                return null;
0167:                            }
0168:                        });
0169:
0170:                boolean b = true;
0171:                if (initContextClass == null)
0172:                    b = false;
0173:                Trc.exit(b);
0174:                return b;
0175:            }
0176:
0177:            /**
0178:             * Given the service and portType identification, return a factory
0179:             * that can produce WSIFPorts for that service/portType combination.
0180:             */
0181:            public static WSIFService lookupFactoryFromJNDI(String serviceNS,
0182:                    String serviceName, String portTypeNS, String portTypeName)
0183:                    throws WSIFException {
0184:                Trc.entry(null, serviceNS, serviceName, portTypeNS,
0185:                        portTypeName);
0186:                if (serviceNS == null)
0187:                    throw new IllegalArgumentException(
0188:                            "service namespace can not be null");
0189:                if (serviceName == null)
0190:                    throw new IllegalArgumentException(
0191:                            "service name can not be null");
0192:                if (portTypeNS == null)
0193:                    throw new IllegalArgumentException(
0194:                            "port type namespace can not be null");
0195:                if (portTypeName == null)
0196:                    throw new IllegalArgumentException(
0197:                            "port type name can not be null");
0198:
0199:                WSIFService ws = null;
0200:                try {
0201:                    if (initContextClass == null) {
0202:                        initContextClass = Class.forName(
0203:                                "javax.naming.InitialContext", true,
0204:                                WSIFUtils.class.getClassLoader());
0205:                    }
0206:                    Object ic = initContextClass.newInstance();
0207:                    Class[] lookupSig = new Class[] { String.class };
0208:                    Object[] lookupArgs = new String[] { serviceNS + "::"
0209:                            + serviceName + "::" + portTypeNS + "::"
0210:                            + portTypeName };
0211:                    Method m = initContextClass.getMethod("lookup", lookupSig);
0212:                    ws = (WSIFService) m.invoke(ic, lookupArgs);
0213:                } catch (Exception e) {
0214:                    Trc.exception(e);
0215:                    throw new WSIFException(
0216:                            "Exception while looking up JNDI factory: "
0217:                                    + e.getMessage(), e);
0218:                }
0219:                Trc.exit(ws);
0220:                return ws;
0221:            }
0222:
0223:            public static Service selectService(Definition def,
0224:                    String serviceNS, String serviceName) throws WSIFException {
0225:                Trc.entry(null, def, serviceNS, serviceName);
0226:                Map services = getAllItems(def, "Service");
0227:                QName serviceQName = ((serviceNS != null && serviceName != null) ? new QName(
0228:                        serviceNS, serviceName)
0229:                        : null);
0230:                Service service = (Service) getNamedItem(services,
0231:                        serviceQName, "Service");
0232:
0233:                Trc.exit(service);
0234:                return service;
0235:            }
0236:
0237:            public static PortType selectPortType(Definition def,
0238:                    String portTypeNS, String portTypeName)
0239:                    throws WSIFException {
0240:                Trc.entry(null, def, portTypeNS, portTypeName);
0241:                Map portTypes = getAllItems(def, "PortType");
0242:                QName portTypeQName = ((portTypeNS != null && portTypeName != null) ? new QName(
0243:                        portTypeNS, portTypeName)
0244:                        : null);
0245:                PortType portType = (PortType) getNamedItem(portTypes,
0246:                        portTypeQName, "PortType");
0247:
0248:                Trc.exit(portType);
0249:                return portType;
0250:            }
0251:
0252:            public static void addDefinedItems(Map fromItems, String itemType,
0253:                    Map toItems) {
0254:                Trc.entry(null, fromItems, itemType, toItems);
0255:
0256:                if (fromItems != null) {
0257:                    Iterator entryIterator = fromItems.entrySet().iterator();
0258:
0259:                    if (itemType.equals("Message")) {
0260:                        while (entryIterator.hasNext()) {
0261:                            Map.Entry entry = (Map.Entry) entryIterator.next();
0262:                            Message message = (Message) entry.getValue();
0263:
0264:                            if (!message.isUndefined()) {
0265:                                toItems.put(entry.getKey(), message);
0266:                            }
0267:                        }
0268:                    } else if (itemType.equals("Operation")) {
0269:                        while (entryIterator.hasNext()) {
0270:                            Map.Entry entry = (Map.Entry) entryIterator.next();
0271:                            Operation operation = (Operation) entry.getValue();
0272:
0273:                            if (!operation.isUndefined()) {
0274:                                toItems.put(entry.getKey(), operation);
0275:                            }
0276:                        }
0277:                    } else if (itemType.equals("PortType")) {
0278:                        while (entryIterator.hasNext()) {
0279:                            Map.Entry entry = (Map.Entry) entryIterator.next();
0280:                            PortType portType = (PortType) entry.getValue();
0281:
0282:                            if (!portType.isUndefined()) {
0283:                                toItems.put(entry.getKey(), portType);
0284:                            }
0285:                        }
0286:                    } else if (itemType.equals("Binding")) {
0287:                        while (entryIterator.hasNext()) {
0288:                            Map.Entry entry = (Map.Entry) entryIterator.next();
0289:                            Binding binding = (Binding) entry.getValue();
0290:
0291:                            if (!binding.isUndefined()) {
0292:                                toItems.put(entry.getKey(), binding);
0293:                            }
0294:                        }
0295:                    } else if (itemType.equals("Service")) {
0296:                        while (entryIterator.hasNext()) {
0297:                            Map.Entry entry = (Map.Entry) entryIterator.next();
0298:                            Service service = (Service) entry.getValue();
0299:
0300:                            toItems.put(entry.getKey(), service);
0301:                        }
0302:                    }
0303:                }
0304:                Trc.exit();
0305:            }
0306:
0307:            private static void getAllItems(Definition def, String itemType,
0308:                    Map toItems) {
0309:                Trc.entry(null, def, itemType, toItems);
0310:                Map items = null;
0311:
0312:                if (itemType.equals("PortType")) {
0313:                    items = def.getPortTypes();
0314:                } else if (itemType.equals("Service")) {
0315:                    items = def.getServices();
0316:                } else {
0317:                    throw new IllegalArgumentException(
0318:                            "Don't know how to find all " + itemType + "s.");
0319:                }
0320:
0321:                addDefinedItems(items, itemType, toItems);
0322:
0323:                Map imports = def.getImports();
0324:
0325:                if (imports != null) {
0326:                    Iterator valueIterator = imports.values().iterator();
0327:
0328:                    while (valueIterator.hasNext()) {
0329:                        List importList = (List) valueIterator.next();
0330:
0331:                        if (importList != null) {
0332:                            Iterator importIterator = importList.iterator();
0333:
0334:                            while (importIterator.hasNext()) {
0335:                                Import tempImport = (Import) importIterator
0336:                                        .next();
0337:
0338:                                if (tempImport != null) {
0339:                                    Definition importedDef = tempImport
0340:                                            .getDefinition();
0341:
0342:                                    if (importedDef != null) {
0343:                                        getAllItems(importedDef, itemType,
0344:                                                toItems);
0345:                                    }
0346:                                }
0347:                            }
0348:                        }
0349:                    }
0350:                }
0351:                Trc.exit();
0352:            }
0353:
0354:            public static Map getAllItems(Definition def, String itemType) {
0355:                Trc.entry(null, def, itemType);
0356:                Map ret = new HashMap();
0357:
0358:                getAllItems(def, itemType, ret);
0359:
0360:                Trc.exit(ret);
0361:                return ret;
0362:            }
0363:
0364:            public static Object getNamedItem(Map items, QName qname,
0365:                    String itemType) throws WSIFException {
0366:                Trc.entry(null, items, qname, itemType);
0367:                if (qname != null) {
0368:                    Object item = items.get(qname);
0369:
0370:                    if (item != null) {
0371:                        Trc.exit(item);
0372:                        return item;
0373:                    } else {
0374:                        throw new WSIFException(itemType + " '" + qname
0375:                                + "' not found. Choices are: "
0376:                                + getCommaListFromQNameMap(items));
0377:                    }
0378:                } else {
0379:                    int size = items.size();
0380:
0381:                    if (size == 1) {
0382:                        Iterator valueIterator = items.values().iterator();
0383:
0384:                        Object o = valueIterator.next();
0385:                        Trc.exit(o);
0386:                        return o;
0387:                    } else if (size == 0) {
0388:                        throw new WSIFException("WSDL document contains no "
0389:                                + itemType + "s.");
0390:                    } else {
0391:                        throw new WSIFException("Please specify a " + itemType
0392:                                + ". Choices are: "
0393:                                + getCommaListFromQNameMap(items));
0394:                    }
0395:                }
0396:            }
0397:
0398:            private static String getCommaListFromQNameMap(Map qnameMap) {
0399:                StringBuffer strBuf = new StringBuffer("{");
0400:                Set keySet = qnameMap.keySet();
0401:                Iterator keyIterator = keySet.iterator();
0402:                int index = 0;
0403:
0404:                while (keyIterator.hasNext()) {
0405:                    QName key = (QName) keyIterator.next();
0406:
0407:                    strBuf.append((index > 0 ? ", " : "") + key);
0408:                    index++;
0409:                }
0410:
0411:                strBuf.append("}");
0412:
0413:                return strBuf.toString();
0414:            }
0415:
0416:            /**
0417:             * Read WSDL - it is different from standard readWSDL method as it is
0418:             * using extensibility elements that were registered for dynamic port
0419:             * factory.
0420:             */
0421:            public static Definition readWSDL(String contextURL, String wsdlLoc)
0422:                    throws WSDLException {
0423:                Trc.entry(null, contextURL, wsdlLoc);
0424:
0425:                initializeProviders();
0426:
0427:                WSDLFactory factory = WSDLFactory
0428:                        .newInstance(WSIFConstants.WSIF_WSDLFACTORY);
0429:                WSDLReader wsdlReader = factory.newWSDLReader();
0430:                wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
0431:                try {
0432:                    Definition def = wsdlReader.readWSDL(contextURL, wsdlLoc);
0433:                    Trc.exitExpandWsdl(def);
0434:                    return def;
0435:                } catch (WSDLException e) {
0436:                    Trc.exception(e);
0437:                    MessageLogger.log("WSIF.0002E", wsdlLoc);
0438:                    throw e;
0439:                }
0440:            }
0441:
0442:            /**
0443:             * Read WSDL - it is different from standard readWSDL method as it is
0444:             * using extensibility elements that were registered for dynamic port
0445:             * factory.  It also uses the accompanying class loader to load imported WSDL
0446:             * resources.
0447:             */
0448:            public static Definition readWSDL(URL documentBase, Reader reader,
0449:                    ClassLoader cl) throws WSDLException {
0450:                String base = (documentBase == null) ? null : documentBase
0451:                        .toString();
0452:                return readWSDL(base, reader, cl);
0453:            }
0454:
0455:            /**
0456:             * Read WSDL - it is different from standard readWSDL method as it is
0457:             * using extensibility elements that were registered for dynamic port
0458:             * factory.  It also uses the accompanying class loader to load imported WSDL
0459:             * resources.
0460:             */
0461:            public static Definition readWSDL(String documentBase,
0462:                    Reader reader, ClassLoader cl) throws WSDLException {
0463:                Trc.entry(null, documentBase, reader, cl);
0464:
0465:                initializeProviders();
0466:
0467:                WSDLFactory factory = WSDLFactory
0468:                        .newInstance(WSIFConstants.WSIF_WSDLFACTORY);
0469:                WSDLReader wsdlReader = factory.newWSDLReader();
0470:                wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
0471:                WSIFWSDLLocatorImpl lo = null;
0472:                try {
0473:                    lo = new WSIFWSDLLocatorImpl(documentBase, reader, cl);
0474:                    Definition def = wsdlReader.readWSDL(lo);
0475:                    Trc.exitExpandWsdl(def);
0476:                    return def;
0477:                } catch (WSDLException e) {
0478:                    Trc.exception(e);
0479:                    MessageLogger.log("WSIF.0002E", documentBase);
0480:                    throw e;
0481:                } finally {
0482:                    try {
0483:                        if (lo != null)
0484:                            lo.close();
0485:                    } catch (IOException ioe) {
0486:                        //ignore
0487:                        Trc.ignoredException(ioe);
0488:                    }
0489:                }
0490:            }
0491:
0492:            /**
0493:             * Read WSDL - it is different from standard readWSDL method as it is
0494:             * using extensibility elements that were registered for dynamic port
0495:             * factory.  It also uses the accompanying class loader to load imported WSDL
0496:             * resources.
0497:             */
0498:            public static Definition readWSDL(URL contextURL, String wsdlLoc,
0499:                    ClassLoader cl) throws WSDLException {
0500:                Trc.entry(null, contextURL, wsdlLoc, cl);
0501:
0502:                initializeProviders();
0503:
0504:                WSDLFactory factory = WSDLFactory
0505:                        .newInstance(WSIFConstants.WSIF_WSDLFACTORY);
0506:                WSDLReader wsdlReader = factory.newWSDLReader();
0507:                wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
0508:                WSIFWSDLLocatorImpl lo = null;
0509:
0510:                try {
0511:                    String url = (contextURL == null) ? null : contextURL
0512:                            .toString();
0513:                    lo = new WSIFWSDLLocatorImpl(url, wsdlLoc, cl);
0514:                    Definition def = wsdlReader.readWSDL(lo);
0515:                    Trc.exitExpandWsdl(def);
0516:                    return def;
0517:                } catch (WSDLException e) {
0518:                    Trc.exception(e);
0519:                    MessageLogger.log("WSIF.0002E", wsdlLoc);
0520:                    throw e;
0521:                } finally {
0522:                    try {
0523:                        if (lo != null)
0524:                            lo.close();
0525:                    } catch (IOException ioe) {
0526:                        //ignore
0527:                        Trc.ignoredException(ioe);
0528:                    }
0529:                }
0530:            }
0531:
0532:            /**
0533:             * Read WSDL - it is different from standard readWSDL method as it is
0534:             * using extensibility elements that were registered for dynamic port
0535:             * factory.
0536:             */
0537:            public static Definition readWSDL(String contextURL, Reader reader)
0538:                    throws WSDLException {
0539:                Trc.entry(null, contextURL, reader);
0540:
0541:                initializeProviders();
0542:
0543:                WSDLFactory factory = WSDLFactory
0544:                        .newInstance(WSIFConstants.WSIF_WSDLFACTORY);
0545:                WSDLReader wsdlReader = factory.newWSDLReader();
0546:                wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
0547:                Definition def = wsdlReader.readWSDL(contextURL,
0548:                        new InputSource(reader));
0549:                Trc.exitExpandWsdl(def);
0550:                return def;
0551:            }
0552:
0553:            /**
0554:             * Read WSDL - it is different from standard readWSDL method as it is
0555:             * using extensibility elements that were registered for dynamic port
0556:             * factory.
0557:             */
0558:            public static Definition readWSDL(String contextURL,
0559:                    Document wsdlDocument) throws WSDLException {
0560:                Trc.entry(null, contextURL, wsdlDocument);
0561:
0562:                initializeProviders();
0563:
0564:                WSDLFactory factory = WSDLFactory
0565:                        .newInstance(WSIFConstants.WSIF_WSDLFACTORY);
0566:                WSDLReader wsdlReader = factory.newWSDLReader();
0567:                wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
0568:                Definition def = wsdlReader.readWSDL(contextURL, wsdlDocument);
0569:
0570:                Trc.exitExpandWsdl(def);
0571:                return def;
0572:            }
0573:
0574:            /**
0575:             * Read WSDL - it is different from standard readWSDL method as it is
0576:             * using extensibility elements that were registered for dynamic port
0577:             * factory.
0578:             */
0579:            public static Definition readWSDL(String contextURL,
0580:                    Element wsdlServicesElement) throws WSDLException {
0581:                Trc.entry(null, contextURL, wsdlServicesElement);
0582:
0583:                initializeProviders();
0584:
0585:                WSDLFactory factory = WSDLFactory
0586:                        .newInstance(WSIFConstants.WSIF_WSDLFACTORY);
0587:                WSDLReader wsdlReader = factory.newWSDLReader();
0588:                wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
0589:                Definition def = wsdlReader.readWSDL(contextURL,
0590:                        wsdlServicesElement);
0591:
0592:                Trc.exitExpandWsdl(def);
0593:                return def;
0594:            }
0595:
0596:            /**
0597:             * Write WSDL - it is different from standard writeWSDL method as it is
0598:             * using extensibility elements that were registered for dynamic port
0599:             * factory.
0600:             */
0601:            public static void writeWSDL(Definition def, Writer sink)
0602:                    throws WSDLException {
0603:                Trc.entry(null, def, sink);
0604:
0605:                WSDLFactory factory = WSDLFactory
0606:                        .newInstance(WSIFConstants.WSIF_WSDLFACTORY);
0607:                WSDLWriter wsdlWriter = factory.newWSDLWriter();
0608:                wsdlWriter.writeWSDL(def, sink);
0609:
0610:                Trc.exit();
0611:            }
0612:
0613:            public static Definition getDefinitionFromLocation(
0614:                    String contextURL, String location) throws WSIFException {
0615:                Trc.entry(null, contextURL, location);
0616:
0617:                if (location == null) {
0618:                    throw new WSIFException("WSDL location must not be null.");
0619:                }
0620:
0621:                Definition def = null;
0622:                try {
0623:                    def = WSIFUtils.readWSDL(contextURL, location);
0624:                } catch (WSDLException e) {
0625:                    Trc.exception(e);
0626:                    throw new WSIFException("Problem reading WSDL document.", e);
0627:                }
0628:                Trc.exitExpandWsdl(def);
0629:                return def;
0630:            }
0631:
0632:            public static Definition getDefinitionFromContent(
0633:                    String contextURL, String content) throws WSIFException {
0634:                Trc.entry(null, contextURL, content);
0635:                if (content == null) {
0636:                    throw new WSIFException("WSDL content must not be null.");
0637:                }
0638:
0639:                Definition def = null;
0640:                try {
0641:                    def = WSIFUtils.readWSDL(contextURL, new StringReader(
0642:                            content));
0643:                } catch (WSDLException e) {
0644:                    Trc.exception(e);
0645:                    throw new WSIFException("Problem reading WSDL document.", e);
0646:                }
0647:                Trc.exitExpandWsdl(def);
0648:                return def;
0649:            }
0650:
0651:            /**
0652:             * Initialize the WSIF providers. Each provider initializes its WSDL
0653:             * extension registries. This has no effect if AutoLoad providers has
0654:             * been turned off on WSIFServiceImpl ... in that case it is the
0655:             * responsibility of the application to initialize providers.
0656:             */
0657:            public static void initializeProviders() {
0658:                synchronized (providersInitialized) {
0659:                    if (!providersInitialized.booleanValue()) {
0660:                        WSIFPluggableProviders.getProvider("/");
0661:                        providersInitialized = new Boolean(true);
0662:                    }
0663:                }
0664:            }
0665:
0666:            /**
0667:             * Create a map of all schema simple types and there Java equivalents.
0668:             */
0669:            public static void createSimpleTypesMap() {
0670:                synchronized (simpleTypesMapCreated) {
0671:                    if (!simpleTypesMapCreated.booleanValue()) {
0672:                        new Schema2Java(WSIFConstants.NS_URI_1999_SCHEMA_XSD)
0673:                                .getRegistry(simpleTypesMap);
0674:                        new Schema2Java(WSIFConstants.NS_URI_2000_SCHEMA_XSD)
0675:                                .getRegistry(simpleTypesMap);
0676:                        new Schema2Java(WSIFConstants.NS_URI_2001_SCHEMA_XSD)
0677:                                .getRegistry(simpleTypesMap);
0678:                        simpleTypesMapCreated = new Boolean(true);
0679:                    }
0680:                }
0681:            }
0682:
0683:            /**
0684:             * Get a map of all schema simple types and there Java equivalents.
0685:             * @return The map of simple types
0686:             */
0687:            public static Map getSimpleTypesMap() {
0688:                if (!simpleTypesMapCreated.booleanValue()) {
0689:                    createSimpleTypesMap();
0690:                }
0691:                return simpleTypesMap;
0692:            }
0693:
0694:            // the following code copied from JCAUtils
0695:            public static WSIFFormatHandler getFormatHandler(Part part,
0696:                    Definition definition, javax.wsdl.Binding binding)
0697:                    throws java.lang.InstantiationException,
0698:                    java.lang.IllegalAccessException,
0699:                    java.lang.ClassNotFoundException {
0700:                Trc.entry(null, part, definition, binding);
0701:                WSIFFormatHandler formatHandler = null;
0702:                javax.xml.namespace.QName partTypeQName = part.getTypeName();
0703:                if (partTypeQName == null)
0704:                    partTypeQName = part.getElementName();
0705:                if (partTypeQName == null)
0706:                    throw new ClassNotFoundException(part.getName());
0707:
0708:                String typePackageName = getPackageNameFromNamespaceURI(partTypeQName
0709:                        .getNamespaceURI());
0710:                String formatHandlerName = typePackageName;
0711:
0712:                String bindingShortName = getPackageNameFromXMLName(definition
0713:                        .getPrefix(getBindingNamespace(binding)));
0714:                if (bindingShortName != null)
0715:                    formatHandlerName = formatHandlerName + DOT
0716:                            + bindingShortName;
0717:
0718:                if (getFormatStylePackage(binding) != null)
0719:                    formatHandlerName = formatHandlerName + DOT
0720:                            + getFormatStylePackage(binding);
0721:
0722:                String formatHandlerShortName = formatHandlerName
0723:                        + DOT
0724:                        + getJavaClassNameFromXMLName(partTypeQName
0725:                                .getLocalPart());
0726:
0727:                try {
0728:                    ClassLoader cl = Thread.currentThread()
0729:                            .getContextClassLoader();
0730:                    formatHandler = (WSIFFormatHandler) cl.loadClass(
0731:                            formatHandlerShortName + FORMAT_HANDLER)
0732:                            .newInstance();
0733:                } catch (ClassNotFoundException exn1) {
0734:                    Trc.ignoredException(exn1);
0735:                    try {
0736:                        ClassLoader cl = Thread.currentThread()
0737:                                .getContextClassLoader();
0738:                        formatHandler = (WSIFFormatHandler) cl
0739:                                .loadClass(
0740:                                        formatHandlerShortName
0741:                                                + ELEMENT_FORMAT_HANDLER)
0742:                                .newInstance();
0743:                    } catch (ClassNotFoundException exn2) {
0744:                        Trc.ignoredException(exn2);
0745:                        try {
0746:                            formatHandler = (WSIFFormatHandler) Class.forName(
0747:                                    formatHandlerShortName + FORMAT_HANDLER)
0748:                                    .newInstance();
0749:                        } catch (ClassNotFoundException exn3) {
0750:                            Trc.ignoredException(exn3);
0751:                            //try {
0752:                            formatHandler = (WSIFFormatHandler) Class.forName(
0753:                                    formatHandlerShortName
0754:                                            + ELEMENT_FORMAT_HANDLER)
0755:                                    .newInstance();
0756:                            //}
0757:                            //catch (ClassNotFoundException exn4) {
0758:                            //	throw new ClassNotFoundException(JCAResource.get("IWAA0101E", formatHandlerName));
0759:                            //}
0760:                        }
0761:                    }
0762:                }
0763:                //catch (Throwable exn3) {
0764:                //throw new ClassNotFoundException(JCAResource.get("IWAA0102E", formatHandlerName, exn3.getLocalizedMessage()));
0765:                //}
0766:                if (formatHandler == null)
0767:                    //throw new ClassNotFoundException(JCAResource.get("IWAA0101E", formatHandlerName));
0768:                    throw new ClassNotFoundException(formatHandlerName);
0769:                else {
0770:                    Trc.exit(formatHandler);
0771:                    return formatHandler;
0772:                }
0773:            }
0774:
0775:            public static String getPackageNameFromNamespaceURI(
0776:                    String namespaceURI) {
0777:                Trc.entry(null, namespaceURI);
0778:                // Get the segments in the namespace URI
0779:                List segments = getNamespaceURISegments(namespaceURI);
0780:
0781:                StringBuffer packageNameBuffer = new StringBuffer();
0782:                for (int i = 0; i < segments.size(); i++) {
0783:                    String name;
0784:
0785:                    // The first segment is the host name
0786:                    if (i == 0) {
0787:
0788:                        // Turn segment into a valid package segment name
0789:                        name = getPackageNameFromXMLName((String) segments
0790:                                .get(i));
0791:
0792:                        // Reverse its components
0793:                        StringTokenizer tokenizer = new StringTokenizer(name,
0794:                                ".");
0795:                        List host = new ArrayList();
0796:                        for (; tokenizer.hasMoreTokens();) {
0797:                            String nextT = tokenizer.nextToken();
0798:                            host.add(0, nextT);
0799:                        }
0800:                        StringBuffer buffer = new StringBuffer();
0801:                        for (Iterator hi = host.iterator(); hi.hasNext();) {
0802:                            if (buffer.length() != 0)
0803:                                buffer.append('.');
0804:                            String nextSegment = (String) hi.next();
0805:                            if (!Character.isJavaIdentifierStart(nextSegment
0806:                                    .toCharArray()[0]))
0807:                                nextSegment = UNDERSCORE + nextSegment;
0808:                            if (isJavaKeyword(nextSegment))
0809:                                nextSegment = UNDERSCORE + nextSegment;
0810:                            buffer.append(nextSegment);
0811:                        }
0812:                        name = buffer.toString();
0813:                    } else {
0814:
0815:                        // Turn segment into a valid java name
0816:                        name = getJavaNameFromXMLName((String) segments.get(i));
0817:
0818:                    }
0819:
0820:                    // Concatenate segments, separated by '.'
0821:                    if (name.length() == 0)
0822:                        continue;
0823:                    if (packageNameBuffer.length() != 0)
0824:                        packageNameBuffer.append('.');
0825:                    packageNameBuffer.append(name);
0826:                }
0827:                Trc.exit(packageNameBuffer.toString());
0828:                return packageNameBuffer.toString();
0829:            }
0830:
0831:            public static String getJavaNameFromXMLName(String xmlName,
0832:                    String delims) {
0833:                Trc.entry(null, xmlName, delims);
0834:                StringTokenizer tokenizer = new StringTokenizer(xmlName, delims);
0835:                StringBuffer buffer = new StringBuffer();
0836:                while (tokenizer.hasMoreTokens()) {
0837:                    buffer.append(tokenizer.nextToken());
0838:                }
0839:                String result = buffer.toString();
0840:                if (!Character.isJavaIdentifierStart(result.toCharArray()[0]))
0841:                    result = UNDERSCORE + result;
0842:                if (isJavaKeyword(result))
0843:                    result = UNDERSCORE + result;
0844:                Trc.exit(result);
0845:                return result;
0846:            }
0847:
0848:            public static String getJavaNameFromXMLName(String xmlName) {
0849:                Trc.entry(null, xmlName);
0850:                String s = getJavaNameFromXMLName(xmlName, XMLSEPARATORS);
0851:                Trc.exit(s);
0852:                return s;
0853:            }
0854:
0855:            public static String getPackageNameFromXMLName(String xmlName) {
0856:                Trc.entry(null, xmlName);
0857:
0858:                // Tokenize, don't consider '.' as a delimiter here
0859:                String name = getJavaNameFromXMLName(xmlName,
0860:                        XMLSEPARATORS_NODOT);
0861:
0862:                // Tokenize using delimiter '.' and add the tokens separated by '.'
0863:                // This is to ensure that we have no heading/trailing/dup '.' in the string
0864:                StringTokenizer tokenizer = new StringTokenizer(name, DOT);
0865:                StringBuffer buffer = new StringBuffer();
0866:                for (; tokenizer.hasMoreTokens();) {
0867:                    if (buffer.length() != 0)
0868:                        buffer.append('.');
0869:                    // -->				
0870:                    String nextSegment = (String) tokenizer.nextToken();
0871:                    if (!Character.isJavaIdentifierStart(nextSegment
0872:                            .toCharArray()[0]))
0873:                        nextSegment = UNDERSCORE + nextSegment;
0874:                    if (isJavaKeyword(nextSegment))
0875:                        nextSegment = UNDERSCORE + nextSegment;
0876:                    buffer.append(nextSegment);
0877:
0878:                    //			buffer.append(tokenizer.nextToken());
0879:                    // <--				
0880:                }
0881:                Trc.exit(buffer.toString());
0882:                return buffer.toString();
0883:            }
0884:
0885:            private static List getNamespaceURISegments(String namespaceURI) {
0886:                Trc.entry(null, namespaceURI);
0887:
0888:                // Tokenize
0889:                List segments = new ArrayList();
0890:                StringTokenizer tokenizer = new StringTokenizer(namespaceURI,
0891:                        ":/");
0892:                while (tokenizer.hasMoreTokens()) {
0893:                    segments.add(tokenizer.nextToken());
0894:                }
0895:
0896:                // Remove protocol
0897:                if (!segments.isEmpty()) {
0898:                    try {
0899:                        URL url = new URL(namespaceURI);
0900:                        if (segments.get(0).equals(url.getProtocol()))
0901:                            segments.remove(0);
0902:                    } catch (MalformedURLException exn) {
0903:                        Trc.ignoredException(exn);
0904:                    }
0905:                }
0906:                Trc.exit(segments);
0907:                return segments;
0908:            }
0909:
0910:            private static String getBindingNamespace(Binding bindingModel) {
0911:                Trc.entry(null, bindingModel);
0912:                Iterator iterator = bindingModel.getExtensibilityElements()
0913:                        .iterator();
0914:                String returnNamespace = null;
0915:                while (iterator.hasNext()) {
0916:                    ExtensibilityElement ee = (ExtensibilityElement) iterator
0917:                            .next();
0918:                    if (returnNamespace == null) {
0919:                        String namespace = ee.getElementType()
0920:                                .getNamespaceURI();
0921:                        if (!namespace.endsWith(PHYSICALREP)
0922:                                && !namespace.endsWith(FORMATBINDING)) {
0923:                            returnNamespace = namespace;
0924:                        }
0925:                    }
0926:                }
0927:                Trc.exit(returnNamespace);
0928:                return returnNamespace;
0929:            }
0930:
0931:            public static String getFormatStylePackage(Binding bindingModel) {
0932:                Trc.entry(null, bindingModel);
0933:
0934:                Iterator iterator = bindingModel.getExtensibilityElements()
0935:                        .iterator();
0936:                String formatPackageName = null;
0937:                while (iterator.hasNext()) {
0938:                    ExtensibilityElement ee = (ExtensibilityElement) iterator
0939:                            .next();
0940:                    if (ee instanceof  TypeMapping) {
0941:                        TypeMapping typeMapping = (TypeMapping) ee;
0942:                        formatPackageName = typeMapping.getEncoding();
0943:                        if (typeMapping.getStyle() != null)
0944:                            formatPackageName += typeMapping.getStyle();
0945:                    }
0946:                    if (formatPackageName != null)
0947:                        break;
0948:                }
0949:                String s = null;
0950:                if (formatPackageName != null) {
0951:                    //			return getJavaNameFromXMLName(formatPackageName);
0952:                    s = getPackageNameFromXMLName(formatPackageName);
0953:                } else {
0954:                    s = formatPackageName;
0955:                }
0956:                Trc.exit(s);
0957:                return s;
0958:            }
0959:
0960:            public static String getFormatHandlerName(Part part,
0961:                    Definition definition, Binding binding)
0962:                    throws java.lang.InstantiationException,
0963:                    java.lang.IllegalAccessException,
0964:                    java.lang.ClassNotFoundException {
0965:                Trc.entry(null, part, definition, binding);
0966:
0967:                javax.xml.namespace.QName partTypeQName = part.getTypeName();
0968:                if (partTypeQName == null)
0969:                    partTypeQName = part.getElementName();
0970:                if (partTypeQName == null)
0971:                    throw new ClassNotFoundException(part.getName());
0972:
0973:                String typePackageName = getPackageNameFromNamespaceURI(partTypeQName
0974:                        .getNamespaceURI());
0975:                String formatHandlerName = typePackageName;
0976:
0977:                String bindingShortName = getPackageNameFromXMLName(definition
0978:                        .getPrefix(getBindingNamespace(binding)));
0979:                if (bindingShortName != null)
0980:                    formatHandlerName = formatHandlerName + DOT
0981:                            + bindingShortName;
0982:
0983:                if (getFormatStylePackage(binding) != null)
0984:                    formatHandlerName = formatHandlerName + DOT
0985:                            + getFormatStylePackage(binding);
0986:
0987:                formatHandlerName = formatHandlerName
0988:                        + DOT
0989:                        + getJavaClassNameFromXMLName(partTypeQName
0990:                                .getLocalPart()) + FORMAT_HANDLER;
0991:
0992:                Trc.exit(formatHandlerName);
0993:                return formatHandlerName;
0994:            }
0995:
0996:            public static String getJavaClassNameFromXMLName(String xmlName) {
0997:                Trc.entry(null, xmlName);
0998:                String s = getJavaClassNameFromXMLName(xmlName, XMLSEPARATORS);
0999:                Trc.exit(s);
1000:                return s;
1001:            }
1002:
1003:            public static String getJavaClassNameFromXMLName(String xmlName,
1004:                    String delims) {
1005:                Trc.entry(null, xmlName, delims);
1006:                StringTokenizer tokenizer = new StringTokenizer(xmlName, delims);
1007:                StringBuffer buffer = new StringBuffer();
1008:                while (tokenizer.hasMoreTokens()) {
1009:                    String nextSegment = (String) tokenizer.nextToken();
1010:                    if (nextSegment.length() > 0) {
1011:                        nextSegment = Character.toUpperCase((nextSegment
1012:                                .toCharArray())[0])
1013:                                + nextSegment.substring(1);
1014:                    }
1015:                    buffer.append(nextSegment);
1016:                }
1017:                String result = buffer.toString();
1018:                if (!Character.isJavaIdentifierStart(result.toCharArray()[0]))
1019:                    result = UNDERSCORE + result;
1020:                Trc.exit(result);
1021:                if (isJavaKeyword(result))
1022:                    return UNDERSCORE + result;
1023:                else
1024:                    return result;
1025:            }
1026:
1027:            public static String getXSDNamespaceFromPackageName(
1028:                    String packageName) {
1029:
1030:                String result = "";
1031:                StringTokenizer tokenizer = new java.util.StringTokenizer(
1032:                        packageName, ".");
1033:                while (tokenizer.hasMoreTokens()) {
1034:                    String nextT = tokenizer.nextToken();
1035:                    result = nextT + "." + result;
1036:                }
1037:                if (result.endsWith("."))
1038:                    return "http://" + result.substring(0, result.length() - 1)
1039:                            + "/";
1040:                return "http://" + result + "/";
1041:            }
1042:
1043:            /**
1044:             * Get a binding operation for a portType operation.
1045:             * 
1046:             * @param binding the WSLD binding the operation will choosen from
1047:             * @param portTypeOp the portType operation the binding operation 
1048:             *         must match
1049:             * @return the BindingOperation  
1050:             */
1051:            public static BindingOperation getBindingOperation(Binding binding,
1052:                    Operation portTypeOp) throws WSIFException {
1053:
1054:                Trc.entry(null, binding, portTypeOp);
1055:                BindingOperation bop;
1056:                if (portTypeOp == null) {
1057:                    bop = null;
1058:                } else {
1059:                    bop = getBindingOperation(binding, portTypeOp.getName(),
1060:                            portTypeOp.getInput() == null ? null : portTypeOp
1061:                                    .getInput().getName(), portTypeOp
1062:                                    .getOutput() == null ? null : portTypeOp
1063:                                    .getOutput().getName());
1064:                }
1065:                Trc.exit(bop);
1066:                return bop;
1067:            }
1068:
1069:            /**
1070:             * Get a binding operation for a portType operation.
1071:             * 
1072:             * @param binding the WSLD binding the operation will choosen from
1073:             * @param opName the portType operation name of the wanted operation
1074:             * @param inName the portType operation input name
1075:             * @param outName the portType operation outpur name
1076:             * @return the BindingOperation  
1077:             */
1078:            public static BindingOperation getBindingOperation(Binding binding,
1079:                    String opName, String inName, String outName)
1080:                    throws WSIFException {
1081:
1082:                Trc.entry(null, binding, opName, inName, outName);
1083:                BindingOperation op = null;
1084:                if (binding != null && opName != null) {
1085:                    ArrayList matchingOps = new ArrayList();
1086:                    List bops = binding.getBindingOperations();
1087:                    if (bops != null) {
1088:                        for (Iterator i = bops.iterator(); i.hasNext();) {
1089:                            BindingOperation bop = (BindingOperation) i.next();
1090:                            if (opName.equalsIgnoreCase(bop.getName())) {
1091:                                matchingOps.add(bop);
1092:                            }
1093:                        }
1094:                        if (matchingOps.size() == 1) {
1095:                            op = (BindingOperation) matchingOps.get(0);
1096:                        } else if (matchingOps.size() > 1) {
1097:                            op = chooseBindingOperation(matchingOps, inName,
1098:                                    outName);
1099:                        }
1100:                    }
1101:                }
1102:                Trc.exit(op);
1103:                return op;
1104:            }
1105:
1106:            private static BindingOperation chooseBindingOperation(
1107:                    ArrayList bindingOps, String inName, String outName)
1108:                    throws WSIFException {
1109:
1110:                BindingOperation choosenOp = null;
1111:                for (Iterator i = bindingOps.iterator(); i.hasNext();) {
1112:                    BindingOperation bop = (BindingOperation) i.next();
1113:                    String binName = (bop.getBindingInput() == null) ? null
1114:                            : bop.getBindingInput().getName();
1115:                    String boutName = (bop.getBindingOutput() == null) ? null
1116:                            : bop.getBindingOutput().getName();
1117:                    if ((inName == null) ? binName == null : inName
1118:                            .equalsIgnoreCase(binName)) {
1119:                        if ((outName == null) ? boutName == null : outName
1120:                                .equalsIgnoreCase(boutName)) {
1121:                            if (choosenOp == null) {
1122:                                choosenOp = bop;
1123:                            } else {
1124:                                throw new WSIFException(
1125:                                        "duplicate operation in binding: "
1126:                                                + bop.getName() + ":" + inName
1127:                                                + ":" + outName);
1128:                            }
1129:                        }
1130:                    }
1131:                }
1132:                return choosenOp;
1133:            }
1134:
1135:            private static boolean isJavaKeyword(String identifier) {
1136:                if (keywordMap == null) {
1137:                    Object value = new Object();
1138:                    keywordMap = new HashMap();
1139:                    keywordMap.put("abstract", value);
1140:                    keywordMap.put("default", value);
1141:                    keywordMap.put("if", value);
1142:                    keywordMap.put("private", value);
1143:                    keywordMap.put("this", value);
1144:                    keywordMap.put("boolean", value);
1145:                    keywordMap.put("do", value);
1146:                    keywordMap.put("implements", value);
1147:                    keywordMap.put("protected", value);
1148:                    keywordMap.put("throw", value);
1149:                    keywordMap.put("break", value);
1150:                    keywordMap.put("double", value);
1151:                    keywordMap.put("import", value);
1152:                    keywordMap.put("public", value);
1153:                    keywordMap.put("throws", value);
1154:                    keywordMap.put("byte", value);
1155:                    keywordMap.put("else", value);
1156:                    keywordMap.put("instanceof", value);
1157:                    keywordMap.put("return", value);
1158:                    keywordMap.put("transient", value);
1159:                    keywordMap.put("case", value);
1160:                    keywordMap.put("extends", value);
1161:                    keywordMap.put("int", value);
1162:                    keywordMap.put("short", value);
1163:                    keywordMap.put("try", value);
1164:                    keywordMap.put("catch", value);
1165:                    keywordMap.put("final", value);
1166:                    keywordMap.put("interface", value);
1167:                    keywordMap.put("static", value);
1168:                    keywordMap.put("void", value);
1169:                    keywordMap.put("char", value);
1170:                    keywordMap.put("finally", value);
1171:                    keywordMap.put("long", value);
1172:                    keywordMap.put("strictfp", value);
1173:                    keywordMap.put("volatile", value);
1174:                    keywordMap.put("class", value);
1175:                    keywordMap.put("float", value);
1176:                    keywordMap.put("native", value);
1177:                    keywordMap.put("super", value);
1178:                    keywordMap.put("while", value);
1179:                    keywordMap.put("const", value);
1180:                    keywordMap.put("for", value);
1181:                    keywordMap.put("new", value);
1182:                    keywordMap.put("switch", value);
1183:                    keywordMap.put("continue", value);
1184:                    keywordMap.put("goto", value);
1185:                    keywordMap.put("package", value);
1186:                    keywordMap.put("synchronized", value);
1187:                    keywordMap.put("null", value);
1188:                    keywordMap.put("true", value);
1189:                    keywordMap.put("false", value);
1190:                    keywordMap.put("assert", value);
1191:                }
1192:                return keywordMap.containsKey(identifier);
1193:
1194:                //	abstract    default    if            private      this
1195:                //	boolean     do         implements    protected    throw
1196:                //	break       double     import        public       throws
1197:                //	byte        else       instanceof    return       transient
1198:                //	case        extends    int           short        try
1199:                //	catch       final      interface     static       void
1200:                //	char        finally    long          strictfp     volatile
1201:                //	class       float      native        super        while
1202:                //	const       for        new           switch
1203:                //	continue    goto       package       synchronized
1204:                //  null        true       false         assert
1205:            }
1206:
1207:            /**
1208:             * Compares two strings taking acount of a wildcard.
1209:             * The first string is compared to the second string taking 
1210:             * account of a wildcard character in the first string. For
1211:             * example, wildcardCompare( "*.ibm.com", "hursley.ibm.com", '*')
1212:             * would return true.
1213:             */
1214:            public static boolean wildcardCompare(String s1, String s2,
1215:                    char wild) {
1216:                if (s1 == null) {
1217:                    return false;
1218:                }
1219:                String w = wild + "";
1220:                return cmp(new StringTokenizer(s1, w, true), s2, w);
1221:            }
1222:
1223:            private static boolean cmp(StringTokenizer st, String s, String wild) {
1224:                if (s == null || s.equals("")) {
1225:                    return !st.hasMoreTokens();
1226:                }
1227:                if (st.hasMoreTokens()) {
1228:                    String s2 = st.nextToken();
1229:                    if (wild.equals(s2)) {
1230:                        if (!st.hasMoreTokens()) {
1231:                            return true; // a trailing wildcard matches anything
1232:                        }
1233:                        s2 = st.nextToken();
1234:                        if (s.equals(s2)) {
1235:                            return false; //  wildcard must be at least 1 character
1236:                        }
1237:                    }
1238:                    int i = s.indexOf(s2);
1239:                    if (i < 0) {
1240:                        return false; // prefix not in s
1241:                    }
1242:                    i += s2.length();
1243:                    if (i < s.length()) {
1244:                        return cmp(st, s.substring(i), wild);
1245:                    } else {
1246:                        return cmp(st, "", wild);
1247:                    }
1248:                }
1249:                return false; // no more tokens but still some s
1250:            }
1251:
1252:            /**
1253:             * Tests if this is wrapped document literal stype operation.
1254:             * An operation is wrapped if:
1255:             *    - there is only one input or output message part
1256:             *      and that part is an element not a type 
1257:             *      (MIME means there can be many parts, so all this 
1258:             *       can check is that there is only one element part)
1259:             *    - the message name is the same as the operation name
1260:             *      (for a response the operation name is appened with "Response")
1261:             */
1262:            public static boolean isWrappedDocLiteral(List parts,
1263:                    String operationName) {
1264:                boolean wrapped = !(parts == null);
1265:                Part elementPart = null;
1266:                for (int i = 0; wrapped && i < parts.size(); i++) {
1267:                    Part p = (Part) parts.get(i);
1268:                    if (p.getElementName() != null) {
1269:                        if (elementPart == null) {
1270:                            elementPart = p;
1271:                            String pName = p.getElementName().getLocalPart();
1272:                            if (!operationName.equals(pName)) {
1273:                                wrapped = false;
1274:                            }
1275:                        } else {
1276:                            wrapped = false;
1277:                        }
1278:                    }
1279:                }
1280:                return wrapped;
1281:            }
1282:
1283:            /**
1284:             * Gets the wrapped Part if this is wrapped document literal
1285:             * stype operation. An operation is wrapped if:
1286:             *    - there is only one input or output message part
1287:             *      and that part is an element not a type 
1288:             *      (MIME means there can be many parts, so all this 
1289:             *       can check is that there is only one element part)
1290:             *    - the message name is the same as the operation name
1291:             *      (for a response the operation name is appened with "Response")
1292:             */
1293:            public static Part getWrappedDocLiteralPart(List parts,
1294:                    String operationName) {
1295:                boolean wrapped = !(parts == null);
1296:                Part elementPart = null;
1297:                for (int i = 0; wrapped && i < parts.size(); i++) {
1298:                    Part p = (Part) parts.get(i);
1299:                    if (p.getElementName() != null) {
1300:                        if (elementPart == null) {
1301:                            elementPart = p;
1302:                            String pName = p.getElementName().getLocalPart();
1303:                            if (!operationName.equals(pName)) {
1304:                                wrapped = false;
1305:                            }
1306:                        } else {
1307:                            wrapped = false;
1308:                        }
1309:                    }
1310:                }
1311:                if (!wrapped) {
1312:                    elementPart = null;
1313:                }
1314:                return elementPart;
1315:            }
1316:
1317:            /**
1318:             * Unwraps a wrapped DocLit style part.
1319:             */
1320:            public static List unWrapPart(Part p, Definition def)
1321:                    throws WSIFException {
1322:
1323:                ArrayList l = new ArrayList();
1324:                Parser.getAllSchemaTypes(def, l, null);
1325:                if (l == null || l.size() < 1) {
1326:                    throw new WSIFException("no schema elements found");
1327:                }
1328:
1329:                QName partQN = p.getElementName();
1330:                if (partQN == null) {
1331:                    throw new WSIFException("part has no QName");
1332:                }
1333:
1334:                ElementType et = null;
1335:                for (int i = 0; i < l.size() && et == null; i++) {
1336:                    Object o = l.get(i);
1337:                    if (o instanceof  ElementType) {
1338:                        QName etQN = ((ElementType) o).getTypeName();
1339:                        if (partQN.equals(etQN)) {
1340:                            et = (ElementType) o;
1341:                        }
1342:                    }
1343:                }
1344:                if (et == null) {
1345:                    throw new WSIFException("no ElementType found for part: "
1346:                            + p);
1347:                }
1348:
1349:                List children = et.getChildren();
1350:                if (children == null || l.size() < 1) {
1351:                    throw new WSIFException(
1352:                            "no ComplexType children on elementType: " + et);
1353:                }
1354:
1355:                ComplexType ct = (ComplexType) children.get(0);
1356:                SequenceElement[] se = ct.getSequenceElements();
1357:                if (se == null) {
1358:                    throw new WSIFException("no sequence elements found on: "
1359:                            + ct);
1360:                }
1361:
1362:                ArrayList unWrappedParts = new ArrayList();
1363:                for (int i = 0; i < se.length; i++) {
1364:                    PartImpl np = new PartImpl();
1365:                    QName type = se[i].getTypeName();
1366:                    if (type == null) {
1367:                        throw new WSIFException(
1368:                                "sequence element has no type name: " + se[i]);
1369:                    }
1370:                    np.setName(type.getLocalPart());
1371:                    np.setElementName(se[i].getElementType());
1372:                    unWrappedParts.add(np);
1373:                }
1374:
1375:                return unWrappedParts;
1376:            }
1377:
1378:            /**
1379:             * Gets the WSIF WSDL Extensions Registry
1380:             * This calls initializeProviders to ensure all providers
1381:             * have registered any custom WSDL extensions.
1382:             * @return ExtensionRegistry   the WSIF ExtensionRegistry 
1383:             */
1384:            public static ExtensionRegistry getExtensionRegistry() {
1385:                Trc.entry(null);
1386:                initializeProviders();
1387:                ExtensionRegistry er = WSIFServiceImpl
1388:                        .getCompositeExtensionRegistry();
1389:                Trc.exit(er);
1390:                return er;
1391:            }
1392:
1393:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.