Index: src/bugs/xml/c1850/mapping.xml =================================================================== --- src/bugs/xml/c1850/mapping.xml (Revision 0) +++ src/bugs/xml/c1850/mapping.xml (Revision 0) @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + Index: src/bugs/xml/c1850/README.txt =================================================================== --- src/bugs/xml/c1850/README.txt (Revision 0) +++ src/bugs/xml/c1850/README.txt (Revision 0) @@ -0,0 +1,3 @@ +bug number: 1368 +description: Bug report template for castor xml. +castor: version 1.0M4 or CVS of 2005-03-31 13:44 Index: src/bugs/xml/c1850/TestTemplate.java =================================================================== --- src/bugs/xml/c1850/TestTemplate.java (Revision 0) +++ src/bugs/xml/c1850/TestTemplate.java (Revision 0) @@ -0,0 +1,90 @@ +package xml.c1850; + +import java.io.FileWriter; +import java.io.PrintWriter; + +import junit.framework.TestCase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.exolab.castor.mapping.Mapping; +import org.exolab.castor.xml.MarshalException; +import org.exolab.castor.xml.Marshaller; +import org.exolab.castor.xml.Unmarshaller; +import org.xml.sax.InputSource; + +public final class TestTemplate extends TestCase { + + private static final String OUTPUT_FILE = "out.xml"; + private static final String SAMPLE_FILE = "entity.xml"; + private static final String MAPPING_FILE = "mapping.xml"; + private static final Log LOG = LogFactory.getLog(TestTemplate.class); + + public TestTemplate() { + super(); + } + + public TestTemplate(final String name) { + super(name); + } + + /** + * Test method. + * @throws Exception For any exception thrown. + */ + public void testUnmarshalEntity() throws Exception { + Mapping mapping = new Mapping(); + mapping.loadMapping(getClass().getResource(MAPPING_FILE).toExternalForm()); + + Unmarshaller unmarshaller = new Unmarshaller (Entity.class); + unmarshaller.setMapping(mapping); + + Entity entity = (Entity) unmarshaller.unmarshal(new InputSource(getClass().getResource(SAMPLE_FILE).toExternalForm())); + assertNotNull (entity); + assertEquals (1, entity.getId().intValue()); + assertEquals("name", entity.getName()); + } + + /** + * Test method. + * @throws Exception For any exception thrown. + */ + public void testMarshalEntity() throws Exception { + Mapping mapping = new Mapping(); + mapping.loadMapping(getClass().getResource(MAPPING_FILE).toExternalForm()); + + PrintWriter out = new PrintWriter(new FileWriter(OUTPUT_FILE)); + Marshaller marshaller = new Marshaller (out); + marshaller.setMapping(mapping); + + Entity entity = new Entity(); + entity.setId(new Integer(100)); + entity.setName("entity 100"); + marshaller.marshal(entity); + } + + public void testWrappedExceptionToString() { + Exception ex = new NullPointerException(); + // note: no message + MarshalException me = new MarshalException(ex); + String strVal = me.toString(); + assertNotNull("MarshalException toString is null", strVal); + } + + public void testWrappedExceptionThrown() throws MarshalException { + Exception ex = new NullPointerException(); + // note: no message + MarshalException me = new MarshalException(ex); + LOG.fatal("x", me); + throw me; + } + + public void testWrappedExceptionThrown2() throws MarshalException { + Exception ex = new NullPointerException(); + // note: no message + IllegalStateException me = new IllegalStateException(ex); + LOG.fatal("x", me); + throw me; + } + +} Index: src/bugs/xml/c1850/entity.xml =================================================================== --- src/bugs/xml/c1850/entity.xml (Revision 0) +++ src/bugs/xml/c1850/entity.xml (Revision 0) @@ -0,0 +1,5 @@ + + + 1 + name + \ Kein Zeilenvorschub am Ende der Datei Index: src/bugs/xml/c1850/Entity.java =================================================================== --- src/bugs/xml/c1850/Entity.java (Revision 0) +++ src/bugs/xml/c1850/Entity.java (Revision 0) @@ -0,0 +1,22 @@ +package xml.c1850; + +public final class Entity { + private Integer _id; + private String _name; + + public Integer getId() { + return _id; + } + + public void setId(final Integer id) { + _id = id; + } + + public String getName() { + return _name; + } + + public void setName(final String name) { + _name = name; + } +} Index: src/main/java/org/exolab/castor/xml/XMLException.java =================================================================== --- src/main/java/org/exolab/castor/xml/XMLException.java (Revision 6854) +++ src/main/java/org/exolab/castor/xml/XMLException.java (Arbeitskopie) @@ -136,19 +136,19 @@ * @return the String representation of this Exception. */ public String toString() { - String message; - - Throwable t = getCause(); - if (t == null) { - message = getMessage(); - } else { - message = t.getMessage(); + StringBuffer buff = new StringBuffer(); + buff.append(this.getClass().getName()); + + String msg = this.getMessage(); + if (msg != null) { + buff.append(": ").append(msg); } - - if (_location == null) { - return message; + + if (this._location != null) { + buff.append("{").append(this._location).append("}"); } - return message + "{" + _location.toString() + "}"; + + return buff.toString(); } //-- toString /**