sandygao 2004/02/03 09:10:38 Modified: java/src/org/apache/xerces/impl/xs XSConstraints.java XSModelImpl.java Log: Expose more information from the implementation of XSModel: 1. Whether this XSModel contains any IDC. 2. To get the substitution group for a give element declaration. Revision Changes Path 1.36 +8 -13 xml-xerces/java/src/org/apache/xerces/impl/xs/XSConstraints.java Index: XSConstraints.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XSConstraints.java,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- XSConstraints.java 11 Nov 2003 20:14:58 -0000 1.35 +++ XSConstraints.java 3 Feb 2004 17:10:38 -0000 1.36 @@ -506,8 +506,7 @@ int pType = particle.fType; - if (pType == XSParticleDecl.PARTICLE_EMPTY || - pType == XSParticleDecl.PARTICLE_WILDCARD) + if (pType == XSParticleDecl.PARTICLE_WILDCARD) return; if (pType == XSParticleDecl.PARTICLE_ELEMENT) { @@ -968,8 +967,7 @@ if (p.fType == XSParticleDecl.PARTICLE_ELEMENT || - p.fType == XSParticleDecl.PARTICLE_WILDCARD || - p.fType == XSParticleDecl.PARTICLE_EMPTY) + p.fType == XSParticleDecl.PARTICLE_WILDCARD) return null; Vector children = new Vector(); @@ -990,9 +988,6 @@ if (type == XSParticleDecl.PARTICLE_MODELGROUP) type = ((XSModelGroupImpl)p.fValue).fCompositor; - if (type == XSParticleDecl.PARTICLE_EMPTY) - return; - if (type == XSParticleDecl.PARTICLE_ELEMENT || type== XSParticleDecl.PARTICLE_WILDCARD) { children.addElement(p); @@ -1130,11 +1125,11 @@ if (checkWCOccurrence && !checkOccurrenceRange(min1,max1,min2,max2)) { throw new XMLSchemaException("rcase-NSCompat.2", new Object[]{ - elem.fName, - Integer.toString(min1), - max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1), - Integer.toString(min2), - max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)}); + elem.fName, + Integer.toString(min1), + max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1), + Integer.toString(min2), + max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)}); } // check wildcard allows namespace of element 1.12 +48 -2 xml-xerces/java/src/org/apache/xerces/impl/xs/XSModelImpl.java Index: XSModelImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XSModelImpl.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- XSModelImpl.java 8 Jan 2004 16:16:48 -0000 1.11 +++ XSModelImpl.java 3 Feb 2004 17:10:38 -0000 1.12 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 2002, 2003 The Apache Software Foundation. All rights + * Copyright (c) 2002-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -134,6 +134,8 @@ private SchemaGrammar[] fGrammarList; // a map from namespace to schema grammar private SymbolHash fGrammarMap; + // a map from element declaration to its substitution group + private SymbolHash fSubGroupMap; // store a certain kind of components from all namespaces private XSNamedMap[] fGlobalComponents; @@ -143,6 +145,9 @@ // store all annotations private XSObjectListImpl fAnnotations = null; + // whether there is any IDC in this XSModel + private boolean fHasIDC = false; + /** * Construct an XSModelImpl, by storing some grammars and grammars imported * by them to this object. @@ -205,11 +210,35 @@ fGrammarMap = new SymbolHash(len*2); for (i = 0; i < len; i++) { fGrammarMap.put(null2EmptyString(fNamespaces[i]), fGrammarList[i]); + // update the idc field + if (fGrammarList[i].hasIDConstraints()) + fHasIDC = true; } fGrammarCount = len; fGlobalComponents = new XSNamedMap[MAX_COMP_IDX+1]; fNSComponents = new XSNamedMap[len][MAX_COMP_IDX+1]; + + // build substitution groups + buildSubGroups(); + } + + private void buildSubGroups() { + SubstitutionGroupHandler sgHandler = new SubstitutionGroupHandler(null); + for (int i = 0 ; i < fGrammarCount; i++) { + sgHandler.addSubstitutionGroup(fGrammarList[i].getSubstitutionGroups()); + } + + XSNamedMap elements = getComponents(XSConstants.ELEMENT_DECLARATION); + int len = elements.getLength(); + fSubGroupMap = new SymbolHash(len*2); + XSElementDecl head; + XSElementDeclaration[] subGroup; + for (int i = 0; i < len; i++) { + head = (XSElementDecl)elements.item(i); + subGroup = sgHandler.getSubstitutionGroup(head); + fSubGroupMap.put(head, new XSObjectListImpl(subGroup, subGroup.length)); + } } /** @@ -469,5 +498,22 @@ return str == null ? XMLSymbols.EMPTY_STRING : str; } + /** + * REVISIT: to expose identity constraints from XSModel. + * For now, we only expose whether there are any IDCs. + * We also need to add these methods to the public + * XSModel interface. + */ + public boolean hasIDConstraints() { + return fHasIDC; + } + + /** + * REVISIT: to expose substitution group of a given element. + * We need to add this to the XSModel interface. + */ + public XSObjectList getSubstitutionGroup(XSElementDeclaration head) { + return (XSObjectList)fSubGroupMap.get(head); + } } // class XSModelImpl
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]