You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2007/09/06 18:48:51 UTC

svn commit: r573322 - in /xerces/java/trunk/src/org/apache/xerces/impl: dtd/models/ xs/ xs/models/

Author: peterjm
Date: Thu Sep  6 09:48:47 2007
New Revision: 573322

URL: http://svn.apache.org/viewvc?rev=573322&view=rev
Log:
For JIRA Issue 1267.  Build a smaller DFA for UPA processing by changing the min/maxOccurs values.

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/dtd/models/CMNode.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XSConstraints.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/models/CMBuilder.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSAllCM.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSCMValidator.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSDFACM.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSEmptyCM.java

Modified: xerces/java/trunk/src/org/apache/xerces/impl/dtd/models/CMNode.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/dtd/models/CMNode.java?rev=573322&r1=573321&r2=573322&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/dtd/models/CMNode.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/dtd/models/CMNode.java Thu Sep  6 09:48:47 2007
@@ -81,6 +81,14 @@
     {
         fMaxStates = maxStates;
     }
+    
+    public boolean isCompactedForUPA() {
+        return fCompactedForUPA;
+    }
+
+    public void setIsCompactUPAModel(boolean value) {
+        fCompactedForUPA = value;
+    }
 
 
     // -------------------------------------------------------------------
@@ -126,6 +134,11 @@
     private CMStateSet fFollowPos  = null;
     private CMStateSet fLastPos    = null;
     private int        fMaxStates  = -1;
-};
-
 
+    /*
+     * This boolean is true if the model represented by the CMNode does not represent
+     * the true model from the schema, but has had its min/maxOccurs modified for a
+     * more compact representation (for purposes of UPA).
+     */
+    private boolean fCompactedForUPA = false;    
+};
\ No newline at end of file

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java?rev=573322&r1=573321&r2=573322&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java Thu Sep  6 09:48:47 2007
@@ -74,6 +74,9 @@
     // if there is a particle, the content model corresponding to that particle
     XSCMValidator fCMValidator = null;
 
+    // the content model that's sufficient for computing UPA
+    XSCMValidator fUPACMValidator = null;
+
     // list of annotations affiliated with this type
     XSObjectListImpl fAnnotations = null;
 
@@ -149,9 +152,26 @@
         fMiscFlags |= CT_IS_ANONYMOUS;
     }
 
