|
|||||||||||||||||||
| 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 | |||||||||||||||
| XStreamMarshaller.java | 83.3% | 81% | 87.5% | 82.9% |
|
||||||||||||||
| 1 |
/**
|
|
| 2 |
*
|
|
| 3 |
* Copyright 2005 LogicBlaze, Inc.
|
|
| 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.logicblaze.lingo.jms.marshall;
|
|
| 19 |
|
|
| 20 |
import com.thoughtworks.xstream.XStream;
|
|
| 21 |
import org.logicblaze.lingo.LingoInvocation;
|
|
| 22 |
import org.logicblaze.lingo.jms.Requestor;
|
|
| 23 |
import org.springframework.remoting.support.RemoteInvocation;
|
|
| 24 |
import org.springframework.remoting.support.RemoteInvocationResult;
|
|
| 25 |
|
|
| 26 |
import javax.jms.JMSException;
|
|
| 27 |
import javax.jms.Message;
|
|
| 28 |
import javax.jms.TextMessage;
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
/**
|
|
| 32 |
* Uses XStream to marshall requests and responses into and out of messages.
|
|
| 33 |
*
|
|
| 34 |
* @version $Revision: 1.1 $
|
|
| 35 |
*/
|
|
| 36 |
public class XStreamMarshaller extends DefaultMarshaller { |
|
| 37 |
private XStream xStream;
|
|
| 38 |
|
|
| 39 | 32 |
public Message createRequestMessage(Requestor requestor, LingoInvocation invocation) throws JMSException { |
| 40 | 32 |
String xml = toXML(invocation); |
| 41 | 32 |
return requestor.getSession().createTextMessage(xml);
|
| 42 |
} |
|
| 43 |
|
|
| 44 | 28 |
public RemoteInvocationResult extractInvocationResult(Message message) throws JMSException { |
| 45 | 28 |
if (message instanceof TextMessage) { |
| 46 | 0 |
TextMessage textMessage = (TextMessage) message; |
| 47 | 0 |
String text = textMessage.getText(); |
| 48 | 0 |
return (RemoteInvocationResult) fromXML(text);
|
| 49 |
} |
|
| 50 | 28 |
return super.extractInvocationResult(message); |
| 51 |
} |
|
| 52 |
|
|
| 53 | 30 |
public RemoteInvocation readRemoteInvocation(Message message) throws JMSException { |
| 54 | 30 |
if (message instanceof TextMessage) { |
| 55 | 29 |
TextMessage textMessage = (TextMessage) message; |
| 56 | 29 |
String text = textMessage.getText(); |
| 57 | 29 |
return (RemoteInvocation) fromXML(text);
|
| 58 |
} |
|
| 59 | 1 |
return super.readRemoteInvocation(message); |
| 60 |
} |
|
| 61 |
|
|
| 62 |
|
|
| 63 |
// Properties
|
|
| 64 |
//-------------------------------------------------------------------------
|
|
| 65 | 61 |
public XStream getXStream() {
|
| 66 | 61 |
if (xStream == null) { |
| 67 | 13 |
xStream = createXStream(); |
| 68 |
} |
|
| 69 | 61 |
return xStream;
|
| 70 |
} |
|
| 71 |
|
|
| 72 | 0 |
public void setXStream(XStream xStream) { |
| 73 | 0 |
this.xStream = xStream;
|
| 74 |
} |
|
| 75 |
|
|
| 76 |
// Implementation methods
|
|
| 77 |
//-------------------------------------------------------------------------
|
|
| 78 | 13 |
protected XStream createXStream() {
|
| 79 | 13 |
XStream answer = new XStream();
|
| 80 | 13 |
answer.alias("invoke", LingoInvocation.class); |
| 81 | 13 |
return answer;
|
| 82 |
} |
|
| 83 |
|
|
| 84 | 29 |
protected Object fromXML(String xml) {
|
| 85 | 29 |
return getXStream().fromXML(xml);
|
| 86 |
} |
|
| 87 |
|
|
| 88 | 32 |
protected String toXML(Object object) {
|
| 89 | 32 |
return getXStream().toXML(object);
|
| 90 |
} |
|
| 91 |
|
|
| 92 |
|
|
| 93 |
} |
|
| 94 |
|
|
||||||||||