Source Code Cross Referenced for AxisService.java in  » Web-Services-AXIS2 » kernal » org » apache » axis2 » description » 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 AXIS2 » kernal » org.apache.axis2.description 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Licensed to the Apache Software Foundation (ASF) under one
0003:         * or more contributor license agreements. See the NOTICE file
0004:         * distributed with this work for additional information
0005:         * regarding copyright ownership. The ASF licenses this file
0006:         * to you under the Apache License, Version 2.0 (the
0007:         * "License"); you may not use this file except in compliance
0008:         * with the License. You may obtain a copy of the License at
0009:         *
0010:         * http://www.apache.org/licenses/LICENSE-2.0
0011:         *
0012:         * Unless required by applicable law or agreed to in writing,
0013:         * software distributed under the License is distributed on an
0014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015:         * KIND, either express or implied. See the License for the
0016:         * specific language governing permissions and limitations
0017:         * under the License.
0018:         */
0019:
0020:        package org.apache.axis2.description;
0021:
0022:        import org.apache.axiom.om.OMElement;
0023:        import org.apache.axis2.AxisFault;
0024:        import org.apache.axis2.Constants;
0025:        import org.apache.axis2.description.java2wsdl.*;
0026:        import org.apache.axis2.addressing.AddressingConstants;
0027:        import org.apache.axis2.addressing.EndpointReference;
0028:        import org.apache.axis2.client.Options;
0029:        import org.apache.axis2.context.MessageContext;
0030:        import org.apache.axis2.dataretrieval.AxisDataLocator;
0031:        import org.apache.axis2.dataretrieval.AxisDataLocatorImpl;
0032:        import org.apache.axis2.dataretrieval.DRConstants;
0033:        import org.apache.axis2.dataretrieval.Data;
0034:        import org.apache.axis2.dataretrieval.DataRetrievalException;
0035:        import org.apache.axis2.dataretrieval.DataRetrievalRequest;
0036:        import org.apache.axis2.dataretrieval.LocatorType;
0037:        import org.apache.axis2.dataretrieval.OutputForm;
0038:        import org.apache.axis2.dataretrieval.WSDLSupplier;
0039:        import org.apache.axis2.deployment.util.PhasesInfo;
0040:        import org.apache.axis2.deployment.util.Utils;
0041:        import org.apache.axis2.deployment.DeploymentConstants;
0042:        import org.apache.axis2.engine.AxisConfiguration;
0043:        import org.apache.axis2.engine.DefaultObjectSupplier;
0044:        import org.apache.axis2.engine.MessageReceiver;
0045:        import org.apache.axis2.engine.ObjectSupplier;
0046:        import org.apache.axis2.engine.ServiceLifeCycle;
0047:        import org.apache.axis2.i18n.Messages;
0048:        import org.apache.axis2.phaseresolver.PhaseResolver;
0049:        import org.apache.axis2.transport.TransportListener;
0050:        import org.apache.axis2.transport.http.server.HttpUtils;
0051:        import org.apache.axis2.util.Loader;
0052:        import org.apache.axis2.util.XMLUtils;
0053:        import org.apache.axis2.util.XMLPrettyPrinter;
0054:        import org.apache.axis2.wsdl.WSDLConstants;
0055:        import org.apache.commons.logging.Log;
0056:        import org.apache.commons.logging.LogFactory;
0057:        import org.apache.neethi.Policy;
0058:        import org.apache.ws.commons.schema.XmlSchema;
0059:        import org.apache.ws.commons.schema.XmlSchemaElement;
0060:        import org.apache.ws.commons.schema.XmlSchemaExternal;
0061:        import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
0062:        import org.apache.ws.commons.schema.utils.NamespaceMap;
0063:        import org.apache.ws.commons.schema.utils.NamespacePrefixList;
0064:        import org.codehaus.jam.JMethod;
0065:        import org.w3c.dom.*;
0066:        import org.xml.sax.SAXException;
0067:
0068:        import javax.wsdl.*;
0069:        import javax.wsdl.extensions.soap.SOAPAddress;
0070:        import javax.wsdl.extensions.schema.Schema;
0071:        import javax.wsdl.extensions.soap12.SOAP12Address;
0072:        import javax.wsdl.extensions.http.HTTPAddress;
0073:        import javax.wsdl.factory.WSDLFactory;
0074:        import javax.wsdl.xml.WSDLReader;
0075:        import javax.wsdl.xml.WSDLWriter;
0076:        import javax.xml.namespace.QName;
0077:        import javax.xml.parsers.ParserConfigurationException;
0078:        import java.io.*;
0079:        import java.net.SocketException;
0080:        import java.net.URL;
0081:        import java.net.URISyntaxException;
0082:        import java.security.PrivilegedAction;
0083:        import java.util.*;
0084:
0085:        /**
0086:         * Class AxisService
0087:         */
0088:        public class AxisService extends AxisDescription {
0089:
0090:            //////////////////////////////////////////////////////////////////
0091:            // Standard Parameter names
0092:
0093:            /**
0094:             * If this param is true, and the service has exactly one AxisOperation,
0095:             * normal operation dispatch (via URI/soapAction/etc) will not be necessary,
0096:             * and we'll just default to funneling all messages to that op.  This is
0097:             * useful for passthrough/ESB/embedded applications.
0098:             */
0099:            public static final String SUPPORT_SINGLE_OP = "supportSingleOperation";
0100:            //////////////////////////////////////////////////////////////////
0101:
0102:            public static final String IMPORT_TAG = "import";
0103:            public static final String INCLUDE_TAG = "include";
0104:            public static final String SCHEMA_LOCATION = "schemaLocation";
0105:
0106:            private Map endpointMap = new HashMap();
0107:
0108:            /*This is a map between the QName of the element of a message
0109:             *specified in the WSDL and an Operation.  It enables SOAP Body-based
0110:             *dispatching for doc-literal bindings.
0111:             */
0112:            private Map messageElementQNameToOperationMap = new HashMap();
0113:
0114:            private int nsCount = 0;
0115:            private static final Log log = LogFactory.getLog(AxisService.class);
0116:            private URL fileName;
0117:
0118:            // Maps httpLocations to corresponding operations. Used to dispatch rest messages.
0119:            private HashMap httpLocationDispatcherMap = null;
0120:
0121:            /**
0122:             * Map from String(action URI) -> AxisOperation
0123:             */
0124:            private HashMap operationsAliasesMap = null;
0125:
0126:            // Collection of aliases that are invalid for this service because they are duplicated across
0127:            // multiple operations under this service.
0128:            private List invalidOperationsAliases = null;
0129:            //    private HashMap operations = new HashMap();
0130:
0131:            // to store module ref at deploy time parsing
0132:            private ArrayList moduleRefs = null;
0133:
0134:            // to keep the time that last update time of the service
0135:            private long lastupdate;
0136:            private HashMap moduleConfigmap;
0137:            private String name;
0138:            private ClassLoader serviceClassLoader;
0139:
0140:            //to keep the XMLScheam getting either from WSDL or java2wsdl
0141:            private ArrayList schemaList;
0142:            //private XmlSchema schema;
0143:
0144:            //wsdl is there for this service or not (in side META-INF)
0145:            private boolean wsdlFound = false;
0146:
0147:            //to store the scope of the service
0148:            private String scope;
0149:
0150:            //to store default message receivers
0151:            private HashMap messageReceivers;
0152:
0153:            // to set the handler chain available in phase info
0154:            private boolean useDefaultChains = true;
0155:
0156:            //to keep the status of the service , since service can stop at the run time
0157:            private boolean active = true;
0158:
0159:            private boolean elementFormDefault = true;
0160:
0161:            //to keep the service target name space
0162:            private String targetNamespace = Java2WSDLConstants.DEFAULT_TARGET_NAMESPACE;
0163:            private String targetNamespacePrefix = Java2WSDLConstants.TARGETNAMESPACE_PREFIX;
0164:
0165:            // to store the target namespace for the schema
0166:            private String schematargetNamespace;// = Java2WSDLConstants.AXIS2_XSD;
0167:            private String schematargetNamespacePrefix = Java2WSDLConstants.SCHEMA_NAMESPACE_PRFIX;
0168:
0169:            private boolean enableAllTransports = true;
0170:            private List exposedTransports = new ArrayList();
0171:
0172:            //To keep reference to ServiceLifeCycle instance , if the user has
0173:            // specified in services.xml
0174:            private ServiceLifeCycle serviceLifeCycle;
0175:
0176:            /**
0177:             * Keeps track whether the schema locations are adjusted
0178:             */
0179:            private boolean schemaLocationsAdjusted = false;
0180:
0181:            private boolean wsdlImportLocationAdjusted = false;
0182:
0183:            /**
0184:             * A table that keeps a mapping of unique xsd names (Strings)
0185:             * against the schema objects. This is populated in the first
0186:             * instance the schemas are asked for and then used to serve
0187:             * the subsequent requests
0188:             */
0189:            private Map schemaMappingTable = null;
0190:
0191:            /**
0192:             * counter variable for naming the schemas
0193:             */
0194:            private int count = 0;
0195:            /**
0196:             * A custom schema Name prefix. if set this will be used to
0197:             * modify the schema names
0198:             */
0199:            private String customSchemaNamePrefix = null;
0200:
0201:            /**
0202:             * A custom schema name suffix. will be attached to the
0203:             * schema file name when the files are uniquely named.
0204:             * A good place to add a file extension if needed
0205:             */
0206:            private String customSchemaNameSuffix = null;
0207:
0208:            /////////////////////////////////////////
0209:            // WSDL related stuff ////////////////////
0210:            ////////////////////////////////////////
0211:
0212:            /** Map of prefix -> namespaceURI */
0213:            private NamespaceMap namespaceMap;
0214:
0215:            private String soapNsUri;
0216:            private String endpointName;
0217:            private String endpointURL;
0218:
0219:            // Flag representing whether WS-Addressing is required to use this service.
0220:            // Reflects the wsaw:UsingAddressing wsdl extension element
0221:            private String wsaddressingFlag = AddressingConstants.ADDRESSING_UNSPECIFIED;
0222:            private boolean clientSide = false;
0223:
0224:            //To keep a ref to ObjectSupplier instance
0225:            private ObjectSupplier objectSupplier;
0226:
0227:            // package to namespace mapping
0228:            private Map p2nMap;
0229:
0230:            private TypeTable typeTable;
0231:
0232:            // Data Locators for  WS-Mex Support
0233:            private HashMap dataLocators;
0234:            private HashMap dataLocatorClassNames;
0235:            private AxisDataLocatorImpl defaultDataLocator;
0236:            // Define search sequence for datalocator based on Data Locator types.
0237:            LocatorType[] availableDataLocatorTypes = new LocatorType[] {
0238:                    LocatorType.SERVICE_DIALECT, LocatorType.SERVICE_LEVEL,
0239:                    LocatorType.GLOBAL_DIALECT, LocatorType.GLOBAL_LEVEL,
0240:                    LocatorType.DEFAULT_AXIS };
0241:
0242:            // name of the  binding used : use in codegeneration
0243:            private String bindingName;
0244:
0245:            // names list keep to preserve the parameter order
0246:            private List operationsNameList;
0247:
0248:            private String[] eprs;
0249:            private boolean customWsdl = false;
0250:
0251:            public AxisEndpoint getEndpoint(String key) {
0252:                return (AxisEndpoint) endpointMap.get(key);
0253:            }
0254:
0255:            public void addEndpoint(String key, AxisEndpoint axisEndpoint) {
0256:                this .endpointMap.put(key, axisEndpoint);
0257:            }
0258:
0259:            public String getWSAddressingFlag() {
0260:                return wsaddressingFlag;
0261:            }
0262:
0263:            public void setWSAddressingFlag(String ar) {
0264:                wsaddressingFlag = ar;
0265:                if (wsaddressingFlag == null) {
0266:                    wsaddressingFlag = AddressingConstants.ADDRESSING_UNSPECIFIED;
0267:                }
0268:            }
0269:
0270:            public boolean isSchemaLocationsAdjusted() {
0271:                return schemaLocationsAdjusted;
0272:            }
0273:
0274:            public void setSchemaLocationsAdjusted(
0275:                    boolean schemaLocationsAdjusted) {
0276:                this .schemaLocationsAdjusted = schemaLocationsAdjusted;
0277:            }
0278:
0279:            public Map getSchemaMappingTable() {
0280:                return schemaMappingTable;
0281:            }
0282:
0283:            public void setSchemaMappingTable(Map schemaMappingTable) {
0284:                this .schemaMappingTable = schemaMappingTable;
0285:            }
0286:
0287:            public String getCustomSchemaNamePrefix() {
0288:                return customSchemaNamePrefix;
0289:            }
0290:
0291:            public void setCustomSchemaNamePrefix(String customSchemaNamePrefix) {
0292:                this .customSchemaNamePrefix = customSchemaNamePrefix;
0293:            }
0294:
0295:            public String getCustomSchemaNameSuffix() {
0296:                return customSchemaNameSuffix;
0297:            }
0298:
0299:            public void setCustomSchemaNameSuffix(String customSchemaNameSuffix) {
0300:                this .customSchemaNameSuffix = customSchemaNameSuffix;
0301:            }
0302:
0303:            /**
0304:             * Constructor AxisService.
0305:             */
0306:            public AxisService() {
0307:                super ();
0308:                this .operationsAliasesMap = new HashMap();
0309:                this .invalidOperationsAliases = new ArrayList();
0310:                moduleConfigmap = new HashMap();
0311:                //by default service scope is for the request
0312:                scope = Constants.SCOPE_REQUEST;
0313:                httpLocationDispatcherMap = new HashMap();
0314:                messageReceivers = new HashMap();
0315:                moduleRefs = new ArrayList();
0316:                schemaList = new ArrayList();
0317:                serviceClassLoader = (ClassLoader) org.apache.axis2.java.security.AccessController
0318:                        .doPrivileged(new PrivilegedAction() {
0319:                            public Object run() {
0320:                                return Thread.currentThread()
0321:                                        .getContextClassLoader();
0322:                            }
0323:                        });
0324:                objectSupplier = new DefaultObjectSupplier();
0325:                dataLocators = new HashMap();
0326:                dataLocatorClassNames = new HashMap();
0327:
0328:            }
0329:
0330:            /**
0331:             * @return name of the port type
0332:             * @deprecated use AxisService#getEndpointName() instead.
0333:             */
0334:            public String getPortTypeName() {
0335:                return endpointName;
0336:            }
0337:
0338:            /**
0339:             * @param portTypeName
0340:             * @deprecated use AxisService#setEndpointName() instead
0341:             */
0342:            public void setPortTypeName(String portTypeName) {
0343:                this .endpointName = portTypeName;
0344:            }
0345:
0346:            public String getBindingName() {
0347:                return bindingName;
0348:            }
0349:
0350:            public void setBindingName(String bindingName) {
0351:                this .bindingName = bindingName;
0352:            }
0353:
0354:            /**
0355:             * get the SOAPVersion
0356:             */
0357:            public String getSoapNsUri() {
0358:                return soapNsUri;
0359:            }
0360:
0361:            public void setSoapNsUri(String soapNsUri) {
0362:                this .soapNsUri = soapNsUri;
0363:            }
0364:
0365:            /**
0366:             * get the endpointName
0367:             */
0368:            public String getEndpointName() {
0369:                return endpointName;
0370:            }
0371:
0372:            public void setEndpointName(String endpoint) {
0373:                this .endpointName = endpoint;
0374:            }
0375:
0376:            /**
0377:             * Constructor AxisService.
0378:             */
0379:            public AxisService(String name) {
0380:                this ();
0381:                this .name = name;
0382:            }
0383:
0384:            public void addMessageReceiver(String mepURI,
0385:                    MessageReceiver messageReceiver) {
0386:                if (WSDL2Constants.MEP_URI_IN_ONLY.equals(mepURI)
0387:                        || WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_ONLY
0388:                                .equals(mepURI)
0389:                        || WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_ONLY
0390:                                .equals(mepURI)) {
0391:                    messageReceivers.put(WSDL2Constants.MEP_URI_IN_ONLY,
0392:                            messageReceiver);
0393:                    messageReceivers.put(
0394:                            WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_ONLY,
0395:                            messageReceiver);
0396:                    messageReceivers
0397:                            .put(
0398:                                    WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_ONLY,
0399:                                    messageReceiver);
0400:                } else if (WSDL2Constants.MEP_URI_OUT_ONLY.equals(mepURI)
0401:                        || WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_ONLY
0402:                                .equals(mepURI)
0403:                        || WSDLConstants.WSDL20_2004_Constants.MEP_URI_OUT_ONLY
0404:                                .equals(mepURI)) {
0405:                    messageReceivers.put(WSDL2Constants.MEP_URI_OUT_ONLY,
0406:                            messageReceiver);
0407:                    messageReceivers
0408:                            .put(
0409:                                    WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_ONLY,
0410:                                    messageReceiver);
0411:                    messageReceivers
0412:                            .put(
0413:                                    WSDLConstants.WSDL20_2004_Constants.MEP_URI_OUT_ONLY,
0414:                                    messageReceiver);
0415:                } else if (WSDL2Constants.MEP_URI_IN_OUT.equals(mepURI)
0416:                        || WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_OUT
0417:                                .equals(mepURI)
0418:                        || WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_OUT
0419:                                .equals(mepURI)) {
0420:                    messageReceivers.put(WSDL2Constants.MEP_URI_IN_OUT,
0421:                            messageReceiver);
0422:                    messageReceivers.put(
0423:                            WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_OUT,
0424:                            messageReceiver);
0425:                    messageReceivers.put(
0426:                            WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_OUT,
0427:                            messageReceiver);
0428:                } else if (WSDL2Constants.MEP_URI_IN_OPTIONAL_OUT
0429:                        .equals(mepURI)
0430:                        || WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_OPTIONAL_OUT
0431:                                .equals(mepURI)
0432:                        || WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_OPTIONAL_OUT
0433:                                .equals(mepURI)) {
0434:                    messageReceivers.put(
0435:                            WSDL2Constants.MEP_URI_IN_OPTIONAL_OUT,
0436:                            messageReceiver);
0437:                    messageReceivers
0438:                            .put(
0439:                                    WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_OPTIONAL_OUT,
0440:                                    messageReceiver);
0441:                    messageReceivers
0442:                            .put(
0443:                                    WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_OPTIONAL_OUT,
0444:                                    messageReceiver);
0445:                } else if (WSDL2Constants.MEP_URI_OUT_IN.equals(mepURI)
0446:                        || WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_IN
0447:                                .equals(mepURI)
0448:                        || WSDLConstants.WSDL20_2004_Constants.MEP_URI_OUT_IN
0449:                                .equals(mepURI)) {
0450:                    messageReceivers.put(WSDL2Constants.MEP_URI_OUT_IN,
0451:                            messageReceiver);
0452:                    messageReceivers.put(
0453:                            WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_IN,
0454:                            messageReceiver);
0455:                    messageReceivers.put(
0456:                            WSDLConstants.WSDL20_2004_Constants.MEP_URI_OUT_IN,
0457:                            messageReceiver);
0458:                } else if (WSDL2Constants.MEP_URI_OUT_OPTIONAL_IN
0459:                        .equals(mepURI)
0460:                        || WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_OPTIONAL_IN
0461:                                .equals(mepURI)
0462:                        || WSDLConstants.WSDL20_2004_Constants.MEP_URI_OUT_OPTIONAL_IN
0463:                                .equals(mepURI)) {
0464:                    messageReceivers.put(
0465:                            WSDL2Constants.MEP_URI_OUT_OPTIONAL_IN,
0466:                            messageReceiver);
0467:                    messageReceivers
0468:                            .put(
0469:                                    WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_OPTIONAL_IN,
0470:                                    messageReceiver);
0471:                    messageReceivers
0472:                            .put(
0473:                                    WSDLConstants.WSDL20_2004_Constants.MEP_URI_OUT_OPTIONAL_IN,
0474:                                    messageReceiver);
0475:                } else if (WSDL2Constants.MEP_URI_ROBUST_OUT_ONLY
0476:                        .equals(mepURI)
0477:                        || WSDLConstants.WSDL20_2006Constants.MEP_URI_ROBUST_OUT_ONLY
0478:                                .equals(mepURI)
0479:                        || WSDLConstants.WSDL20_2004_Constants.MEP_URI_ROBUST_OUT_ONLY
0480:                                .equals(mepURI)) {
0481:                    messageReceivers.put(
0482:                            WSDL2Constants.MEP_URI_ROBUST_OUT_ONLY,
0483:                            messageReceiver);
0484:                    messageReceivers
0485:                            .put(
0486:                                    WSDLConstants.WSDL20_2006Constants.MEP_URI_ROBUST_OUT_ONLY,
0487:                                    messageReceiver);
0488:                    messageReceivers
0489:                            .put(
0490:                                    WSDLConstants.WSDL20_2004_Constants.MEP_URI_ROBUST_OUT_ONLY,
0491:                                    messageReceiver);
0492:                } else if (WSDL2Constants.MEP_URI_ROBUST_IN_ONLY.equals(mepURI)
0493:                        || WSDLConstants.WSDL20_2006Constants.MEP_URI_ROBUST_IN_ONLY
0494:                                .equals(mepURI)
0495:                        || WSDLConstants.WSDL20_2004_Constants.MEP_URI_ROBUST_IN_ONLY
0496:                                .equals(mepURI)) {
0497:                    messageReceivers.put(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY,
0498:                            messageReceiver);
0499:                    messageReceivers
0500:                            .put(
0501:                                    WSDLConstants.WSDL20_2006Constants.MEP_URI_ROBUST_IN_ONLY,
0502:                                    messageReceiver);
0503:                    messageReceivers
0504:                            .put(
0505:                                    WSDLConstants.WSDL20_2004_Constants.MEP_URI_ROBUST_IN_ONLY,
0506:                                    messageReceiver);
0507:                } else {
0508:                    messageReceivers.put(mepURI, messageReceiver);
0509:                }
0510:            }
0511:
0512:            public MessageReceiver getMessageReceiver(String mepURL) {
0513:                return (MessageReceiver) messageReceivers.get(mepURL);
0514:            }
0515:
0516:            /**
0517:             * Adds module configuration , if there is moduleConfig tag in service.
0518:             *
0519:             * @param moduleConfiguration
0520:             */
0521:            public void addModuleConfig(ModuleConfiguration moduleConfiguration) {
0522:                moduleConfigmap.put(moduleConfiguration.getModuleName(),
0523:                        moduleConfiguration);
0524:            }
0525:
0526:            /**
0527:             * Add any control operations defined by a Module to this service.
0528:             *
0529:             * @param module the AxisModule which has just been engaged
0530:             * @throws AxisFault if a problem occurs
0531:             */
0532:            void addModuleOperations(AxisModule module) throws AxisFault {
0533:                HashMap map = module.getOperations();
0534:                Collection col = map.values();
0535:                PhaseResolver phaseResolver = new PhaseResolver(
0536:                        getAxisConfiguration());
0537:                for (Iterator iterator = col.iterator(); iterator.hasNext();) {
0538:                    AxisOperation axisOperation = copyOperation((AxisOperation) iterator
0539:                            .next());
0540:                    if (this .getOperation(axisOperation.getName()) == null) {
0541:                        ArrayList wsamappings = axisOperation
0542:                                .getWSAMappingList();
0543:                        if (wsamappings != null) {
0544:                            for (int j = 0, size = wsamappings.size(); j < size; j++) {
0545:                                String mapping = (String) wsamappings.get(j);
0546:                                mapActionToOperation(mapping, axisOperation);
0547:                            }
0548:                        }
0549:                        // If we've set the "expose" parameter for this operation, it's normal (non-
0550:                        // control) and therefore it will appear in generated WSDL.  If we haven't,
0551:                        // it's a control operation and will be ignored at WSDL-gen time.
0552:                        if (axisOperation
0553:                                .isParameterTrue(DeploymentConstants.TAG_EXPOSE)) {
0554:                            axisOperation.setControlOperation(false);
0555:                        } else {
0556:                            axisOperation.setControlOperation(true);
0557:                        }
0558:
0559:                        phaseResolver.engageModuleToOperation(axisOperation,
0560:                                module);
0561:
0562:                        this .addOperation(axisOperation);
0563:                    }
0564:                }
0565:            }
0566:
0567:            public void addModuleref(String moduleref) {
0568:                moduleRefs.add(moduleref);
0569:            }
0570:
0571:            /*
0572:             * (non-Javadoc)
0573:             *
0574:             * @see org.apache.axis2.description.AxisService#addOperation(org.apache.axis2.description.AxisOperation)
0575:             */
0576:
0577:            /**
0578:             * Method addOperation.
0579:             *
0580:             * @param axisOperation
0581:             */
0582:            public void addOperation(AxisOperation axisOperation) {
0583:                axisOperation.setParent(this );
0584:
0585:                Iterator modules = getEngagedModules().iterator();
0586:
0587:                while (modules.hasNext()) {
0588:                    AxisModule module = (AxisModule) modules.next();
0589:                    try {
0590:                        axisOperation.engageModule(module);
0591:                    } catch (AxisFault axisFault) {
0592:                        log.info(Messages
0593:                                .getMessage("modulealredyengagetoservice",
0594:                                        module.getName()));
0595:                    }
0596:                }
0597:                if (axisOperation.getMessageReceiver() == null) {
0598:                    axisOperation
0599:                            .setMessageReceiver(loadDefaultMessageReceiver(
0600:                                    axisOperation.getMessageExchangePattern(),
0601:                                    this ));
0602:                }
0603:                if (axisOperation.getInputAction() == null) {
0604:                    axisOperation.setSoapAction("urn:"
0605:                            + axisOperation.getName().getLocalPart());
0606:                }
0607:
0608:                if (axisOperation.getOutputAction() == null) {
0609:                    axisOperation.setOutputAction("urn:"
0610:                            + axisOperation.getName().getLocalPart()
0611:                            + Java2WSDLConstants.RESPONSE);
0612:                }
0613:                addChild(axisOperation);
0614:
0615:                String operationName = axisOperation.getName().getLocalPart();
0616:
0617:                /*
0618:                   Some times name of the operation can be different from the name of the first child of the SOAPBody.
0619:                   This will put the correct mapping associating that name with  the operation. This will be useful especially for
0620:                   the SOAPBodyBasedDispatcher
0621:                 */
0622:
0623:                Iterator axisMessageIter = axisOperation.getChildren();
0624:
0625:                while (axisMessageIter.hasNext()) {
0626:                    AxisMessage axisMessage = (AxisMessage) axisMessageIter
0627:                            .next();
0628:                    String messageName = axisMessage.getName();
0629:                    if (messageName != null
0630:                            && !messageName.equals(operationName)) {
0631:                        mapActionToOperation(messageName, axisOperation);
0632:                    }
0633:                }
0634:
0635:                mapActionToOperation(operationName, axisOperation);
0636:
0637:                String action = axisOperation.getInputAction();
0638:                if (action.length() > 0) {
0639:                    mapActionToOperation(action, axisOperation);
0640:                }
0641:
0642:                ArrayList wsamappings = axisOperation.getWSAMappingList();
0643:                if (wsamappings != null) {
0644:                    for (int j = 0, size = wsamappings.size(); j < size; j++) {
0645:                        String mapping = (String) wsamappings.get(j);
0646:                        mapActionToOperation(mapping, axisOperation);
0647:                    }
0648:                }
0649:
0650:                if (axisOperation.getMessageReceiver() == null) {
0651:                    axisOperation
0652:                            .setMessageReceiver(loadDefaultMessageReceiver(
0653:                                    axisOperation.getMessageExchangePattern(),
0654:                                    this ));
0655:                }
0656:            }
0657:
0658:            private MessageReceiver loadDefaultMessageReceiver(String mepURL,
0659:                    AxisService service) {
0660:                MessageReceiver messageReceiver;
0661:                if (mepURL == null) {
0662:                    mepURL = WSDL2Constants.MEP_URI_IN_OUT;
0663:                }
0664:                if (service != null) {
0665:                    messageReceiver = service.getMessageReceiver(mepURL);
0666:                    if (messageReceiver != null) {
0667:                        return messageReceiver;
0668:                    }
0669:                }
0670:                if (getAxisConfiguration() != null) {
0671:                    return getAxisConfiguration().getMessageReceiver(mepURL);
0672:                }
0673:                return null;
0674:            }
0675:
0676:            /**
0677:             * Gets a copy from module operation.
0678:             *
0679:             * @param axisOperation
0680:             * @return Returns AxisOperation.
0681:             * @throws AxisFault
0682:             */
0683:            private AxisOperation copyOperation(AxisOperation axisOperation)
0684:                    throws AxisFault {
0685:                AxisOperation operation = AxisOperationFactory
0686:                        .getOperationDescription(axisOperation
0687:                                .getMessageExchangePattern());
0688:
0689:                operation
0690:                        .setMessageReceiver(axisOperation.getMessageReceiver());
0691:                operation.setName(axisOperation.getName());
0692:
0693:                Iterator parameters = axisOperation.getParameters().iterator();
0694:
0695:                while (parameters.hasNext()) {
0696:                    Parameter parameter = (Parameter) parameters.next();
0697:
0698:                    operation.addParameter(parameter);
0699:                }
0700:
0701:                PolicyInclude policyInclude = new PolicyInclude(operation);
0702:                PolicyInclude axisOperationPolicyInclude = axisOperation
0703:                        .getPolicyInclude();
0704:
0705:                if (axisOperationPolicyInclude != null) {
0706:                    Policy policy = axisOperationPolicyInclude.getPolicy();
0707:                    if (policy != null) {
0708:                        policyInclude.setPolicy(axisOperationPolicyInclude
0709:                                .getPolicy());
0710:                    }
0711:                }
0712:                operation.setPolicyInclude(policyInclude);
0713:
0714:                operation.setWsamappingList(axisOperation.getWSAMappingList());
0715:                operation.setRemainingPhasesInFlow(axisOperation
0716:                        .getRemainingPhasesInFlow());
0717:                operation.setPhasesInFaultFlow(axisOperation
0718:                        .getPhasesInFaultFlow());
0719:                operation.setPhasesOutFaultFlow(axisOperation
0720:                        .getPhasesOutFaultFlow());
0721:                operation.setPhasesOutFlow(axisOperation.getPhasesOutFlow());
0722:
0723:                operation.setOutputAction(axisOperation.getOutputAction());
0724:                String[] faultActionNames = axisOperation.getFaultActionNames();
0725:                for (int i = 0; i < faultActionNames.length; i++) {
0726:                    operation.addFaultAction(faultActionNames[i], axisOperation
0727:                            .getFaultAction(faultActionNames[i]));
0728:                }
0729:
0730:                return operation;
0731:            }
0732:
0733:            /*
0734:             * (non-Javadoc)
0735:             *
0736:             * @see org.apache.axis2.description.AxisService#addToengagedModules(javax.xml.namespace.QName)
0737:             */
0738:
0739:            /**
0740:             * Engages a module. It is required to use this method.
0741:             *
0742:             * @param axisModule
0743:             * @param engager
0744:             */
0745:            public void onEngage(AxisModule axisModule, AxisDescription engager)
0746:                    throws AxisFault {
0747:                // adding module operations
0748:                addModuleOperations(axisModule);
0749:
0750:                Iterator operations = getOperations();
0751:                while (operations.hasNext()) {
0752:                    AxisOperation axisOperation = (AxisOperation) operations
0753:                            .next();
0754:                    axisOperation.engageModule(axisModule, engager);
0755:                }
0756:            }
0757:
0758:            /**
0759:             * Maps an action (a SOAPAction or WSA action) to the given operation. This is used by
0760:             * dispatching (both SOAPAction- and WSAddressing- based dispatching) to figure out which
0761:             * operation a given message is for.  Some notes on restrictions of "action"
0762:             * - A null or empty action will be ignored
0763:             * - An action that is a duplicate and references an idential operation is allowed
0764:             * - An acton that is a duplicate and references a different operation is NOT allowed.  In this
0765:             * case, the action for the original operation is removed from the alias table, thus removing
0766:             * the ability to route based on this action.  This is necessary to prevent mis-directing
0767:             * incoming message to the wrong operation based on SOAPAction.
0768:             *
0769:             * @param action        the action key
0770:             * @param axisOperation the operation to map to
0771:             */
0772:            public void mapActionToOperation(String action,
0773:                    AxisOperation axisOperation) {
0774:                if (action == null || "".equals(action)) {
0775:                    if (log.isDebugEnabled()) {
0776:                        log
0777:                                .debug("mapActionToOperation: A null or empty action cannot be used to map to an operation.");
0778:                    }
0779:                    return;
0780:                }
0781:                if (log.isDebugEnabled()) {
0782:                    log
0783:                            .debug("mapActionToOperation: Mapping Action to Operation: action: "
0784:                                    + action + "; operation: " + axisOperation);
0785:                }
0786:
0787:                // First check if this action has already been flagged as invalid because it is a duplicate.
0788:                if (invalidOperationsAliases.contains(action)) {
0789:                    // This SOAPAction has already been determined to be invalid; log a message
0790:                    // and do not add it to the operation alias map.
0791:                    if (log.isDebugEnabled()) {
0792:                        log
0793:                                .debug("mapActionToOperation: The action: "
0794:                                        + action
0795:                                        + " can not be used for operation: "
0796:                                        + axisOperation
0797:                                        + " with operation name: "
0798:                                        + axisOperation.getName()
0799:                                        + " because that SOAPAction is not unique for this service.");
0800:                    }
0801:                    return;
0802:                }
0803:
0804:                // Check if the action is currently mapping to an operation.
0805:                AxisOperation currentlyMappedOperation = getOperationByAction(action);
0806:                if (currentlyMappedOperation != null) {
0807:                    if (currentlyMappedOperation == axisOperation) {
0808:                        // This maps to the same operation, then it is already in the alias table, so
0809:                        // just silently ignore this mapping request.
0810:                        if (log.isDebugEnabled()) {
0811:                            log
0812:                                    .debug("mapActionToOperation: This operation is already mapped to this action: "
0813:                                            + action
0814:                                            + "; AxisOperation: "
0815:                                            + currentlyMappedOperation
0816:                                            + " named: "
0817:                                            + currentlyMappedOperation
0818:                                                    .getName());
0819:                        }
0820:                    } else {
0821:                        // This action is already mapped, but it is to a different operation.  Remove
0822:                        // the action mapping from the alias table and add it to the list of invalid mappings
0823:                        operationsAliasesMap.remove(action);
0824:                        invalidOperationsAliases.add(action);
0825:                        if (log.isDebugEnabled()) {
0826:                            log
0827:                                    .debug("mapActionToOperation: The action is already mapped to a different "
0828:                                            + "operation.  The mapping of the action to any operations will be "
0829:                                            + "removed.  Action: "
0830:                                            + action
0831:                                            + "; original operation: "
0832:                                            + currentlyMappedOperation
0833:                                            + " named "
0834:                                            + currentlyMappedOperation
0835:                                                    .getName()
0836:                                            + "; new operation: "
0837:                                            + axisOperation
0838:                                            + " named "
0839:                                            + axisOperation.getName());
0840:                        }
0841:                    }
0842:                } else {
0843:                    operationsAliasesMap.put(action, axisOperation);
0844:                    //Adding operation name to the mapping table
0845:                    //            operationsAliasesMap.put(axisOperation.getName().getLocalPart(), axisOperation);
0846:                }
0847:            }
0848:
0849:            /**
0850:             * Maps an constant string in the whttp:location to the given operation. This is used by
0851:             * RequestURIOperationDispatcher based dispatching to figure out which operation it is that a
0852:             * given message is for.
0853:             *
0854:             * @param string        the constant drawn from whttp:location
0855:             * @param axisOperation the operation to map to
0856:             */
0857:            public void addHttpLocationDispatcherString(String string,
0858:                    AxisOperation axisOperation) {
0859:                httpLocationDispatcherMap.put(string, axisOperation);
0860:            }
0861:
0862:            public void printSchema(OutputStream out) throws AxisFault {
0863:                for (int i = 0; i < schemaList.size(); i++) {
0864:                    XmlSchema schema = addNameSpaces(i);
0865:                    schema.write(out);
0866:                }
0867:            }
0868:
0869:            public XmlSchema getSchema(int index) {
0870:                return addNameSpaces(index);
0871:            }
0872:
0873:            /**
0874:             * Release the list of schema objects.
0875:             * <p/>
0876:             * In some environments, this can provide significant relief
0877:             * of memory consumption in the java heap, as long as the
0878:             * need for the schema list has completed.
0879:             */
0880:            public void releaseSchemaList() {
0881:                if (schemaList != null) {
0882:                    // release the schema list
0883:                    schemaList.clear();
0884:                }
0885:
0886:                if (log.isDebugEnabled()) {
0887:                    log
0888:                            .debug("releaseSchemaList: schema list has been released.");
0889:                }
0890:            }
0891:
0892:            private XmlSchema addNameSpaces(int i) {
0893:                XmlSchema schema = (XmlSchema) schemaList.get(i);
0894:                NamespaceMap map = (NamespaceMap) namespaceMap.clone();
0895:                NamespacePrefixList namespaceContext = schema
0896:                        .getNamespaceContext();
0897:                String prefixes[] = namespaceContext.getDeclaredPrefixes();
0898:                for (int j = 0; j < prefixes.length; j++) {
0899:                    String prefix = prefixes[j];
0900:                    map.add(prefix, namespaceContext.getNamespaceURI(prefix));
0901:                }
0902:                schema.setNamespaceContext(map);
0903:                return schema;
0904:            }
0905:
0906:            public void setEPRs(String[] eprs) {
0907:                this .eprs = eprs;
0908:            }
0909:
0910:            public String[] getEPRs() throws AxisFault {
0911:                if (eprs != null && eprs.length != 0) {
0912:                    return eprs;
0913:                }
0914:                eprs = calculateEPRs();
0915:                return eprs;
0916:            }
0917:
0918:            private String[] calculateEPRs() {
0919:                try {
0920:                    String requestIP = HttpUtils
0921:                            .getIpAddress(getAxisConfiguration());
0922:                    return calculateEPRs(requestIP);
0923:                } catch (SocketException e) {
0924:                    log.error("Cannot get local IP address", e);
0925:                }
0926:                return new String[0];
0927:            }
0928:
0929:            private String[] calculateEPRs(String requestIP) {
0930:                AxisConfiguration axisConfig = getAxisConfiguration();
0931:                if (axisConfig == null) {
0932:                    return null;
0933:                }
0934:                ArrayList eprList = new ArrayList();
0935:                if (enableAllTransports) {
0936:                    for (Iterator transports = axisConfig.getTransportsIn()
0937:                            .values().iterator(); transports.hasNext();) {
0938:                        TransportInDescription transportIn = (TransportInDescription) transports
0939:                                .next();
0940:                        TransportListener listener = transportIn.getReceiver();
0941:                        if (listener != null) {
0942:                            try {
0943:                                EndpointReference[] eprsForService = listener
0944:                                        .getEPRsForService(this .name, requestIP);
0945:                                if (eprsForService != null) {
0946:                                    for (int i = 0; i < eprsForService.length; i++) {
0947:                                        EndpointReference endpointReference = eprsForService[i];
0948:                                        if (endpointReference != null) {
0949:                                            String address = endpointReference
0950:                                                    .getAddress();
0951:                                            if (address != null) {
0952:                                                eprList.add(address);
0953:                                            }
0954:                                        }
0955:                                    }
0956:                                }
0957:                            } catch (AxisFault axisFault) {
0958:                                log.warn(axisFault.getMessage());
0959:                            }
0960:                        }
0961:                    }
0962:                } else {
0963:                    List trs = this .exposedTransports;
0964:                    for (int i = 0; i < trs.size(); i++) {
0965:                        String trsName = (String) trs.get(i);
0966:                        TransportInDescription transportIn = axisConfig
0967:                                .getTransportIn(trsName);
0968:                        if (transportIn != null) {
0969:                            TransportListener listener = transportIn
0970:                                    .getReceiver();
0971:                            if (listener != null) {
0972:                                try {
0973:                                    EndpointReference[] eprsForService = listener
0974:                                            .getEPRsForService(this .name,
0975:                                                    requestIP);
0976:                                    if (eprsForService != null) {
0977:                                        for (int j = 0; j < eprsForService.length; j++) {
0978:                                            EndpointReference endpointReference = eprsForService[j];
0979:                                            if (endpointReference != null) {
0980:                                                String address = endpointReference
0981:                                                        .getAddress();
0982:                                                if (address != null) {
0983:                                                    eprList.add(address);
0984:                                                }
0985:                                            }
0986:                                        }
0987:                                    }
0988:                                } catch (AxisFault axisFault) {
0989:                                    log.warn(axisFault.getMessage());
0990:                                }
0991:                            }
0992:                        }
0993:                    }
0994:                }
0995:                eprs = (String[]) eprList.toArray(new String[eprList.size()]);
0996:                return eprs;
0997:            }
0998:
0999:            private void printDefinitionObject(Definition definition,
1000:                    OutputStream out) throws AxisFault, WSDLException {
1001:                if (isModifyUserWSDLPortAddress()) {
1002:                    setPortAddress(definition);
1003:                }
1004:                if (!wsdlImportLocationAdjusted) {
1005:                    changeImportAndIncludeLocations(definition);
1006:                    wsdlImportLocationAdjusted = true;
1007:                }
1008:                WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
1009:                writer.writeWSDL(definition, out);
1010:            }
1011:
1012:            public void printUserWSDL(OutputStream out, String wsdlName)
1013:                    throws AxisFault {
1014:                Definition definition = null;
1015:                // first find the correct wsdl definition
1016:                Parameter wsdlParameter = getParameter(WSDLConstants.WSDL_4_J_DEFINITION);
1017:                if (wsdlParameter != null) {
1018:                    definition = (Definition) wsdlParameter.getValue();
1019:                }
1020:
1021:                if (definition != null) {
1022:                    try {
1023:                        printDefinitionObject(getWSDLDefinition(definition,
1024:                                wsdlName), out);
1025:                    } catch (WSDLException e) {
1026:                        throw AxisFault.makeFault(e);
1027:                    }
1028:                } else {
1029:                    printWSDLError(out);
1030:                }
1031:
1032:            }
1033:
1034:            /**
1035:             * find the defintion object for given name
1036:             * @param parentDefinition
1037:             * @param name
1038:             * @return wsdl definition
1039:             */
1040:            private Definition getWSDLDefinition(Definition parentDefinition,
1041:                    String name) {
1042:
1043:                if (name == null)
1044:                    return parentDefinition;
1045:
1046:                Definition importedDefinition = null;
1047:                Iterator iter = parentDefinition.getImports().values()
1048:                        .iterator();
1049:                Vector values = null;
1050:                Import wsdlImport = null;
1051:                for (; iter.hasNext();) {
1052:                    values = (Vector) iter.next();
1053:                    for (Iterator valuesIter = values.iterator(); valuesIter
1054:                            .hasNext();) {
1055:                        wsdlImport = (Import) valuesIter.next();
1056:                        if (wsdlImport.getLocationURI().endsWith(name)) {
1057:                            importedDefinition = wsdlImport.getDefinition();
1058:                            break;
1059:                        } else {
1060:                            importedDefinition = getWSDLDefinition(wsdlImport
1061:                                    .getDefinition(), name);
1062:                        }
1063:                        if (importedDefinition != null) {
1064:                            break;
1065:                        }
1066:                    }
1067:                    if (importedDefinition != null) {
1068:                        break;
1069:                    }
1070:                }
1071:                return importedDefinition;
1072:            }
1073:
1074:            /**
1075:             * this procesdue recursively adjust the wsdl imports locations
1076:             * and the schmea import and include locations.
1077:             * @param definition
1078:             */
1079:            private void changeImportAndIncludeLocations(Definition definition) {
1080:
1081:                //adjust the schema locations in types section
1082:                Types types = definition.getTypes();
1083:                if (types != null) {
1084:                    List extensibilityElements = types
1085:                            .getExtensibilityElements();
1086:                    Object extensibilityElement = null;
1087:                    Schema schema = null;
1088:                    for (Iterator iter = extensibilityElements.iterator(); iter
1089:                            .hasNext();) {
1090:                        extensibilityElement = iter.next();
1091:                        if (extensibilityElement instanceof  Schema) {
1092:                            schema = (Schema) extensibilityElement;
1093:                            changeLocations(schema.getElement());
1094:                        }
1095:                    }
1096:                }
1097:
1098:                Iterator iter = definition.getImports().values().iterator();
1099:                Vector values = null;
1100:                Import wsdlImport = null;
1101:                String originalImprotString = null;
1102:                for (; iter.hasNext();) {
1103:                    values = (Vector) iter.next();
1104:                    for (Iterator valuesIter = values.iterator(); valuesIter
1105:                            .hasNext();) {
1106:                        wsdlImport = (Import) valuesIter.next();
1107:                        originalImprotString = wsdlImport.getLocationURI();
1108:                        wsdlImport.setLocationURI(this .name + "?wsdl="
1109:                                + originalImprotString);
1110:                        changeImportAndIncludeLocations(wsdlImport
1111:                                .getDefinition());
1112:                    }
1113:                }
1114:            }
1115:
1116:            /**
1117:             * change the schema Location in the elemment
1118:             * @param element
1119:             */
1120:
1121:            private void changeLocations(Element element) {
1122:                NodeList nodeList = element.getChildNodes();
1123:                String tagName;
1124:                for (int i = 0; i < nodeList.getLength(); i++) {
1125:                    tagName = nodeList.item(i).getLocalName();
1126:                    if (IMPORT_TAG.equals(tagName)
1127:                            || INCLUDE_TAG.equals(tagName)) {
1128:                        processImport(nodeList.item(i));
1129:                    }
1130:                }
1131:            }
1132:
1133:            private void processImport(Node importNode) {
1134:                NamedNodeMap nodeMap = importNode.getAttributes();
1135:                Node attribute;
1136:                String attributeValue;
1137:                for (int i = 0; i < nodeMap.getLength(); i++) {
1138:                    attribute = nodeMap.item(i);
1139:                    if (attribute.getNodeName().equals("schemaLocation")) {
1140:                        attributeValue = attribute.getNodeValue();
1141:                        attribute.setNodeValue(this .name + "?xsd="
1142:                                + attributeValue);
1143:                    }
1144:                }
1145:            }
1146:
1147:            /**
1148:             * Produces a WSDL for this AxisService and prints it to the specified OutputStream.
1149:             *
1150:             * @param out destination stream.  The WSDL will be sent here.
1151:             * @param requestIP the hostname the WSDL request was directed at.  This should be the address
1152:             *                  that appears in the generated WSDL.
1153:             * @throws AxisFault if an error occurs
1154:             */
1155:            public void printWSDL(OutputStream out, String requestIP)
1156:                    throws AxisFault {
1157:                // If we're looking for pre-existing WSDL, use that.
1158:                if (isUseUserWSDL()) {
1159:                    printUserWSDL(out, null);
1160:                    return;
1161:                }
1162:
1163:                // If we find a WSDLSupplier, use that
1164:                WSDLSupplier supplier = (WSDLSupplier) getParameterValue("WSDLSupplier");
1165:                if (supplier != null) {
1166:                    try {
1167:                        Definition definition = supplier.getWSDL(this );
1168:                        if (definition != null) {
1169:                            printDefinitionObject(getWSDLDefinition(definition,
1170:                                    null), out);
1171:                        }
1172:                    } catch (Exception e) {
1173:                        printWSDLError(out, e);
1174:                    }
1175:                    return;
1176:                }
1177:
1178:                // Otherwise, generate WSDL ourselves
1179:                String[] eprArray = requestIP == null ? new String[] { this .endpointName }
1180:                        : calculateEPRs(requestIP);
1181:                getWSDL(out, eprArray);
1182:            }
1183:
1184:            /**
1185:             * Print the WSDL with a default URL. This will be called only during codegen time.
1186:             *
1187:             * @param out
1188:             * @throws AxisFault
1189:             */
1190:            public void printWSDL(OutputStream out) throws AxisFault {
1191:                printWSDL(out, null);
1192:            }
1193:
1194:            private void setPortAddress(Definition definition) throws AxisFault {
1195:                setPortAddress(definition, null);
1196:            }
1197:
1198:            private void setPortAddress(Definition definition, String requestIP)
1199:                    throws AxisFault {
1200:                Iterator serviceItr = definition.getServices().values()
1201:                        .iterator();
1202:                while (serviceItr.hasNext()) {
1203:                    Service serviceElement = (Service) serviceItr.next();
1204:                    Iterator portItr = serviceElement.getPorts().values()
1205:                            .iterator();
1206:                    while (portItr.hasNext()) {
1207:                        Port port = (Port) portItr.next();
1208:                        List list = port.getExtensibilityElements();
1209:                        for (int i = 0; i < list.size(); i++) {
1210:                            Object extensibilityEle = list.get(i);
1211:                            if (extensibilityEle instanceof  SOAPAddress) {
1212:                                if (requestIP == null) {
1213:                                    ((SOAPAddress) extensibilityEle)
1214:                                            .setLocationURI(getEPRs()[0]);
1215:                                } else {
1216:                                    ((SOAPAddress) extensibilityEle)
1217:                                            .setLocationURI(calculateEPRs(requestIP)[0]);
1218:                                }
1219:                            } else if (extensibilityEle instanceof  SOAP12Address) {
1220:                                if (requestIP == null) {
1221:                                    ((SOAP12Address) extensibilityEle)
1222:                                            .setLocationURI(getEPRs()[0]);
1223:                                } else {
1224:                                    ((SOAP12Address) extensibilityEle)
1225:                                            .setLocationURI(calculateEPRs(requestIP)[0]);
1226:                                }
1227:                            } else if (extensibilityEle instanceof  HTTPAddress) {
1228:                                if (requestIP == null) {
1229:                                    ((HTTPAddress) extensibilityEle)
1230:                                            .setLocationURI(getEPRs()[0]);
1231:                                } else {
1232:                                    ((HTTPAddress) extensibilityEle)
1233:                                            .setLocationURI(calculateEPRs(requestIP)[0]);
1234:                                }
1235:                            }
1236:                            //TODO : change the Endpoint refrence addess as well.
1237:                        }
1238:                    }
1239:                }
1240:            }
1241:
1242:            private void getWSDL(OutputStream out, String[] serviceURL)
1243:                    throws AxisFault {
1244:                // Retrieve WSDL using the same data retrieval path for GetMetadata request.
1245:                DataRetrievalRequest request = new DataRetrievalRequest();
1246:                request.putDialect(DRConstants.SPEC.DIALECT_TYPE_WSDL);
1247:                request.putOutputForm(OutputForm.INLINE_FORM);
1248:
1249:                MessageContext context = new MessageContext();
1250:                context.setAxisService(this );
1251:                context.setTo(new EndpointReference(serviceURL[0]));
1252:
1253:                Data[] result = getData(request, context);
1254:                OMElement wsdlElement;
1255:                if (result != null && result.length > 0) {
1256:                    wsdlElement = (OMElement) (result[0].getData());
1257:                    try {
1258:                        XMLPrettyPrinter.prettify(wsdlElement, out);
1259:                        out.flush();
1260:                        out.close();
1261:                    } catch (Exception e) {
1262:                        throw AxisFault.makeFault(e);
1263:                    }
1264:                }
1265:            }
1266:
1267:            private void printWSDLError(OutputStream out) throws AxisFault {
1268:                printWSDLError(out, null);
1269:            }
1270:
1271:            private void printWSDLError(OutputStream out, Exception e)
1272:                    throws AxisFault {
1273:                try {
1274:                    String wsdlntfound = "<error>"
1275:                            + "<description>Unable to generate WSDL 1.1 for this service</description>"
1276:                            + "<reason>If you wish Axis2 to automatically generate the WSDL 1.1, then please +"
1277:                            + "set useOriginalwsdl as false in your services.xml</reason>";
1278:                    out.write(wsdlntfound.getBytes());
1279:                    if (e != null) {
1280:                        PrintWriter pw = new PrintWriter(out);
1281:                        e.printStackTrace(pw);
1282:                        pw.flush();
1283:                    }
1284:                    out.write("</error>".getBytes());
1285:                    out.flush();
1286:                    out.close();
1287:                } catch (IOException ex) {
1288:                    throw AxisFault.makeFault(ex);
1289:                }
1290:            }
1291:
1292:            /**
1293:             * Print the WSDL2.0 with a default URL. This will be called only during codegen time.
1294:             *
1295:             * @param out
1296:             * @throws AxisFault
1297:             */
1298:            public void printWSDL2(OutputStream out) throws AxisFault {
1299:                printWSDL2(out, null);
1300:            }
1301:
1302:            public void printWSDL2(OutputStream out, String requestIP)
1303:                    throws AxisFault {
1304:                AxisService2WSDL20 axisService2WSDL2 = new AxisService2WSDL20(
1305:                        this );
1306:                try {
1307:                    if (requestIP != null) {
1308:                        axisService2WSDL2.setEPRs(calculateEPRs(requestIP));
1309:                    }
1310:                    OMElement wsdlElement = axisService2WSDL2.generateOM();
1311:                    wsdlElement.serialize(out);
1312:                    out.flush();
1313:                    out.close();
1314:                } catch (Exception e) {
1315:                    throw AxisFault.makeFault(e);
1316:                }
1317:            }
1318:
1319:            /**
1320:             * Gets the description about the service which is specified in services.xml.
1321:             *
1322:             * @return Returns String.
1323:             * @deprecated Use getDocumentation() instead
1324:             */
1325:            public String getServiceDescription() {
1326:                return getDocumentation();
1327:            }
1328:
1329:            /**
1330:             * Method getClassLoader.
1331:             *
1332:             * @return Returns ClassLoader.
1333:             */
1334:            public ClassLoader getClassLoader() {
1335:                return this .serviceClassLoader;
1336:            }
1337:
1338:            /**
1339:             * Gets the control operation which are added by module like RM.
1340:             */
1341:            public ArrayList getControlOperations() {
1342:                Iterator op_itr = getOperations();
1343:                ArrayList operationList = new ArrayList();
1344:
1345:                while (op_itr.hasNext()) {
1346:                    AxisOperation operation = (AxisOperation) op_itr.next();
1347:
1348:                    if (operation.isControlOperation()) {
1349:                        operationList.add(operation);
1350:                    }
1351:                }
1352:
1353:                return operationList;
1354:            }
1355:
1356:            public URL getFileName() {
1357:                return fileName;
1358:            }
1359:
1360:            public long getLastupdate() {
1361:                return lastupdate;
1362:            }
1363:
1364:            public ModuleConfiguration getModuleConfig(String moduleName) {
1365:                return (ModuleConfiguration) moduleConfigmap.get(moduleName);
1366:            }
1367:
1368:            public ArrayList getModules() {
1369:                return moduleRefs;
1370:            }
1371:
1372:            public String getName() {
1373:                return name;
1374:            }
1375:
1376:            /**
1377:             * Method getOperation.
1378:             *
1379:             * @param operationName
1380:             * @return Returns AxisOperation.
1381:             */
1382:            public AxisOperation getOperation(QName operationName) {
1383:                AxisOperation axisOperation = (AxisOperation) getChild(operationName);
1384:                if (axisOperation == null) {
1385:                    axisOperation = (AxisOperation) getChild(new QName(
1386:                            getTargetNamespace(), operationName.getLocalPart()));
1387:                }
1388:                if (axisOperation == null) {
1389:                    axisOperation = (AxisOperation) operationsAliasesMap
1390:                            .get(operationName.getLocalPart());
1391:                }
1392:
1393:                return axisOperation;
1394:            }
1395:
1396:            /**
1397:             * Returns the AxisOperation which has been mapped to the given action.
1398:             *
1399:             * @param action the action key
1400:             * @return Returns the corresponding AxisOperation or null if it isn't found.
1401:             */
1402:            public AxisOperation getOperationByAction(String action) {
1403:                return (AxisOperation) operationsAliasesMap.get(action);
1404:            }
1405:
1406:            /**
1407:             * Returns the operation given a SOAP Action. This
1408:             * method should be called if only one Endpoint is defined for
1409:             * this Service. If more than one Endpoint exists, one of them will be
1410:             * picked. If more than one Operation is found with the given SOAP Action;
1411:             * null will be returned. If no particular Operation is found with the given
1412:             * SOAP Action; null will be returned.
1413:             *
1414:             * @param soapAction SOAP Action defined for the particular Operation
1415:             * @return Returns an AxisOperation if a unique Operation can be found with the given
1416:             *         SOAP Action otherwise will return null.
1417:             */
1418:            public AxisOperation getOperationBySOAPAction(String soapAction) {
1419:                if ((soapAction == null) || soapAction.length() == 0) {
1420:                    return null;
1421:                }
1422:
1423:                AxisOperation operation = (AxisOperation) getChild(new QName(
1424:                        soapAction));
1425:
1426:                if (operation != null) {
1427:                    return operation;
1428:                }
1429:
1430:                operation = (AxisOperation) operationsAliasesMap
1431:                        .get(soapAction);
1432:
1433:                return operation;
1434:            }
1435:
1436:            /**
1437:             * Method getOperations.
1438:             *
1439:             * @return Returns HashMap
1440:             */
1441:            public Iterator getOperations() {
1442:                return getChildren();
1443:            }
1444:
1445:            /*
1446:             * (non-Javadoc)
1447:             *
1448:             * @see org.apache.axis2.description.ParameterInclude#getParameter(java.lang.String)
1449:             */
1450:
1451:            /**
1452:             * Gets only the published operations.
1453:             */
1454:            public ArrayList getPublishedOperations() {
1455:                Iterator op_itr = getOperations();
1456:                ArrayList operationList = new ArrayList();
1457:
1458:                while (op_itr.hasNext()) {
1459:                    AxisOperation operation = (AxisOperation) op_itr.next();
1460:
1461:                    if (!operation.isControlOperation()) {
1462:                        operationList.add(operation);
1463:                    }
1464:                }
1465:
1466:                return operationList;
1467:            }
1468:
1469:            /**
1470:             * Sets the description about the service which is specified in services.xml
1471:             *
1472:             * @param documentation
1473:             * @deprecated Use setDocumentation() instead
1474:             */
1475:            public void setServiceDescription(String documentation) {
1476:                setDocumentation(documentation);
1477:            }
1478:
1479:            /**
1480:             * Method setClassLoader.
1481:             *
1482:             * @param classLoader
1483:             */
1484:            public void setClassLoader(ClassLoader classLoader) {
1485:                this .serviceClassLoader = classLoader;
1486:            }
1487:
1488:            public void setFileName(URL fileName) {
1489:                this .fileName = fileName;
1490:            }
1491:
1492:            /**
1493:             * Sets the current time as last update time of the service.
1494:             */
1495:            public void setLastupdate() {
1496:                lastupdate = new Date().getTime();
1497:            }
1498:
1499:            public void setName(String name) {
1500:                this .name = name;
1501:            }
1502:
1503:            public ArrayList getSchema() {
1504:                return schemaList;
1505:            }
1506:
1507:            public void addSchema(XmlSchema schema) {
1508:                if (schema != null) {
1509:                    schemaList.add(schema);
1510:                    if (schema.getTargetNamespace() != null) {
1511:                        addSchemaNameSpace(schema);
1512:                    }
1513:                }
1514:            }
1515:
1516:            public void addSchema(Collection schemas) {
1517:                Iterator iterator = schemas.iterator();
1518:                while (iterator.hasNext()) {
1519:                    XmlSchema schema = (XmlSchema) iterator.next();
1520:                    schemaList.add(schema);
1521:                    addSchemaNameSpace(schema);
1522:                }
1523:            }
1524:
1525:            public boolean isWsdlFound() {
1526:                return wsdlFound;
1527:            }
1528:
1529:            public void setWsdlFound(boolean wsdlFound) {
1530:                this .wsdlFound = wsdlFound;
1531:            }
1532:
1533:            public String getScope() {
1534:                return scope;
1535:            }
1536:
1537:            /**
1538:             * @param scope - Available scopes :
1539:             *              Constants.SCOPE_APPLICATION
1540:             *              Constants.SCOPE_TRANSPORT_SESSION
1541:             *              Constants.SCOPE_SOAP_SESSION
1542:             *              Constants.SCOPE_REQUEST.equals
1543:             */
1544:            public void setScope(String scope) {
1545:                if (Constants.SCOPE_APPLICATION.equals(scope)
1546:                        || Constants.SCOPE_TRANSPORT_SESSION.equals(scope)
1547:                        || Constants.SCOPE_SOAP_SESSION.equals(scope)
1548:                        || Constants.SCOPE_REQUEST.equals(scope)) {
1549:                    this .scope = scope;
1550:                }
1551:            }
1552:
1553:            public boolean isUseDefaultChains() {
1554:                return useDefaultChains;
1555:            }
1556:
1557:            public void setUseDefaultChains(boolean useDefaultChains) {
1558:                this .useDefaultChains = useDefaultChains;
1559:            }
1560:
1561:            public Object getKey() {
1562:                return this .name;
1563:            }
1564:
1565:            public boolean isActive() {
1566:                return active;
1567:            }
1568:
1569:            public void setActive(boolean active) {
1570:                this .active = active;
1571:            }
1572:
1573:            public String getSchematargetNamespace() {
1574:                return schematargetNamespace;
1575:            }
1576:
1577:            public void setSchemaTargetNamespace(String schematargetNamespace) {
1578:                this .schematargetNamespace = schematargetNamespace;
1579:            }
1580:
1581:            public String getSchemaTargetNamespacePrefix() {
1582:                return schematargetNamespacePrefix;
1583:            }
1584:
1585:            public void setSchematargetNamespacePrefix(
1586:                    String schematargetNamespacePrefix) {
1587:                this .schematargetNamespacePrefix = schematargetNamespacePrefix;
1588:            }
1589:
1590:            public String getTargetNamespace() {
1591:                return targetNamespace;
1592:            }
1593:
1594:            public void setTargetNamespace(String targetNamespace) {
1595:                this .targetNamespace = targetNamespace;
1596:            }
1597:
1598:            public String getTargetNamespacePrefix() {
1599:                return targetNamespacePrefix;
1600:            }
1601:
1602:            public void setTargetNamespacePrefix(String targetNamespacePrefix) {
1603:                this .targetNamespacePrefix = targetNamespacePrefix;
1604:            }
1605:
1606:            public XmlSchemaElement getSchemaElement(QName elementQName) {
1607:                XmlSchemaElement element;
1608:                for (int i = 0; i < schemaList.size(); i++) {
1609:                    XmlSchema schema = (XmlSchema) schemaList.get(i);
1610:                    if (schema != null) {
1611:                        element = schema.getElementByName(elementQName);
1612:                        if (element != null) {
1613:                            return element;
1614:                        }
1615:                    }
1616:                }
1617:                return null;
1618:            }
1619:
1620:            public boolean isEnableAllTransports() {
1621:                return enableAllTransports;
1622:            }
1623:
1624:            /**
1625:             * To eneble service to be expose in all the transport
1626:             *
1627:             * @param enableAllTransports
1628:             */
1629:            public void setEnableAllTransports(boolean enableAllTransports) {
1630:                this .enableAllTransports = enableAllTransports;
1631:                eprs = calculateEPRs();
1632:            }
1633:
1634:            public List getExposedTransports() {
1635:                return this .exposedTransports;
1636:            }
1637:
1638:            public void setExposedTransports(List transports) {
1639:                enableAllTransports = false;
1640:                this .exposedTransports = transports;
1641:                eprs = null; //Do not remove this. We need to force EPR recalculation.
1642:            }
1643:
1644:            public void addExposedTransport(String transport) {
1645:                enableAllTransports = false;
1646:                if (!this .exposedTransports.contains(transport)) {
1647:                    this .exposedTransports.add(transport);
1648:                    try {
1649:                        eprs = calculateEPRs();
1650:                    } catch (Exception e) {
1651:                        eprs = null;
1652:                    }
1653:                }
1654:            }
1655:
1656:            public void removeExposedTransport(String transport) {
1657:                enableAllTransports = false;
1658:                this .exposedTransports.remove(transport);
1659:                try {
1660:                    eprs = calculateEPRs();
1661:                } catch (Exception e) {
1662:                    eprs = null;
1663:                }
1664:            }
1665:
1666:            public boolean isExposedTransport(String transport) {
1667:                return exposedTransports.contains(transport);
1668:            }
1669:
1670:            public void onDisengage(AxisModule module) throws AxisFault {
1671:                removeModuleOperations(module);
1672:                for (Iterator operations = getChildren(); operations.hasNext();) {
1673:                    AxisOperation axisOperation = (AxisOperation) operations
1674:                            .next();
1675:                    axisOperation.disengageModule(module);
1676:                }
1677:                AxisConfiguration config = getAxisConfiguration();
1678:                if (!config.isEngaged(module.getName())) {
1679:                    PhaseResolver phaseResolver = new PhaseResolver(config);
1680:                    phaseResolver.disengageModuleFromGlobalChains(module);
1681:                }
1682:            }
1683:
1684:            /**
1685:             * Remove any operations which were added by a given module.
1686:             *
1687:             * @param module the module in question
1688:             */
1689:            private void removeModuleOperations(AxisModule module) {
1690:                HashMap moduleOperations = module.getOperations();
1691:                if (moduleOperations != null) {
1692:                    for (Iterator modOpsIter = moduleOperations.values()
1693:                            .iterator(); modOpsIter.hasNext();) {
1694:                        AxisOperation operation = (AxisOperation) modOpsIter
1695:                                .next();
1696:                        removeOperation(operation.getName());
1697:                    }
1698:                }
1699:            }
1700:
1701:            //#######################################################################################
1702:            //                    APIs to create AxisService
1703:
1704:            //
1705:
1706:            /**
1707:             * To create a AxisService for a given WSDL and the created client is most suitable for client side
1708:             * invocation not for server side invocation. Since all the soap action and wsa action is added to
1709:             * operations
1710:             *
1711:             * @param wsdlURL         location of the WSDL
1712:             * @param wsdlServiceName name of the service to be invoke , if it is null then the first one will
1713:             *                        be selected if there are more than one
1714:             * @param portName        name of the port , if there are more than one , if it is null then the
1715:             *                        first one in the  iterator will be selected
1716:             * @param options         Service client options, to set the target EPR
1717:             * @return AxisService , the created service will be return
1718:             */
1719:            public static AxisService createClientSideAxisService(URL wsdlURL,
1720:                    QName wsdlServiceName, String portName, Options options)
1721:                    throws AxisFault {
1722:                try {
1723:                    InputStream in = wsdlURL.openConnection().getInputStream();
1724:                    Document doc = XMLUtils.newDocument(in);
1725:                    WSDLReader reader = WSDLFactory.newInstance()
1726:                            .newWSDLReader();
1727:                    reader.setFeature("javax.wsdl.importDocuments", true);
1728:                    Definition wsdlDefinition = reader.readWSDL(
1729:                            getBaseURI(wsdlURL.toString()), doc);
1730:                    return createClientSideAxisService(wsdlDefinition,
1731:                            wsdlServiceName, portName, options);
1732:                } catch (IOException e) {
1733:                    log.error(e.getMessage(), e);
1734:                    throw AxisFault.makeFault(e);
1735:                } catch (ParserConfigurationException e) {
1736:                    log.error(e.getMessage(), e);
1737:                    throw AxisFault.makeFault(e);
1738:                } catch (SAXException e) {
1739:                    log.error(e.getMessage(), e);
1740:                    throw AxisFault.makeFault(e);
1741:                } catch (WSDLException e) {
1742:                    log.error(e.getMessage(), e);
1743:                    throw AxisFault.makeFault(e);
1744:                }
1745:            }
1746:
1747:            private static String getBaseURI(String currentURI) {
1748:                try {
1749:                    File file = new File(currentURI);
1750:                    if (file.exists()) {
1751:                        return file.getCanonicalFile().getParentFile().toURI()
1752:                                .toString();
1753:                    }
1754:                    String uriFragment = currentURI.substring(0, currentURI
1755:                            .lastIndexOf("/"));
1756:                    return uriFragment + (uriFragment.endsWith("/") ? "" : "/");
1757:                } catch (IOException e) {
1758:                    return null;
1759:                }
1760:            }
1761:
1762:            public static AxisService createClientSideAxisService(
1763:                    Definition wsdlDefinition, QName wsdlServiceName,
1764:                    String portName, Options options) throws AxisFault {
1765:                WSDL11ToAxisServiceBuilder serviceBuilder = new WSDL11ToAxisServiceBuilder(
1766:                        wsdlDefinition, wsdlServiceName, portName);
1767:                serviceBuilder.setServerSide(false);
1768:                AxisService axisService = serviceBuilder.populateService();
1769:                AxisEndpoint axisEndpoint = (AxisEndpoint) axisService
1770:                        .getEndpoints().get(axisService.getEndpointName());
1771:                options.setTo(new EndpointReference(axisEndpoint
1772:                        .getEndpointURL()));
1773:                if (axisEndpoint != null) {
1774:                    options.setSoapVersionURI((String) axisEndpoint
1775:                            .getBinding().getProperty(
1776:                                    WSDL2Constants.ATTR_WSOAP_VERSION));
1777:                }
1778:                return axisService;
1779:            }
1780:
1781:            /**
1782:             * To create an AxisService using given service impl class name
1783:             * first generate schema corresponding to the given java class , next for each methods AxisOperation
1784:             * will be created. If the method is in-out it will uses RPCMessageReceiver else
1785:             * RPCInOnlyMessageReceiver
1786:             * <p/>
1787:             * Note : Inorder to work this properly RPCMessageReceiver should be available in the class path
1788:             * otherewise operation can not continue
1789:             *
1790:             * @param implClass  Service implementation class
1791:             * @param axisConfig Current AxisConfiguration
1792:             * @return return created AxisSrevice the creted service , it can either be null or valid service
1793:             */
1794:            public static AxisService createService(String implClass,
1795:                    AxisConfiguration axisConfig) throws AxisFault {
1796:
1797:                try {
1798:                    HashMap messageReciverMap = new HashMap();
1799:                    Class inOnlyMessageReceiver = Loader
1800:                            .loadClass("org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver");
1801:                    MessageReceiver messageReceiver = (MessageReceiver) inOnlyMessageReceiver
1802:                            .newInstance();
1803:                    messageReciverMap.put(WSDL2Constants.MEP_URI_IN_ONLY,
1804:                            messageReceiver);
1805:                    Class inoutMessageReceiver = Loader
1806:                            .loadClass("org.apache.axis2.rpc.receivers.RPCMessageReceiver");
1807:                    MessageReceiver inOutmessageReceiver = (MessageReceiver) inoutMessageReceiver
1808:                            .newInstance();
1809:                    messageReciverMap.put(WSDL2Constants.MEP_URI_IN_OUT,
1810:                            inOutmessageReceiver);
1811:                    messageReciverMap.put(
1812:                            WSDL2Constants.MEP_URI_ROBUST_IN_ONLY,
1813:                            inOutmessageReceiver);
1814:
1815:                    return createService(implClass, axisConfig,
1816:                            messageReciverMap, null, null, axisConfig
1817:                                    .getSystemClassLoader());
1818:                } catch (Exception e) {
1819:                    throw AxisFault.makeFault(e);
1820:                }
1821:            }
1822:
1823:            /**
1824:             * messageReceiverClassMap will hold the MessageReceivers for given meps. Key will be the
1825:             * mep and value will be the instance of the MessageReceiver class.
1826:             * Ex:
1827:             * Map mrMap = new HashMap();
1828:             * mrMap.put("http://www.w3.org/2004/08/wsdl/in-only",
1829:             * RPCInOnlyMessageReceiver.class.newInstance());
1830:             * mrMap.put("http://www.w3.org/2004/08/wsdl/in-out",
1831:             * RPCMessageReceiver.class.newInstance());
1832:             *
1833:             * @param implClass
1834:             * @param axisConfiguration
1835:             * @param messageReceiverClassMap
1836:             * @param targetNamespace
1837:             * @param schemaNamespace
1838:             * @throws AxisFault
1839:             */
1840:            public static AxisService createService(String implClass,
1841:                    AxisConfiguration axisConfiguration,
1842:                    Map messageReceiverClassMap, String targetNamespace,
1843:                    String schemaNamespace, ClassLoader loader)
1844:                    throws AxisFault {
1845:                int index = implClass.lastIndexOf(".");
1846:                String serviceName;
1847:                if (index > 0) {
1848:                    serviceName = implClass.substring(index + 1, implClass
1849:                            .length());
1850:                } else {
1851:                    serviceName = implClass;
1852:                }
1853:
1854:                SchemaGenerator schemaGenerator;
1855:                ArrayList excludeOpeartion = new ArrayList();
1856:                AxisService service = new AxisService();
1857:                service.setParent(axisConfiguration);
1858:                service.setName(serviceName);
1859:
1860:                try {
1861:                    Parameter generateBare = service
1862:                            .getParameter(Java2WSDLConstants.DOC_LIT_BARE_PARAMETER);
1863:                    if (generateBare != null
1864:                            && "true".equals(generateBare.getValue())) {
1865:                        schemaGenerator = new DocLitBareSchemaGenerator(loader,
1866:                                implClass, schemaNamespace,
1867:                                Java2WSDLConstants.SCHEMA_NAMESPACE_PRFIX,
1868:                                service);
1869:                    } else {
1870:                        schemaGenerator = new DefaultSchemaGenerator(loader,
1871:                                implClass, schemaNamespace,
1872:                                Java2WSDLConstants.SCHEMA_NAMESPACE_PRFIX,
1873:                                service);
1874:                    }
1875:                    schemaGenerator
1876:                            .setElementFormDefault(Java2WSDLConstants.FORM_DEFAULT_UNQUALIFIED);
1877:                    Utils.addExcludeMethods(excludeOpeartion);
1878:                    schemaGenerator.setExcludeMethods(excludeOpeartion);
1879:                } catch (Exception e) {
1880:                    throw AxisFault.makeFault(e);
1881:                }
1882:
1883:                return createService(implClass, serviceName, axisConfiguration,
1884:                        messageReceiverClassMap, targetNamespace, loader,
1885:                        schemaGenerator, service);
1886:            }
1887:
1888:            /**
1889:             * messageReceiverClassMap will hold the MessageReceivers for given meps. Key will be the
1890:             * mep and value will be the instance of the MessageReceiver class.
1891:             * Ex:
1892:             * Map mrMap = new HashMap();
1893:             * mrMap.put("http://www.w3.org/2004/08/wsdl/in-only",
1894:             * RPCInOnlyMessageReceiver.class.newInstance());
1895:             * mrMap.put("http://www.w3.org/2004/08/wsdl/in-out",
1896:             * RPCMessageReceiver.class.newInstance());
1897:             *
1898:             * @param implClass
1899:             * @param axisConfiguration
1900:             * @param messageReceiverClassMap
1901:             * @param targetNamespace
1902:             * @throws AxisFault
1903:             */
1904:            public static AxisService createService(String implClass,
1905:                    String serviceName, AxisConfiguration axisConfiguration,
1906:                    Map messageReceiverClassMap, String targetNamespace,
1907:                    ClassLoader loader, SchemaGenerator schemaGenerator,
1908:                    AxisService axisService) throws AxisFault {
1909:                Parameter parameter = new Parameter(Constants.SERVICE_CLASS,
1910:                        implClass);
1911:                OMElement paraElement = Utils.getParameter(
1912:                        Constants.SERVICE_CLASS, implClass, false);
1913:                parameter.setParameterElement(paraElement);
1914:                axisService.setUseDefaultChains(false);
1915:                axisService.addParameter(parameter);
1916:                axisService.setName(serviceName);
1917:                axisService.setClassLoader(loader);
1918:
1919:                NamespaceMap map = new NamespaceMap();
1920:                map.put(Java2WSDLConstants.AXIS2_NAMESPACE_PREFIX,
1921:                        Java2WSDLConstants.AXIS2_XSD);
1922:                map.put(Java2WSDLConstants.DEFAULT_SCHEMA_NAMESPACE_PREFIX,
1923:                        Java2WSDLConstants.URI_2001_SCHEMA_XSD);
1924:                axisService.setNameSpacesMap(map);
1925:                axisService.setElementFormDefault(false);
1926:                try {
1927:                    axisService.addSchema(schemaGenerator.generateSchema());
1928:                } catch (Exception e) {
1929:                    throw AxisFault.makeFault(e);
1930:                }
1931:                axisService.setSchemaTargetNamespace(schemaGenerator
1932:                        .getSchemaTargetNameSpace());
1933:                axisService.setTypeTable(schemaGenerator.getTypeTable());
1934:                if (targetNamespace == null) {
1935:                    targetNamespace = schemaGenerator
1936:                            .getSchemaTargetNameSpace();
1937:                }
1938:                if (targetNamespace != null && !"".equals(targetNamespace)) {
1939:                    axisService.setTargetNamespace(targetNamespace);
1940:                }
1941:                JMethod[] method = schemaGenerator.getMethods();
1942:                PhasesInfo pinfo = axisConfiguration.getPhasesInfo();
1943:                for (int i = 0; i < method.length; i++) {
1944:                    JMethod jmethod = method[i];
1945:                    AxisOperation operation = axisService
1946:                            .getOperation(new QName(jmethod.getSimpleName()));
1947:                    String mep = operation.getMessageExchangePattern();
1948:                    MessageReceiver mr;
1949:                    if (messageReceiverClassMap != null) {
1950:
1951:                        if (messageReceiverClassMap.get(mep) != null) {
1952:                            Object obj = messageReceiverClassMap.get(mep);
1953:                            if (obj instanceof  MessageReceiver) {
1954:                                mr = (MessageReceiver) obj;
1955:                                operation.setMessageReceiver(mr);
1956:                            } else {
1957:                                log
1958:                                        .error("Object is not an instance of MessageReceiver, thus, default MessageReceiver has been set");
1959:                                mr = axisConfiguration
1960:                                        .getMessageReceiver(operation
1961:                                                .getMessageExchangePattern());
1962:                                operation.setMessageReceiver(mr);
1963:                            }
1964:                        } else {
1965:                            log
1966:                                    .error("Required MessageReceiver couldn't be found, thus, default MessageReceiver has been used");
1967:                            mr = axisConfiguration.getMessageReceiver(operation
1968:                                    .getMessageExchangePattern());
1969:                            operation.setMessageReceiver(mr);
1970:                        }
1971:                    } else {
1972:                        log
1973:                                .error("MessageRecevierClassMap couldn't be found, thus, default MessageReceiver has been used");
1974:                        mr = axisConfiguration.getMessageReceiver(operation
1975:                                .getMessageExchangePattern());
1976:                        operation.setMessageReceiver(mr);
1977:                    }
1978:                    pinfo.setOperationPhases(operation);
1979:                    axisService.addOperation(operation);
1980:                }
1981:                return axisService;
1982:
1983:            }
1984:
1985:            public void removeOperation(QName opName) {
1986:                AxisOperation operation = getOperation(opName);
1987:                if (operation != null) {
1988:                    removeChild(opName);
1989:                    ArrayList mappingList = operation.getWSAMappingList();
1990:                    if (mappingList != null) {
1991:                        for (int i = 0; i < mappingList.size(); i++) {
1992:                            String actionMapping = (String) mappingList.get(i);
1993:                            operationsAliasesMap.remove(actionMapping);
1994:                        }
1995:                    }
1996:                    operationsAliasesMap.remove(operation.getName()
1997:                            .getLocalPart());
1998:                }
1999:            }
2000:
2001:            /**
2002:             * Get the namespace map for this service.
2003:             *
2004:             * @return a Map of prefix (String) to namespace URI (String)
2005:             * @deprecated please use getNamespaceMap()
2006:             */
2007:            public Map getNameSpacesMap() {
2008:                return namespaceMap;
2009:            }
2010:
2011:            /**
2012:             * Get the namespace map for this service.
2013:             *
2014:             * @return a Map of prefix (String) to namespace URI (String)
2015:             */
2016:            public Map getNamespaceMap() {
2017:                return namespaceMap;
2018:            }
2019:
2020:            /**
2021:             * Sets the
2022:             * @param nameSpacesMap
2023:             */
2024:            public void setNameSpacesMap(NamespaceMap nameSpacesMap) {
2025:                this .namespaceMap = nameSpacesMap;
2026:            }
2027:
2028:            public void setNamespaceMap(NamespaceMap namespaceMap) {
2029:                this .namespaceMap = namespaceMap;
2030:            }
2031:
2032:            private void addSchemaNameSpace(XmlSchema schema) {
2033:                String targetNameSpace = schema.getTargetNamespace();
2034:                String prefix = schema.getNamespaceContext().getPrefix(
2035:                        targetNameSpace);
2036:
2037:                boolean found = false;
2038:                if (namespaceMap != null && namespaceMap.size() > 0) {
2039:                    Iterator itr = namespaceMap.values().iterator();
2040:                    Set keys = namespaceMap.keySet();
2041:                    while (itr.hasNext()) {
2042:                        String value = (String) itr.next();
2043:                        if (value.equals(targetNameSpace)
2044:                                && keys.contains(prefix)) {
2045:                            found = true;
2046:                        }
2047:                    }
2048:                }
2049:                if (namespaceMap == null) {
2050:                    namespaceMap = new NamespaceMap();
2051:                }
2052:                if (!found) {
2053:                    namespaceMap.put("ns" + nsCount, targetNameSpace);
2054:                    nsCount++;
2055:                }
2056:            }
2057:
2058:            /**
2059:             * runs the schema mappings if it has not been run previously
2060:             * it is best that this logic be in the axis service since one can
2061:             * call the axis service to populate the schema mappings
2062:             */
2063:            public Map populateSchemaMappings() {
2064:
2065:                //populate the axis service with the necessary schema references
2066:                ArrayList schema = this .schemaList;
2067:                Map changedScheamLocations = null;
2068:                if (!this .schemaLocationsAdjusted) {
2069:                    Hashtable nameTable = new Hashtable();
2070:                    //calculate unique names for the schemas
2071:                    calcualteSchemaNames(schema, nameTable);
2072:                    //adjust the schema locations as per the calculated names
2073:                    changedScheamLocations = adjustSchemaNames(schema,
2074:                            nameTable);
2075:                    //reverse the nametable so that there is a mapping from the
2076:                    //name to the schemaObject
2077:                    setSchemaMappingTable(swapMappingTable(nameTable));
2078:                    setSchemaLocationsAdjusted(true);
2079:                }
2080:                return changedScheamLocations;
2081:            }
2082:
2083:            /**
2084:             * run 1 -calcualte unique names
2085:             *
2086:             * @param schemas
2087:             */
2088:            private void calcualteSchemaNames(List schemas, Hashtable nameTable) {
2089:                //first traversal - fill the hashtable
2090:                for (int i = 0; i < schemas.size(); i++) {
2091:                    XmlSchema schema = (XmlSchema) schemas.get(i);
2092:                    XmlSchemaObjectCollection includes = schema.getIncludes();
2093:
2094:                    for (int j = 0; j < includes.getCount(); j++) {
2095:                        Object item = includes.getItem(j);
2096:                        XmlSchema s;
2097:                        if (item instanceof  XmlSchemaExternal) {
2098:                            XmlSchemaExternal externalSchema = (XmlSchemaExternal) item;
2099:                            s = externalSchema.getSchema();
2100:                            if (s != null && nameTable.get(s) == null) {
2101:                                //insert the name into the table
2102:                                insertIntoNameTable(nameTable, s);
2103:                                //recursively call the same procedure
2104:                                calcualteSchemaNames(Arrays
2105:                                        .asList(new XmlSchema[] { s }),
2106:                                        nameTable);
2107:                            }
2108:                        }
2109:                    }
2110:                }
2111:            }
2112:
2113:            /**
2114:             * A quick private sub routine to insert the names
2115:             *
2116:             * @param nameTable
2117:             * @param s
2118:             */
2119:            private void insertIntoNameTable(Hashtable nameTable, XmlSchema s) {
2120:                nameTable
2121:                        .put(
2122:                                s,
2123:                                ("xsd" + count++)
2124:                                        + (customSchemaNameSuffix != null ? customSchemaNameSuffix
2125:                                                : ""));
2126:            }
2127:
2128:            /**
2129:             * Run 2  - adjust the names
2130:             */
2131:            private Map adjustSchemaNames(List schemas, Hashtable nameTable) {
2132:                Hashtable importedSchemas = new Hashtable();
2133:                //process the schemas in the main schema list
2134:                for (int i = 0; i < schemas.size(); i++) {
2135:                    adjustSchemaName((XmlSchema) schemas.get(i), nameTable,
2136:                            importedSchemas);
2137:                }
2138:                //process all the rest in the name table
2139:                Enumeration nameTableKeys = nameTable.keys();
2140:                while (nameTableKeys.hasMoreElements()) {
2141:                    adjustSchemaName((XmlSchema) nameTableKeys.nextElement(),
2142:                            nameTable, importedSchemas);
2143:
2144:                }
2145:                return importedSchemas;
2146:            }
2147:
2148:            /**
2149:             * Adjust a single schema
2150:             *
2151:             * @param parentSchema
2152:             * @param nameTable
2153:             */
2154:            private void adjustSchemaName(XmlSchema parentSchema,
2155:                    Hashtable nameTable, Hashtable importedScheams) {
2156:                XmlSchemaObjectCollection includes = parentSchema.getIncludes();
2157:                for (int j = 0; j < includes.getCount(); j++) {
2158:                    Object item = includes.getItem(j);
2159:                    if (item instanceof  XmlSchemaExternal) {
2160:                        XmlSchemaExternal xmlSchemaExternal = (XmlSchemaExternal) item;
2161:                        XmlSchema s = xmlSchemaExternal.getSchema();
2162:                        adjustSchemaLocation(s, xmlSchemaExternal, nameTable,
2163:                                importedScheams);
2164:                    }
2165:                }
2166:
2167:            }
2168:
2169:            /**
2170:             * Adjusts a given schema location
2171:             *
2172:             * @param s
2173:             * @param xmlSchemaExternal
2174:             * @param nameTable
2175:             */
2176:            private void adjustSchemaLocation(XmlSchema s,
2177:                    XmlSchemaExternal xmlSchemaExternal, Hashtable nameTable,
2178:                    Hashtable importedScheams) {
2179:                if (s != null) {
2180:                    String schemaLocation = xmlSchemaExternal
2181:                            .getSchemaLocation();
2182:                    if (importedScheams.get(schemaLocation) != null) {
2183:                        xmlSchemaExternal
2184:                                .setSchemaLocation((String) importedScheams
2185:                                        .get(xmlSchemaExternal
2186:                                                .getSchemaLocation()));
2187:                    } else {
2188:                        String newscheamlocation = customSchemaNamePrefix == null ?
2189:                        //use the default mode
2190:                        (getName() + "?xsd=" + nameTable.get(s))
2191:                                :
2192:                                //custom prefix is present - add the custom prefix
2193:                                (customSchemaNamePrefix + nameTable.get(s));
2194:                        xmlSchemaExternal.setSchemaLocation(newscheamlocation);
2195:                        importedScheams.put(schemaLocation, newscheamlocation);
2196:                    }
2197:
2198:                }
2199:            }
2200:
2201:            /**
2202:             * Swap the key,value pairs
2203:             *
2204:             * @param originalTable
2205:             */
2206:            private Map swapMappingTable(Map originalTable) {
2207:                HashMap swappedTable = new HashMap(originalTable.size());
2208:                Iterator keys = originalTable.keySet().iterator();
2209:                Object key;
2210:                while (keys.hasNext()) {
2211:                    key = keys.next();
2212:                    swappedTable.put(originalTable.get(key), key);
2213:                }
2214:
2215:                return swappedTable;
2216:            }
2217:
2218:            public boolean isClientSide() {
2219:                return clientSide;
2220:            }
2221:
2222:            public void setClientSide(boolean clientSide) {
2223:                this .clientSide = clientSide;
2224:            }
2225:
2226:            public boolean isElementFormDefault() {
2227:                return elementFormDefault;
2228:            }
2229:
2230:            public void setElementFormDefault(boolean elementFormDefault) {
2231:                this .elementFormDefault = elementFormDefault;
2232:            }
2233:
2234:            /**
2235:             * User can set a parameter in services.xml saying he want to show the original wsdl
2236:             * that he put into META-INF once someone ask for ?wsdl
2237:             * so if you want to use your own wsdl then add following parameter into
2238:             * services.xml
2239:             * <parameter name="useOriginalwsdl">true</parameter>
2240:             */
2241:            public boolean isUseUserWSDL() {
2242:                Parameter parameter = getParameter("useOriginalwsdl");
2243:                if (parameter != null) {
2244:                    String value = (String) parameter.getValue();
2245:                    if ("true".equals(value)) {
2246:                        return true;
2247:                    }
2248:                }
2249:                return false;
2250:            }
2251:
2252:            /**
2253:             * By default the port address in user WSDLs is modified, set
2254:             * the following parameter to override this behaviour
2255:             * <parameter name="modifyUserWSDLPortAddress">false</parameter>
2256:             */
2257:            public boolean isModifyUserWSDLPortAddress() {
2258:                Parameter parameter = getParameter("modifyUserWSDLPortAddress");
2259:                if (parameter != null) {
2260:                    String value = (String) parameter.getValue();
2261:                    if ("false".equals(value)) {
2262:                        return false;
2263:                    }
2264:                }
2265:                return true;
2266:            }
2267:
2268:            public ServiceLifeCycle getServiceLifeCycle() {
2269:                return serviceLifeCycle;
2270:            }
2271:
2272:            public void setServiceLifeCycle(ServiceLifeCycle serviceLifeCycle) {
2273:                this .serviceLifeCycle = serviceLifeCycle;
2274:            }
2275:
2276:            public Map getP2nMap() {
2277:                return p2nMap;
2278:            }
2279:
2280:            public void setP2nMap(Map p2nMap) {
2281:                this .p2nMap = p2nMap;
2282:            }
2283:
2284:            public ObjectSupplier getObjectSupplier() {
2285:                return objectSupplier;
2286:            }
2287:
2288:            public void setObjectSupplier(ObjectSupplier objectSupplier) {
2289:                this .objectSupplier = objectSupplier;
2290:            }
2291:
2292:            public TypeTable getTypeTable() {
2293:                return typeTable;
2294:            }
2295:
2296:            public void setTypeTable(TypeTable typeTable) {
2297:                this .typeTable = typeTable;
2298:            }
2299:
2300:            /**
2301:             * Find a data locator from the available data locators (both configured and default ones) to retrieve Metadata or data
2302:             * specified in the request.
2303:             *
2304:             * @param request    an {@link DataRetrievalRequest} object
2305:             * @param msgContext message context
2306:             * @return array of {@link Data} object for the request.
2307:             * @throws AxisFault
2308:             */
2309:
2310:            public Data[] getData(DataRetrievalRequest request,
2311:                    MessageContext msgContext) throws AxisFault {
2312:
2313:                Data[] data;
2314:                String dialect = request.getDialect();
2315:                AxisDataLocator dataLocator = null;
2316:                int nextDataLocatorIndex = 0;
2317:                int totalLocators = availableDataLocatorTypes.length;
2318:                for (int i = 0; i < totalLocators; i++) {
2319:                    dataLocator = getDataLocator(availableDataLocatorTypes[i],
2320:                            dialect);
2321:                    if (dataLocator != null) {
2322:                        nextDataLocatorIndex = i + 1;
2323:                        break;
2324:                    }
2325:                }
2326:
2327:                if (dataLocator == null) {
2328:                    return null;
2329:                }
2330:
2331:                data = dataLocator.getData(request, msgContext);
2332:                // Null means Data Locator not understood request. Automatically find
2333:                // Data Locator in the hierarchy to process the request.
2334:                if (data == null) {
2335:                    if (nextDataLocatorIndex < totalLocators) {
2336:                        data = bubbleupDataLocators(nextDataLocatorIndex,
2337:                                request, msgContext);
2338:                    }
2339:
2340:                }
2341:                return data;
2342:            }
2343:
2344:            /*
2345:             * To search the next Data Locator from the available Data Locators that understood
2346:             * the data retrieval request.
2347:             */
2348:            private Data[] bubbleupDataLocators(int nextIndex,
2349:                    DataRetrievalRequest request, MessageContext msgContext)
2350:                    throws AxisFault {
2351:                Data[] data = null;
2352:                if (nextIndex < availableDataLocatorTypes.length) {
2353:                    AxisDataLocator dataLocator = getDataLocator(
2354:                            availableDataLocatorTypes[nextIndex], request
2355:                                    .getDialect());
2356:                    nextIndex++;
2357:                    if (dataLocator != null) {
2358:                        data = dataLocator.getData(request, msgContext);
2359:                        if (data == null) {
2360:                            data = bubbleupDataLocators(nextIndex, request,
2361:                                    msgContext);
2362:                        } else {
2363:                            return data;
2364:                        }
2365:
2366:                    } else {
2367:                        data = bubbleupDataLocators(nextIndex, request,
2368:                                msgContext);
2369:                    }
2370:
2371:                }
2372:                return data;
2373:            }
2374:
2375:            /**
2376:             * Save data Locator configured at service level for this Axis Service
2377:             *
2378:             * @param dialect-             an absolute URI represents the Dialect i.e. WSDL, Policy, Schema or
2379:             *                             "ServiceLevel" for non-dialect service level data locator.
2380:             * @param dataLocatorClassName - class name of the Data Locator configured to support data retrieval
2381:             *                             for the specified dialect.
2382:             */
2383:            public void addDataLocatorClassNames(String dialect,
2384:                    String dataLocatorClassName) {
2385:                dataLocatorClassNames.put(dialect, dataLocatorClassName);
2386:            }
2387:
2388:            /*
2389:             * Get data locator instance based on the LocatorType and dialect.
2390:             */
2391:            private AxisDataLocator getDataLocator(LocatorType locatorType,
2392:                    String dialect) throws AxisFault {
2393:                AxisDataLocator locator;
2394:                if (locatorType == LocatorType.SERVICE_DIALECT) {
2395:                    locator = getServiceDataLocator(dialect);
2396:                } else if (locatorType == LocatorType.SERVICE_LEVEL) {
2397:                    locator = getServiceDataLocator(DRConstants.SERVICE_LEVEL);
2398:                } else if (locatorType == LocatorType.GLOBAL_DIALECT) {
2399:                    locator = getGlobalDataLocator(dialect);
2400:                } else if (locatorType == LocatorType.GLOBAL_LEVEL) {
2401:                    locator = getGlobalDataLocator(DRConstants.GLOBAL_LEVEL);
2402:                } else if (locatorType == LocatorType.DEFAULT_AXIS) {
2403:                    locator = getDefaultDataLocator();
2404:                } else {
2405:                    locator = getDefaultDataLocator();
2406:                }
2407:
2408:                return locator;
2409:            }
2410:
2411:            // Return default Axis2 Data Locator
2412:            private AxisDataLocator getDefaultDataLocator()
2413:                    throws DataRetrievalException {
2414:
2415:                if (defaultDataLocator == null) {
2416:                    defaultDataLocator = new AxisDataLocatorImpl(this );
2417:                }
2418:
2419:                defaultDataLocator.loadServiceData();
2420:
2421:                return defaultDataLocator;
2422:            }
2423:
2424:            /*
2425:             * Checks if service level data locator configured for specified dialect.
2426:             * Returns an instance of the data locator if exists, and null otherwise.
2427:             */
2428:            private AxisDataLocator getServiceDataLocator(String dialect)
2429:                    throws AxisFault {
2430:                AxisDataLocator locator;
2431:                locator = (AxisDataLocator) dataLocators.get(dialect);
2432:                if (locator == null) {
2433:                    String className = (String) dataLocatorClassNames
2434:                            .get(dialect);
2435:                    if (className != null) {
2436:                        locator = loadDataLocator(className);
2437:                        dataLocators.put(dialect, locator);
2438:                    }
2439:
2440:                }
2441:
2442:                return locator;
2443:
2444:            }
2445:
2446:            /*
2447:             * Checks if global level data locator configured for specified dialect.
2448:             * @param dialect- an absolute URI represents the Dialect i.e. WSDL, Policy, Schema or
2449:             *                 "GlobalLevel" for non-dialect Global level data locator.
2450:             * Returns an instance of the data locator if exists, and null otherwise.
2451:             */
2452:
2453:            public AxisDataLocator getGlobalDataLocator(String dialect)
2454:                    throws AxisFault {
2455:                AxisConfiguration axisConfig = getAxisConfiguration();
2456:                AxisDataLocator locator = null;
2457:                if (axisConfig != null) {
2458:                    locator = axisConfig.getDataLocator(dialect);
2459:                    if (locator == null) {
2460:                        String className = axisConfig
2461:                                .getDataLocatorClassName(dialect);
2462:                        if (className != null) {
2463:                            locator = loadDataLocator(className);
2464:                            axisConfig.addDataLocator(dialect, locator);
2465:                        }
2466:                    }
2467:                }
2468:
2469:                return locator;
2470:
2471:            }
2472:
2473:            protected AxisDataLocator loadDataLocator(String className)
2474:                    throws AxisFault {
2475:
2476:                AxisDataLocator locator;
2477:
2478:                try {
2479:                    Class dataLocator;
2480:                    dataLocator = Class.forName(className, true,
2481:                            serviceClassLoader);
2482:                    locator = (AxisDataLocator) dataLocator.newInstance();
2483:                } catch (ClassNotFoundException e) {
2484:                    throw AxisFault.makeFault(e);
2485:                } catch (IllegalAccessException e) {
2486:                    throw AxisFault.makeFault(e);
2487:                } catch (InstantiationException e) {
2488:                    throw AxisFault.makeFault(e);
2489:
2490:                }
2491:
2492:                return locator;
2493:            }
2494:
2495:            /**
2496:             * Set the map of WSDL message element QNames to AxisOperations for this
2497:             * service.  This map is used during SOAP Body-based routing for
2498:             * document/literal bare services to match the first child element of the
2499:             * SOAP Body element to an operation.  (Routing for RPC and
2500:             * document/literal wrapped services occurs via the operationsAliasesMap.)
2501:             * <p/>
2502:             * From section 4.7.6 of the WS-I BP 1.1:
2503:             * the "operation signature" is "the fully qualified name of the child
2504:             * element of SOAP body of the SOAP input message described by an operation
2505:             * in a WSDL binding," and thus this map must be from a QName to an
2506:             * operation.
2507:             *
2508:             * @param messageElementQNameToOperationMap
2509:             *         The map from WSDL message
2510:             *         element QNames to
2511:             *         AxisOperations.
2512:             */
2513:            public void setMessageElementQNameToOperationMap(
2514:                    Map messageElementQNameToOperationMap) {
2515:                this .messageElementQNameToOperationMap = messageElementQNameToOperationMap;
2516:            }
2517:
2518:            /**
2519:             * Look up an AxisOperation for this service based off of an element QName
2520:             * from a WSDL message element.
2521:             *
2522:             * @param messageElementQName The QName to search for.
2523:             * @return The AxisOperation registered to the QName or null if no match
2524:             *         was found.
2525:             * @see #setMessageElementQNameToOperationMap(Map)
2526:             */
2527:            public AxisOperation getOperationByMessageElementQName(
2528:                    QName messageElementQName) {
2529:                return (AxisOperation) messageElementQNameToOperationMap
2530:                        .get(messageElementQName);
2531:            }
2532:
2533:            /**
2534:             * Add an entry to the map between element QNames in WSDL messages and
2535:             * AxisOperations for this service.
2536:             *
2537:             * @param messageElementQName The QName of the element on the input message
2538:             *                            that maps to the given operation.
2539:             * @param operation           The AxisOperation to be mapped to.
2540:             * @see #setMessageElementQNameToOperationMap(Map)
2541:             */
2542:            public void addMessageElementQNameToOperationMapping(
2543:                    QName messageElementQName, AxisOperation operation) {
2544:                // when setting an operation we have to set it only if the messegeElementQName does not
2545:                // exists in the map.
2546:                // does exists means there are two or more operations which has the same input element (in doc/literal
2547:                // this is possible. In this case better to set it as null without giving
2548:                // a random operation.
2549:                if (messageElementQNameToOperationMap
2550:                        .containsKey(messageElementQName)
2551:                        && messageElementQNameToOperationMap
2552:                                .get(messageElementQName) != operation) {
2553:                    messageElementQNameToOperationMap.put(messageElementQName,
2554:                            null);
2555:                } else {
2556:                    messageElementQNameToOperationMap.put(messageElementQName,
2557:                            operation);
2558:                }
2559:
2560:            }
2561:
2562:            //@deprecated - use getEndpointURL in axisEndpoint
2563:            public String getEndpointURL() {
2564:                return endpointURL;
2565:            }
2566:
2567:            //@deprecated - use setEndpointURL in axisEndpoint
2568:            public void setEndpointURL(String endpointURL) {
2569:                this .endpointURL = endpointURL;
2570:            }
2571:
2572:            // TODO : Explain what goes in this map!
2573:            public Map getEndpoints() {
2574:                return endpointMap;
2575:            }
2576:
2577:            public boolean isCustomWsdl() {
2578:                return customWsdl;
2579:            }
2580:
2581:            public void setCustomWsdl(boolean customWsdl) {
2582:                this .customWsdl = customWsdl;
2583:            }
2584:
2585:            public List getOperationsNameList() {
2586:                return operationsNameList;
2587:            }
2588:
2589:            public void setOperationsNameList(List operationsNameList) {
2590:                this .operationsNameList = operationsNameList;
2591:            }
2592:
2593:            public AxisServiceGroup getAxisServiceGroup() {
2594:                return (AxisServiceGroup) parent;
2595:            }
2596:
2597:            public void setParent(AxisServiceGroup parent) {
2598:                this .parent = parent;
2599:            }
2600:
2601:            public String toString() {
2602:                return getName();
2603:            }
2604:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.