KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > util > Utils


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.util;
17
18 import org.apache.axis2.Constants;
19 import org.apache.axis2.description.*;
20 import org.apache.axis2.engine.AxisConfiguration;
21 import org.apache.axis2.engine.AxisFault;
22 import org.apache.axis2.engine.Handler;
23 import org.apache.axis2.engine.MessageReceiver;
24 import org.apache.axis2.phaseresolver.PhaseException;
25 import org.apache.axis2.phaseresolver.PhaseResolver;
26 import org.apache.axis2.receivers.AbstractMessageReceiver;
27 import org.apache.axis2.receivers.RawXMLINOutMessageReceiver;
28 import org.apache.wsdl.WSDLService;
29
30 import javax.xml.namespace.QName JavaDoc;
31
32 public class Utils {
33
34     public static void addHandler(Flow flow, Handler handler, String JavaDoc phaseName) {
35         HandlerDescription handlerDesc = new HandlerDescription();
36         PhaseRule rule = new PhaseRule(phaseName);
37         handlerDesc.setRules(rule);
38         handler.init(handlerDesc);
39         handlerDesc.setHandler(handler);
40         flow.addHandler(handlerDesc);
41     }
42
43     // public static void addPhasesToServiceFromFlow(
44
// ServiceContext serviceContext,
45
// String phaseName,
46
// Flow flow,
47
// int flowtype)
48
// throws AxisFault {
49
// ArrayList faultchain = new ArrayList();
50
// Phase p = new Phase(Constants.PHASE_SERVICE);
51
// faultchain.add(p);
52
// addHandlers(flow, p);
53
// serviceContext.setPhases(faultchain, flowtype);
54
// }
55

56     // public static void createExecutionChains(ServiceContext serviceContext) throws AxisFault {
57
// ServiceDescription service = serviceContext.getServiceConfig();
58
// addPhasesToServiceFromFlow(
59
// serviceContext,
60
// Constants.PHASE_SERVICE,
61
// service.getInFlow(),
62
// AxisConfiguration.INFLOW);
63
// addPhasesToServiceFromFlow(
64
// serviceContext,
65
// Constants.PHASE_SERVICE,
66
// service.getOutFlow(),
67
// AxisConfiguration.OUTFLOW);
68
// addPhasesToServiceFromFlow(
69
// serviceContext,
70
// Constants.PHASE_SERVICE,
71
// service.getFaultInFlow(),
72
// AxisConfiguration.FAULT_IN_FLOW);
73
// }
74

75     public static ServiceDescription createSimpleService(
76         QName JavaDoc serviceName,
77         MessageReceiver messageReceiver,
78         String JavaDoc className,
79         QName JavaDoc opName) {
80         ServiceDescription service = new ServiceDescription(serviceName);
81         service.setClassLoader(Thread.currentThread().getContextClassLoader());
82         service.addParameter(new ParameterImpl(AbstractMessageReceiver.SERVICE_CLASS, className));
83
84         OperationDescription axisOp = new OperationDescription(opName);
85         axisOp.setMessageReciever(messageReceiver);
86         axisOp.setStyle(WSDLService.STYLE_RPC);
87         service.addOperation(axisOp);
88         return service;
89     }
90
91     // public static ServiceContext createServiceContext(
92
// ServiceDescription service,
93
// ConfigurationContext engineContext)
94
// throws AxisFault {
95
// ServiceContext serviceContext = new ServiceContext(service, engineContext);
96
// createExecutionChains(serviceContext);
97
// return serviceContext;
98
// }
99

100     public static ServiceDescription createSimpleService(
101         QName JavaDoc serviceName,
102         String JavaDoc className,
103         QName JavaDoc opName) {
104         return createSimpleService(
105             serviceName,
106             new RawXMLINOutMessageReceiver(),
107             className,
108             opName);
109     }
110
111     // public static void addHandlers(Flow flow, Phase phase) throws AxisFault {
112
// if (flow != null) {
113
// int handlerCount = flow.getHandlerCount();
114
// for (int i = 0; i < handlerCount; i++) {
115
// phase.addHandler(flow.getHandler(i).getHandler());
116
// }
117
// }
118
// }
119
public static void resolvePhases(AxisConfiguration axisconfig, ServiceDescription serviceDesc)
120         throws AxisFault, PhaseException {
121         PhaseResolver pr = new PhaseResolver(axisconfig, serviceDesc);
122         pr.buildchains();
123     }
124
125     public static String JavaDoc getParameterValue(Parameter param) {
126         if (param == null) {
127             return null;
128         } else {
129             return (String JavaDoc) param.getValue();
130         }
131     }
132
133  
134
135     public static String JavaDoc[] parseRequestURLForServiceAndOperation(String JavaDoc filePart) {
136         String JavaDoc[] values = new String JavaDoc[2];
137
138         int index = filePart.lastIndexOf(Constants.REQUEST_URL_PREFIX);
139         String JavaDoc serviceStr = null;
140         if (-1 != index) {
141             serviceStr = filePart.substring(index + Constants.REQUEST_URL_PREFIX.length() + 1);
142             if ((index = serviceStr.indexOf('/')) > 0) {
143                 values[0] = serviceStr.substring(0, index);
144                 int lastIndex = serviceStr.indexOf('?');
145                 if(lastIndex >= 0){
146                     values[1] = serviceStr.substring(index + 1,lastIndex);
147                 }else{
148                     values[1] = serviceStr.substring(index + 1);
149                 }
150             } else {
151                 values[0] = serviceStr;
152             }
153         }
154         return values;
155     }
156
157 }
158
Popular Tags