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 2011/01/31 21:31:00 UTC

svn commit: r1065753 - in /xerces/java/trunk/src/org/apache/xerces: dom/PSVIAttrNSImpl.java dom/PSVIElementNSImpl.java impl/xs/AttributePSVImpl.java impl/xs/ElementPSVImpl.java xs/ItemPSVI.java

Author: mrglavas
Date: Mon Jan 31 20:31:00 2011
New Revision: 1065753

URL: http://svn.apache.org/viewvc?rev=1065753&view=rev
Log:
JIRA Issue #1494: http://issues.apache.org/jira/browse/XERCESJ-1494. Adding isConstant() and constant() methods to ItemPSVI to make it easier for users to persist PSVI information that they receive from a PSVIProvider or PSVI annotated DOM.

Modified:
    xerces/java/trunk/src/org/apache/xerces/dom/PSVIAttrNSImpl.java
    xerces/java/trunk/src/org/apache/xerces/dom/PSVIElementNSImpl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/AttributePSVImpl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/ElementPSVImpl.java
    xerces/java/trunk/src/org/apache/xerces/xs/ItemPSVI.java

Modified: xerces/java/trunk/src/org/apache/xerces/dom/PSVIAttrNSImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/dom/PSVIAttrNSImpl.java?rev=1065753&r1=1065752&r2=1065753&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/dom/PSVIAttrNSImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/dom/PSVIAttrNSImpl.java Mon Jan 31 20:31:00 2011
@@ -23,8 +23,10 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 
 import org.apache.xerces.impl.dv.ValidatedInfo;
+import org.apache.xerces.impl.xs.AttributePSVImpl;
 import org.apache.xerces.impl.xs.util.StringListImpl;
 import org.apache.xerces.xs.AttributePSVI;
+import org.apache.xerces.xs.ItemPSVI;
 import org.apache.xerces.xs.ShortList;
 import org.apache.xerces.xs.StringList;
 import org.apache.xerces.xs.XSAttributeDeclaration;
@@ -93,6 +95,20 @@ public class PSVIAttrNSImpl extends Attr
     //
     // AttributePSVI methods
     //
