KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > engine > SOAPMessageBodyBasedDispatcher


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis2.engine;
17
18 import org.apache.axis2.context.ConfigurationContext;
19 import org.apache.axis2.context.MessageContext;
20 import org.apache.axis2.description.HandlerDescription;
21 import org.apache.axis2.description.OperationDescription;
22 import org.apache.axis2.description.ServiceDescription;
23 import org.apache.axis2.om.OMElement;
24 import org.apache.axis2.om.OMNamespace;
25 import org.apache.axis2.util.Utils;
26
27 import javax.xml.namespace.QName JavaDoc;
28
29 /**
30  * Class Dispatcher
31  */

32 public class SOAPMessageBodyBasedDispatcher extends AbstractDispatcher {
33     /**
34      * Field NAME
35      */

36     public static final QName JavaDoc NAME =
37         new QName JavaDoc("http://axis.ws.apache.org", "SOAPMessageBodyBasedDispatcher");
38     QName JavaDoc serviceName = null;
39     QName JavaDoc operatoinName = null;
40
41     /**
42      * Constructor Dispatcher
43      */

44     public SOAPMessageBodyBasedDispatcher() {
45         init(new HandlerDescription(NAME));
46     }
47
48     public OperationDescription findOperation(
49         ServiceDescription service,
50         MessageContext messageContext)
51         throws AxisFault {
52         OMElement bodyFirstChild = messageContext.getEnvelope().getBody().getFirstElement();
53         operatoinName = new QName JavaDoc(bodyFirstChild.getLocalName());
54
55         OperationDescription axisOp = service.getOperation(operatoinName);
56         return axisOp;
57     }
58
59     /* (non-Javadoc)
60      * @see org.apache.axis2.engine.AbstractDispatcher#findService(org.apache.axis2.context.MessageContext)
61      */

62     public ServiceDescription findService(MessageContext messageContext) throws AxisFault {
63         final String JavaDoc URI_ID_STRING = "/services";
64         OMElement bodyFirstChild = messageContext.getEnvelope().getBody().getFirstElement();
65         OMNamespace ns = bodyFirstChild.getNamespace();
66         if (ns != null) {
67             String JavaDoc filePart = ns.getName();
68
69             String JavaDoc[] values = Utils.parseRequestURLForServiceAndOperation(filePart);
70             if (values[1] != null) {
71                 operatoinName = new QName JavaDoc(values[1]);
72             }
73             if (values[0] != null) {
74                 serviceName = new QName JavaDoc(values[0]);
75                 AxisConfiguration registry =
76                     messageContext.getSystemContext().getAxisConfiguration();
77                 return registry.getService(serviceName);
78             }
79         }
80         return null;
81
82     }
83 }
84
Popular Tags