Index: xml/c1891/CastorConstructorWithArgumentsTest.java =================================================================== --- xml/c1891/CastorConstructorWithArgumentsTest.java (Revision 0) +++ xml/c1891/CastorConstructorWithArgumentsTest.java (Revision 0) @@ -0,0 +1,86 @@ +package xml.c1891; + +import java.io.File; +import java.io.FileReader; +import java.io.PrintWriter; +import java.io.StringReader; +import java.io.StringWriter; + +import junit.framework.TestCase; + +import org.exolab.castor.mapping.Mapping; +import org.exolab.castor.xml.Marshaller; +import org.exolab.castor.xml.Unmarshaller; +import org.xml.sax.InputSource; + +public class CastorConstructorWithArgumentsTest extends TestCase { + private SimpleMessage msg1; + + private SimpleMessage msg2; + + private SimpleMessage msg3; + + private Unmarshaller unmarshaller; + + private File f; + + public CastorConstructorWithArgumentsTest(String s) { + super(s); + } + + protected void setUp() throws Exception { + super.setUp(); + + msg1 = new SimpleMessage("cannot delete temporary file", + Severity.WARNING); + msg2 = new SimpleMessage("marked object as obsolete", Severity.WARNING); + msg3 = new SimpleMessage("must shut down system", Severity.ERROR); + + Mapping mapping = new Mapping(); + f = new File("map3.xml"); + mapping.loadMapping(new InputSource(getClass().getResource("mapping.xml").toExternalForm())); + + unmarshaller = new Unmarshaller(); + unmarshaller.setValidation(true); + unmarshaller.setLogWriter(new PrintWriter(System.err)); + unmarshaller.setMapping(mapping); + } + + public void testWrite() throws Exception { + Mapping mapping = new Mapping(); + mapping.loadMapping(new InputSource(getClass().getResource("mapping.xml").toExternalForm())); + StringWriter out = new StringWriter(); + + Marshaller marshaller = new Marshaller(out); + marshaller.setValidation(true); + marshaller.setLogWriter(new PrintWriter(System.err)); + marshaller.setMapping(mapping); + + marshaller.marshal(msg1); + marshaller.marshal(msg2); + marshaller.marshal(msg3); + + out.close(); + assertTrue(out.toString().length() > 0); + System.out.println(out); + } + + public void testReadWarning() throws Exception { + String s = ""; + SimpleMessage simple = (SimpleMessage) unmarshaller + .unmarshal(new StringReader(s)); + assertNotNull(simple); + assertEquals(msg1.severity(), simple.severity()); + assertEquals(msg1.formattedText(), simple.formattedText()); + } + + public void testReadError() throws Exception { + String s = ""; + SimpleMessage simple = (SimpleMessage) unmarshaller + .unmarshal(new StringReader(s)); + assertNotNull(simple); + assertEquals(msg3.severity(), simple.severity()); + assertEquals(msg3.formattedText(), simple.formattedText()); + } + +} Index: xml/c1891/SeverityHandler.java =================================================================== --- xml/c1891/SeverityHandler.java (Revision 0) +++ xml/c1891/SeverityHandler.java (Revision 0) @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2003-2006 Uthlande Cooperation. + * c/o Blohm + Voss GmbH, Hermann-Blohm-Strasse 3, 20457 Hamburg, Germany + * All rights reserved. + * + * This Software is the confidential and proprietary information of the + * Uthlande Cooperation ("Confidential Information") and protected by Copyright + * Law. You shall not disclose such Confidential Information to any third party. + * The use of the Confidential Information is subject only to the Terms of the + * (License) Agreement you entered into with the Uthlande Cooperation. + * Any reproduction, publication, distribution or other use of the Software or + * parts thereof beyond the Terms of the (License) Agreement with the Uthlande + * Cooperation is expressly prohibited and will lead to criminal and private law + * prosecution. + */ + +package xml.c1891; + +import org.exolab.castor.mapping.GeneralizedFieldHandler; + +public class SeverityHandler extends GeneralizedFieldHandler { + + /** + * do the transformation is used for marshalling + */ + public Object convertUponGet(Object value) { + return ((Severity) value).toString(); + } + + /** + * do the inverse transformation, is used for unmarshalling + */ + public Object convertUponSet(Object value) { + if (value.equals(Severity.ERROR.toString())) { + return Severity.ERROR; + } else if (value.equals(Severity.OK.toString())) { + return Severity.OK; + } + + return Severity.WARNING; + } + + /* + * (non-Javadoc) + * + * @see org.exolab.castor.mapping.GeneralizedFieldHandler#getFieldType() + */ + public Class getFieldType() { + return Severity.class; + } + +} \ Kein Zeilenvorschub am Ende der Datei Index: xml/c1891/Severity.java =================================================================== --- xml/c1891/Severity.java (Revision 0) +++ xml/c1891/Severity.java (Revision 0) @@ -0,0 +1,21 @@ +package xml.c1891; + +public final class Severity { + + public static final Severity ERROR = new Severity("Error"); + + public static final Severity WARNING = new Severity("Warning"); + + public static final Severity OK = new Severity("OK"); + + private final transient String name; + + private Severity(String name) { + this.name = name; + } + + public String toString() { + return name; + } + +} Index: xml/c1891/mapping.xml =================================================================== --- xml/c1891/mapping.xml (Revision 0) +++ xml/c1891/mapping.xml (Revision 0) @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ Kein Zeilenvorschub am Ende der Datei Index: xml/c1891/SimpleMessage.java =================================================================== --- xml/c1891/SimpleMessage.java (Revision 0) +++ xml/c1891/SimpleMessage.java (Revision 0) @@ -0,0 +1,22 @@ +package xml.c1891; + +public final class SimpleMessage { + + private Severity severity; + + private String text; + + public SimpleMessage(String text, Severity severity) { + this.text = text; + this.severity = severity; + } + + public Severity severity() { + return severity; + } + + public String formattedText() { + return text; + } + +}