+    
+    /* (non-Javadoc)
+     * @see org.apache.xerces.xs.ItemPSVI#constant()
+     */
+    public ItemPSVI constant() {
+        return new AttributePSVImpl(true, this);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.xerces.xs.ItemPSVI#isConstant()
+     */
+    public boolean isConstant() {
+        return false;
+    }
 
     /**
      * [schema default]

Modified: xerces/java/trunk/src/org/apache/xerces/dom/PSVIElementNSImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/dom/PSVIElementNSImpl.java?rev=1065753&r1=1065752&r2=1065753&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/dom/PSVIElementNSImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/dom/PSVIElementNSImpl.java Mon Jan 31 20:31:00 2011
@@ -23,8 +23,10 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 
 import org.apache.xerces.impl.dv.ValidatedInfo;
+import org.apache.xerces.impl.xs.ElementPSVImpl;
 import org.apache.xerces.impl.xs.util.StringListImpl;
 import org.apache.xerces.xs.ElementPSVI;
+import org.apache.xerces.xs.ItemPSVI;
 import org.apache.xerces.xs.ShortList;
 import org.apache.xerces.xs.StringList;
 import org.apache.xerces.xs.XSComplexTypeDefinition;
@@ -107,6 +109,20 @@ public class PSVIElementNSImpl extends E
     //
     // ElementPSVI methods
     //
+    
+    /* (non-Javadoc)
+     * @see org.apache.xerces.xs.ItemPSVI#constant()
+     */
+    public ItemPSVI constant() {
+        return new ElementPSVImpl(true, this);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.xerces.xs.ItemPSVI#isConstant()
+     */
+    public boolean isConstant() {
+        return false;
+    }
 
     /**
      * [schema default]

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/AttributePSVImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/AttributePSVImpl.java?rev=1065753&r1=1065752&r2=1065753&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/AttributePSVImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/AttributePSVImpl.java Mon Jan 31 20:31:00 2011
@@ -20,6 +20,7 @@ package org.apache.xerces.impl.xs;
 import org.apache.xerces.impl.dv.ValidatedInfo;
 import org.apache.xerces.impl.xs.util.StringListImpl;
 import org.apache.xerces.xs.AttributePSVI;
+import org.apache.xerces.xs.ItemPSVI;
 import org.apache.xerces.xs.ShortList;
 import org.apache.xerces.xs.StringList;
 import org.apache.xerces.xs.XSAttributeDeclaration;
@@ -62,10 +63,61 @@ public class AttributePSVImpl implements
 
     /** validation context: could be QName or XPath expression*/
     protected String fValidationContext = null;
+    
+    /** true if this object is immutable **/
+    protected boolean fIsConstant;
+    
+    public AttributePSVImpl() {}
+    
+    public AttributePSVImpl(boolean isConstant, AttributePSVI attrPSVI) {
+        fDeclaration = attrPSVI.getAttributeDeclaration();
+        fTypeDecl = attrPSVI.getTypeDefinition();
+        fSpecified = attrPSVI.getIsSchemaSpecified();
+        fValue.copyFrom(attrPSVI.getSchemaValue());
+        fValidationAttempted = attrPSVI.getValidationAttempted();
+        fValidity = attrPSVI.getValidity();
+        if (attrPSVI instanceof AttributePSVImpl) {
+            final AttributePSVImpl attrPSVIImpl = (AttributePSVImpl) attrPSVI;
+            fErrors = (attrPSVIImpl.fErrors != null) ?
+                    (String[]) attrPSVIImpl.fErrors.clone() : null;
+        }
+        else {
+            final StringList errorCodes = attrPSVI.getErrorCodes();
+            final int length = errorCodes.getLength();
+            if (length > 0) {
+                final StringList errorMessages = attrPSVI.getErrorMessages();
+                final String[] errors = new String[length << 1];
+                for (int i = 0, j = 0; i < length; ++i) {
+                    errors[j++] = errorCodes.item(i);
+                    errors[j++] = errorMessages.item(i);
+                }
+                fErrors = errors;
+            }
+        }
+        fValidationContext = attrPSVI.getValidationContext();
+        fIsConstant = isConstant;
+    }
 
     //
     // AttributePSVI methods
     //
+    
+    /* (non-Javadoc)
+     * @see org.apache.xerces.xs.ItemPSVI#constant()
+     */
+    public ItemPSVI constant() {
+        if (isConstant()) {
+            return this;
+        }
+        return new AttributePSVImpl(true, this);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.xerces.xs.ItemPSVI#isConstant()
+     */
+    public boolean isConstant() {
+        return fIsConstant;
+    }
 
     /**
      * [schema default]

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/ElementPSVImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/ElementPSVImpl.java?rev=1065753&r1=1065752&r2=1065753&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/ElementPSVImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/ElementPSVImpl.java Mon Jan 31 20:31:00 2011
@@ -20,6 +20,7 @@ package org.apache.xerces.impl.xs;
 import org.apache.xerces.impl.dv.ValidatedInfo;
 import org.apache.xerces.impl.xs.util.StringListImpl;
 import org.apache.xerces.xs.ElementPSVI;
+import org.apache.xerces.xs.ItemPSVI;
 import org.apache.xerces.xs.ShortList;
 import org.apache.xerces.xs.StringList;
 import org.apache.xerces.xs.XSElementDeclaration;
@@ -84,9 +85,64 @@ public class ElementPSVImpl implements E
     /** the schema information property */
     protected XSModel fSchemaInformation = null;
     
+    /** true if this object is immutable **/
+    protected boolean fIsConstant;
+    
+    public ElementPSVImpl() {}
+    
+    public ElementPSVImpl(boolean isConstant, ElementPSVI elementPSVI) {
+        fDeclaration = elementPSVI.getElementDeclaration();
+        fTypeDecl = elementPSVI.getTypeDefinition();
+        fNil = elementPSVI.getNil();
+        fSpecified = elementPSVI.getIsSchemaSpecified();
+        fValue.copyFrom(elementPSVI.getSchemaValue());
+        fNotation = elementPSVI.getNotation();
+        fValidationAttempted = elementPSVI.getValidationAttempted();
+        fValidity = elementPSVI.getValidity();
+        fValidationContext = elementPSVI.getValidationContext();
+        if (elementPSVI instanceof ElementPSVImpl) {
+            final ElementPSVImpl elementPSVIImpl = (ElementPSVImpl) elementPSVI;
+            fErrors = (elementPSVIImpl.fErrors != null) ?
+                    (String[]) elementPSVIImpl.fErrors.clone() : null;
+            elementPSVIImpl.copySchemaInformationTo(this);
+        }
+        else {
+            final StringList errorCodes = elementPSVI.getErrorCodes();
+            final int length = errorCodes.getLength();
+            if (length > 0) {
+                final StringList errorMessages = elementPSVI.getErrorMessages();
+                final String[] errors = new String[length << 1];
+                for (int i = 0, j = 0; i < length; ++i) {
+                    errors[j++] = errorCodes.item(i);
+                    errors[j++] = errorMessages.item(i);
+                }
+                fErrors = errors;
+            }
+            fSchemaInformation = elementPSVI.getSchemaInformation();
+        }
+        fIsConstant = isConstant;
+    }
+    
     //
     // ElementPSVI methods
     //
+    
+    /* (non-Javadoc)
+     * @see org.apache.xerces.xs.ItemPSVI#constant()
+     */
+    public ItemPSVI constant() {
+        if (isConstant()) {
+            return this;
+        }
+        return new ElementPSVImpl(true, this);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.xerces.xs.ItemPSVI#isConstant()
+     */
+    public boolean isConstant() {
+        return fIsConstant;
+    }
 
     /**
      * [schema default]

Modified: xerces/java/trunk/src/org/apache/xerces/xs/ItemPSVI.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/xs/ItemPSVI.java?rev=1065753&r1=1065752&r2=1065753&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/xs/ItemPSVI.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/xs/ItemPSVI.java Mon Jan 31 20:31:00 2011
@@ -54,6 +54,19 @@ public interface ItemPSVI {
      * performed on the item. 
      */
     public static final short VALIDATION_FULL           = 2;
+    
+    /**
+     * Returns a reference to an immutable instance with the same data
+     * that this instance of <code>ItemPSVI</code> currently has.
+     */
+    public ItemPSVI constant();
+    
+    /** 
+     * Returns <code>true</code> if this specific instance of
+     * <code>ItemPSVI</code> is immutable, otherwise <code>false</code>.
+     */
+    public boolean isConstant();
+    
     /**
      * The nearest ancestor element information item with a 
      * <code>[schema information]</code> property (or this element item 



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