You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2001/08/28 20:50:48 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/v2 XSAttributeChecker.java XSDAbstractTraverser.java XSDHandler.java XSDSimpleTypeTraverser.java XSDocumentInfo.java
neilg 01/08/28 11:50:48
Modified: java/src/org/apache/xerces/impl/v2 XSAttributeChecker.java
XSDAbstractTraverser.java XSDHandler.java
XSDSimpleTypeTraverser.java XSDocumentInfo.java
Added: java/src/org/apache/xerces/util DOMUtil.java
Log:
acting a suggestion from AndyC, renaming XMLManipulator to DOMUtil.
Revision Changes Path
1.1 xml-xerces/java/src/org/apache/xerces/util/DOMUtil.java
Index: DOMUtil.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.util;
import org.apache.xerces.dom.AttrImpl;
import org.apache.xerces.dom.DocumentImpl;
import org.apache.xerces.dom.NodeImpl;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
/**
* Some useful utility methods.
* This class was modified in Xerces2 with a view to abstracting as
* much as possible away from the representation of the underlying
* parsed structure (i.e., the DOM). This was done so that, if Xerces
* ever adopts an in-memory representation more efficient than the DOM
* (such as a DTM), we should easily be able to convert our schema
* parsing to utilize it.
*
* @version $ID DOMUtil
*/
public class DOMUtil {
//
// Constructors
//
/** This class cannot be instantiated. */
protected DOMUtil() {}
//
// Public static methods
//
/**
* Copies the source tree into the specified place in a destination
* tree. The source node and its children are appended as children
* of the destination node.
* <p>
* <em>Note:</em> This is an iterative implementation.
*/
public static void copyInto(Node src, Node dest) throws DOMException {
// get node factory
Document factory = dest.getOwnerDocument();
boolean domimpl = factory instanceof DocumentImpl;
// placement variables
Node start = src;
Node parent = src;
Node place = src;
// traverse source tree
while (place != null) {
// copy this node
Node node = null;
int type = place.getNodeType();
switch (type) {
case Node.CDATA_SECTION_NODE: {
node = factory.createCDATASection(place.getNodeValue());
break;
}
case Node.COMMENT_NODE: {
node = factory.createComment(place.getNodeValue());
break;
}
case Node.ELEMENT_NODE: {
Element element = factory.createElement(place.getNodeName());
node = element;
NamedNodeMap attrs = place.getAttributes();
int attrCount = attrs.getLength();
for (int i = 0; i < attrCount; i++) {
Attr attr = (Attr)attrs.item(i);
String attrName = attr.getNodeName();
String attrValue = attr.getNodeValue();
element.setAttribute(attrName, attrValue);
if (domimpl && !attr.getSpecified()) {
((AttrImpl)element.getAttributeNode(attrName)).setSpecified(false);
}
}
break;
}
case Node.ENTITY_REFERENCE_NODE: {
node = factory.createEntityReference(place.getNodeName());
break;
}
case Node.PROCESSING_INSTRUCTION_NODE: {
node = factory.createProcessingInstruction(place.getNodeName(),
place.getNodeValue());
break;
}
case Node.TEXT_NODE: {
node = factory.createTextNode(place.getNodeValue());
break;
}
default: {
throw new IllegalArgumentException("can't copy node type, "+
type+" ("+
node.getNodeName()+')');
}
}
dest.appendChild(node);
// iterate over children
if (place.hasChildNodes()) {
parent = place;
place = place.getFirstChild();
dest = node;
}
// advance
else {
place = place.getNextSibling();
while (place == null && parent != start) {
place = parent.getNextSibling();
parent = parent.getParentNode();
dest = dest.getParentNode();
}
}
}
} // copyInto(Node,Node)
/** Finds and returns the first child element node. */
public static Element getFirstChildElement(Node parent) {
// search for node
Node child = parent.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
return (Element)child;
}
child = child.getNextSibling();
}
// not found
return null;
} // getFirstChildElement(Node):Element
/** Finds and returns the first visible child element node. */
public static Element getFirstVisibleChildElement(Node parent) {
// search for node
Node child = parent.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE &&
((NodeImpl)child).getReadOnly()) {
return (Element)child;
}
child = child.getNextSibling();
}
// not found
return null;
} // getFirstChildElement(Node):Element
/** Finds and returns the last child element node. */
public static Element getLastChildElement(Node parent) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
return (Element)child;
}
child = child.getPreviousSibling();
}
// not found
return null;
} // getLastChildElement(Node):Element
/** Finds and returns the last visible child element node. */
public static Element getLastVisibleChildElement(Node parent) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE &&
((NodeImpl)child).getReadOnly()) {
return (Element)child;
}
child = child.getPreviousSibling();
}
// not found
return null;
} // getLastChildElement(Node):Element
/** Finds and returns the next sibling element node. */
public static Element getNextSiblingElement(Node node) {
// search for node
Node sibling = node.getNextSibling();
while (sibling != null) {
if (sibling.getNodeType() == Node.ELEMENT_NODE) {
return (Element)sibling;
}
sibling = sibling.getNextSibling();
}
// not found
return null;
} // getNextSiblingElement(Node):Element
// get next visible (un-hidden) node.
public static Element getNextVisibleSiblingElement(Node node) {
// search for node
Node sibling = node.getNextSibling();
while (sibling != null) {
if (sibling.getNodeType() == Node.ELEMENT_NODE &&
((NodeImpl)sibling).getReadOnly()) {
return (Element)sibling;
}
sibling = sibling.getNextSibling();
}
// not found
return null;
} // getNextSiblingdElement(Node):Element
// set this Node as being hidden
public static void setHidden(Node node) {
((NodeImpl)node).setReadOnly(true, false);
} // setTraversed(node):void
// is this node hidden?
public static boolean isHidden(Node node) {
return ((NodeImpl)node).getReadOnly();
} // isHidden(Node):boolean
/** Finds and returns the first child node with the given name. */
public static Element getFirstChildElement(Node parent, String elemName) {
// search for node
Node child = parent.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
if (child.getNodeName().equals(elemName)) {
return (Element)child;
}
}
child = child.getNextSibling();
}
// not found
return null;
} // getFirstChildElement(Node,String):Element
/** Finds and returns the last child node with the given name. */
public static Element getLastChildElement(Node parent, String elemName) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
if (child.getNodeName().equals(elemName)) {
return (Element)child;
}
}
child = child.getPreviousSibling();
}
// not found
return null;
} // getLastChildElement(Node,String):Element
/** Finds and returns the next sibling node with the given name. */
public static Element getNextSiblingElement(Node node, String elemName) {
// search for node
Node sibling = node.getNextSibling();
while (sibling != null) {
if (sibling.getNodeType() == Node.ELEMENT_NODE) {
if (sibling.getNodeName().equals(elemName)) {
return (Element)sibling;
}
}
sibling = sibling.getNextSibling();
}
// not found
return null;
} // getNextSiblingdElement(Node,String):Element
/** Finds and returns the first child node with the given qualified name. */
public static Element getFirstChildElementNS(Node parent,
String uri, String localpart) {
// search for node
Node child = parent.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
String childURI = child.getNamespaceURI();
if (childURI != null && childURI.equals(uri) &&
child.getLocalName().equals(localpart)) {
return (Element)child;
}
}
child = child.getNextSibling();
}
// not found
return null;
} // getFirstChildElementNS(Node,String,String):Element
/** Finds and returns the last child node with the given qualified name. */
public static Element getLastChildElementNS(Node parent,
String uri, String localpart) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
String childURI = child.getNamespaceURI();
if (childURI != null && childURI.equals(uri) &&
child.getLocalName().equals(localpart)) {
return (Element)child;
}
}
child = child.getPreviousSibling();
}
// not found
return null;
} // getLastChildElementNS(Node,String,String):Element
/** Finds and returns the next sibling node with the given qualified name. */
public static Element getNextSiblingElementNS(Node node,
String uri, String localpart) {
// search for node
Node sibling = node.getNextSibling();
while (sibling != null) {
if (sibling.getNodeType() == Node.ELEMENT_NODE) {
String siblingURI = sibling.getNamespaceURI();
if (siblingURI != null && siblingURI.equals(uri) &&
sibling.getLocalName().equals(localpart)) {
return (Element)sibling;
}
}
sibling = sibling.getNextSibling();
}
// not found
return null;
} // getNextSiblingdElementNS(Node,String,String):Element
/** Finds and returns the first child node with the given name. */
public static Element getFirstChildElement(Node parent, String elemNames[]) {
// search for node
Node child = parent.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
for (int i = 0; i < elemNames.length; i++) {
if (child.getNodeName().equals(elemNames[i])) {
return (Element)child;
}
}
}
child = child.getNextSibling();
}
// not found
return null;
} // getFirstChildElement(Node,String[]):Element
/** Finds and returns the last child node with the given name. */
public static Element getLastChildElement(Node parent, String elemNames[]) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
for (int i = 0; i < elemNames.length; i++) {
if (child.getNodeName().equals(elemNames[i])) {
return (Element)child;
}
}
}
child = child.getPreviousSibling();
}
// not found
return null;
} // getLastChildElement(Node,String[]):Element
/** Finds and returns the next sibling node with the given name. */
public static Element getNextSiblingElement(Node node, String elemNames[]) {
// search for node
Node sibling = node.getNextSibling();
while (sibling != null) {
if (sibling.getNodeType() == Node.ELEMENT_NODE) {
for (int i = 0; i < elemNames.length; i++) {
if (sibling.getNodeName().equals(elemNames[i])) {
return (Element)sibling;
}
}
}
sibling = sibling.getNextSibling();
}
// not found
return null;
} // getNextSiblingdElement(Node,String[]):Element
/** Finds and returns the first child node with the given qualified name. */
public static Element getFirstChildElementNS(Node parent,
String[][] elemNames) {
// search for node
Node child = parent.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
for (int i = 0; i < elemNames.length; i++) {
String uri = child.getNamespaceURI();
if (uri != null && uri.equals(elemNames[i][0]) &&
child.getLocalName().equals(elemNames[i][1])) {
return (Element)child;
}
}
}
child = child.getNextSibling();
}
// not found
return null;
} // getFirstChildElementNS(Node,String[][]):Element
/** Finds and returns the last child node with the given qualified name. */
public static Element getLastChildElementNS(Node parent,
String[][] elemNames) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
for (int i = 0; i < elemNames.length; i++) {
String uri = child.getNamespaceURI();
if (uri != null && uri.equals(elemNames[i][0]) &&
child.getLocalName().equals(elemNames[i][1])) {
return (Element)child;
}
}
}
child = child.getPreviousSibling();
}
// not found
return null;
} // getLastChildElementNS(Node,String[][]):Element
/** Finds and returns the next sibling node with the given qualified name. */
public static Element getNextSiblingElementNS(Node node,
String[][] elemNames) {
// search for node
Node sibling = node.getNextSibling();
while (sibling != null) {
if (sibling.getNodeType() == Node.ELEMENT_NODE) {
for (int i = 0; i < elemNames.length; i++) {
String uri = sibling.getNamespaceURI();
if (uri != null && uri.equals(elemNames[i][0]) &&
sibling.getLocalName().equals(elemNames[i][1])) {
return (Element)sibling;
}
}
}
sibling = sibling.getNextSibling();
}
// not found
return null;
} // getNextSiblingdElementNS(Node,String[][]):Element
/**
* Finds and returns the first child node with the given name and
* attribute name, value pair.
*/
public static Element getFirstChildElement(Node parent,
String elemName,
String attrName,
String attrValue) {
// search for node
Node child = parent.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element)child;
if (element.getNodeName().equals(elemName) &&
element.getAttribute(attrName).equals(attrValue)) {
return element;
}
}
child = child.getNextSibling();
}
// not found
return null;
} // getFirstChildElement(Node,String,String,String):Element
/**
* Finds and returns the last child node with the given name and
* attribute name, value pair.
*/
public static Element getLastChildElement(Node parent,
String elemName,
String attrName,
String attrValue) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element)child;
if (element.getNodeName().equals(elemName) &&
element.getAttribute(attrName).equals(attrValue)) {
return element;
}
}
child = child.getPreviousSibling();
}
// not found
return null;
} // getLastChildElement(Node,String,String,String):Element
/**
* Finds and returns the next sibling node with the given name and
* attribute name, value pair. Since only elements have attributes,
* the node returned will be of type Node.ELEMENT_NODE.
*/
public static Element getNextSiblingElement(Node node,
String elemName,
String attrName,
String attrValue) {
// search for node
Node sibling = node.getNextSibling();
while (sibling != null) {
if (sibling.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element)sibling;
if (element.getNodeName().equals(elemName) &&
element.getAttribute(attrName).equals(attrValue)) {
return element;
}
}
sibling = sibling.getNextSibling();
}
// not found
return null;
} // getNextSiblingElement(Node,String,String,String):Element
/**
* Returns the concatenated child text of the specified node.
* This method only looks at the immediate children of type
* <code>Node.TEXT_NODE</code> or the children of any child
* node that is of type <code>Node.CDATA_SECTION_NODE</code>
* for the concatenation.
*
* @param node The node to look at.
*/
public static String getChildText(Node node) {
// is there anything to do?
if (node == null) {
return null;
}
// concatenate children text
StringBuffer str = new StringBuffer();
Node child = node.getFirstChild();
while (child != null) {
short type = child.getNodeType();
if (type == Node.TEXT_NODE) {
str.append(child.getNodeValue());
}
else if (type == Node.CDATA_SECTION_NODE) {
str.append(getChildText(child));
}
child = child.getNextSibling();
}
// return text value
return str.toString();
} // getChildText(Node):String
// return the name of this element
public static String getLocalName(Node node) {
return node.getLocalName();
} // getLocalName(Element): String
public static Element getParent(Element elem) {
return (Element)elem.getParentNode();
} // getParent(Element):Element
// get the Document of which this Node is a part
public static Document getDocument(Node node) {
return node.getOwnerDocument();
} // getDocument(Node):Document
// return this Document's root node
public static Element getRoot(Document doc) {
return doc.getDocumentElement();
} // getRoot(Document(: Element
// some methods for handling attributes:
// return the right attribute node
public static Attr getAttr(Element elem, String name) {
return elem.getAttributeNode(name);
} // getAttr(Element, String):Attr
// return the right attribute node
public static Attr getAttrNS(Element elem, String nsUri,
String localName) {
return elem.getAttributeNodeNS(nsUri, localName);
} // getAttrNS(Element, String):Attr
// get all the attributes for an Element
public static Attr[] getAttrs(Element elem) {
NamedNodeMap attrMap = elem.getAttributes();
Attr [] attrArray = new Attr[attrMap.getLength()];
for (int i=0; i<attrMap.getLength(); i++)
attrArray[i] = (Attr)attrMap.item(i);
return attrArray;
} // getAttrs(Element): Attr[]
// get attribute's value
public static String getValue(Attr attribute) {
return attribute.getValue();
} // getValue(Attr):String
// It is noteworthy that, because of the way the DOM specs
// work, the next two methods return the empty string (not
// null!) when the attribute with the specified name does not
// exist on an element. Beware!
// return the value of the attribute of the given element
// with the given name
public static String getAttrValue(Element elem, String name) {
return elem.getAttribute(name);
} // getAttr(Element, String):Attr
// return the value of the attribute of the given element
// with the given name
public static String getAttrValueNS(Element elem, String nsUri,
String localName) {
return elem.getAttributeNS(nsUri, localName);
} // getAttrValueNS(Element, String):Attr
// return the namespace URI
public static String getNamespaceURI(Node node) {
return node.getNamespaceURI();
}
} // class XUtil
1.6 +13 -13 xml-xerces/java/src/org/apache/xerces/impl/v2/XSAttributeChecker.java
Index: XSAttributeChecker.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSAttributeChecker.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XSAttributeChecker.java 2001/08/27 22:53:56 1.5
+++ XSAttributeChecker.java 2001/08/28 18:50:48 1.6
@@ -61,7 +61,7 @@
import org.w3c.dom.*;
import org.apache.xerces.impl.v2.datatypes.*;
import org.apache.xerces.impl.XMLErrorReporter;
-import org.apache.xerces.util.XMLManipulator;
+import org.apache.xerces.util.DOMUtil;
import org.apache.xerces.xni.QName;
/*import org.apache.xerces.validators.common.XMLAttributeDecl;
import org.apache.xerces.validators.common.GrammarResolver;
@@ -69,7 +69,7 @@
*/
/**
- * @version $Id: XSAttributeChecker.java,v 1.5 2001/08/27 22:53:56 sandygao Exp $
+ * @version $Id: XSAttributeChecker.java,v 1.6 2001/08/28 18:50:48 neilg Exp $
*/
public class XSAttributeChecker {
@@ -942,10 +942,10 @@
// if the parent is xs:appInfo or xs:documentation,
// then skip the validation, and return am empty list
- Element parent = XMLManipulator.getParent(element);
+ Element parent = DOMUtil.getParent(element);
if (parent != null) {
- String pUri = XMLManipulator.getNamespaceURI(parent);
- String pName = XMLManipulator.getLocalName(parent);
+ String pUri = DOMUtil.getNamespaceURI(parent);
+ String pName = DOMUtil.getLocalName(parent);
if (pUri.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA) &&
(pName.equals(SchemaSymbols.ELT_APPINFO) ||
pName.equals(SchemaSymbols.ELT_DOCUMENTATION))) {
@@ -953,8 +953,8 @@
}
}
- String uri = XMLManipulator.getNamespaceURI(element);
- String elName = XMLManipulator.getLocalName(element), name;
+ String uri = DOMUtil.getNamespaceURI(element);
+ String elName = DOMUtil.getLocalName(element), name;
if (uri == null || !uri.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)) {
reportSchemaError("Con3X3ElementSchemaURI", new Object[] {elName});
@@ -968,7 +968,7 @@
name = PRE_GLOBAL + elName;
}
else {
- if (XMLManipulator.getAttr(element, SchemaSymbols.ATT_REF) == null)
+ if (DOMUtil.getAttr(element, SchemaSymbols.ATT_REF) == null)
name = PRE_LOC_NAME + elName;
else
name = PRE_LOC_REF + elName;
@@ -986,13 +986,13 @@
Hashtable attrList = oneEle.attrList;
// traverse all attributes
- Attr[] attrs = XMLManipulator.getAttrs(element);
+ Attr[] attrs = DOMUtil.getAttrs(element);
Attr sattr = null;
for (int i = 0; i < attrs.length; i++) {
sattr = attrs[i++];
// get the attribute name/value
- String attrName = XMLManipulator.getLocalName(sattr);
- String attrVal = XMLManipulator.getValue(sattr);
+ String attrName = DOMUtil.getLocalName(sattr);
+ String attrVal = DOMUtil.getValue(sattr);
// skip anything starts with x/X m/M l/L
// simply put their values in the return hashtable
@@ -1003,7 +1003,7 @@
// for attributes with namespace prefix
//
- String attrURI = XMLManipulator.getNamespaceURI(sattr);
+ String attrURI = DOMUtil.getNamespaceURI(sattr);
if (attrURI != null && attrURI.length() != 0) {
// attributes with schema namespace are not allowed
// and not allowed on "document" and "appInfo"
@@ -1100,7 +1100,7 @@
OneAttr oneAttr = reqAttrs[i];
// if the attribute appreared, skip to the next one
- if (XMLManipulator.getAttr(element, oneAttr.name) != null)
+ if (DOMUtil.getAttr(element, oneAttr.name) != null)
continue;
// if the attribute is required, report an error
1.6 +4 -4 xml-xerces/java/src/org/apache/xerces/impl/v2/XSDAbstractTraverser.java
Index: XSDAbstractTraverser.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSDAbstractTraverser.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XSDAbstractTraverser.java 2001/08/28 15:06:35 1.5
+++ XSDAbstractTraverser.java 2001/08/28 18:50:48 1.6
@@ -61,14 +61,14 @@
import org.apache.xerces.util.SymbolTable;
import org.w3c.dom.Element;
import java.util.Hashtable;
-import org.apache.xerces.util.XMLManipulator;
+import org.apache.xerces.util.DOMUtil;
/**
* Class <code>XSDAbstractTraverser</code> serves as the base class for all
* other <code>XSD???Traverser</code>s. It holds the common data and provide
* a unified way to initialize these data.
*
- * @version $Id: XSDAbstractTraverser.java,v 1.5 2001/08/28 15:06:35 elena Exp $
+ * @version $Id: XSDAbstractTraverser.java,v 1.6 2001/08/28 18:50:48 neilg Exp $
*/
abstract class XSDAbstractTraverser {
@@ -106,9 +106,9 @@
// so we assume it's always global.
Hashtable attrValues = fAttrChecker.checkAttributes(annotationDecl, true);
- for(Element child = XMLManipulator.getFirstChildElement(annotationDecl);
+ for(Element child = DOMUtil.getFirstChildElement(annotationDecl);
child != null;
- child = XMLManipulator.getNextSiblingElement(child)) {
+ child = DOMUtil.getNextSiblingElement(child)) {
String name = child.getLocalName();
// the only valid children of "annotation" are
1.9 +40 -32 xml-xerces/java/src/org/apache/xerces/impl/v2/XSDHandler.java
Index: XSDHandler.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSDHandler.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- XSDHandler.java 2001/08/28 15:06:35 1.8
+++ XSDHandler.java 2001/08/28 18:50:48 1.9
@@ -65,7 +65,7 @@
import org.apache.xerces.xni.parser.XMLEntityResolver;
import org.apache.xerces.xni.parser.XMLInputSource;
import org.apache.xerces.util.SymbolTable;
-import org.apache.xerces.util.XMLManipulator;
+import org.apache.xerces.util.DOMUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Attr;
@@ -86,7 +86,7 @@
* schema, other grammars may be constructed as a side-effect.
*
* @author Neil Graham, IBM
- * @version $Id: XSDHandler.java,v 1.8 2001/08/28 15:06:35 elena Exp $
+ * @version $Id: XSDHandler.java,v 1.9 2001/08/28 18:50:48 neilg Exp $
*/
class XSDHandler {
@@ -253,15 +253,15 @@
XSDocumentInfo currSchemaInfo = new
XSDocumentInfo(schemaRoot);
Vector dependencies = new Vector();
- Element rootNode = XMLManipulator.getRoot(schemaRoot);
+ Element rootNode = DOMUtil.getRoot(schemaRoot);
String schemaNamespace=EMPTY_STRING;
String schemaHint=null;
Document newSchemaRoot = null;
for (Element child =
- XMLManipulator.getFirstChildElement(rootNode);
+ DOMUtil.getFirstChildElement(rootNode);
child != null;
- child = XMLManipulator.getNextSiblingElement(child)) {
- String localName = XMLManipulator.getLocalName(child);
+ child = DOMUtil.getNextSiblingElement(child)) {
+ String localName = DOMUtil.getLocalName(child);
if (localName.equals(SchemaSymbols.ELT_ANNOTATION))
continue;
else if (localName.equals(SchemaSymbols.ELT_IMPORT)) {
@@ -316,85 +316,85 @@
XSDocumentInfo currSchemaDoc =
(XSDocumentInfo)schemasToProcess.pop();
Document currDoc = currSchemaDoc.fSchemaDoc;
- if(XMLManipulator.isHidden(currDoc)) {
+ if(DOMUtil.isHidden(currDoc)) {
// must have processed this already!
continue;
}
- Element currRoot = XMLManipulator.getRoot(currDoc);
+ Element currRoot = DOMUtil.getRoot(currDoc);
// process this schema's global decls
boolean dependenciesCanOccur = true;
for(Element globalComp =
- XMLManipulator.getFirstChildElement(currRoot);
+ DOMUtil.getFirstChildElement(currRoot);
globalComp != null;
- globalComp = XMLManipulator.getNextSiblingElement(globalComp)){
+ globalComp = DOMUtil.getNextSiblingElement(globalComp)){
// this loop makes sure the <schema> element ordering is
// also valid.
- if(XMLManipulator.getLocalName(globalComp).equals(SchemaSymbols.ELT_ANNOTATION)) {
+ if(DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_ANNOTATION)) {
//skip it; traverse it later
continue;
- } else if(XMLManipulator.getLocalName(globalComp).equals(SchemaSymbols.ELT_INCLUDE) ||
- XMLManipulator.getLocalName(globalComp).equals(SchemaSymbols.ELT_IMPORT)) {
+ } else if(DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_INCLUDE) ||
+ DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_IMPORT)) {
if(!dependenciesCanOccur) {
// REVISIT: schema element ordreing violation
}
// we've dealt with this; mark as traversed
- XMLManipulator.setHidden(globalComp);
- } else if(XMLManipulator.getLocalName(globalComp).equals(SchemaSymbols.ELT_REDEFINE)) {
+ DOMUtil.setHidden(globalComp);
+ } else if(DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_REDEFINE)) {
if(!dependenciesCanOccur) {
// REVISIT: schema element ordreing violation
}
- for(Element redefineComp = XMLManipulator.getFirstChildElement(globalComp);
+ for(Element redefineComp = DOMUtil.getFirstChildElement(globalComp);
redefineComp != null;
- redefineComp = XMLManipulator.getNextSiblingElement(redefineComp)) {
- String lName = XMLManipulator.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME);
+ redefineComp = DOMUtil.getNextSiblingElement(redefineComp)) {
+ String lName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME);
if(lName.length() == 0) // an error we'll catch later
continue;
String qName = currSchemaDoc.fTargetNamespace +","+lName;
- String componentType = XMLManipulator.getLocalName(globalComp);
+ String componentType = DOMUtil.getLocalName(redefineComp);
if(componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) {
checkForDuplicateNames(qName, fUnparsedAttributeGroupRegistry, globalComp, currSchemaDoc);
// the check will have changed our name;
- String targetLName = XMLManipulator.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME);
+ String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME);
// and all we need to do is error-check+rename our kkids:
// REVISIT!!!
-// renameRedefiningComponents(SchemaSymbols.ELT_ATTRIBUTEGROUP),
+// renameRedefiningComponents(redefineComp, SchemaSymbols.ELT_ATTRIBUTEGROUP),
// lName, targetLName);
} else if((componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) ||
(componentType.equals(SchemaSymbols.ELT_SIMPLETYPE))) {
checkForDuplicateNames(qName, fUnparsedTypeRegistry, globalComp, currSchemaDoc);
// the check will have changed our name;
- String targetLName = XMLManipulator.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME);
+ String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME);
// and all we need to do is error-check+rename our kkids:
// REVISIT!!!
if(componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) {
-// renameRedefiningComponents(SchemaSymbols.ELT_COMPLEXTYPE),
+// renameRedefiningComponents(redefineComp, SchemaSymbols.ELT_COMPLEXTYPE),
// lName, targetLName);
} else { // must be simpleType
-// renameRedefiningComponents(SchemaSymbols.ELT_SIMPLETYPE),
+// renameRedefiningComponents(redefineComp, SchemaSymbols.ELT_SIMPLETYPE),
// lName, targetLName);
}
} else if(componentType.equals(SchemaSymbols.ELT_GROUP)) {
checkForDuplicateNames(qName, fUnparsedGroupRegistry, globalComp, currSchemaDoc);
// the check will have changed our name;
- String targetLName = XMLManipulator.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME);
+ String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME);
// and all we need to do is error-check+rename our kkids:
// REVISIT!!!
-// renameRedefiningComponents(SchemaSymbols.ELT_GROUP),
+// renameRedefiningComponents(redefineComp, SchemaSymbols.ELT_GROUP),
// lName, targetLName);
} else {
// REVISIT: report schema element ordering error
}
} // end march through <redefine> children
// and now set as traversed
- XMLManipulator.setHidden(globalComp);
+ DOMUtil.setHidden(globalComp);
} else {
dependenciesCanOccur = false;
- String lName = XMLManipulator.getAttrValue(globalComp, SchemaSymbols.ATT_NAME);
+ String lName = DOMUtil.getAttrValue(globalComp, SchemaSymbols.ATT_NAME);
if(lName.length() == 0) // an error we'll catch later
continue;
String qName = currSchemaDoc.fTargetNamespace +","+lName;
- String componentType = XMLManipulator.getLocalName(globalComp);
+ String componentType = DOMUtil.getLocalName(globalComp);
if(componentType.equals(SchemaSymbols.ELT_ATTRIBUTE)) {
checkForDuplicateNames(qName, fUnparsedAttributeRegistry, globalComp, currSchemaDoc);
} else if(componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) {
@@ -415,7 +415,7 @@
} // end for
// now we're done with this one!
- XMLManipulator.setHidden(currDoc);
+ DOMUtil.setHidden(currDoc);
// now add the schemas this guy depends on
Vector currSchemaDepends = (Vector)fDependencyMap.get(currSchemaDoc);
for(int i = 0; i < currSchemaDepends.size(); i++) {
@@ -608,7 +608,7 @@
registry.put(qName, currComp);
} else {
Element collidingElem = (Element)objElem;
- XSDocumentInfo redefinedSchema = (XSDocumentInfo)(fRedefine2XSDMap.get(XMLManipulator.getParent(collidingElem)));
+ XSDocumentInfo redefinedSchema = (XSDocumentInfo)(fRedefine2XSDMap.get(DOMUtil.getParent(collidingElem)));
if(redefinedSchema == currSchema) { // object comp. okay here
// now have to do some renaming...
String newName = qName.substring(qName.lastIndexOf(','));
@@ -643,6 +643,14 @@
return null;
}
-
+ // the purpose of this method is to take the component of the
+ // specified type and rename references to itself so that they
+ // refer to the object being redefined. It takes special care of
+ // <group>s and <attributeGroup>s to ensure that information
+ // relating to implicit restrictions is preserved for those
+ // traversers.
+ private void renameRedefiningComponents(Element component, String componentType,
+ String oldName, String newName) {
+ } // renameRedefiningComponents(Element, String, String, String):void
} // XSDHandler
1.6 +28 -28 xml-xerces/java/src/org/apache/xerces/impl/v2/XSDSimpleTypeTraverser.java
Index: XSDSimpleTypeTraverser.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSDSimpleTypeTraverser.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XSDSimpleTypeTraverser.java 2001/08/28 15:06:35 1.5
+++ XSDSimpleTypeTraverser.java 2001/08/28 18:50:48 1.6
@@ -58,7 +58,7 @@
package org.apache.xerces.impl.v2;
import org.apache.xerces.impl.XMLErrorReporter;
-import org.apache.xerces.util.XMLManipulator;
+import org.apache.xerces.util.DOMUtil;
import org.apache.xerces.impl.v2.datatypes.NOTATIONDatatypeValidator;
import org.apache.xerces.impl.v2.datatypes.UnionDatatypeValidator;
import org.apache.xerces.impl.v2.datatypes.ListDatatypeValidator;
@@ -106,7 +106,7 @@
* {any attributes with non-schema namespace . . .}>
* Content: (annotation?, (simpleType*))
* </union>
- * @version $Id: XSDSimpleTypeTraverser.java,v 1.5 2001/08/28 15:06:35 elena Exp $
+ * @version $Id: XSDSimpleTypeTraverser.java,v 1.6 2001/08/28 18:50:48 neilg Exp $
*/
class XSDSimpleTypeTraverser extends XSDAbstractTraverser {
@@ -151,7 +151,7 @@
private String traverseSimpleTypeDecl(Element simpleTypeDecl) {
- String nameProperty = XMLManipulator.getAttrValue(simpleTypeDecl, SchemaSymbols.ATT_NAME);
+ String nameProperty = DOMUtil.getAttrValue(simpleTypeDecl, SchemaSymbols.ATT_NAME);
String qualifiedName = nameProperty;
@@ -195,11 +195,11 @@
// REVISIT!
// update _final_ registry
//----------------------------------------------------------
- Attr finalAttr = XMLManipulator.getAttr(simpleTypeDecl, SchemaSymbols.ATT_FINAL);
+ Attr finalAttr = DOMUtil.getAttr(simpleTypeDecl, SchemaSymbols.ATT_FINAL);
int finalProperty = 0;
if (finalAttr != null)
- finalProperty = parseFinalSet(XMLManipulator.getValue( finalAttr));
+ finalProperty = parseFinalSet(DOMUtil.getValue( finalAttr));
else
finalProperty = parseFinalSet(null);
@@ -218,7 +218,7 @@
//----------------------------------------------------------------------
//annotation?,(list|restriction|union)
//----------------------------------------------------------------------
- Element content = XMLManipulator.getFirstChildElement(simpleTypeDecl);
+ Element content = DOMUtil.getFirstChildElement(simpleTypeDecl);
content = checkContent(simpleTypeDecl, content, false);
if (content == null) {
return resetSimpleTypeNameStack(fSchemaHandler.EMPTY_STRING);
@@ -230,7 +230,7 @@
//----------------------------------------------------------------------
//use content.getLocalName for the cases there "xsd:" is a prefix, ei. "xsd:list"
//----------------------------------------------------------------------
- String varietyProperty = XMLManipulator.getLocalName(content); //content.getLocalName();
+ String varietyProperty = DOMUtil.getLocalName(content); //content.getLocalName();
String baseTypeQNameProperty = null;
Vector dTValidators = null;
int size = 0;
@@ -241,7 +241,7 @@
int numOfTypes = 0; //list/restriction = 1, union = "+"
if (varietyProperty.equals(SchemaSymbols.ELT_LIST)) { //traverse List
- baseTypeQNameProperty = XMLManipulator.getAttrValue(content, SchemaSymbols.ATT_ITEMTYPE);//content.getAttribute( SchemaSymbols.ATT_ITEMTYPE );
+ baseTypeQNameProperty = DOMUtil.getAttrValue(content, SchemaSymbols.ATT_ITEMTYPE);//content.getAttribute( SchemaSymbols.ATT_ITEMTYPE );
list = true;
if (fListName.length() != 0) { // parent is <list> datatype
reportCosListOfAtomic();
@@ -252,13 +252,13 @@
}
}
else if (varietyProperty.equals(SchemaSymbols.ELT_RESTRICTION)) { //traverse Restriction
- baseTypeQNameProperty = XMLManipulator.getAttrValue(content, SchemaSymbols.ATT_BASE);
+ baseTypeQNameProperty = DOMUtil.getAttrValue(content, SchemaSymbols.ATT_BASE);
//content.getAttribute( SchemaSymbols.ATT_BASE );
restriction= true;
}
else if (varietyProperty.equals(SchemaSymbols.ELT_UNION)) { //traverse union
union = true;
- baseTypeQNameProperty = XMLManipulator.getAttrValue(content, SchemaSymbols.ATT_MEMBERTYPES);
+ baseTypeQNameProperty = DOMUtil.getAttrValue(content, SchemaSymbols.ATT_MEMBERTYPES);
//content.getAttribute( SchemaSymbols.ATT_MEMBERTYPES);
if (baseTypeQNameProperty.length() != 0) {
unionMembers = new StringTokenizer( baseTypeQNameProperty );
@@ -275,7 +275,7 @@
// new Object [] { varietyProperty });
// return fSchemaHandler.EMPTY_STRING;
}
- if (XMLManipulator.getNextSiblingElement(content) != null) {
+ if (DOMUtil.getNextSiblingElement(content) != null) {
// REVISIT: Localize
reportGenericSchemaError("error in content of simpleType");
}
@@ -288,14 +288,14 @@
//---------------------------
//content = {annotation?,simpleType?...}
- content = XMLManipulator.getFirstChildElement(content);
+ content = DOMUtil.getFirstChildElement(content);
//check content (annotation?, ...)
content = checkContent(simpleTypeDecl, content, false);
if (content == null) {
return resetSimpleTypeNameStack(fSchemaHandler.EMPTY_STRING);
}
- if (XMLManipulator.getLocalName(content).equals( SchemaSymbols.ELT_SIMPLETYPE )) {
+ if (DOMUtil.getLocalName(content).equals( SchemaSymbols.ELT_SIMPLETYPE )) {
simpleTypeName = traverse(content, fSchemaDoc, fGrammar);
if (!simpleTypeName.equals(fSchemaHandler.EMPTY_STRING)) {
baseValidator=fSchemaHandler.getSimpleTypeValidator(simpleTypeName);
@@ -373,10 +373,10 @@
// <base!=empty)->[facets]
// ------------------------------------------
if (baseTypeQNameProperty.length() == 0) {
- content = XMLManipulator.getNextSiblingElement( content );
+ content = DOMUtil.getNextSiblingElement( content );
}
else {
- content = XMLManipulator.getFirstChildElement(content);
+ content = DOMUtil.getFirstChildElement(content);
}
// ------------------------------------------
@@ -407,7 +407,7 @@
// simpleTypeDecl.getAttribute(SchemaSymbols.ATT_NAME)});
return fSchemaHandler.EMPTY_STRING;
}
- content = XMLManipulator.getNextSiblingElement( content );
+ content = DOMUtil.getNextSiblingElement( content );
}
} // end - traverse Union
@@ -433,10 +433,10 @@
// General Attribute Checking
fAttributes = fAttrChecker.checkAttributes(content, false);
numFacets++;
- facet = XMLManipulator.getLocalName(content);
+ facet = DOMUtil.getLocalName(content);
if (facet.equals(SchemaSymbols.ELT_ENUMERATION)) {
numEnumerationLiterals++;
- String enumVal = XMLManipulator.getAttrValue(content, SchemaSymbols.ATT_VALUE);
+ String enumVal = DOMUtil.getAttrValue(content, SchemaSymbols.ATT_VALUE);
String localName;
if (baseValidator instanceof NOTATIONDatatypeValidator) {
String prefix = "";
@@ -462,7 +462,7 @@
enumVal=nameProperty;
}
enumData.addElement(enumVal);
- checkContent(simpleTypeDecl, XMLManipulator.getFirstChildElement( content ), true);
+ checkContent(simpleTypeDecl, DOMUtil.getFirstChildElement( content ), true);
}
else if (facet.equals(SchemaSymbols.ELT_ANNOTATION) || facet.equals(SchemaSymbols.ELT_SIMPLETYPE)) {
//REVISIT:
@@ -472,15 +472,15 @@
else if (facet.equals(SchemaSymbols.ELT_PATTERN)) {
if (fPattern == null) {
//REVISIT: size of buffer
- fPattern = new StringBuffer (XMLManipulator.getAttrValue( content, SchemaSymbols.ATT_VALUE ));
+ fPattern = new StringBuffer (DOMUtil.getAttrValue( content, SchemaSymbols.ATT_VALUE ));
}
else {
// ---------------------------------------------
//datatypes: 5.2.4 pattern: src-multiple-pattern
// ---------------------------------------------
fPattern.append("|");
- fPattern.append(XMLManipulator.getAttrValue(content, SchemaSymbols.ATT_VALUE ));
- checkContent(simpleTypeDecl, XMLManipulator.getFirstChildElement( content ), true);
+ fPattern.append(DOMUtil.getAttrValue(content, SchemaSymbols.ATT_VALUE ));
+ checkContent(simpleTypeDecl, DOMUtil.getFirstChildElement( content ), true);
}
}
else {
@@ -526,10 +526,10 @@
flags |= DatatypeValidator.FACET_WHITESPACE;
}
}
- checkContent(simpleTypeDecl, XMLManipulator.getFirstChildElement( content ), true);
+ checkContent(simpleTypeDecl, DOMUtil.getFirstChildElement( content ), true);
}
}
- content = XMLManipulator.getNextSiblingElement(content);
+ content = DOMUtil.getNextSiblingElement(content);
}
if (numEnumerationLiterals > 0) {
fFacetData.put(SchemaSymbols.ELT_ENUMERATION, enumData);
@@ -643,8 +643,8 @@
baseRefContext == SchemaSymbols.RESTRICTION) {
//REVISIT
//reportSchemaError(SchemaMessageProvider.UnknownBaseDatatype,
- // new Object [] { XMLManipulator.getAttrValue(elm, SchemaSymbols.ATT_BASE),
- // XMLManipulator.getAttrValue(elm, SchemaSymbols.ATT_NAME)});
+ // new Object [] { DOMUtil.getAttrValue(elm, SchemaSymbols.ATT_BASE),
+ // DOMUtil.getAttrValue(elm, SchemaSymbols.ATT_NAME)});
return null;
}
baseValidator = fSchemaHandler.getDatatypeValidator(uri, localpart);
@@ -659,8 +659,8 @@
if (baseValidator == null) {
//REVISIT
//reportSchemaError(SchemaMessageProvider.UnknownBaseDatatype,
- // new Object [] { XMLManipulator.getAttrValue(elm, SchemaSymbols.ATT_BASE ),
- // XMLManipulator.getAttrValue(elm,SchemaSymbols.ATT_NAME)});
+ // new Object [] { DOMUtil.getAttrValue(elm, SchemaSymbols.ATT_BASE ),
+ // DOMUtil.getAttrValue(elm,SchemaSymbols.ATT_NAME)});
}
else {
finalValue =
1.3 +2 -2 xml-xerces/java/src/org/apache/xerces/impl/v2/XSDocumentInfo.java
Index: XSDocumentInfo.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSDocumentInfo.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XSDocumentInfo.java 2001/08/24 23:00:36 1.2
+++ XSDocumentInfo.java 2001/08/28 18:50:48 1.3
@@ -58,7 +58,7 @@
package org.apache.xerces.impl.v2;
import org.apache.xerces.util.NamespaceSupport;
-import org.apache.xerces.util.XMLManipulator;
+import org.apache.xerces.util.DOMUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.Hashtable;
@@ -96,7 +96,7 @@
XSDocumentInfo (Document schemaDoc) {
fSchemaDoc = schemaDoc;
- Element root = XMLManipulator.getRoot(schemaDoc);
+ Element root = DOMUtil.getRoot(schemaDoc);
// assign attributes appropriately according to
// generalAttrCheck as applied to root.
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org