-    public synchronized XSCMValidator getContentModel(CMBuilder cmBuilder) {
-        if (fCMValidator == null)
-            fCMValidator = cmBuilder.getContentModel(this);
+    public XSCMValidator getContentModel(CMBuilder cmBuilder) {
+        return getContentModel(cmBuilder, false);
+    }
+
+    public synchronized XSCMValidator getContentModel(CMBuilder cmBuilder, boolean forUPA) {
+        if (fCMValidator == null) {
+            if (forUPA) {
+                if (fUPACMValidator == null) {
+                    fUPACMValidator = cmBuilder.getContentModel(this, true);
+
+                    if (fUPACMValidator != null && !fUPACMValidator.isCompactedForUPA()) {
+                        fCMValidator = fUPACMValidator;
+                    }
+                }
+                return fUPACMValidator;
+            }
+            else {
+                fCMValidator = cmBuilder.getContentModel(this, false);
+            }
+        }
 
         return fCMValidator;
     }
@@ -516,6 +536,7 @@
         fXSSimpleType = null;
         fParticle = null;
         fCMValidator = null;
+        fUPACMValidator = null;
         if(fAnnotations != null) {
             // help out the garbage collector
             fAnnotations.clear();

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XSConstraints.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSConstraints.java?rev=573322&r1=573321&r2=573322&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XSConstraints.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XSConstraints.java Thu Sep  6 09:48:47 2007
@@ -462,7 +462,7 @@
                 }
                 // 3. UPA
                 // get the content model and check UPA
-                XSCMValidator cm = types[j].getContentModel(cmBuilder);
+                XSCMValidator cm = types[j].getContentModel(cmBuilder, true);
                 further = false;
                 if (cm != null) {
                     try {

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/models/CMBuilder.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/models/CMBuilder.java?rev=573322&r1=573321&r2=573322&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/models/CMBuilder.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/models/CMBuilder.java Thu Sep  6 09:48:47 2007
@@ -65,7 +65,7 @@
      * @param typeDecl  get content model for which complex type
      * @return          a content model validator
      */
-    public XSCMValidator getContentModel(XSComplexTypeDecl typeDecl) {
+    public XSCMValidator getContentModel(XSComplexTypeDecl typeDecl, boolean forUPA) {
 
         // for complex type with empty or simple content,
         // there is no content model validator
@@ -90,7 +90,7 @@
             cmValidator = createAllCM(particle);
         }
         else {
-            cmValidator = createDFACM(particle);
+            cmValidator = createDFACM(particle, forUPA);
         }
 
         //now we are throught building content model and have passed sucessfully of the nodecount check
@@ -122,11 +122,11 @@
         return allContent;
     }
 
-    XSCMValidator createDFACM(XSParticleDecl particle) {
+    XSCMValidator createDFACM(XSParticleDecl particle, boolean forUPA) {
         fLeafCount = 0;
         fParticleCount = 0;
         // convert particle tree to CM tree
-        CMNode node = useRepeatingLeafNodes(particle) ? buildCompactSyntaxTree(particle) : buildSyntaxTree(particle);
+        CMNode node = useRepeatingLeafNodes(particle) ? buildCompactSyntaxTree(particle) : buildSyntaxTree(particle, forUPA);
         if (node == null)
             return null;
         // build DFA content model from the CM tree
@@ -139,10 +139,31 @@
     // 3. convert model groups (a, b, c, ...) or (a | b | c | ...) to
     //    binary tree: (((a,b),c),...) or (((a|b)|c)|...)
     // 4. make sure each leaf node (XSCMLeaf) has a distinct position
-    private CMNode buildSyntaxTree(XSParticleDecl particle) {
+    private CMNode buildSyntaxTree(XSParticleDecl particle, boolean forUPA) {
 
         int maxOccurs = particle.fMaxOccurs;
         int minOccurs = particle.fMinOccurs;
+        
+        boolean compactedForUPA = false;
+        if (forUPA) {
+            // When doing UPA, we reduce the size of the minOccurs/maxOccurs values to make
+            // processing the DFA faster.  For UPA the exact values don't matter.
+            if (minOccurs > 1) {
+                if (maxOccurs > minOccurs || particle.getMaxOccursUnbounded()) {
+                    minOccurs = 1;
+                    compactedForUPA = true;
+                }
+                else { // maxOccurs == minOccurs
+                    minOccurs = 2;
+                    compactedForUPA = true;
+                }
+            }
+            if (maxOccurs > 1) {
+                maxOccurs = 2;
+                compactedForUPA = true;
+            }
+        }
+        
         short type = particle.fType;
         CMNode nodeRet = null;
 
@@ -157,6 +178,9 @@
             nodeRet = fNodeFactory.getCMLeafNode(particle.fType, particle.fValue, fParticleCount++, fLeafCount++);
             // (task 2) expand occurrence values
             nodeRet = expandContentModel(nodeRet, minOccurs, maxOccurs);
+            if (nodeRet != null) {
+                nodeRet.setIsCompactUPAModel(compactedForUPA);
+            }
         }
         else if (type == XSParticleDecl.PARTICLE_MODELGROUP) {
             // (task 1,3) convert model groups to binary trees
@@ -174,9 +198,10 @@
             int count = 0;
             for (int i = 0; i < group.fParticleCount; i++) {
                 // first convert each child to a CM tree
-                temp = buildSyntaxTree(group.fParticles[i]);
+                temp = buildSyntaxTree(group.fParticles[i], forUPA);
                 // then combine them using binary operation
                 if (temp != null) {
+                    compactedForUPA |= temp.isCompactedForUPA();
                     ++count;
                     if (nodeRet == null) {
                         nodeRet = temp;
@@ -194,6 +219,7 @@
                     nodeRet = fNodeFactory.getCMUniOpNode(XSParticleDecl.PARTICLE_ZERO_OR_ONE, nodeRet);
                 }
                 nodeRet = expandContentModel(nodeRet, minOccurs, maxOccurs);
+                nodeRet.setIsCompactUPAModel(compactedForUPA);
             }
         }
 

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSAllCM.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSAllCM.java?rev=573322&r1=573321&r2=573322&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSAllCM.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSAllCM.java Thu Sep  6 09:48:47 2007
@@ -213,5 +213,8 @@
         return ret;
     }
 
+    public boolean isCompactedForUPA() {
+        return false;
+    }
 } // class XSAllCM
 

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSCMValidator.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSCMValidator.java?rev=573322&r1=573321&r2=573322&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSCMValidator.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSCMValidator.java Thu Sep  6 09:48:47 2007
@@ -89,4 +89,12 @@
      */
     public Vector whatCanGoHere(int[] state);
     
+    /**
+     * Checks if this content model has had its min/maxOccurs values reduced for
+     * purposes of speeding up UPA.  If so, this content model should not be used
+     * for any purpose other than checking unique particle attribution
+     * 
+     * @return a boolean that says whether this content has been compacted for UPA
+     */
+    public boolean isCompactedForUPA();
 } // XSCMValidator

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSDFACM.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSDFACM.java?rev=573322&r1=573321&r2=573322&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSDFACM.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSDFACM.java Thu Sep  6 09:48:47 2007
@@ -164,6 +164,8 @@
      */
     private int fTransTableSize = 0;
 
+    private boolean fIsCompactedForUPA;
+    
     // temp variables
 
     //
@@ -183,6 +185,7 @@
    
         // Store away our index and pools in members
         fLeafCount = leafCount;
+        fIsCompactedForUPA = syntaxTree.isCompactedForUPA();
 
         //
         //  Create some string pool indexes that represent the names of some
@@ -1140,4 +1143,7 @@
         return ret;
     }
         
+    public boolean isCompactedForUPA() {
+        return fIsCompactedForUPA;
+    }
 } // class DFAContentModel

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSEmptyCM.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSEmptyCM.java?rev=573322&r1=573321&r2=573322&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSEmptyCM.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/models/XSEmptyCM.java Thu Sep  6 09:48:47 2007
@@ -130,4 +130,7 @@
         return EMPTY;
     }
     
+    public boolean isCompactedForUPA() {
+        return false;
+    }
 } // class XSEmptyCM



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