You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@apache.org on 2005/05/10 17:36:43 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/xs XSComplexTypeDecl.java
ankitp 2005/05/10 08:36:42
Modified: java/src/org/apache/xerces/dom ElementNSImpl.java
CoreDOMImplementationImpl.java DOMNormalizer.java
java/src/org/apache/xerces/impl/dtd XMLDTDValidator.java
java/src/org/apache/xerces/impl/xs/traversers
XSDSimpleTypeTraverser.java
java/src/org/apache/xerces/impl/dv/xs XSSimpleTypeDecl.java
java/src/org/apache/xerces/impl/xs XSComplexTypeDecl.java
Log:
bug fixes
Revision Changes Path
1.48 +10 -3 xml-xerces/java/src/org/apache/xerces/dom/ElementNSImpl.java
Index: ElementNSImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ElementNSImpl.java,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- ElementNSImpl.java 2 May 2005 22:02:22 -0000 1.47
+++ ElementNSImpl.java 10 May 2005 15:36:42 -0000 1.48
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2002,2004 The Apache Software Foundation.
+ * Copyright 1999-2002,2004,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -424,7 +424,11 @@
*/
public String getTypeName() {
if (type !=null){
- return type.getName();
+ if (type instanceof XSSimpleTypeDefinition) {
+ return ((XSSimpleTypeDecl) type).getTypeName();
+ } else {
+ return ((XSComplexTypeDecl) type).getTypeName();
+ }
}
return null;
}
@@ -456,6 +460,9 @@
*/
public boolean isDerivedFrom(String typeNamespaceArg, String typeNameArg,
int derivationMethod) {
+ if(needsSyncData()) {
+ synchronizeData();
+ }
if (type != null) {
if (type instanceof XSSimpleTypeDefinition) {
return ((XSSimpleTypeDecl) type).isDOMDerivedFrom(
1.35 +53 -21 xml-xerces/java/src/org/apache/xerces/dom/CoreDOMImplementationImpl.java
Index: CoreDOMImplementationImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CoreDOMImplementationImpl.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- CoreDOMImplementationImpl.java 4 May 2005 04:23:46 -0000 1.34
+++ CoreDOMImplementationImpl.java 10 May 2005 15:36:42 -0000 1.35
@@ -18,6 +18,7 @@
import org.apache.xerces.impl.RevalidationHandler;
import org.apache.xerces.parsers.DOMParserImpl;
import org.apache.xerces.util.XMLChar;
+import org.apache.xerces.xni.grammars.XMLGrammarDescription;
import org.apache.xml.serialize.DOMSerializerImpl;
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
@@ -56,7 +57,10 @@
// validators pool
private static final int SIZE = 2;
private RevalidationHandler validators[] = new RevalidationHandler[SIZE];
+
+ private RevalidationHandler dtdValidators[] = new RevalidationHandler[SIZE];
private int freeValidatorIndex = -1;
+ private int freeDTDValidatorIndex = -1;
private int currentSize = SIZE;
// Document and doctype counter. Used to assign order to documents and
@@ -380,8 +384,8 @@
* reference to the default error handler.
*/
public LSSerializer createLSSerializer() {
- return new DOMSerializerImpl();
- }
+ return new DOMSerializerImpl();
+ }
/**
* DOM Level 3 LS CR - Experimental.
* Create a new empty input source.
@@ -397,36 +401,64 @@
/** NON-DOM: retrieve validator. */
synchronized RevalidationHandler getValidator(String schemaType) {
// REVISIT: implement retrieving DTD validator
- if (freeValidatorIndex < 0) {
+ if (schemaType == XMLGrammarDescription.XML_SCHEMA) {
// create new validator - we should not attempt
// to restrict the number of validation handlers being
// requested
- return (RevalidationHandler) (ObjectFactory
- .newInstance(
- "org.apache.xerces.impl.xs.XMLSchemaValidator",
- ObjectFactory.findClassLoader(),
- true));
-
+ if(freeValidatorIndex < 0) {
+ return (RevalidationHandler) (ObjectFactory
+ .newInstance(
+ "org.apache.xerces.impl.xs.XMLSchemaValidator",
+ ObjectFactory.findClassLoader(),
+ true));
+ }
+ // return first available validator
+ RevalidationHandler val = validators[freeValidatorIndex];
+ validators[freeValidatorIndex--] = null;
+ return val;
}
- // return first available validator
- RevalidationHandler val = validators[freeValidatorIndex];
- validators[freeValidatorIndex--] = null;
- return val;
+ else if(schemaType == XMLGrammarDescription.XML_DTD) {
+ if(freeDTDValidatorIndex < 0) {
+ return (RevalidationHandler) (ObjectFactory
+ .newInstance(
+ "org.apache.xerces.impl.dtd.XMLDTDValidator",
+ ObjectFactory.findClassLoader(),
+ true));
+ }
+ // return first available validator
+ RevalidationHandler val = dtdValidators[freeDTDValidatorIndex];
+ dtdValidators[freeDTDValidatorIndex--] = null;
+ return val;
+ }
+ return null;
}
/** NON-DOM: release validator */
synchronized void releaseValidator(String schemaType,
RevalidationHandler validator) {
// REVISIT: implement support for DTD validators as well
- ++freeValidatorIndex;
- if (validators.length == freeValidatorIndex ){
- // resize size of the validators
- currentSize+=SIZE;
- RevalidationHandler newarray[] = new RevalidationHandler[currentSize];
- System.arraycopy(validators, 0, newarray, 0, validators.length);
- validators = newarray;
+ if(schemaType == XMLGrammarDescription.XML_SCHEMA) {
+ ++freeValidatorIndex;
+ if (validators.length == freeValidatorIndex ){
+ // resize size of the validators
+ currentSize+=SIZE;
+ RevalidationHandler newarray[] = new RevalidationHandler[currentSize];
+ System.arraycopy(validators, 0, newarray, 0, validators.length);
+ validators = newarray;
+ }
+ validators[freeValidatorIndex]=validator;
+ }
+ else if(schemaType == XMLGrammarDescription.XML_DTD) {
+ ++freeDTDValidatorIndex;
+ if (dtdValidators.length == freeDTDValidatorIndex ){
+ // resize size of the validators
+ currentSize+=SIZE;
+ RevalidationHandler newarray[] = new RevalidationHandler[currentSize];
+ System.arraycopy(dtdValidators, 0, newarray, 0, dtdValidators.length);
+ dtdValidators = newarray;
+ }
+ dtdValidators[freeDTDValidatorIndex]=validator;
}
- validators[freeValidatorIndex]=validator;
}
/** NON-DOM: increment document/doctype counter */
1.61 +157 -45 xml-xerces/java/src/org/apache/xerces/dom/DOMNormalizer.java
Index: DOMNormalizer.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMNormalizer.java,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- DOMNormalizer.java 2 May 2005 22:02:22 -0000 1.60
+++ DOMNormalizer.java 10 May 2005 15:36:42 -0000 1.61
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2002,2004 The Apache Software Foundation.
+ * Copyright 1999-2002,2004, 2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,18 +17,24 @@
package org.apache.xerces.dom;
+import java.io.IOException;
+import java.io.StringReader;
import java.util.Vector;
-import org.w3c.dom.DOMError;
-import org.w3c.dom.DOMErrorHandler;
import org.apache.xerces.impl.Constants;
import org.apache.xerces.impl.RevalidationHandler;
+import org.apache.xerces.impl.dtd.DTDGrammar;
+import org.apache.xerces.impl.dtd.XMLDTDDescription;
+import org.apache.xerces.impl.dtd.XMLDTDValidator;
import org.apache.xerces.impl.dv.XSSimpleType;
-import org.apache.xerces.xs.XSTypeDefinition;
import org.apache.xerces.impl.xs.util.SimpleLocator;
+import org.apache.xerces.parsers.XMLGrammarPreparser;
import org.apache.xerces.util.AugmentationsImpl;
import org.apache.xerces.util.NamespaceSupport;
import org.apache.xerces.util.SymbolTable;
+import org.apache.xerces.util.XML11Char;
+import org.apache.xerces.util.XMLChar;
+import org.apache.xerces.util.XMLGrammarPoolImpl;
import org.apache.xerces.util.XMLSymbols;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.NamespaceContext;
@@ -40,23 +46,26 @@
import org.apache.xerces.xni.XMLString;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.grammars.XMLGrammarDescription;
+import org.apache.xerces.xni.grammars.XMLGrammarPool;
import org.apache.xerces.xni.parser.XMLComponent;
import org.apache.xerces.xni.parser.XMLDocumentSource;
+import org.apache.xerces.xni.parser.XMLInputSource;
import org.apache.xerces.xs.AttributePSVI;
import org.apache.xerces.xs.ElementPSVI;
+import org.apache.xerces.xs.XSTypeDefinition;
import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-import org.w3c.dom.ProcessingInstruction;
-import org.apache.xerces.util.XML11Char;
-import org.apache.xerces.util.XMLChar;
+import org.w3c.dom.Comment;
+import org.w3c.dom.DOMError;
+import org.w3c.dom.DOMErrorHandler;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
+import org.w3c.dom.Element;
import org.w3c.dom.Entity;
import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Comment;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
/**
* This class adds implementation for normalizeDocument method.
* It acts as if the document was going through a save and load cycle, putting
@@ -150,6 +159,12 @@
*/
public static final RuntimeException abort = new RuntimeException();
+ //DTD validator
+ private XMLDTDValidator fDTDValidator;
+
+ //Check if element content is all "ignorable whitespace"
+ private boolean allWhitespace = false;
+
// Constructor
//
@@ -174,21 +189,28 @@
fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING);
if ((fConfiguration.features & DOMConfigurationImpl.VALIDATE) != 0) {
- fValidationHandler =
- CoreDOMImplementationImpl.singleton.getValidator(XMLGrammarDescription.XML_SCHEMA);
- fConfiguration.setFeature(DOMConfigurationImpl.XERCES_VALIDATION, true);
- fConfiguration.setFeature(DOMConfigurationImpl.SCHEMA, true);
- // report fatal error on DOM Level 1 nodes
- fNamespaceValidation = true;
+ String schemaLang = (String)fConfiguration.getProperty(DOMConfigurationImpl.JAXP_SCHEMA_LANGUAGE);
+
+ if(schemaLang != null && schemaLang.equals(Constants.NS_XMLSCHEMA)) {
+ fValidationHandler =
+ CoreDOMImplementationImpl.singleton.getValidator(XMLGrammarDescription.XML_SCHEMA);
+ fConfiguration.setFeature(DOMConfigurationImpl.SCHEMA, true);
+ // report fatal error on DOM Level 1 nodes
+ fNamespaceValidation = true;
+
+ // check if we need to fill in PSVI
+ fPSVI = ((fConfiguration.features & DOMConfigurationImpl.PSVI) !=0)?true:false;
+ }
- // check if we need to fill in PSVI
- fPSVI = ((fConfiguration.features & DOMConfigurationImpl.PSVI) !=0)?true:false;
+ fConfiguration.setFeature(DOMConfigurationImpl.XERCES_VALIDATION, true);
// reset ID table
fDocument.clearIdentifiers();
+ if(fValidationHandler != null)
// reset schema validator
- ((XMLComponent) fValidationHandler).reset(fConfiguration);
+ ((XMLComponent) fValidationHandler).reset(fConfiguration);
+
}
fErrorHandler = (DOMErrorHandler) fConfiguration.getParameter(Constants.DOM_ERROR_HANDLER);
@@ -252,6 +274,15 @@
if (DEBUG_ND) {
System.out.println("==>normalizeNode:{doctype}");
}
+ DocumentTypeImpl docType = (DocumentTypeImpl)node;
+ fDTDValidator = (XMLDTDValidator)CoreDOMImplementationImpl.singleton.getValidator(XMLGrammarDescription.XML_DTD);
+ fDTDValidator.setDocumentHandler(this);
+ fConfiguration.setProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY, createGrammarPool(docType));
+ fDTDValidator.reset(fConfiguration);
+ fDTDValidator.startDocument(
+ new SimpleLocator(fDocument.fDocumentURI, fDocument.fDocumentURI,
+ -1, -1 ), fDocument.encoding, fNamespaceContext, null);
+ fDTDValidator.doctypeDecl(docType.getName(), docType.getPublicId(), docType.getSystemId(), null);
//REVISIT: well-formness encoding info
break;
}
@@ -348,6 +379,20 @@
// call re-validation handler
fValidationHandler.startElement(fQName, fAttrProxy, null);
}
+
+ if (fDTDValidator != null) {
+ // REVISIT: possible solutions to discard default content are:
+ // either we pass some flag to XML Schema validator
+ // or rely on the PSVI information.
+ fAttrProxy.setAttributes(attributes, fDocument, elem);
+ updateQName(elem, fQName); // updates global qname
+ // set error node in the dom error wrapper
+ // so if error occurs we can report an error node
+ fConfiguration.fErrorHandlerWrapper.fCurrentNode = node;
+ fCurrentNode = node;
+ // call re-validation handler
+ fDTDValidator.startElement(fQName, fAttrProxy, null);
+ }
// normalize children
Node kid, next;
@@ -378,6 +423,16 @@
fCurrentNode = node;
fValidationHandler.endElement(fQName, null);
}
+
+ if (fDTDValidator != null) {
+ updateQName(elem, fQName); // updates global qname
+ //
+ // set error node in the dom error wrapper
+ // so if error occurs we can report an error node
+ fConfiguration.fErrorHandlerWrapper.fCurrentNode = node;
+ fCurrentNode = node;
+ fDTDValidator.endElement(fQName, null);
+ }
// pop namespace context
fNamespaceContext.popContext();
@@ -477,6 +532,16 @@
fValidationHandler.characterData(node.getNodeValue(), null);
fValidationHandler.endCDATA(null);
}
+
+ if (fDTDValidator != null) {
+ // set error node in the dom error wrapper
+ // so if error occurs we can report an error node
+ fConfiguration.fErrorHandlerWrapper.fCurrentNode = node;
+ fCurrentNode = node;
+ fDTDValidator.startCDATA(null);
+ fDTDValidator.characterData(node.getNodeValue(), null);
+ fDTDValidator.endCDATA(null);
+ }
String value = node.getNodeValue();
if ((fConfiguration.features & DOMConfigurationImpl.SPLITCDATA) != 0) {
@@ -557,7 +622,20 @@
System.out.println("=====>characterData(),"+nextType);
}
- }
+ }
+ if (fDTDValidator != null) {
+ fConfiguration.fErrorHandlerWrapper.fCurrentNode = node;
+ fCurrentNode = node;
+ fDTDValidator.characterData(node.getNodeValue(), null);
+ if (DEBUG_ND) {
+ System.out.println("=====>characterData(),"+nextType);
+
+ }
+ if(allWhitespace) {
+ allWhitespace = false;
+ ((TextImpl)node).setIgnorableWhitespace(true);
+ }
+ }
}
else {
if (DEBUG_ND) {
@@ -603,6 +681,37 @@
return null;
}//normalizeNode
+ private XMLGrammarPool createGrammarPool(DocumentTypeImpl docType) {
+
+ XMLGrammarPoolImpl pool = new XMLGrammarPoolImpl();
+
+ XMLGrammarPreparser preParser = new XMLGrammarPreparser(fSymbolTable);
+ preParser.registerPreparser(XMLGrammarDescription.XML_DTD, null);
+ preParser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
+ preParser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, true);
+ preParser.setProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY, pool);
+
+ String internalSubset = docType.getInternalSubset();
+ XMLInputSource is = new XMLInputSource(docType.getPublicId(), docType.getSystemId(), null);
+
+ if(internalSubset != null)
+ is.setCharacterStream(new StringReader(internalSubset));
+ try {
+ DTDGrammar g = (DTDGrammar)preParser.preparseGrammar(XMLGrammarDescription.XML_DTD, is);
+ ((XMLDTDDescription)g.getGrammarDescription()).setRootName(docType.getName());
+ is.setCharacterStream(null);
+ g = (DTDGrammar)preParser.preparseGrammar(XMLGrammarDescription.XML_DTD, is);
+ ((XMLDTDDescription)g.getGrammarDescription()).setRootName(docType.getName());
+
+ } catch (XNIException e) {
+ } catch (IOException e) {
+ }
+
+ return pool;
+ }
+
+
+
protected final void expandEntityRef (Node parent, Node reference){
Node kid, next;
for (kid = reference.getFirstChild(); kid != null; kid = next) {
@@ -1822,6 +1931,7 @@
* Thrown by handler to signal an error.
*/
public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException{
+ allWhitespace = true;
}
/**
@@ -1838,30 +1948,32 @@
System.out.println("==>endElement: " + element);
}
- ElementPSVI elementPSVI = (ElementPSVI) augs.getItem(Constants.ELEMENT_PSVI);
- if (elementPSVI != null) {
- ElementImpl elementNode = (ElementImpl) fCurrentNode;
- if (fPSVI) {
- ((PSVIElementNSImpl) fCurrentNode).setPSVI(elementPSVI);
- }
- // include element default content (if one is available)
- String normalizedValue = elementPSVI.getSchemaNormalizedValue();
- if ((fConfiguration.features & DOMConfigurationImpl.DTNORMALIZATION) != 0) {
- if (normalizedValue !=null)
- elementNode.setTextContent(normalizedValue);
- }
- else {
- // NOTE: this is a hack: it is possible that DOM had an empty element
- // and validator sent default value using characters(), which we don't
- // implement. Thus, here we attempt to add the default value.
- String text = elementNode.getTextContent();
- if (text.length() == 0) {
- // default content could be provided
+ if(augs != null) {
+ ElementPSVI elementPSVI = (ElementPSVI) augs.getItem(Constants.ELEMENT_PSVI);
+ if (elementPSVI != null) {
+ ElementImpl elementNode = (ElementImpl) fCurrentNode;
+ if (fPSVI) {
+ ((PSVIElementNSImpl) fCurrentNode).setPSVI(elementPSVI);
+ }
+ // include element default content (if one is available)
+ String normalizedValue = elementPSVI.getSchemaNormalizedValue();
+ if ((fConfiguration.features & DOMConfigurationImpl.DTNORMALIZATION) != 0) {
if (normalizedValue !=null)
- elementNode.setTextContent(normalizedValue);
- }
- }
- }
+ elementNode.setTextContent(normalizedValue);
+ }
+ else {
+ // NOTE: this is a hack: it is possible that DOM had an empty element
+ // and validator sent default value using characters(), which we don't
+ // implement. Thus, here we attempt to add the default value.
+ String text = elementNode.getTextContent();
+ if (text.length() == 0) {
+ // default content could be provided
+ if (normalizedValue !=null)
+ elementNode.setTextContent(normalizedValue);
+ }
+ }
+ }
+ }
}
1.62 +9 -3 xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java
Index: XMLDTDValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -r1.61 -r1.62
--- XMLDTDValidator.java 4 Oct 2004 21:57:30 -0000 1.61
+++ XMLDTDValidator.java 10 May 2005 15:36:42 -0000 1.62
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package org.apache.xerces.impl.dtd;
import org.apache.xerces.impl.Constants;
+import org.apache.xerces.impl.RevalidationHandler;
import org.apache.xerces.impl.XMLEntityManager;
import org.apache.xerces.impl.XMLErrorReporter;
import org.apache.xerces.impl.dtd.models.ContentModelValidator;
@@ -81,7 +82,7 @@
* @version $Id$
*/
public class XMLDTDValidator
- implements XMLComponent, XMLDocumentFilter, XMLDTDValidatorFilter {
+ implements XMLComponent, XMLDocumentFilter, XMLDTDValidatorFilter, RevalidationHandler {
//
// Constants
@@ -2083,4 +2084,9 @@
return XMLChar.isSpace(c);
} // isSpace(int): boolean
+ public boolean characterData(String data, Augmentations augs) {
+ characters(new XMLString(data.toCharArray(), 0, data.length()), augs);
+ return true;
+ }
+
} // class XMLDTDValidator
1.31 +38 -21 xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDSimpleTypeTraverser.java
Index: XSDSimpleTypeTraverser.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDSimpleTypeTraverser.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- XSDSimpleTypeTraverser.java 20 Dec 2004 05:43:36 -0000 1.30
+++ XSDSimpleTypeTraverser.java 10 May 2005 15:36:42 -0000 1.31
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
import org.apache.xerces.impl.dv.SchemaDVFactory;
import org.apache.xerces.impl.dv.XSSimpleType;
import org.apache.xerces.impl.dv.xs.SchemaDVFactoryImpl;
+import org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl;
import org.apache.xerces.impl.xs.SchemaGrammar;
import org.apache.xerces.impl.xs.SchemaSymbols;
import org.apache.xerces.impl.xs.XSAnnotationImpl;
@@ -31,6 +32,7 @@
import org.apache.xerces.xni.QName;
import org.apache.xerces.xs.XSConstants;
import org.apache.xerces.xs.XSObjectList;
+import org.apache.xerces.xs.XSSimpleTypeDefinition;
import org.apache.xerces.xs.XSTypeDefinition;
import org.w3c.dom.Element;
@@ -121,7 +123,10 @@
// General Attribute Checking
Object[] attrValues = fAttrChecker.checkAttributes(elmNode, false, schemaDoc);
- XSSimpleType type = traverseSimpleTypeDecl (elmNode, attrValues, schemaDoc, grammar);
+ String name = genAnonTypeName(elmNode);
+ XSSimpleType type = getSimpleType (name, elmNode, attrValues, schemaDoc, grammar);
+ if(type instanceof XSSimpleTypeDefinition)
+ ((XSSimpleTypeDecl)type).setAnonymous(true);
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
return type;
@@ -134,9 +139,38 @@
// get name and final values
String name = (String)attrValues[XSAttributeChecker.ATTIDX_NAME];
+ return getSimpleType(name, simpleTypeDecl, attrValues, schemaDoc, grammar);
+ }
+
+ /*
+ * Generate a name for an anonymous type
+ */
+ private String genAnonTypeName(Element simpleTypeDecl) {
+
+ // Generate a unique name for the anonymous type by concatenating together the
+ // names of parent nodes
+ // The name is quite good for debugging/error purposes, but we may want to
+ // revisit how this is done for performance reasons (LM).
+ StringBuffer typeName = new StringBuffer("#AnonType_");
+ Element node = DOMUtil.getParent(simpleTypeDecl);
+ while (node != null && (node != DOMUtil.getRoot(DOMUtil.getDocument(node)))) {
+ typeName.append(node.getAttribute(SchemaSymbols.ATT_NAME));
+ node = DOMUtil.getParent(node);
+ }
+ return typeName.toString();
+ }
+
+ /**
+ * @param name
+ * @param simpleTypeDecl
+ * @param attrValues
+ * @param schemaDoc
+ * @param grammar
+ * @return
+ */
+ private XSSimpleType getSimpleType(String name, Element simpleTypeDecl, Object[] attrValues, XSDocumentInfo schemaDoc, SchemaGrammar grammar) {
XInt finalAttr = (XInt)attrValues[XSAttributeChecker.ATTIDX_FINAL];
int finalProperty = finalAttr == null ? schemaDoc.fFinalDefault : finalAttr.intValue();
-
// annotation?,(list|restriction|union)
Element child = DOMUtil.getFirstChildElement(simpleTypeDecl);
XSAnnotationImpl [] annotations = null;
@@ -153,13 +187,11 @@
annotations = new XSAnnotationImpl[] {annotation};
}
}
-
// (list|restriction|union)
if (child == null) {
reportSchemaError("s4s-elt-must-match.2", new Object[]{SchemaSymbols.ELT_SIMPLETYPE, "(annotation?, (restriction | list | union))"}, simpleTypeDecl);
return errorType(name, schemaDoc.fTargetNamespace, XSConstants.DERIVATION_RESTRICTION);
}
-
// derivation type: restriction/list/union
String varietyProperty = DOMUtil.getLocalName(child);
short refType = XSConstants.DERIVATION_RESTRICTION;
@@ -180,23 +212,19 @@
reportSchemaError("s4s-elt-must-match.1", new Object[]{SchemaSymbols.ELT_SIMPLETYPE, "(annotation?, (restriction | list | union))", varietyProperty}, simpleTypeDecl);
return errorType(name, schemaDoc.fTargetNamespace, XSConstants.DERIVATION_RESTRICTION);
}
-
// nothing should follow this element
Element nextChild = DOMUtil.getNextSiblingElement(child);
if (nextChild != null) {
reportSchemaError("s4s-elt-must-match.1", new Object[]{SchemaSymbols.ELT_SIMPLETYPE, "(annotation?, (restriction | list | union))", DOMUtil.getLocalName(nextChild)}, nextChild);
}
-
// General Attribute Checking: get base/item/member types
Object[] contentAttrs = fAttrChecker.checkAttributes(child, false, schemaDoc);
QName baseTypeName = (QName)contentAttrs[restriction ?
XSAttributeChecker.ATTIDX_BASE :
XSAttributeChecker.ATTIDX_ITEMTYPE];
Vector memberTypes = (Vector)contentAttrs[XSAttributeChecker.ATTIDX_MEMBERTYPES];
-
//content = {annotation?,simpleType?...}
Element content = DOMUtil.getFirstChildElement(child);
-
//check content (annotation?, ...)
if (content != null && DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_ANNOTATION)) {
XSAnnotationImpl annotation = traverseAnnotationDecl(content, contentAttrs, false, schemaDoc);
@@ -228,7 +256,6 @@
}
}
}
-
// get base type from "base" attribute
XSSimpleType baseValidator = null;
if ((restriction || list) && baseTypeName != null) {
@@ -239,7 +266,6 @@
return null;
}
}
-
// get types from "memberTypes" attribute
Vector dTValidators = null;
XSSimpleType dv = null;
@@ -264,12 +290,10 @@
}
}
}
-
// when there is an error finding the base type of a restriction
// we use anySimpleType as the base, then we should skip the facets,
// because anySimpleType doesn't recognize any facet.
boolean skipFacets = false;
-
// check if there is a child "simpleType"
if (content != null && DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_SIMPLETYPE)) {
if (restriction || list) {
@@ -319,7 +343,6 @@
dTValidators = new Vector(1);
dTValidators.addElement(SchemaGrammar.fAnySimpleType);
}
-
// error finding "base" or error traversing "simpleType".
// don't need to report an error, since some error has been reported.
if ((restriction || list) && baseValidator == null) {
@@ -331,12 +354,10 @@
dTValidators = new Vector(1);
dTValidators.addElement(SchemaGrammar.fAnySimpleType);
}
-
// item type of list types can't have list content
if (list && isListDatatype(baseValidator)) {
reportSchemaError("cos-st-restricts.2.1", new Object[]{name, baseValidator.getName()}, child);
}
-
// create the simple type based on the "base" type
XSSimpleType newDecl = null;
if (restriction) {
@@ -354,7 +375,6 @@
newDecl = schemaFactory.createTypeUnion(name, schemaDoc.fTargetNamespace, (short)finalProperty, memberDecls,
annotations == null? null : new XSObjectListImpl(annotations, annotations.length));
}
-
// now traverse facets, if it's derived by restriction
if (restriction && content != null) {
FacetInfo fi = traverseFacets(content, baseValidator, schemaDoc);
@@ -369,7 +389,6 @@
}
}
}
-
// now element should appear after this point
if (content != null) {
if (restriction) {
@@ -382,9 +401,7 @@
reportSchemaError("s4s-elt-must-match.1", new Object[]{SchemaSymbols.ELT_UNION, "(annotation?, (simpleType*))", DOMUtil.getLocalName(content)}, content);
}
}
-
fAttrChecker.returnAttrArray(contentAttrs, schemaDoc);
-
// return the new type
return newDecl;
}
1.69 +60 -15 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
Index: XSSimpleTypeDecl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -r1.68 -r1.69
--- XSSimpleTypeDecl.java 7 Apr 2005 17:37:07 -0000 1.68
+++ XSSimpleTypeDecl.java 10 May 2005 15:36:42 -0000 1.69
@@ -207,7 +207,7 @@
public void addIdRef(String name) {
}
public String getSymbol (String symbol) {
- return symbol.intern();
+ return symbol.intern();
}
public String getURI(String prefix) {
return null;
@@ -538,8 +538,12 @@
}
public String getName() {
- return fTypeName;
+ return getAnonymous()?null:fTypeName;
}
+
+ public String getTypeName() {
+ return fTypeName;
+ }
public String getNamespace() {
return fTargetNamespace;
@@ -558,7 +562,7 @@
}
public boolean getAnonymous() {
- return fTypeName == null;
+ return fAnonymous || (fTypeName == null);
}
public short getVariety(){
@@ -1560,6 +1564,8 @@
Object ob = validatedInfo.actualValue;
String content = validatedInfo.normalizedValue;
+ short type = validatedInfo.actualValueType;
+ ShortList itemType = validatedInfo.itemValueTypes;
// For QName and NOTATION types, we don't check length facets
if (fValidationDV != DV_QNAME && fValidationDV != DV_NOTATION) {
@@ -1594,9 +1600,18 @@
if ( ((fFacetsDefined & FACET_ENUMERATION) != 0 ) ) {
boolean present = false;
for (int i = 0; i < fEnumeration.size(); i++) {
- if (fEnumeration.elementAt(i).equals(ob)) {
- present = true;
- break;
+ if (fEnumerationType[i] == type && fEnumeration.elementAt(i).equals(ob)) {
+ if(type == XSConstants.LIST_DT || type == XSConstants.LISTOFUNION_DT) {
+ ShortList enumItemType = fEnumerationItemType[i];
+ if(enumItemType.equals(itemType)) {
+ present = true;
+ break;
+ }
+ }
+ else {
+ present = true;
+ break;
+ }
}
}
if(!present){
@@ -1812,9 +1827,31 @@
} catch(InvalidDatatypeValueException invalidValue) {
}
}
-
- throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.2",
- new Object[]{content, fTypeName});
+ StringBuffer typesBuffer = new StringBuffer();
+ XSSimpleTypeDecl decl;
+ for(int i = 0;i < fMemberTypes.length; i++) {
+ if(i != 0)
+ typesBuffer.append(" | ");
+ decl = fMemberTypes[i];
+ if(decl.fTargetNamespace != null) {
+ typesBuffer.append('{');
+ typesBuffer.append(decl.fTargetNamespace);
+ typesBuffer.append('}');
+ }
+ typesBuffer.append(decl.fTypeName);
+ if(decl.fEnumeration != null) {
+ Vector v = decl.fEnumeration;
+ typesBuffer.append(" : [");
+ for(int j = 0;j < v.size(); j++) {
+ if(j != 0)
+ typesBuffer.append(',');
+ typesBuffer.append(v.elementAt(j));
+ }
+ typesBuffer.append(']');
+ }
+ }
+ throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.3",
+ new Object[]{content, fTypeName, typesBuffer.toString()});
}
}//getActualValue()
@@ -2522,9 +2559,9 @@
XSTypeDefinition type) {
boolean derivedFrom = false;
-
+ XSTypeDefinition oldType = null;
// for each base, item or member type
- while (type != null) {
+ while (type != null && type != oldType) {
// If the ancestor type is reached or is the same as this type.
if ((ancestorName.equals(type.getName()))
@@ -2542,7 +2579,7 @@
} else if (isDerivedByUnion(ancestorNS, ancestorName, type)) {
return true;
}
-
+ oldType = type;
// get the base, item or member type depending on the variety
if (((XSSimpleTypeDecl) type).getVariety() == VARIETY_ABSENT
|| ((XSSimpleTypeDecl) type).getVariety() == VARIETY_ATOMIC) {
@@ -2577,13 +2614,15 @@
* reference type
*/
private boolean isDerivedByRestriction (String ancestorNS, String ancestorName, XSTypeDefinition type) {
- while (type != null) {
+ XSTypeDefinition oldType = null;
+ while (type != null && type != oldType) {
if ((ancestorName.equals(type.getName()))
&& ((ancestorNS != null && ancestorNS.equals(type.getNamespace()))
|| (type.getNamespace() == null && ancestorNS == null))) {
return true;
}
+ oldType = type;
type = type.getBaseType();
}
@@ -2698,13 +2737,15 @@
}
public String getSymbol (String symbol) {
- return symbol.intern();
+ return symbol.intern();
}
public String getURI(String prefix) {
return null;
}
};
+
+ private boolean fAnonymous = false;
/**
* A wrapper of ValidationContext, to provide a way of switching to a
@@ -3005,6 +3046,10 @@
public Object getMaxExclusiveValue() {
return fMaxExclusive;
}
+
+ public void setAnonymous(boolean anon) {
+ fAnonymous = anon;
+ }
private static final class XSFacetImpl implements XSFacet {
final short kind;
1.21 +22 -18 xml-xerces/java/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java
Index: XSComplexTypeDecl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- XSComplexTypeDecl.java 6 Oct 2004 15:14:55 -0000 1.20
+++ XSComplexTypeDecl.java 10 May 2005 15:36:42 -0000 1.21
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -285,14 +285,17 @@
ancestorName = SchemaSymbols.ATTVAL_ANYSIMPLETYPE;
}
- if (fBaseType != null && fBaseType instanceof XSSimpleTypeDecl) {
-
- return ((XSSimpleTypeDecl) fBaseType).isDOMDerivedFrom(ancestorNS,
- ancestorName, derivationMethod);
- } else if (fBaseType != null
- && fBaseType instanceof XSComplexTypeDecl) {
- return ((XSComplexTypeDecl) fBaseType).isDOMDerivedFrom(
- ancestorNS, ancestorName, derivationMethod);
+ if(!(fName.equals(SchemaSymbols.ATTVAL_ANYTYPE)
+ && fTargetNamespace.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA))){
+ if (fBaseType != null && fBaseType instanceof XSSimpleTypeDecl) {
+
+ return ((XSSimpleTypeDecl) fBaseType).isDOMDerivedFrom(ancestorNS,
+ ancestorName, derivationMethod);
+ } else if (fBaseType != null
+ && fBaseType instanceof XSComplexTypeDecl) {
+ return ((XSComplexTypeDecl) fBaseType).isDOMDerivedFrom(
+ ancestorNS, ancestorName, derivationMethod);
+ }
}
}
@@ -328,9 +331,9 @@
*/
private boolean isDerivedByAny(String ancestorNS, String ancestorName,
int derivationMethod, XSTypeDefinition type) {
-
+ XSTypeDefinition oldType = null;
boolean derivedFrom = false;
- while (type != null) {
+ while (type != null && type != oldType) {
// If the ancestor type is reached or is the same as this type.
if ((ancestorName.equals(type.getName()))
@@ -349,7 +352,7 @@
derivationMethod, type)) {
return true;
}
-
+ oldType = type;
type = type.getBaseType();
}
@@ -375,7 +378,8 @@
private boolean isDerivedByRestriction(String ancestorNS,
String ancestorName, int derivationMethod, XSTypeDefinition type) {
- while (type != null) {
+ XSTypeDefinition oldType = null;
+ while (type != null && type != oldType) {
// ancestor is anySimpleType, return false
if (ancestorNS != null
@@ -409,7 +413,7 @@
return false;
}
}
-
+ oldType = type;
type = type.getBaseType();
}
@@ -437,8 +441,8 @@
String ancestorName, int derivationMethod, XSTypeDefinition type) {
boolean extension = false;
-
- while (type != null) {
+ XSTypeDefinition oldType = null;
+ while (type != null && type != oldType) {
// If ancestor is anySimpleType return false.
if (ancestorNS != null
&& ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)
@@ -484,7 +488,7 @@
extension = extension | true;
}
}
-
+ oldType = type;
type = type.getBaseType();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org