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


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:
020:        package org.apache.axis2.deployment;
021:
022:        import org.apache.axiom.om.OMAttribute;
023:        import org.apache.axiom.om.OMElement;
024:        import org.apache.axis2.AxisFault;
025:        import org.apache.axis2.context.ConfigurationContext;
026:        import org.apache.axis2.dataretrieval.DRConstants;
027:        import org.apache.axis2.deployment.util.PhasesInfo;
028:        import org.apache.axis2.deployment.util.Utils;
029:        import org.apache.axis2.description.AxisMessage;
030:        import org.apache.axis2.description.AxisOperation;
031:        import org.apache.axis2.description.AxisOperationFactory;
032:        import org.apache.axis2.description.AxisService;
033:        import org.apache.axis2.description.InOutAxisOperation;
034:        import org.apache.axis2.description.ModuleConfiguration;
035:        import org.apache.axis2.description.ParameterInclude;
036:        import org.apache.axis2.description.PolicyInclude;
037:        import org.apache.axis2.description.WSDL2Constants;
038:        import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
039:        import org.apache.axis2.description.java2wsdl.TypeTable;
040:        import org.apache.axis2.engine.MessageReceiver;
041:        import org.apache.axis2.engine.ObjectSupplier;
042:        import org.apache.axis2.engine.ServiceLifeCycle;
043:        import org.apache.axis2.i18n.Messages;
044:        import org.apache.axis2.util.Loader;
045:        import org.apache.axis2.wsdl.WSDLConstants;
046:        import org.apache.commons.logging.Log;
047:        import org.apache.commons.logging.LogFactory;
048:
049:        import javax.xml.namespace.QName;
050:        import javax.xml.stream.XMLStreamException;
051:        import java.io.InputStream;
052:        import java.io.StringWriter;
053:        import java.util.ArrayList;
054:        import java.util.HashMap;
055:        import java.util.Hashtable;
056:        import java.util.Iterator;
057:        import java.util.Map;
058:
059:        /**
060:         * Builds a service description from OM
061:         */
062:        public class ServiceBuilder extends DescriptionBuilder {
063:            private static final Log log = LogFactory
064:                    .getLog(ServiceBuilder.class);
065:            private AxisService service;
066:            private HashMap wsdlServiceMap = new HashMap();
067:
068:            public ServiceBuilder(ConfigurationContext configCtx,
069:                    AxisService service) {
070:                this .service = service;
071:                this .configCtx = configCtx;
072:                this .axisConfig = this .configCtx.getAxisConfiguration();
073:            }
074:
075:            public ServiceBuilder(InputStream serviceInputStream,
076:                    ConfigurationContext configCtx, AxisService service) {
077:                super (serviceInputStream, configCtx);
078:                this .service = service;
079:            }
080:
081:            /**
082:             * Populates service from corresponding OM.
083:             *
084:             * @param service_element an OMElement for the <service> tag
085:             * @return a filled-in AxisService, configured from the passed XML
086:             * @throws DeploymentException if there is a problem
087:             */
088:            public AxisService populateService(OMElement service_element)
089:                    throws DeploymentException {
090:                try {
091:                    // Determine whether service should be activated.
092:                    String serviceActivate = service_element
093:                            .getAttributeValue(new QName(ATTRIBUTE_ACTIVATE));
094:                    if (serviceActivate != null) {
095:                        if ("true".equals(serviceActivate)) {
096:                            service.setActive(true);
097:                        } else if ("false".equals(serviceActivate)) {
098:                            service.setActive(false);
099:                        }
100:                    }
101:
102:                    // Processing service level parameters
103:                    OMAttribute serviceNameatt = service_element
104:                            .getAttribute(new QName(ATTRIBUTE_NAME));
105:
106:                    // If the service name is explicitly specified in the services.xml
107:                    // then use that as the service name
108:                    if (serviceNameatt != null) {
109:                        if (!"".equals(serviceNameatt.getAttributeValue()
110:                                .trim())) {
111:                            AxisService wsdlService = (AxisService) wsdlServiceMap
112:                                    .get(serviceNameatt.getAttributeValue());
113:                            if (wsdlService != null) {
114:                                wsdlService.setClassLoader(service
115:                                        .getClassLoader());
116:                                wsdlService.setParent(service
117:                                        .getAxisServiceGroup());
118:                                service = wsdlService;
119:                                service.setWsdlFound(true);
120:                                service.setCustomWsdl(true);
121:                            }
122:                            service.setName(serviceNameatt.getAttributeValue());
123:                            //To be on the safe side
124:                            if (service.getDocumentation() == null) {
125:                                service.setDocumentation(serviceNameatt
126:                                        .getAttributeValue());
127:                            }
128:                        }
129:                    }
130:
131:                    Iterator itr = service_element
132:                            .getChildrenWithName(new QName(TAG_PARAMETER));
133:                    processParameters(itr, service, service.getParent());
134:
135:                    // process service description
136:                    OMElement descriptionElement = service_element
137:                            .getFirstChildWithName(new QName(TAG_DESCRIPTION));
138:                    if (descriptionElement != null) {
139:                        OMElement descriptionValue = descriptionElement
140:                                .getFirstElement();
141:                        if (descriptionValue != null) {
142:                            StringWriter writer = new StringWriter();
143:                            descriptionValue.build();
144:                            descriptionValue.serialize(writer);
145:                            writer.flush();
146:                            service.setDocumentation(writer.toString());
147:                        } else {
148:                            service.setDocumentation(descriptionElement
149:                                    .getText());
150:                        }
151:                    } else {
152:                        serviceNameatt = service_element
153:                                .getAttribute(new QName(ATTRIBUTE_NAME));
154:
155:                        if (serviceNameatt != null) {
156:                            if (!"".equals(serviceNameatt.getAttributeValue()
157:                                    .trim())
158:                                    && service.getDocumentation() == null) {
159:                                service.setDocumentation(serviceNameatt
160:                                        .getAttributeValue());
161:                            }
162:                        }
163:                    }
164:
165:                    if (service.getParameter("ServiceClass") == null) {
166:                        log.debug("The Service " + service.getName()
167:                                + " does not specify a Service Class");
168:                    }
169:
170:                    // Process WS-Addressing flag attribute
171:                    OMAttribute addressingRequiredatt = service_element
172:                            .getAttribute(new QName(ATTRIBUTE_WSADDRESSING));
173:                    if (addressingRequiredatt != null) {
174:                        String addressingRequiredString = addressingRequiredatt
175:                                .getAttributeValue();
176:                        service.setWSAddressingFlag(addressingRequiredString);
177:                    }
178:
179:                    //Setting service target namespace if any
180:                    OMAttribute targetNameSpace = service_element
181:                            .getAttribute(new QName(TARGET_NAME_SPACE));
182:                    if (targetNameSpace != null) {
183:                        String nameSpeceVale = targetNameSpace
184:                                .getAttributeValue();
185:                        if (nameSpeceVale != null && !"".equals(nameSpeceVale)) {
186:                            service.setTargetNamespace(nameSpeceVale);
187:                        }
188:                    } else {
189:                        if (service.getTargetNamespace() == null
190:                                || "".equals(service.getTargetNamespace())) {
191:                            service
192:                                    .setTargetNamespace(Java2WSDLConstants.DEFAULT_TARGET_NAMESPACE);
193:                        }
194:                    }
195:
196:                    //Processing service lifecycle attribute
197:                    OMAttribute serviceLifeCycleClass = service_element
198:                            .getAttribute(new QName(TAG_CLASS_NAME));
199:                    if (serviceLifeCycleClass != null) {
200:                        String className = serviceLifeCycleClass
201:                                .getAttributeValue();
202:                        loadServiceLifeCycleClass(className);
203:                    }
204:                    //Setting schema namespece if any
205:                    OMElement schemaElement = service_element
206:                            .getFirstChildWithName(new QName(SCHEMA));
207:                    if (schemaElement != null) {
208:                        OMAttribute schemaNameSpace = schemaElement
209:                                .getAttribute(new QName(SCHEMA_NAME_SPACE));
210:                        if (schemaNameSpace != null) {
211:                            String nameSpeceVale = schemaNameSpace
212:                                    .getAttributeValue();
213:                            if (nameSpeceVale != null
214:                                    && !"".equals(nameSpeceVale)) {
215:                                service.setSchemaTargetNamespace(nameSpeceVale);
216:                            }
217:                        }
218:                        OMAttribute elementFormDefault = schemaElement
219:                                .getAttribute(new QName(
220:                                        SCHEMA_ELEMENT_QUALIFIED));
221:                        if (elementFormDefault != null) {
222:                            String value = elementFormDefault
223:                                    .getAttributeValue();
224:                            if ("true".equals(value)) {
225:                                service.setElementFormDefault(true);
226:                            } else if ("false".equals(value)) {
227:                                service.setElementFormDefault(false);
228:                            }
229:                        }
230:
231:                        //package to namespace mapping. This will be an element that maps pkg names to a namespace
232:                        //when this is doing AxisService.getSchematargetNamespace will be overridden
233:                        //This will be <mapping/>  with @namespace and @package
234:                        Iterator mappingIterator = schemaElement
235:                                .getChildrenWithName(new QName(MAPPING));
236:                        if (mappingIterator != null) {
237:                            Map pkg2nsMap = new Hashtable();
238:                            while (mappingIterator.hasNext()) {
239:                                OMElement mappingElement = (OMElement) mappingIterator
240:                                        .next();
241:                                OMAttribute namespaceAttribute = mappingElement
242:                                        .getAttribute(new QName(
243:                                                ATTRIBUTE_NAMESPACE));
244:                                OMAttribute packageAttribute = mappingElement
245:                                        .getAttribute(new QName(
246:                                                ATTRIBUTE_PACKAGE));
247:                                if (namespaceAttribute != null
248:                                        && packageAttribute != null) {
249:                                    String namespaceAttributeValue = namespaceAttribute
250:                                            .getAttributeValue();
251:                                    String packageAttributeValue = packageAttribute
252:                                            .getAttributeValue();
253:                                    if (namespaceAttributeValue != null
254:                                            && packageAttributeValue != null) {
255:                                        pkg2nsMap.put(packageAttributeValue
256:                                                .trim(),
257:                                                namespaceAttributeValue.trim());
258:                                    } else {
259:                                        log
260:                                                .warn("Either value of @namespce or @packagename not available. Thus, generated will be selected.");
261:                                    }
262:                                } else {
263:                                    log
264:                                            .warn("Either @namespce or @packagename not available. Thus, generated will be selected.");
265:                                }
266:                            }
267:                            service.setP2nMap(pkg2nsMap);
268:
269:                        }
270:
271:                    }
272:
273:                    //processing Default Message receivers
274:                    OMElement messageReceiver = service_element
275:                            .getFirstChildWithName(new QName(
276:                                    TAG_MESSAGE_RECEIVERS));
277:                    if (messageReceiver != null) {
278:                        HashMap mrs = processMessageReceivers(service
279:                                .getClassLoader(), messageReceiver);
280:                        Iterator keys = mrs.keySet().iterator();
281:                        while (keys.hasNext()) {
282:                            String key = (String) keys.next();
283:                            service.addMessageReceiver(key,
284:                                    (MessageReceiver) mrs.get(key));
285:                        }
286:                    }
287:
288:                    //Removing exclude operations
289:                    OMElement excludeOperations = service_element
290:                            .getFirstChildWithName(new QName(
291:                                    TAG_EXCLUDE_OPERATIONS));
292:                    ArrayList excludeops = null;
293:                    if (excludeOperations != null) {
294:                        excludeops = processExcludeOperations(excludeOperations);
295:                    }
296:                    if (excludeops == null) {
297:                        excludeops = new ArrayList();
298:                    }
299:                    Utils.addExcludeMethods(excludeops);
300:
301:                    //<schema targetNamespace="http://x.y.z"/>
302:                    // setting the PolicyInclude
303:                    // processing <wsp:Policy> .. </..> elements
304:                    Iterator policyElements = service_element
305:                            .getChildrenWithName(new QName(POLICY_NS_URI,
306:                                    TAG_POLICY));
307:
308:                    if (policyElements != null && policyElements.hasNext()) {
309:                        processPolicyElements(
310:                                PolicyInclude.AXIS_SERVICE_POLICY,
311:                                policyElements, service.getPolicyInclude());
312:                    }
313:
314:                    // processing <wsp:PolicyReference> .. </..> elements
315:                    Iterator policyRefElements = service_element
316:                            .getChildrenWithName(new QName(POLICY_NS_URI,
317:                                    TAG_POLICY_REF));
318:
319:                    if (policyRefElements != null
320:                            && policyRefElements.hasNext()) {
321:                        processPolicyRefElements(
322:                                PolicyInclude.AXIS_SERVICE_POLICY,
323:                                policyRefElements, service.getPolicyInclude());
324:                    }
325:
326:                    //processing service scope
327:                    String sessionScope = service_element
328:                            .getAttributeValue(new QName(ATTRIBUTE_SCOPE));
329:                    if (sessionScope != null) {
330:                        service.setScope(sessionScope);
331:                    }
332:
333:                    // processing service-wide modules which required to engage globally
334:                    Iterator moduleRefs = service_element
335:                            .getChildrenWithName(new QName(TAG_MODULE));
336:
337:                    processModuleRefs(moduleRefs);
338:
339:                    //processing transports
340:                    OMElement transports = service_element
341:                            .getFirstChildWithName(new QName(TAG_TRANSPORTS));
342:                    if (transports != null) {
343:                        Iterator transport_itr = transports
344:                                .getChildrenWithName(new QName(TAG_TRANSPORT));
345:                        ArrayList trs = new ArrayList();
346:                        while (transport_itr.hasNext()) {
347:                            OMElement trsEle = (OMElement) transport_itr.next();
348:                            String transportName = trsEle.getText().trim();
349:                            trs.add(transportName);
350:                            if (axisConfig.getTransportIn(transportName) == null) {
351:                                throw new AxisFault(
352:                                        "Service [ "
353:                                                + service.getName()
354:                                                + "] is trying to expose in a transport : "
355:                                                + transports
356:                                                + " and which is not available in Axis2");
357:                            }
358:                        }
359:                        service.setExposedTransports(trs);
360:                    }
361:                    // processing operations
362:                    Iterator operationsIterator = service_element
363:                            .getChildrenWithName(new QName(TAG_OPERATION));
364:                    ArrayList ops = processOperations(operationsIterator);
365:
366:                    for (int i = 0; i < ops.size(); i++) {
367:                        AxisOperation operationDesc = (AxisOperation) ops
368:                                .get(i);
369:                        ArrayList wsamappings = operationDesc
370:                                .getWSAMappingList();
371:                        if (wsamappings == null) {
372:                            continue;
373:                        }
374:                        if (service.getOperation(operationDesc.getName()) == null) {
375:                            service.addOperation(operationDesc);
376:                        }
377:                        for (int j = 0; j < wsamappings.size(); j++) {
378:                            String mapping = (String) wsamappings.get(j);
379:                            if (mapping.length() > 0) {
380:                                service.mapActionToOperation(mapping,
381:                                        operationDesc);
382:                            }
383:                        }
384:                    }
385:                    String objectSupplierValue = (String) service
386:                            .getParameterValue(TAG_OBJECT_SUPPLIER);
387:                    if (objectSupplierValue != null) {
388:                        loadObjectSupplierClass(objectSupplierValue);
389:                    }
390:                    // Set the default message receiver for the operations that were
391:                    // not listed in the services.xml
392:                    setDefaultMessageReceivers();
393:                    if (!service.isUseUserWSDL()) {
394:                        // Generating schema for the service if the impl class is Java
395:                        if (!service.isWsdlFound()) {
396:                            //trying to generate WSDL for the service using JAM  and Java reflection
397:                            try {
398:                                if (generateWsdl(service)) {
399:                                    Utils.fillAxisService(service, axisConfig,
400:                                            excludeops, null);
401:                                } else {
402:                                    ArrayList nonRpcOperations = getNonRPCMethods(service);
403:                                    Utils.fillAxisService(service, axisConfig,
404:                                            excludeops, nonRpcOperations);
405:                                }
406:                            } catch (Exception e) {
407:                                throw new DeploymentException(Messages
408:                                        .getMessage("errorinschemagen", e
409:                                                .getMessage()), e);
410:                            }
411:                        }
412:                    }
413:                    if (service.isCustomWsdl()) {
414:                        OMElement mappingElement = service_element
415:                                .getFirstChildWithName(new QName(
416:                                        TAG_PACKAGE2QNAME));
417:                        if (mappingElement != null) {
418:                            processTypeMappings(mappingElement);
419:                        }
420:                    }
421:
422:                    for (int i = 0; i < excludeops.size(); i++) {
423:                        String opName = (String) excludeops.get(i);
424:                        service.removeOperation(new QName(opName));
425:                    }
426:
427:                    // Need to call the same logic towice
428:                    setDefaultMessageReceivers();
429:                    Iterator moduleConfigs = service_element
430:                            .getChildrenWithName(new QName(TAG_MODULE_CONFIG));
431:                    processServiceModuleConfig(moduleConfigs, service, service);
432:
433:                    // Loading Data Locator(s) configured
434:                    OMElement dataLocatorElement = service_element
435:                            .getFirstChildWithName(new QName(
436:                                    DRConstants.DATA_LOCATOR_ELEMENT));
437:                    if (dataLocatorElement != null) {
438:                        processDataLocatorConfig(dataLocatorElement, service);
439:                    }
440:
441:                } catch (XMLStreamException e) {
442:                    throw new DeploymentException(e);
443:                } catch (AxisFault axisFault) {
444:                    throw new DeploymentException(axisFault);
445:                }
446:                return service;
447:            }
448:
449:            private void setDefaultMessageReceivers() {
450:                Iterator operations = service.getPublishedOperations()
451:                        .iterator();
452:                while (operations.hasNext()) {
453:                    AxisOperation operation = (AxisOperation) operations.next();
454:                    if (operation.getMessageReceiver() == null) {
455:                        MessageReceiver messageReceiver = loadDefaultMessageReceiver(
456:                                operation.getMessageExchangePattern(), service);
457:                        if (messageReceiver == null &&
458:                        //we assume that if the MEP is ROBUST_IN_ONLY then the in-out MR can handle that
459:                                WSDL2Constants.MEP_URI_ROBUST_IN_ONLY
460:                                        .equals(operation
461:                                                .getMessageExchangePattern())) {
462:                            messageReceiver = loadDefaultMessageReceiver(
463:                                    WSDL2Constants.MEP_URI_IN_OUT, service);
464:
465:                        }
466:                        operation.setMessageReceiver(messageReceiver);
467:                    }
468:                }
469:            }
470:
471:            private void loadObjectSupplierClass(String objectSupplierValue)
472:                    throws AxisFault {
473:                try {
474:                    ClassLoader loader = service.getClassLoader();
475:                    Class objectSupplierImpl = Loader.loadClass(loader,
476:                            objectSupplierValue.trim());
477:                    ObjectSupplier objectSupplier = (ObjectSupplier) objectSupplierImpl
478:                            .newInstance();
479:                    service.setObjectSupplier(objectSupplier);
480:                } catch (Exception e) {
481:                    throw AxisFault.makeFault(e);
482:                }
483:            }
484:
485:            /**
486:             * Process the package name to QName mapping:
487:             *
488:             * &lt;packageMapping&gt;
489:             * &lt;mapping packageName="foo.bar" qname="http://foo/bar/xsd"%gt;
490:             * ......
491:             * ......
492:             * &lt;/packageMapping&gt;
493:             *
494:             * @param packageMappingElement OMElement for the packageMappingElement
495:             */
496:            private void processTypeMappings(OMElement packageMappingElement) {
497:                Iterator elementItr = packageMappingElement
498:                        .getChildrenWithName(new QName(TAG_MAPPING));
499:                TypeTable typeTable = service.getTypeTable();
500:                if (typeTable == null) {
501:                    typeTable = new TypeTable();
502:                }
503:                while (elementItr.hasNext()) {
504:                    OMElement mappingElement = (OMElement) elementItr.next();
505:                    String packageName = mappingElement
506:                            .getAttributeValue(new QName(TAG_PACKAGE_NAME));
507:                    String qName = mappingElement.getAttributeValue(new QName(
508:                            TAG_QNAME));
509:                    if (packageName == null || qName == null) {
510:                        continue;
511:                    }
512:                    Iterator keys = service.getNamespaceMap().keySet()
513:                            .iterator();
514:                    while (keys.hasNext()) {
515:                        String key = (String) keys.next();
516:                        if (qName.equals(service.getNamespaceMap().get(key))) {
517:                            typeTable.addComplexSchema(packageName, new QName(
518:                                    qName, packageName, key));
519:                        }
520:                    }
521:                }
522:                service.setTypeTable(typeTable);
523:            }
524:
525:            private void loadServiceLifeCycleClass(String className)
526:                    throws DeploymentException {
527:                if (className != null) {
528:                    try {
529:                        ClassLoader loader = service.getClassLoader();
530:                        Class serviceLifeCycleClassImpl = Loader.loadClass(
531:                                loader, className);
532:                        ServiceLifeCycle serviceLifeCycle = (ServiceLifeCycle) serviceLifeCycleClassImpl
533:                                .newInstance();
534:                        serviceLifeCycle.startUp(configCtx, service);
535:                        service.setServiceLifeCycle(serviceLifeCycle);
536:                    } catch (Exception e) {
537:                        throw new DeploymentException(e.getMessage(), e);
538:                    }
539:                }
540:            }
541:
542:            private boolean generateWsdl(AxisService axisService) {
543:                Iterator operatins = axisService.getOperations();
544:                if (operatins.hasNext()) {
545:                    while (operatins.hasNext()) {
546:                        AxisOperation axisOperation = (AxisOperation) operatins
547:                                .next();
548:
549:                        if (axisOperation.isControlOperation()) {
550:                            continue;
551:                        }
552:
553:                        if (axisOperation.getMessageReceiver() == null) {
554:                            continue;
555:                        }
556:                        String messageReceiverClass = axisOperation
557:                                .getMessageReceiver().getClass().getName();
558:                        if (!("org.apache.axis2.rpc.receivers.RPCMessageReceiver"
559:                                .equals(messageReceiverClass)
560:                                || "org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"
561:                                        .equals(messageReceiverClass)
562:                                || "org.apache.axis2.rpc.receivers.RPCInOutAsyncMessageReceiver"
563:                                        .equals(messageReceiverClass) || "org.apache.axis2.jaxws.server.JAXWSMessageReceiver"
564:                                .equals(messageReceiverClass))) {
565:                            return false;
566:                        }
567:                    }
568:                }
569:                return true;
570:            }
571:
572:            /**
573:             * To get the methods which do not use RPC* MessageReceivers
574:             *
575:             * @param axisService the AxisService to search
576:             * @return an ArrayList of the LOCAL PARTS of the QNames of any non-RPC operations
577:             * TODO: Why not just return the AxisOperations themselves??
578:             */
579:            private ArrayList getNonRPCMethods(AxisService axisService) {
580:                ArrayList excludeOperations = new ArrayList();
581:                Iterator operatins = axisService.getOperations();
582:                if (operatins.hasNext()) {
583:                    while (operatins.hasNext()) {
584:                        AxisOperation axisOperation = (AxisOperation) operatins
585:                                .next();
586:                        if (axisOperation.getMessageReceiver() == null) {
587:                            continue;
588:                        }
589:                        String messageReceiverClass = axisOperation
590:                                .getMessageReceiver().getClass().getName();
591:                        if (!("org.apache.axis2.rpc.receivers.RPCMessageReceiver"
592:                                .equals(messageReceiverClass)
593:                                || "org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"
594:                                        .equals(messageReceiverClass)
595:                                || "org.apache.axis2.rpc.receivers.RPCInOutAsyncMessageReceiver"
596:                                        .equals(messageReceiverClass) || "org.apache.axis2.jaxws.server.JAXWSMessageReceiver"
597:                                .equals(messageReceiverClass))) {
598:                            excludeOperations.add(axisOperation.getName()
599:                                    .getLocalPart());
600:                        }
601:                    }
602:                }
603:                return excludeOperations;
604:            }
605:
606:            /**
607:             * Process &lt;excludeOperation&gt; element in services.xml.  Each operation referenced
608:             * will be removed from the AxisService.
609:             *
610:             * @param excludeOperations the &lt;excludeOperations&gt; element from services.xml
611:             * @return an ArrayList of the String contents of the &lt;operation&gt; elements
612:             */
613:            private ArrayList processExcludeOperations(
614:                    OMElement excludeOperations) {
615:                ArrayList exOps = new ArrayList();
616:                Iterator excludeOp_itr = excludeOperations
617:                        .getChildrenWithName(new QName(TAG_OPERATION));
618:                while (excludeOp_itr.hasNext()) {
619:                    OMElement opName = (OMElement) excludeOp_itr.next();
620:                    exOps.add(opName.getText().trim());
621:                }
622:                return exOps;
623:            }
624:
625:            private void processMessages(Iterator messages,
626:                    AxisOperation operation) throws DeploymentException {
627:                while (messages.hasNext()) {
628:                    OMElement messageElement = (OMElement) messages.next();
629:                    OMAttribute label = messageElement.getAttribute(new QName(
630:                            TAG_LABEL));
631:
632:                    if (label == null) {
633:                        throw new DeploymentException(Messages
634:                                .getMessage("messagelabelcannotfound"));
635:                    }
636:
637:                    AxisMessage message = operation.getMessage(label
638:                            .getAttributeValue());
639:
640:                    Iterator parameters = messageElement
641:                            .getChildrenWithName(new QName(TAG_PARAMETER));
642:
643:                    // processing <wsp:Policy> .. </..> elements
644:                    Iterator policyElements = messageElement
645:                            .getChildrenWithName(new QName(POLICY_NS_URI,
646:                                    TAG_POLICY));
647:
648:                    if (policyElements != null) {
649:                        processPolicyElements(
650:                                PolicyInclude.AXIS_MESSAGE_POLICY,
651:                                policyElements, message.getPolicyInclude());
652:                    }
653:
654:                    // processing <wsp:PolicyReference> .. </..> elements
655:                    Iterator policyRefElements = messageElement
656:                            .getChildrenWithName(new QName(POLICY_NS_URI,
657:                                    TAG_POLICY_REF));
658:
659:                    if (policyRefElements != null) {
660:                        processPolicyRefElements(
661:                                PolicyInclude.AXIS_MESSAGE_POLICY,
662:                                policyRefElements, message.getPolicyInclude());
663:                    }
664:
665:                    processParameters(parameters, message, operation);
666:
667:                }
668:            }
669:
670:            /**
671:             * Gets the list of modules that is required to be engaged globally.
672:             *
673:             * @param moduleRefs <code>java.util.Iterator</code>
674:             * @throws DeploymentException <code>DeploymentException</code>
675:             */
676:            protected void processModuleRefs(Iterator moduleRefs)
677:                    throws DeploymentException {
678:                try {
679:                    while (moduleRefs.hasNext()) {
680:                        OMElement moduleref = (OMElement) moduleRefs.next();
681:                        OMAttribute moduleRefAttribute = moduleref
682:                                .getAttribute(new QName(TAG_REFERENCE));
683:
684:                        if (moduleRefAttribute != null) {
685:                            String refName = moduleRefAttribute
686:                                    .getAttributeValue();
687:
688:                            if (axisConfig.getModule(refName) == null) {
689:                                throw new DeploymentException(
690:                                        Messages
691:                                                .getMessage(
692:                                                        DeploymentErrorMsgs.MODULE_NOT_FOUND,
693:                                                        refName));
694:                            } else {
695:                                service.addModuleref(refName);
696:                            }
697:                        }
698:                    }
699:                } catch (AxisFault axisFault) {
700:                    throw new DeploymentException(axisFault);
701:                }
702:            }
703:
704:            protected void processOperationModuleConfig(Iterator moduleConfigs,
705:                    ParameterInclude parent, AxisOperation operation)
706:                    throws DeploymentException {
707:                while (moduleConfigs.hasNext()) {
708:                    OMElement moduleConfig = (OMElement) moduleConfigs.next();
709:                    OMAttribute moduleName_att = moduleConfig
710:                            .getAttribute(new QName(ATTRIBUTE_NAME));
711:
712:                    if (moduleName_att == null) {
713:                        throw new DeploymentException(
714:                                Messages
715:                                        .getMessage(DeploymentErrorMsgs.INVALID_MODULE_CONFIG));
716:                    } else {
717:                        String module = moduleName_att.getAttributeValue();
718:                        ModuleConfiguration moduleConfiguration = new ModuleConfiguration(
719:                                module, parent);
720:                        Iterator parameters = moduleConfig
721:                                .getChildrenWithName(new QName(TAG_PARAMETER));
722:
723:                        processParameters(parameters, moduleConfiguration,
724:                                parent);
725:                        operation.addModuleConfig(moduleConfiguration);
726:                    }
727:                }
728:            }
729:
730:            private ArrayList processOperations(Iterator operationsIterator)
731:                    throws AxisFault {
732:                ArrayList operations = new ArrayList();
733:                while (operationsIterator.hasNext()) {
734:                    OMElement operation = (OMElement) operationsIterator.next();
735:                    //getting operation name
736:                    OMAttribute op_name_att = operation.getAttribute(new QName(
737:                            ATTRIBUTE_NAME));
738:                    if (op_name_att == null) {
739:                        throw new DeploymentException(Messages
740:                                .getMessage(Messages.getMessage(
741:                                        DeploymentErrorMsgs.INVALID_OP,
742:                                        "operation name missing")));
743:                    }
744:
745:                    // setting the MEP of the operation
746:                    OMAttribute op_mep_att = operation.getAttribute(new QName(
747:                            TAG_MEP));
748:                    String mepurl = null;
749:
750:                    if (op_mep_att != null) {
751:                        mepurl = op_mep_att.getAttributeValue();
752:                    }
753:
754:                    String opname = op_name_att.getAttributeValue();
755:                    AxisOperation op_descrip;
756:                    op_descrip = service.getOperation(new QName(opname));
757:                    if (op_descrip == null) {
758:                        op_descrip = service.getOperation(new QName(service
759:                                .getTargetNamespace(), opname));
760:                    }
761:                    if (op_descrip == null) {
762:                        if (mepurl == null) {
763:                            // assumed MEP is in-out
764:                            op_descrip = new InOutAxisOperation();
765:                            op_descrip.setParent(service);
766:
767:                        } else {
768:                            op_descrip = AxisOperationFactory
769:                                    .getOperationDescription(mepurl);
770:                        }
771:                        op_descrip.setName(new QName(opname));
772:                        String MEP = op_descrip.getMessageExchangePattern();
773:                        if (WSDL2Constants.MEP_URI_IN_ONLY.equals(MEP)
774:                                || WSDL2Constants.MEP_URI_IN_OPTIONAL_OUT
775:                                        .equals(MEP)
776:                                || WSDL2Constants.MEP_URI_OUT_OPTIONAL_IN
777:                                        .equals(MEP)
778:                                || WSDL2Constants.MEP_URI_ROBUST_OUT_ONLY
779:                                        .equals(MEP)
780:                                || WSDL2Constants.MEP_URI_ROBUST_IN_ONLY
781:                                        .equals(MEP)
782:                                || WSDL2Constants.MEP_URI_IN_OUT.equals(MEP)) {
783:                            AxisMessage inaxisMessage = op_descrip
784:                                    .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
785:                            if (inaxisMessage != null) {
786:                                inaxisMessage.setName(opname
787:                                        + Java2WSDLConstants.MESSAGE_SUFFIX);
788:                            }
789:                        }
790:
791:                        if (WSDL2Constants.MEP_URI_OUT_ONLY.equals(MEP)
792:                                || WSDL2Constants.MEP_URI_OUT_OPTIONAL_IN
793:                                        .equals(MEP)
794:                                || WSDL2Constants.MEP_URI_IN_OPTIONAL_OUT
795:                                        .equals(MEP)
796:                                || WSDL2Constants.MEP_URI_ROBUST_OUT_ONLY
797:                                        .equals(MEP)
798:                                || WSDL2Constants.MEP_URI_IN_OUT.equals(MEP)) {
799:                            AxisMessage outAxisMessage = op_descrip
800:                                    .getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
801:                            if (outAxisMessage != null) {
802:                                outAxisMessage.setName(opname
803:                                        + Java2WSDLConstants.RESPONSE);
804:                            }
805:                        }
806:                    }
807:
808:                    // setting the PolicyInclude
809:
810:                    // processing <wsp:Policy> .. </..> elements
811:                    Iterator policyElements = operation
812:                            .getChildrenWithName(new QName(POLICY_NS_URI,
813:                                    TAG_POLICY));
814:
815:                    if (policyElements != null && policyElements.hasNext()) {
816:                        processPolicyElements(
817:                                PolicyInclude.AXIS_OPERATION_POLICY,
818:                                policyElements, op_descrip.getPolicyInclude());
819:                    }
820:
821:                    // processing <wsp:PolicyReference> .. </..> elements
822:                    Iterator policyRefElements = operation
823:                            .getChildrenWithName(new QName(POLICY_NS_URI,
824:                                    TAG_POLICY_REF));
825:
826:                    if (policyRefElements != null
827:                            && policyRefElements.hasNext()) {
828:                        processPolicyRefElements(
829:                                PolicyInclude.AXIS_OPERATION_POLICY,
830:                                policyRefElements, op_descrip
831:                                        .getPolicyInclude());
832:                    }
833:
834:                    // Operation Parameters
835:                    Iterator parameters = operation
836:                            .getChildrenWithName(new QName(TAG_PARAMETER));
837:                    processParameters(parameters, op_descrip, service);
838:                    //To process wsamapping;
839:                    processActionMappings(operation, op_descrip);
840:
841:                    // loading the message receivers
842:                    OMElement receiverElement = operation
843:                            .getFirstChildWithName(new QName(
844:                                    TAG_MESSAGE_RECEIVER));
845:
846:                    if (receiverElement != null) {
847:                        MessageReceiver messageReceiver = loadMessageReceiver(
848:                                service.getClassLoader(), receiverElement);
849:
850:                        op_descrip.setMessageReceiver(messageReceiver);
851:                    } else {
852:                        // setting default message receiver
853:                        MessageReceiver msgReceiver = loadDefaultMessageReceiver(
854:                                op_descrip.getMessageExchangePattern(), service);
855:                        op_descrip.setMessageReceiver(msgReceiver);
856:                    }
857:
858:                    // Process Module Refs
859:                    Iterator modules = operation.getChildrenWithName(new QName(
860:                            TAG_MODULE));
861:
862:                    processOperationModuleRefs(modules, op_descrip);
863:
864:                    // processing Messages
865:                    Iterator messages = operation
866:                            .getChildrenWithName(new QName(TAG_MESSAGE));
867:
868:                    processMessages(messages, op_descrip);
869:
870:                    // setting Operation phase
871:                    if (axisConfig != null) {
872:                        PhasesInfo info = axisConfig.getPhasesInfo();
873:
874:                        info.setOperationPhases(op_descrip);
875:                    }
876:                    Iterator moduleConfigs = operation
877:                            .getChildrenWithName(new QName(TAG_MODULE_CONFIG));
878:                    processOperationModuleConfig(moduleConfigs, op_descrip,
879:                            op_descrip);
880:                    // adding the operation
881:                    operations.add(op_descrip);
882:                }
883:                return operations;
884:            }
885:
886:            protected void processServiceModuleConfig(Iterator moduleConfigs,
887:                    ParameterInclude parent, AxisService service)
888:                    throws DeploymentException {
889:                while (moduleConfigs.hasNext()) {
890:                    OMElement moduleConfig = (OMElement) moduleConfigs.next();
891:                    OMAttribute moduleName_att = moduleConfig
892:                            .getAttribute(new QName(ATTRIBUTE_NAME));
893:
894:                    if (moduleName_att == null) {
895:                        throw new DeploymentException(
896:                                Messages
897:                                        .getMessage(DeploymentErrorMsgs.INVALID_MODULE_CONFIG));
898:                    } else {
899:                        String module = moduleName_att.getAttributeValue();
900:                        ModuleConfiguration moduleConfiguration = new ModuleConfiguration(
901:                                module, parent);
902:                        Iterator parameters = moduleConfig
903:                                .getChildrenWithName(new QName(TAG_PARAMETER));
904:
905:                        processParameters(parameters, moduleConfiguration,
906:                                parent);
907:                        service.addModuleConfig(moduleConfiguration);
908:                    }
909:                }
910:            }
911:
912:            /*
913:             * process data locator configuration for data retrieval.
914:             */
915:            private void processDataLocatorConfig(OMElement dataLocatorElement,
916:                    AxisService service) {
917:                OMAttribute serviceOverallDataLocatorclass = dataLocatorElement
918:                        .getAttribute(new QName(DRConstants.CLASS_ATTRIBUTE));
919:                if (serviceOverallDataLocatorclass != null) {
920:                    String className = serviceOverallDataLocatorclass
921:                            .getAttributeValue();
922:                    service.addDataLocatorClassNames(DRConstants.SERVICE_LEVEL,
923:                            className);
924:                }
925:                Iterator iterator = dataLocatorElement
926:                        .getChildrenWithName(new QName(
927:                                DRConstants.DIALECT_LOCATOR_ELEMENT));
928:
929:                while (iterator.hasNext()) {
930:                    OMElement locatorElement = (OMElement) iterator.next();
931:                    OMAttribute dialect = locatorElement
932:                            .getAttribute(new QName(
933:                                    DRConstants.DIALECT_ATTRIBUTE));
934:                    OMAttribute dialectclass = locatorElement
935:                            .getAttribute(new QName(DRConstants.CLASS_ATTRIBUTE));
936:                    service.addDataLocatorClassNames(dialect
937:                            .getAttributeValue(), dialectclass
938:                            .getAttributeValue());
939:
940:                }
941:
942:            }
943:
944:            public void setWsdlServiceMap(HashMap wsdlServiceMap) {
945:                this.wsdlServiceMap = wsdlServiceMap;
946:            }
947:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.