Index: src/test/java/xml/c2044/TestSourceGenerator.java =================================================================== --- src/test/java/xml/c2044/TestSourceGenerator.java (Revision 0) +++ src/test/java/xml/c2044/TestSourceGenerator.java (Revision 0) @@ -0,0 +1,29 @@ +package xml.c2044; + +import junit.framework.TestCase; + +import org.exolab.castor.builder.SourceGenerator; +import org.xml.sax.InputSource; + +public class TestSourceGenerator extends TestCase { + + public void testGeneration() throws Exception { + SourceGenerator generator = new SourceGenerator(); + String xmlSchema = getClass().getResource("test.xsd").toExternalForm(); + InputSource inputSource = new InputSource(xmlSchema); + generator.setDestDir("./codegen/src/test/java"); + generator.setSuppressNonFatalWarnings(true); + + // uncomment the next line to set a binding file for source generation +// generator.setBinding(new InputSource(getClass().getResource("binding.xml").toExternalForm())); + + // uncomment the next lines to set custom properties for source generation +// Properties properties = new Properties(); +// properties.load(getClass().getResource("builder.properties").openStream()); +// generator.setDefaultProperties(properties); + + generator.generateSource(inputSource, getClass().getPackage().getName() + ".generated"); + } + +} + Index: src/test/java/xml/c2044/TestTemplate.java =================================================================== --- src/test/java/xml/c2044/TestTemplate.java (Revision 0) +++ src/test/java/xml/c2044/TestTemplate.java (Revision 0) @@ -0,0 +1,55 @@ +package xml.c2044; + +import junit.framework.TestCase; + +import org.exolab.castor.types.Duration; +import org.exolab.castor.xml.Unmarshaller; +import org.xml.sax.InputSource; + +import xml.c2044.generated.Test; + +public final class TestTemplate extends TestCase { + + private static final String SAMPLE_FILE = "input.xml"; + + public TestTemplate() { + super(); + } + + public TestTemplate(final String name) { + super(name); + } + + /** + * Test method. + * @throws Exception For any exception thrown. + */ + public void testUnmarshalEntity() throws Exception { + Unmarshaller unmarshaller = new Unmarshaller (Test.class); + + InputSource inputSource = + new InputSource(getClass().getResource(SAMPLE_FILE).toExternalForm()); + Test entity = (Test) unmarshaller.unmarshal(inputSource); + assertNotNull (entity); + } + + /** + * Test method. + * @throws Exception For any exception thrown. + */ + public void testUnmarshalMillisecond() throws Exception { + Unmarshaller unmarshaller = new Unmarshaller (Test.class); + + InputSource inputSource = + new InputSource(getClass().getResource("input-including-milli.xml").toExternalForm()); + Test entity = (Test) unmarshaller.unmarshal(inputSource); + assertNotNull (entity); + + Duration duration = entity.getDuration(); + assertNotNull(duration); + assertEquals(30, duration.getMinute()); + assertEquals(12, duration.getSeconds()); + assertEquals(357, duration.getMilli()); + } + +} Index: src/test/java/xml/c2044/generated/Test.java =================================================================== --- src/test/java/xml/c2044/generated/Test.java (Revision 0) +++ src/test/java/xml/c2044/generated/Test.java (Revision 0) @@ -0,0 +1,144 @@ +/* + * This class was automatically generated with + * Castor 1.1.2.1, using an XML + * Schema. + * $Id$ + */ + +package xml.c2044.generated; + + //---------------------------------/ + //- Imported classes and packages -/ +//---------------------------------/ + +import org.exolab.castor.xml.Marshaller; +import org.exolab.castor.xml.Unmarshaller; + +/** + * Class Test. + * + * @version $Revision$ $Date$ + */ +public class Test implements java.io.Serializable { + + + //--------------------------/ + //- Class/Member Variables -/ + //--------------------------/ + + /** + * Field _duration. + */ + private org.exolab.castor.types.Duration _duration; + + + //----------------/ + //- Constructors -/ + //----------------/ + + public Test() { + super(); + } + + + //-----------/ + //- Methods -/ + //-----------/ + + /** + * Returns the value of field 'duration'. + * + * @return the value of field 'Duration'. + */ + public org.exolab.castor.types.Duration getDuration( + ) { + return this._duration; + } + + /** + * Method isValid. + * + * @return true if this object is valid according to the schema + */ + public boolean isValid( + ) { + try { + validate(); + } catch (org.exolab.castor.xml.ValidationException vex) { + return false; + } + return true; + } + + /** + * + * + * @param out + * @throws org.exolab.castor.xml.MarshalException if object is + * null or if any SAXException is thrown during marshaling + * @throws org.exolab.castor.xml.ValidationException if this + * object is an invalid instance according to the schema + */ + public void marshal( + final java.io.Writer out) + throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException { + Marshaller.marshal(this, out); + } + + /** + * + * + * @param handler + * @throws java.io.IOException if an IOException occurs during + * marshaling + * @throws org.exolab.castor.xml.ValidationException if this + * object is an invalid instance according to the schema + * @throws org.exolab.castor.xml.MarshalException if object is + * null or if any SAXException is thrown during marshaling + */ + public void marshal( + final org.xml.sax.ContentHandler handler) + throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException { + Marshaller.marshal(this, handler); + } + + /** + * Sets the value of field 'duration'. + * + * @param duration the value of field 'duration'. + */ + public void setDuration( + final org.exolab.castor.types.Duration duration) { + this._duration = duration; + } + + /** + * Method unmarshal. + * + * @param reader + * @throws org.exolab.castor.xml.MarshalException if object is + * null or if any SAXException is thrown during marshaling + * @throws org.exolab.castor.xml.ValidationException if this + * object is an invalid instance according to the schema + * @return the unmarshaled xml.c2044.generated.Test + */ + public static xml.c2044.generated.Test unmarshal( + final java.io.Reader reader) + throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException { + return (xml.c2044.generated.Test) Unmarshaller.unmarshal(xml.c2044.generated.Test.class, reader); + } + + /** + * + * + * @throws org.exolab.castor.xml.ValidationException if this + * object is an invalid instance according to the schema + */ + public void validate( + ) + throws org.exolab.castor.xml.ValidationException { + org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator(); + validator.validate(this); + } + +} Index: src/test/java/xml/c2044/generated/.castor.cdr =================================================================== --- src/test/java/xml/c2044/generated/.castor.cdr (Revision 0) +++ src/test/java/xml/c2044/generated/.castor.cdr (Revision 0) @@ -0,0 +1,2 @@ +#Tue Sep 11 15:37:55 CEST 2007 +xml.c2044.generated.Test=xml.c2044.generated.descriptors.TestDescriptor Index: src/test/java/xml/c2044/generated/descriptors/TestDescriptor.java =================================================================== --- src/test/java/xml/c2044/generated/descriptors/TestDescriptor.java (Revision 0) +++ src/test/java/xml/c2044/generated/descriptors/TestDescriptor.java (Revision 0) @@ -0,0 +1,203 @@ +/* + * This class was automatically generated with + * Castor 1.1.2.1, using an XML + * Schema. + * $Id$ + */ + +package xml.c2044.generated.descriptors; + + //---------------------------------/ + //- Imported classes and packages -/ +//---------------------------------/ + +import xml.c2044.generated.Test; + +/** + * Class TestDescriptor. + * + * @version $Revision$ $Date$ + */ +public class TestDescriptor extends org.exolab.castor.xml.util.XMLClassDescriptorImpl { + + + //--------------------------/ + //- Class/Member Variables -/ + //--------------------------/ + + /** + * Field _elementDefinition. + */ + private boolean _elementDefinition; + + /** + * Field _nsPrefix. + */ + private java.lang.String _nsPrefix; + + /** + * Field _nsURI. + */ + private java.lang.String _nsURI; + + /** + * Field _xmlName. + */ + private java.lang.String _xmlName; + + /** + * Field _identity. + */ + private org.exolab.castor.xml.XMLFieldDescriptor _identity; + + + //----------------/ + //- Constructors -/ + //----------------/ + + public TestDescriptor() { + super(); + _xmlName = "test"; + _elementDefinition = true; + + //-- set grouping compositor + setCompositorAsSequence(); + org.exolab.castor.xml.util.XMLFieldDescriptorImpl desc = null; + org.exolab.castor.mapping.FieldHandler handler = null; + org.exolab.castor.xml.FieldValidator fieldValidator = null; + //-- initialize attribute descriptors + + //-- initialize element descriptors + + //-- _duration + desc = new org.exolab.castor.xml.util.XMLFieldDescriptorImpl(org.exolab.castor.types.Duration.class, "_duration", "duration", org.exolab.castor.xml.NodeType.Element); + handler = new org.exolab.castor.xml.XMLFieldHandler() { + public java.lang.Object getValue( java.lang.Object object ) + throws IllegalStateException + { + Test target = (Test) object; + return target.getDuration(); + } + public void setValue( java.lang.Object object, java.lang.Object value) + throws IllegalStateException, IllegalArgumentException + { + try { + Test target = (Test) object; + target.setDuration( (org.exolab.castor.types.Duration) value); + } catch (java.lang.Exception ex) { + throw new IllegalStateException(ex.toString()); + } + } + public java.lang.Object newInstance(java.lang.Object parent) { + return new org.exolab.castor.types.Duration(); + } + }; + desc.setSchemaType("duration"); + desc.setHandler(handler); + desc.setRequired(true); + desc.setMultivalued(false); + addFieldDescriptor(desc); + addSequenceElement(desc); + + //-- validation code for: _duration + fieldValidator = new org.exolab.castor.xml.FieldValidator(); + fieldValidator.setMinOccurs(1); + { //-- local scope + org.exolab.castor.xml.validators.DurationValidator typeValidator; + typeValidator = new org.exolab.castor.xml.validators.DurationValidator(); + fieldValidator.setValidator(typeValidator); + } + desc.setValidator(fieldValidator); + } + + + //-----------/ + //- Methods -/ + //-----------/ + + /** + * Method getAccessMode. + * + * @return the access mode specified for this class. + */ + public org.exolab.castor.mapping.AccessMode getAccessMode( + ) { + return null; + } + + /** + * Method getIdentity. + * + * @return the identity field, null if this class has no + * identity. + */ + public org.exolab.castor.mapping.FieldDescriptor getIdentity( + ) { + return _identity; + } + + /** + * Method getJavaClass. + * + * @return the Java class represented by this descriptor. + */ + public java.lang.Class getJavaClass( + ) { + return xml.c2044.generated.Test.class; + } + + /** + * Method getNameSpacePrefix. + * + * @return the namespace prefix to use when marshaling as XML. + */ + public java.lang.String getNameSpacePrefix( + ) { + return _nsPrefix; + } + + /** + * Method getNameSpaceURI. + * + * @return the namespace URI used when marshaling and + * unmarshaling as XML. + */ + public java.lang.String getNameSpaceURI( + ) { + return _nsURI; + } + + /** + * Method getValidator. + * + * @return a specific validator for the class described by this + * ClassDescriptor. + */ + public org.exolab.castor.xml.TypeValidator getValidator( + ) { + return this; + } + + /** + * Method getXMLName. + * + * @return the XML Name for the Class being described. + */ + public java.lang.String getXMLName( + ) { + return _xmlName; + } + + /** + * Method isElementDefinition. + * + * @return true if XML schema definition of this Class is that + * of a global + * element or element with anonymous type definition. + */ + public boolean isElementDefinition( + ) { + return _elementDefinition; + } + +} Index: src/test/resources/xml/c2044/input-including-milli.xml =================================================================== --- src/test/resources/xml/c2044/input-including-milli.xml (Revision 0) +++ src/test/resources/xml/c2044/input-including-milli.xml (Revision 0) @@ -0,0 +1,4 @@ + + + P1Y2M3DT10H30M12.357S + Index: src/test/resources/xml/c2044/test.xsd =================================================================== --- src/test/resources/xml/c2044/test.xsd (Revision 0) +++ src/test/resources/xml/c2044/test.xsd (Revision 0) @@ -0,0 +1,12 @@ + + + + + + + + + + + + Index: src/test/resources/xml/c2044/input.xml =================================================================== --- src/test/resources/xml/c2044/input.xml (Revision 0) +++ src/test/resources/xml/c2044/input.xml (Revision 0) @@ -0,0 +1,4 @@ + + + P1Y2M3DT10H30M12.3S +