|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| XStreamInvokeMethodHandler.java | 50% | 100% | 100% | 92.9% |
|
||||||||||||||
| 1 |
/**
|
|
| 2 |
*
|
|
| 3 |
* Copyright 2004 Protique Ltd
|
|
| 4 |
*
|
|
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 6 |
* you may not use this file except in compliance with the License.
|
|
| 7 |
* You may obtain a copy of the License at
|
|
| 8 |
*
|
|
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 10 |
*
|
|
| 11 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 14 |
* See the License for the specific language governing permissions and
|
|
| 15 |
* limitations under the License.
|
|
| 16 |
*
|
|
| 17 |
**/
|
|
| 18 |
package org.codehaus.activesoap.handler.xstream;
|
|
| 19 |
|
|
| 20 |
import org.codehaus.activesoap.MessageExchange;
|
|
| 21 |
|
|
| 22 |
import javax.xml.stream.XMLStreamWriter;
|
|
| 23 |
import java.lang.reflect.Method;
|
|
| 24 |
|
|
| 25 |
/**
|
|
| 26 |
* @version $Revision: 1.3 $
|
|
| 27 |
*/
|
|
| 28 |
public class XStreamInvokeMethodHandler extends XStreamHandler { |
|
| 29 |
private Class serviceClass;
|
|
| 30 |
private Method method;
|
|
| 31 |
|
|
| 32 | 21 |
public XStreamInvokeMethodHandler(Class serviceClass, Method method) {
|
| 33 | 21 |
this.serviceClass = serviceClass;
|
| 34 | 21 |
this.method = method;
|
| 35 |
} |
|
| 36 |
|
|
| 37 |
// Implementation methods
|
|
| 38 |
//-------------------------------------------------------------------------
|
|
| 39 | 7 |
protected void handleBody(MessageExchange exchange, Object body, XMLStreamWriter out) throws Exception { |
| 40 | 7 |
Object instance = createService(); |
| 41 | 7 |
invokeService(body, exchange, out, instance); |
| 42 |
} |
|
| 43 |
|
|
| 44 |
/**
|
|
| 45 |
* Invokes the service on the given serviceInstance
|
|
| 46 |
*/
|
|
| 47 | 7 |
protected void invokeService(Object body, MessageExchange exchange, XMLStreamWriter out, Object serviceInstance) throws Exception { |
| 48 | 7 |
Object answer = method.invoke(serviceInstance, new Object[]{body});
|
| 49 | 7 |
if (answer != null) { |
| 50 | 7 |
xstream.marshal(answer, driver.createStaxWriter(out)); |
| 51 |
} |
|
| 52 |
} |
|
| 53 |
|
|
| 54 |
/**
|
|
| 55 |
* Factory method to create a new instance temporary instance of the service
|
|
| 56 |
*
|
|
| 57 |
* @return
|
|
| 58 |
*/
|
|
| 59 | 7 |
protected Object createService() throws Exception { |
| 60 | 7 |
return serviceClass.newInstance();
|
| 61 |
} |
|
| 62 |
} |
|
| 63 |
|
|
||||||||||