Index: src/main/java/org/exolab/castor/xml/schema/ElementDecl.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/ElementDecl.java (Revision 6895) +++ src/main/java/org/exolab/castor/xml/schema/ElementDecl.java (Arbeitskopie) @@ -798,11 +798,11 @@ //--do you really allow parent to be null??? if (getParent() != null) { if (getParent().getStructureType() == Structure.SCHEMA) { - if (getMinOccurs() > 1) { + if (isMinOccursSet()) { String err = "'minOccurs' declaration is prohibited on top level element."; throw new ValidationException(err); } - if ((getMaxOccurs() >1) || (getMaxOccurs() < 0) ) { + if (isMaxOccursSet()) { String err = "'maxOccurs' declaration is prohibited on top level element."; throw new ValidationException(err); } Index: src/main/java/org/exolab/castor/xml/schema/Particle.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/Particle.java (Revision 6895) +++ src/main/java/org/exolab/castor/xml/schema/Particle.java (Arbeitskopie) @@ -62,6 +62,11 @@ * The maximum occurance **/ private int _maxOccurs = 1; + + /** + * Indicates whether maxOccurs has been set. + */ + private boolean _maxOccursSet = false; /** * The minimum occurance @@ -69,6 +74,11 @@ private int _minOccurs = 1; /** + * Indicates whether minOccurs has been set. + */ + private boolean _minOccursSet = false; + + /** * A constant to represent an UNBOUNDED particle */ public static int UNBOUNDED = -1; @@ -90,7 +100,9 @@ protected Particle(int minOccurs, int maxOccurs) { super(); setMinOccurs(minOccurs); + _minOccursSet = true; setMaxOccurs(maxOccurs); + _maxOccursSet = true; } //-- Particle /** @@ -124,6 +136,7 @@ **/ public final void setMaxOccurs(int maxOccurs) { _maxOccurs = maxOccurs; + _maxOccursSet = true; } //-- setMaxOccurs /** @@ -135,6 +148,7 @@ **/ public final void setMinOccurs(int minOccurs) { _minOccurs = minOccurs; + _minOccursSet = true; } //-- setMinOccurs /** @@ -148,5 +162,21 @@ } return false; } + + /** + * Indicates whetehr maxOccurs has been set. + * @return True if maxOccurs has been set. + */ + public final boolean isMaxOccursSet() { + return _maxOccursSet; + } + /** + * Indicates whether minOccurs has been set. + * @return True if minOccurs has been set. + */ + public final boolean isMinOccursSet() { + return _maxOccursSet; + } + } //-- CMParticle \ Kein Zeilenvorschub am Ende der Datei Index: src/main/java/org/exolab/castor/xml/schema/reader/ElementUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/ElementUnmarshaller.java (Revision 6895) +++ src/main/java/org/exolab/castor/xml/schema/reader/ElementUnmarshaller.java (Arbeitskopie) @@ -113,7 +113,7 @@ * @param resolver the resolver being used for reference resolving **/ public ElementUnmarshaller - (Schema schema, AttributeSet atts, Resolver resolver) + (final Schema schema, final AttributeSet atts, final Resolver resolver) throws XMLException { super(); @@ -122,9 +122,9 @@ this._schema = schema; _element = new ElementDecl(schema); - + String attValue = null; - + //-- @ref attValue = atts.getValue(SchemaNames.REF_ATTR); if (attValue != null) { Index: codegen/src/main/java/org/exolab/castor/builder/SourceGenerator.java =================================================================== --- codegen/src/main/java/org/exolab/castor/builder/SourceGenerator.java (Revision 6895) +++ codegen/src/main/java/org/exolab/castor/builder/SourceGenerator.java (Arbeitskopie) @@ -601,6 +601,13 @@ } Schema schema = schemaUnmarshaller.getSchema(); + + try { + schema.validate(); + } catch (ValidationException vx) { + throw new NestedIOException(vx); + } + generateSource(schema, packageName); } //-- generateSource