]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Integrate XML-based file exchanges.
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 5 Oct 2008 13:42:54 +0000 (13:42 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 5 Oct 2008 13:42:54 +0000 (13:42 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@1701 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.slc.agent/src/main/java/org/argeo/slc/lib/detached/DetachedXmlConverterSpring.java
org.argeo.slc.agent/src/test/java/org/argeo/slc/lib/detached/DetachedCastorTest.java

index c3e9e304a5f5421659b103a2d768068a49b1835f..799b4739cf7c02ddd8a054091e4c876b0997808f 100644 (file)
@@ -7,6 +7,8 @@ import javax.xml.transform.Source;
 
 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;
@@ -19,35 +21,39 @@ public class DetachedXmlConverterSpring implements DetachedXmlConverter {
        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);
                }
        }
 
index b178c821187a3357834fbeca74f3d758ddb527d3..0425ce0888278b91abf57860d31d949e89da8741 100644 (file)
@@ -32,13 +32,13 @@ public class DetachedCastorTest extends AbstractSpringTestCase {
                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);
        }
 
@@ -46,39 +46,39 @@ public class DetachedCastorTest extends AbstractSpringTestCase {
                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);
        }
 
@@ -114,7 +114,7 @@ public class DetachedCastorTest extends AbstractSpringTestCase {
                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));
@@ -131,7 +131,7 @@ public class DetachedCastorTest extends AbstractSpringTestCase {
                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));
@@ -139,18 +139,4 @@ public class DetachedCastorTest extends AbstractSpringTestCase {
                                        .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();
-               }
-       }
-
 }