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)
@@ -179,14 +179,14 @@
* @param name the name of the Element being declared
**/
public ElementDecl(Schema schema, String name) {
- super(1,1);
+ super();
+ setName(name);
if (schema == null) {
String err = NULL_ARGUMENT + "; 'schema' must not be null.";
throw new IllegalArgumentException(err);
}
- _schema = schema;
+ setSchema(schema);
_constraints = new Vector(3);
- setName(name);
} //-- ElementDecl
/**
@@ -798,12 +798,12 @@
//--do you really allow parent to be null???
if (getParent() != null) {
if (getParent().getStructureType() == Structure.SCHEMA) {
- if (getMinOccurs() > 1) {
- String err = "'minOccurs' declaration is prohibited on top level element.";
+ if (isMinOccursSet()) {
+ String err = "'minOccurs' declaration is prohibited on top level element '/" + getName() + "'.";
throw new ValidationException(err);
}
- if ((getMaxOccurs() >1) || (getMaxOccurs() < 0) ) {
- String err = "'maxOccurs' declaration is prohibited on top level element.";
+ if (isMaxOccursSet()) {
+ String err = "'maxOccurs' declaration is prohibited on top level element '/" + getName() + "'.";
throw new ValidationException(err);
}
}
@@ -852,6 +852,15 @@
}
- } //-- validate
+ } //-- validate
+
+ /**
+ * Sets the XMl schema to where this element has been defined
+ * @param schema The defining XML schema
+ */
+ private void setSchema(final Schema schema) {
+ _schema = schema;
+ }
+
} //-- Element
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;
@@ -81,19 +91,6 @@
} //-- Particle
/**
- * Constructor for Particle which allows setting the values for
- * maximum and minimum occurances
- *
- * @param minOccurs the minimum occurance
- * @param maxOccurs the maximum occurance ( -1 for unbounded)
- **/
- protected Particle(int minOccurs, int maxOccurs) {
- super();
- setMinOccurs(minOccurs);
- setMaxOccurs(maxOccurs);
- } //-- Particle
-
- /**
* Returns the maximum number of occurances that this CMParticle
* may appear
* @return the maximum number of occurances that this CMParticle
@@ -124,6 +121,7 @@
**/
public final void setMaxOccurs(int maxOccurs) {
_maxOccurs = maxOccurs;
+ _maxOccursSet = true;
} //-- setMaxOccurs
/**
@@ -135,6 +133,7 @@
**/
public final void setMinOccurs(int minOccurs) {
_minOccurs = minOccurs;
+ _minOccursSet = true;
} //-- setMinOccurs
/**
@@ -148,5 +147,21 @@
}
return false;
}
+
+ /**
+ * Indicates whetehr maxOccurs has been set.
+ * @return True if maxOccurs has been set.
+ */
+ protected final boolean isMaxOccursSet() {
+ return _maxOccursSet;
+ }
+ /**
+ * Indicates whether minOccurs has been set.
+ * @return True if minOccurs has been set.
+ */
+ protected final boolean isMinOccursSet() {
+ return _minOccursSet;
+ }
+
} //-- 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) {
@@ -235,10 +235,8 @@
int maxOccurs = toInt(attValue);
_element.setMaxOccurs(maxOccurs);
}
- else if (minOccurs > 0)
+ else if (minOccurs > 1)
_element.setMaxOccurs(minOccurs);
- else
- _element.setMaxOccurs(1);
charUnmarshaller = new CharacterUnmarshaller();
} //-- ElementUnmarshaller
Index: xmlctf/tests/MasterTestSuite/sourcegenerator/generationOnly/NameCollisions/javaLang/element/test.xsd
===================================================================
--- xmlctf/tests/MasterTestSuite/sourcegenerator/generationOnly/NameCollisions/javaLang/element/test.xsd (Revision 6895)
+++ xmlctf/tests/MasterTestSuite/sourcegenerator/generationOnly/NameCollisions/javaLang/element/test.xsd (Arbeitskopie)
@@ -4,6 +4,6 @@
elementFormDefault="qualified"
attributeFormDefault="unqualified">
-
+
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