import org.argeo.slc.core.SlcException;
import org.argeo.slc.detached.DetachedAnswer;
+import org.argeo.slc.detached.DetachedCommunication;
+import org.argeo.slc.detached.DetachedException;
import org.argeo.slc.detached.DetachedRequest;
import org.argeo.slc.detached.DetachedXmlConverter;
import org.springframework.oxm.Marshaller;
private Marshaller marshaller;
private Unmarshaller unmarshaller;
- public void marshallRequest(DetachedRequest request, Result result) {
- try {
- marshaller.marshal(request, result);
- } catch (Exception e) {
- throw new SlcException("Could not marshall", e);
+ public void marshallCommunication(DetachedCommunication detCom,
+ Result result) {
+ if (detCom instanceof DetachedRequest) {
+ marshallRequest((DetachedRequest) detCom, result);
+ } else if (detCom instanceof DetachedAnswer) {
+ marshallAnswer((DetachedAnswer) detCom, result);
+ } else {
+ throw new DetachedException("Unkown communication type "
+ + detCom.getClass());
}
}
- public void marshallAnswer(DetachedAnswer answer, Result result) {
+ public DetachedCommunication unmarshallCommunication(Source source) {
try {
- marshaller.marshal(answer, result);
+ return (DetachedCommunication) unmarshaller.unmarshal(source);
} catch (Exception e) {
- throw new SlcException("Could not marshall", e);
+ throw new SlcException("Could not unmarshall", e);
}
}
- public DetachedAnswer unmarshallAnswer(Source source) {
+ public void marshallRequest(DetachedRequest request, Result result) {
try {
- return (DetachedAnswer) unmarshaller.unmarshal(source);
+ marshaller.marshal(request, result);
} catch (Exception e) {
- throw new SlcException("Could not unmarshall", e);
+ throw new SlcException("Could not marshall", e);
}
}
- public DetachedRequest unmarshallRequest(Source source) {
+ public void marshallAnswer(DetachedAnswer answer, Result result) {
try {
- return (DetachedRequest) unmarshaller.unmarshal(source);
+ marshaller.marshal(answer, result);
} catch (Exception e) {
- throw new SlcException("Could not unmarshall", e);
+ throw new SlcException("Could not marshall", e);
}
}
DetachedRequest request = createTestRequest();
StringResult result = new StringResult();
- converter.marshallRequest(request, result);
+ converter.marshallCommunication(request, result);
String xml = result.toString();
log.debug(xml + "\n");
UnitXmlUtils.assertXmlValidation(validator, new StringSource(xml));
- DetachedRequest requestUnm = converter
- .unmarshallRequest(new StringSource(xml));
+ DetachedRequest requestUnm = (DetachedRequest) converter
+ .unmarshallCommunication(new StringSource(xml));
assertDetachedRequest(request, requestUnm);
}
DetachedRequest request = createTestRequest();
StringResult result = new StringResult();
- converter.marshallRequest(request, result);
+ converter.marshallCommunication(request, result);
String xml = result.toString();
log.debug(xml + "\n");
UnitXmlUtils.assertXmlValidation(validator, new StringSource(xml));
- DetachedRequest requestUnm = converterCompat
- .unmarshallRequest(new StringSource(xml));
+ DetachedRequest requestUnm = (DetachedRequest) converterCompat
+ .unmarshallCommunication(new StringSource(xml));
assertDetachedRequest(request, requestUnm);
}
public void testAnswer() throws Exception {
DetachedAnswer answer = createTestAnswer();
StringResult result = new StringResult();
- converter.marshallAnswer(answer, result);
+ converter.marshallCommunication(answer, result);
String xml = result.toString();
log.debug(xml + "\n");
UnitXmlUtils.assertXmlValidation(validator, new StringSource(xml));
- DetachedAnswer answerUnm = converter.unmarshallAnswer(new StringSource(
- xml));
+ DetachedAnswer answerUnm = (DetachedAnswer) converter
+ .unmarshallCommunication(new StringSource(xml));
assertDetachedAnswer(answer, answerUnm);
}
public void testAnswerCompat() throws Exception {
DetachedAnswer answer = createTestAnswer();
StringResult result = new StringResult();
- converterCompat.marshallAnswer(answer, result);
+ converterCompat.marshallCommunication(answer, result);
String xml = result.toString();
log.debug(xml + "\n");
UnitXmlUtils.assertXmlValidation(validator, new StringSource(xml));
- DetachedAnswer answerUnm = converter.unmarshallAnswer(new StringSource(
- xml));
+ DetachedAnswer answerUnm = (DetachedAnswer) converter
+ .unmarshallCommunication(new StringSource(xml));
assertDetachedAnswer(answer, answerUnm);
}
Properties expectedProps = expected.getProperties();
Properties reachedProps = reached.getProperties();
assertEquals(expectedProps.size(), reachedProps.size());
- Enumeration keys = expectedProps.keys();
+ Enumeration<Object> keys = expectedProps.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
assertTrue(reachedProps.containsKey(key));
Properties expectedProps = expected.getProperties();
Properties reachedProps = reached.getProperties();
assertEquals(expectedProps.size(), reachedProps.size());
- Enumeration keys = expectedProps.keys();
+ Enumeration<Object> keys = expectedProps.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
assertTrue(reachedProps.containsKey(key));
.getProperty(key));
}
}
-
- private void validate() {
-
- }
-
- public static void main(String[] args) {
- try {
- new DetachedCastorTest().testRequest();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
}