You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2005/02/21 14:40:29 UTC
cvs commit: ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg ComplexContentSG.java
jochen 2005/02/21 05:40:29
Modified: src/jaxme/org/apache/ws/jaxme/impl JMValidatorImpl.java
src/jaxme/org/apache/ws/jaxme/generator/sg/impl
JAXBComplexContentTypeSG.java
JAXBComplexTypeSG.java
src/jaxme/org/apache/ws/jaxme/generator/sg
ComplexContentSG.java
Removed: src/test/jaxb/jira mpeg7_tva.xsd
Log:
Added validation for JAXB SPEC 1.0, 5.9.7.
Revision Changes Path
1.4 +1 -1 ws-jaxme/src/jaxme/org/apache/ws/jaxme/impl/JMValidatorImpl.java
Index: JMValidatorImpl.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/impl/JMValidatorImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JMValidatorImpl.java 21 Feb 2005 09:15:23 -0000 1.3
+++ JMValidatorImpl.java 21 Feb 2005 13:40:29 -0000 1.4
@@ -63,6 +63,6 @@
}
public boolean validateRoot(Object pObject) throws JAXBException {
- throw new IllegalStateException("Not implemented, use validate(Object)");
+ return validate(pObject);
}
}
1.5 +185 -5 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBComplexContentTypeSG.java
Index: JAXBComplexContentTypeSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBComplexContentTypeSG.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JAXBComplexContentTypeSG.java 13 Oct 2004 22:51:53 -0000 1.4
+++ JAXBComplexContentTypeSG.java 21 Feb 2005 13:40:29 -0000 1.5
@@ -15,24 +15,61 @@
*/
package org.apache.ws.jaxme.generator.sg.impl;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.ws.jaxme.generator.sg.ComplexContentSG;
import org.apache.ws.jaxme.generator.sg.ComplexContentSGChain;
import org.apache.ws.jaxme.generator.sg.ComplexTypeSG;
import org.apache.ws.jaxme.generator.sg.GroupSG;
+import org.apache.ws.jaxme.generator.sg.ObjectSG;
+import org.apache.ws.jaxme.generator.sg.ParticleSG;
import org.apache.ws.jaxme.xs.XSGroup;
import org.apache.ws.jaxme.xs.XSParticle;
import org.apache.ws.jaxme.xs.XSType;
+import org.xml.sax.Locator;
import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
/** Default implementation of
* {@link org.apache.ws.jaxme.generator.sg.ComplexContentSG}.
*/
public class JAXBComplexContentTypeSG implements ComplexContentSGChain {
- private final GroupSG groupSG;
+ private static class Particle {
+ private final GroupSG[] stack;
+ private final ParticleSG particle;
+ Particle(GroupSG[] pStack, ParticleSG pParticle) {
+ stack = pStack;
+ particle = pParticle;
+ }
+ ParticleSG getParticleSG() { return particle; }
+ Object[] getStack() { return stack; }
+ GroupSG getClosestCommonAnchestor(Particle pParticle) {
+ int len = Math.min(stack.length, pParticle.stack.length);
+ GroupSG anchestor = stack[0];
+ for (int i = 1; i < len; i++) {
+ if (stack[i] != pParticle.stack[i]) {
+ break;
+ }
+ }
+ return anchestor;
+ }
+ }
+ private final GroupSG groupSG;
private final boolean isEmpty, isMixed;
-
+
+ private boolean isInitialized;
+ private final Locator locator;
+ private final List elementParticles = new ArrayList();
+ private Particle[] elementParticleArray;
+ private final List mixedContentParticles = new ArrayList();
+ private final List groupParticlesWithMultiplicityGreaterOne = new ArrayList();
+ private final List wildcardParticles = new ArrayList();
+ private final List stack = new ArrayList();
+
protected JAXBComplexContentTypeSG(ComplexTypeSG pComplexTypeSG, XSType pType) throws SAXException {
+ locator = pType.getLocator();
if (pType.getComplexType().isEmpty()) {
groupSG = null;
isEmpty = true;
@@ -52,10 +89,17 @@
isMixed = pType.getComplexType().isMixed();
}
}
+
+ public Locator getLocator(ComplexContentSG pController) { return locator; }
+
+ public void init(ComplexContentSG pController) throws SAXException {
+ }
- public void init(ComplexContentSG pController) throws SAXException {}
-
- public GroupSG getGroupSG(ComplexContentSG pController) {
+ public GroupSG getGroupSG(ComplexContentSG pController) throws SAXException {
+ if (!isInitialized && !isEmpty) {
+ isInitialized = true;
+ verify(pController);
+ }
return groupSG;
}
@@ -66,4 +110,140 @@
public boolean isMixed(ComplexContentSG pController) {
return isMixed;
}
+
+
+ private void findParticles(GroupSG[] pStack, ParticleSG pParticle) throws SAXException {
+ if (pParticle.isGroup()) {
+ if (pParticle.getMaxOccurs() > 1) {
+ groupParticlesWithMultiplicityGreaterOne.add(new Particle(pStack, pParticle));
+ } else {
+ findParticles(pParticle.getGroupSG());
+ }
+ } else if (pParticle.isWildcard()) {
+ wildcardParticles.add(new Particle(pStack, pParticle));
+ } else if (pParticle.isElement()) {
+ Particle p = new Particle(pStack, pParticle);
+ elementParticles.add(p);
+ } else {
+ throw new SAXParseException("Invalid particle type", pParticle.getLocator());
+ }
+ }
+
+ private String asString(Locator pLocator) {
+ StringBuffer sb = new StringBuffer();
+ String systemId = pLocator.getSystemId();
+ if (systemId != null) {
+ sb.append(systemId);
+ }
+ int lineNumber = pLocator.getLineNumber();
+ if (lineNumber != -1) {
+ if (sb.length() > 0) {
+ sb.append(", ");
+ }
+ sb.append("line ").append(lineNumber);
+ }
+ int colNumber = pLocator.getColumnNumber();
+ if (colNumber != -1) {
+ if (sb.length() > 0) {
+ sb.append(", ");
+ }
+ sb.append("column ").append(colNumber);
+ }
+ return sb.toString();
+ }
+
+ private void findParticles(GroupSG pGroup) throws SAXException {
+ stack.add(pGroup);
+ ParticleSG[] particles = pGroup.getParticles();
+ GroupSG[] groups = (GroupSG[]) stack.toArray(new GroupSG[stack.size()]);
+ for (int i = 0; i < particles.length; i++) {
+ findParticles(groups, particles[i]);
+ }
+ stack.remove(stack.size()-1);
+ }
+
+ /** Verifies the contents of a complex type with complex content, according
+ * to the JAXB 1.0 specification, 5.9.7.
+ */
+ private void verify(ComplexContentSG pController) throws SAXException {
+ findParticles(pController.getGroupSG());
+
+ /* 5.9.7, 1) If {content type} is mixed, bind the entire content model
+ * to a general content property with the content-property name "content".
+ * See Section 5.9.4, "Bind mixed content" for more details.
+ */
+ if (pController.isMixed()) {
+ throw new SAXParseException("Mixed content is not yet supported.",
+ pController.getLocator());
+ }
+ /* 5.9.7, 2) If (1) a particle has {max occurs} > 1 and (2) its term
+ * is a model group, then that particle and its descendants are mapped
+ * to one general content property that represents them. See Section
+ * 5.9.6, "Bind a repeating occurrence model group" for details.
+ */
+ if (groupParticlesWithMultiplicityGreaterOne.size() > 0) {
+ Particle particle = (Particle) groupParticlesWithMultiplicityGreaterOne.get(0);
+ throw new SAXParseException("Model groups with maxOccurs > 1 are not yet supported.",
+ particle.getParticleSG().getLocator());
+ }
+ /* 5.9.7, 3) Process all remaining particles 1) whose {term} are
+ * wildcard particles and (2) that did not belong to a repeating
+ * occurrence model group bound in step 2. If there is only one
+ * wildcard, bind it as specified in Section 5.9.5, "Bind wildcard
+ * schema component". If there is more than one, then fallback to
+ * representing the entire content model as a single general
+ * content property.
+ */
+ if (wildcardParticles.size() > 0) {
+ Particle particle = (Particle) wildcardParticles.get(0);
+ throw new SAXParseException("Wildcards are unsupported",
+ particle.getParticleSG().getLocator());
+ }
+ /* 5.9.7, 4) Process all particles (1) whose {term} are element
+ * declarations and (2) that do not belong to a repeating occurrence
+ * model group bound in step 2
+ *
+ * First we say a particle has a label L, if it refers to an element
+ * declaration whose {name} is L. Then, for all the possible pair of
+ * particles P and Q in this set, ensure the following constraints are
+ * met:
+ * a) If P and Q have the same label, then they must refer to the same
+ * element declaration.
+ * b) If P and Q refer to the same element reference, then its closest
+ * common ancestor particle may not have sequence as its {term}.
+ *
+ * If either of the above constraints are violated, then the binding
+ * compiler must report a property naming collision, that can be
+ * corrected via customization.
+ */
+ elementParticleArray = (Particle[]) elementParticles.toArray(new Particle[elementParticles.size()]);
+ for (int i = 0; i < elementParticleArray.length; i++) {
+ Particle pParticle = elementParticleArray[i];
+ ParticleSG p = pParticle.getParticleSG();
+ String name = p.getPropertySG().getXMLFieldName();
+ for (int j = i+1; j < elementParticles.size(); j++) {
+ Particle qParticle = elementParticleArray[j];
+ ParticleSG q = qParticle.getParticleSG();
+ if (name.equals(q.getPropertySG().getXMLFieldName())) {
+ ObjectSG pObject = p.getObjectSG();
+ ObjectSG qObject = q.getObjectSG();
+ if (!pObject.isGlobal() || !qObject.isGlobal() ||
+ pObject != qObject) {
+ throw new SAXParseException("Multiple element particles named " + name
+ + ", which aren't references to "
+ + " a common global element, are present in a common"
+ + " complex type. (JAXB 1.0, 5.9.7.4.a) Use jaxb:property/@name"
+ + " for customization.", pController.getLocator());
+ }
+ GroupSG group = pParticle.getClosestCommonAnchestor(pParticle);
+ if (group.isSequence()) {
+ throw new SAXParseException("Multiple element particles named " + name
+ + " are contained in a common sequence."
+ + " (JAXB 1.0, 5.9.7.4.b) Use jaxb:property/@name"
+ + " for customization.", pController.getLocator());
+ }
+ }
+ }
+ }
+ }
}
1.13 +1 -1 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBComplexTypeSG.java
Index: JAXBComplexTypeSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBComplexTypeSG.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- JAXBComplexTypeSG.java 8 Sep 2004 22:56:53 -0000 1.12
+++ JAXBComplexTypeSG.java 21 Feb 2005 13:40:29 -0000 1.13
@@ -171,7 +171,7 @@
complexContentSG.init();
}
}
-
+
public boolean hasSimpleContent(ComplexTypeSG pController) { return hasSimpleContent; }
public TypeSG getTypeSG(ComplexTypeSG pController) { return typeSG; }
1.5 +10 -5 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/ComplexContentSG.java
Index: ComplexContentSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/ComplexContentSG.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ComplexContentSG.java 13 Oct 2004 22:51:53 -0000 1.4
+++ ComplexContentSG.java 21 Feb 2005 13:40:29 -0000 1.5
@@ -15,6 +15,7 @@
*/
package org.apache.ws.jaxme.generator.sg;
+import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.apache.ws.jaxme.generator.sg.GroupSG;
@@ -22,10 +23,14 @@
/** Interface of a complex type with a complex content model.
*/
public interface ComplexContentSG {
- /** Initializes the ComplexContentSG.
- */
- public void init() throws SAXException;
-
+ /** <p>Returns the items location in the schema; useful for
+ * error messages.</p>
+ */
+ public Locator getLocator();
+
+ /** <p>Initializes the item.</p>
+ */
+ public void init() throws SAXException;
/** Returns, whether the types content model is empty.
*/
public boolean isEmpty();
@@ -36,5 +41,5 @@
/** <p>Returns the child elements.</p>
*/
- public GroupSG getGroupSG();
+ public GroupSG getGroupSG() throws SAXException;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org