You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2005/09/16 00:04:11 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/xs/traversers XSDAbstractTraverser.java

mrglavas    2005/09/15 15:04:11

  Modified:    java/src/org/apache/xerces/impl/xs/opti SchemaDOMParser.java
                        ElementImpl.java SchemaDOM.java
               java/src/org/apache/xerces/util DOMUtil.java
               java/src/org/apache/xerces/impl/xs/traversers
                        XSDAbstractTraverser.java
  Log:
  Fixing a bug. When an annotation has no <documentation> or <appinfo> children
  a text child containing the annotation text was stored on the first child of its parent.
  Only if the annotation is the first child will we find the text node there, otherwise it is
  lost. We now store the annotation text in a field on the <annotation> element node
  where it will always be found.
  
  Revision  Changes    Path
  1.20      +24 -12    xml-xerces/java/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java
  
  Index: SchemaDOMParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SchemaDOMParser.java	30 May 2005 04:17:11 -0000	1.19
  +++ SchemaDOMParser.java	15 Sep 2005 22:04:11 -0000	1.20
  @@ -78,6 +78,8 @@
           this.config = config;
       }
       
  +    // Reference to the current annotation element.
  +    private ElementImpl fCurrentAnnotationElement;
       // where an annotation element itself begins
       // -1 means not in an annotation's scope
       private int fAnnotationDepth = -1;
  @@ -106,7 +108,8 @@
           fGenerateSyntheticAnnotation = config.getFeature(GENERATE_SYNTHETIC_ANNOTATION);
           fHasNonSchemaAttributes.clear();
           fSawAnnotation.clear();
  -        schemaDOM = new SchemaDOM(); 
  +        schemaDOM = new SchemaDOM();
  +        fCurrentAnnotationElement = null;
           fAnnotationDepth = -1;
           fInnerAnnotationDepth = -1;
           fDepth = -1;
  @@ -235,15 +238,22 @@
                   }
                   fAnnotationDepth = fDepth;
                   schemaDOM.startAnnotation(element, attributes, fNamespaceContext);
  +                fCurrentAnnotationElement = schemaDOM.startElement(element, attributes, 
  +                        fLocator.getLineNumber(),
  +                        fLocator.getColumnNumber(),
  +                        fLocator.getCharacterOffset());
  +                return;
               } 
               else if (element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA && fGenerateSyntheticAnnotation) {
                   fSawAnnotation.push(false);
                   fHasNonSchemaAttributes.push(hasNonSchemaAttributes(element, attributes));
               }
  -        } else if(fDepth == fAnnotationDepth+1) {
  +        } 
  +        else if (fDepth == fAnnotationDepth + 1) {
               fInnerAnnotationDepth = fDepth;
               schemaDOM.startAnnotationElement(element, attributes);
  -        } else {
  +        } 
  +        else {
               schemaDOM.startAnnotationElement(element, attributes);
               // avoid falling through; don't call startElement in this case
               return;
  @@ -308,11 +318,12 @@
                       element.localpart == SchemaSymbols.ELT_ANNOTATION) {
                   schemaDOM.startAnnotation(element, attributes, fNamespaceContext);
               }
  -        } else {
  +        } 
  +        else {
               schemaDOM.startAnnotationElement(element, attributes);
           }
           
  -        schemaDOM.emptyElement(element, attributes, 
  +        ElementImpl newElem = schemaDOM.emptyElement(element, attributes, 
                   fLocator.getLineNumber(),
                   fLocator.getColumnNumber(),
                   fLocator.getCharacterOffset());
  @@ -321,10 +332,11 @@
               // this is messed up, but a case to consider:
               if (element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA &&
                       element.localpart == SchemaSymbols.ELT_ANNOTATION) {
  -                schemaDOM.endAnnotationElement(element, true);
  +                schemaDOM.endAnnotation(element, newElem);
               }
  -        } else {
  -            schemaDOM.endAnnotationElement(element, false);
  +        } 
  +        else {
  +            schemaDOM.endAnnotationElement(element);
           } 
       }
       
  @@ -345,14 +357,14 @@
           if(fAnnotationDepth > -1) {
               if (fInnerAnnotationDepth == fDepth) {
                   fInnerAnnotationDepth = -1;
  -                schemaDOM.endAnnotationElement(element, false);
  +                schemaDOM.endAnnotationElement(element);
                   schemaDOM.endElement();
               } else if (fAnnotationDepth == fDepth) {
                   fAnnotationDepth = -1;
  -                schemaDOM.endAnnotationElement(element, true);
  +                schemaDOM.endAnnotation(element, fCurrentAnnotationElement);
                   schemaDOM.endElement();
               } else { // inside a child of annotation
  -                schemaDOM.endAnnotationElement(element, false);
  +                schemaDOM.endAnnotationElement(element);
               }
           } else { // not in an annotation at all
               if(element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA && fGenerateSyntheticAnnotation) {
  
  
  
  1.10      +6 -1      xml-xerces/java/src/org/apache/xerces/impl/xs/opti/ElementImpl.java
  
  Index: ElementImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/opti/ElementImpl.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ElementImpl.java	16 Dec 2004 16:45:20 -0000	1.9
  +++ ElementImpl.java	15 Sep 2005 22:04:11 -0000	1.10
  @@ -40,6 +40,7 @@
       int line;
       int column;
       int charOffset;
  +    String fAnnotation;
       String fSyntheticAnnotation;
       
       public ElementImpl(int line, int column, int offset) {
  @@ -246,6 +247,10 @@
           return charOffset;
       }
       
  +    public String getAnnotation() {
  +        return fAnnotation;
  +    }
  +    
       public String getSyntheticAnnotation() {
           return fSyntheticAnnotation;
       }
  
  
  
  1.12      +18 -44    xml-xerces/java/src/org/apache/xerces/impl/xs/opti/SchemaDOM.java
  
  Index: SchemaDOM.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/opti/SchemaDOM.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SchemaDOM.java	22 Jul 2005 21:42:26 -0000	1.11
  +++ SchemaDOM.java	15 Sep 2005 22:04:11 -0000	1.12
  @@ -58,33 +58,32 @@
       }
       
       
  -    public void startElement(QName element, XMLAttributes attributes,
  +    public ElementImpl startElement(QName element, XMLAttributes attributes,
               int line, int column, int offset) {
           ElementImpl node = new ElementImpl(line, column, offset);
           processElement(element, attributes, node);
           // now the current node added, becomes the parent
           parent = node;
  +        return node;
       }
       
  -    
  -    public void emptyElement(QName element, XMLAttributes attributes,
  +    public ElementImpl emptyElement(QName element, XMLAttributes attributes,
               int line, int column, int offset) {
           ElementImpl node = new ElementImpl(line, column, offset);
           processElement(element, attributes, node);
  +        return node;
       }
       
  -    public void startElement(QName element, XMLAttributes attributes,
  +    public ElementImpl startElement(QName element, XMLAttributes attributes,
               int line, int column) {
  -        startElement(element, attributes, line, column, -1);
  +        return startElement(element, attributes, line, column, -1);
       }
       
  -    
  -    public void emptyElement(QName element, XMLAttributes attributes,
  +    public ElementImpl emptyElement(QName element, XMLAttributes attributes,
               int line, int column) {
  -        emptyElement(element, attributes, line, column, -1);
  +        return emptyElement(element, attributes, line, column, -1);
       }
       
  -    
       private void processElement(QName element, XMLAttributes attributes, ElementImpl node) {
           
           // populate node
  @@ -191,40 +190,15 @@
           }
       }
       
  -    void endAnnotationElement(QName elemName, boolean complete) {
  -        if(complete) {
  -            fAnnotationBuffer.append("\n</").append(elemName.rawname).append(">");
  -            // note that this is always called after endElement on <annotation>'s
  -            // child and before endElement on annotation.
  -            // hence, we must make this the child of the current
  -            // parent's only child.
  -            ElementImpl child = (ElementImpl)relations[currLoc][1];
  -            
  -            // check if array needs to be resized
  -            if (nextFreeLoc == relations.length) {
  -                resizeRelations();
  -            }
  -            int newRow = child.parentRow = nextFreeLoc++; 
  -            
  -            // now find the place to insert this node
  -            boolean foundPlace = false;
  -            int i = 1;
  -            for (; i<relations[newRow].length; i++) {
  -                if (relations[newRow][i] == null) {
  -                    foundPlace = true;
  -                    break;
  -                }
  -            }
  -            
  -            if (!foundPlace) {
  -                resizeRelations(newRow);
  -            }
  -            relations[newRow][i] = new TextImpl(fAnnotationBuffer, this, newRow, i);
  -            // apparently, there is no sensible way of resetting
  -            // these things
  -            fAnnotationBuffer = null;
  -        } else      //capturing character calls
  -            fAnnotationBuffer.append("</").append(elemName.rawname).append(">");
  +    void endAnnotation(QName elemName, ElementImpl annotation) {
  +        fAnnotationBuffer.append("\n</").append(elemName.rawname).append(">");
  +        annotation.fAnnotation = fAnnotationBuffer.toString();
  +        // apparently, there is no sensible way of resetting these things
  +        fAnnotationBuffer = null;
  +    }
  +    
  +    void endAnnotationElement(QName elemName) {
  +        fAnnotationBuffer.append("</").append(elemName.rawname).append(">");
       }
       
       void endSyntheticAnnotationElement(QName elemName, boolean complete) {
  
  
  
  1.12      +11 -3     xml-xerces/java/src/org/apache/xerces/util/DOMUtil.java
  
  Index: DOMUtil.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/util/DOMUtil.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DOMUtil.java	30 May 2005 04:17:12 -0000	1.11
  +++ DOMUtil.java	15 Sep 2005 22:04:11 -0000	1.12
  @@ -821,9 +821,17 @@
           return node.getNamespaceURI();
       }
       
  -    //return synthetic annotation
  +    // return annotation
  +    public static String getAnnotation(Node node) {
  +        if (node instanceof ElementImpl) {
  +            return ((ElementImpl)node).getAnnotation();
  +        }
  +        return null;
  +    }
  +    
  +    // return synthetic annotation
       public static String getSyntheticAnnotation(Node node) {
  -        if(node instanceof ElementImpl) {
  +        if (node instanceof ElementImpl) {
               return ((ElementImpl)node).getSyntheticAnnotation();
           }
           return null;
  
  
  
  1.42      +3 -19     xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
  
  Index: XSDAbstractTraverser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- XSDAbstractTraverser.java	20 Dec 2004 05:43:36 -0000	1.41
  +++ XSDAbstractTraverser.java	15 Sep 2005 22:04:11 -0000	1.42
  @@ -33,6 +33,7 @@
   import org.apache.xerces.impl.xs.XSWildcardDecl;
   import org.apache.xerces.xs.XSObjectList;
   import org.apache.xerces.xs.XSTypeDefinition;
  +import org.apache.xerces.impl.xs.opti.ElementImpl;
   import org.apache.xerces.impl.xs.util.XInt;
   import org.apache.xerces.impl.xs.util.XSObjectListImpl;
   import org.apache.xerces.util.DOMUtil;
  @@ -106,7 +107,7 @@
           Object[] attrValues = fAttrChecker.checkAttributes(annotationDecl, isGlobal, schemaDoc);
           fAttrChecker.returnAttrArray(attrValues, schemaDoc);
           
  -        String contents = null;
  +        String contents = DOMUtil.getAnnotation(annotationDecl);
           Element child = DOMUtil.getFirstChildElement(annotationDecl);
           if (child != null) {
               do {
  @@ -117,11 +118,6 @@
                   if (!((name.equals(SchemaSymbols.ELT_APPINFO)) ||
                           (name.equals(SchemaSymbols.ELT_DOCUMENTATION)))) {
                       reportSchemaError("src-annotation", new Object[]{name}, child);
  -                } else { // the annotation, as we currently know it, is a Text child
  -                    Node textContent = child.getFirstChild();
  -                    if(textContent != null && textContent.getNodeType() == Node.TEXT_NODE) {
  -                        contents = ((Text)textContent).getData();
  -                    }
                   }
                   
                   // General Attribute Checking
  @@ -134,18 +130,6 @@
               }
               while (child != null);
           }
  -        // REVISIT: When an annotation has no <documentation> or
  -        // <appinfo> children the text child is stored on the first child of its
  -        // parent. Only if the annotation is the first child will we find the
  -        // text node there. See SchemaDOM. We need to store the string representation
  -        // in a consistent place so it can be reliably retrieved, perhaps as 
  -        // user data. -- mrglavas
  -        else {
  -            Node textContent = annotationDecl.getFirstChild();
  -            if(textContent != null && textContent.getNodeType() == Node.TEXT_NODE) {
  -                contents = ((Text)textContent).getData();
  -            }
  -        }
           // if contents was null, must have been some kind of error;
           // nothing to contribute to PSVI
           if (contents == null) return null;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org