You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by lm...@apache.org on 2001/10/05 15:34:07 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/v2 XSWildcardDecl.java

lmartin     01/10/05 06:34:07

  Modified:    java/src/org/apache/xerces/impl/v2 XSWildcardDecl.java
  Log:
  Rahul's code for wildcard subset, intersection, union
  
  Revision  Changes    Path
  1.6       +206 -1    xml-xerces/java/src/org/apache/xerces/impl/v2/XSWildcardDecl.java
  
  Index: XSWildcardDecl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSWildcardDecl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XSWildcardDecl.java	2001/09/25 21:33:40	1.5
  +++ XSWildcardDecl.java	2001/10/05 13:34:07	1.6
  @@ -58,13 +58,16 @@
   package org.apache.xerces.impl.v2;
   
   import org.apache.xerces.xni.QName;
  +import java.util.Vector;
   
   /**
    * The XML representation for a wildcard declaration
    * schema component is an <any> or <anyAttribute> element information item
    *
    * @author Sandy Gao, IBM
  - * @version $Id: XSWildcardDecl.java,v 1.5 2001/09/25 21:33:40 neilg Exp $
  + * @author Rahul Srivastava, Sun Microsystems Inc.
  + *
  + * @version $Id: XSWildcardDecl.java,v 1.6 2001/10/05 13:34:07 lmartin Exp $
    */
   public class XSWildcardDecl  extends XSElementDecl {
   
  @@ -116,6 +119,208 @@
   
           return false;
       }
  +
  +    //NOTE: ##OTHER means not targetNamespace, according to spec.
  +    //      We are not considering it as, not and a set of URI's, where targetNamespace is
  +    //      one of the element in the set. This may be taken as an enhanced feature, later.
  +
  +    public boolean isSubsetOf(XSWildcardDecl superWildcard) {
  +    	// For a namespace constraint (call it sub) to be an intensional subset of another namespace 
  +    	// constraint (call it super) one of the following must be true:
  +    	
  +        // 1 super must be any. 
  +	if (superWildcard.fType == WILDCARD_ANY) {
  +		return true;
  +	}
  +	// 2 All of the following must be true:
  +	//   2.1 sub must be a pair of not and a namespace name or �absent�.
  +	//   2.2 super must be a pair of not and the same value.
  +	else if ( (fType == WILDCARD_OTHER) && (superWildcard.fType == WILDCARD_OTHER) ){
  +		return (fNamespaceList[0] == superWildcard.fNamespaceList[0]);
  +	}
  +	// 3 All of the following must be true:
  +	//   3.1 sub must be a set whose members are either namespace names or �absent�. 
  +	//   3.2 One of the following must be true:
  +	//       3.2.1 super must be the same set or a superset thereof. 
  +	//       3.2.2 super must be a pair of not and a namespace name or �absent� and 
  +	//             that value must not be in sub's set. 
  +	else if (fType == WILDCARD_LIST) {
  +		if (superWildcard.fType == WILDCARD_LIST) {
  +			boolean found;
  +			
  +			for (int i=0; i<fNamespaceList.length; i++) {
  +				found = false;
  +				for (int j=0; j<superWildcard.fNamespaceList.length; j++)
  +					if (fNamespaceList[i] == superWildcard.fNamespaceList[j]) {
  +						found = true;
  +						break;
  +					}
  +				if (!found) return false;
  +			}
  +			return true;
  +		}
  +		else if (superWildcard.fType == WILDCARD_OTHER) {
  +			for (int i=0; i<fNamespaceList.length; i++) {
  +				if (superWildcard.fNamespaceList[0] == fNamespaceList[i])
  +					return false;
  +			}
  +			return true;
  +		}
  +	}
  +	
  +	return false;
  +    }
  +    
  +    
  +    public XSWildcardDecl performUnionWith(XSWildcardDecl wildcard) {
  +    	// For a wildcard's {namespace constraint} value to be the intensional union of two other such 
  +    	// values (call them O1 and O2): the appropriate case among the following must be true:
  +        
  +	XSWildcardDecl unionWildcard = new XSWildcardDecl();
  +	
  +        // 1 If O1 and O2 are the same value, then that value must be the value.     
  +	if (fType == wildcard.fType) {
  +		unionWildcard.fType = fType;
  +	}
  +	// 2 If either O1 or O2 is any, then any must be the value.
  +	else if ( (fType == WILDCARD_ANY) || (wildcard.fType == WILDCARD_ANY) ) {
  +		unionWildcard.fType = WILDCARD_ANY;
  +	}
  +	// 3 If both O1 and O2 are sets of (namespace names or �absent�), then the union of those sets 
  +	//   must be the value.
  +	else if ( (fType == WILDCARD_LIST) && (wildcard.fType == WILDCARD_LIST) ) {
  +		Vector union = new Vector(fNamespaceList.length, wildcard.fNamespaceList.length);
  +		
  +		for (int i=0; i<fNamespaceList.length; i++)
  +			union.addElement(fNamespaceList[i]);
  +		
  +		boolean found;
  +		for (int i=0; i<wildcard.fNamespaceList.length; i++) {
  +			found = false;
  +			for (int j=0; j<fNamespaceList.length; j++)
  +				if (fNamespaceList[j] == wildcard.fNamespaceList[i]) {
  +					found = true;
  +					break;
  +				}
  +			if (!found)
  +				union.addElement(wildcard.fNamespaceList[i]);
  +		}
  +        	
  +        	unionWildcard.fType = WILDCARD_LIST;
  +        	// copy elements from vector to array
  +        	int size = union.size();
  +        	unionWildcard.fNamespaceList = new String[size];
  +        	union.copyInto(unionWildcard.fNamespaceList);
  +	}
  +	// 4 If the two are negations of different namespace names, then the intersection is not expressible.
  +	
  +	// 5 If either O1 or O2 is a pair of not and a namespace name and the other is a set of 
  +	//   (namespace names or �absent�), then The appropriate case among the following must be true:
  +        //      5.1 If the set includes the negated namespace name, then any must be the value.
  +        //      5.2 If the set does not include the negated namespace name, then whichever of O1 or O2 
  +        //          is a pair of not and a namespace name must be the value.
  +	else if ( ((fType == WILDCARD_OTHER) && (wildcard.fType == WILDCARD_LIST)) ||
  +	          ((fType == WILDCARD_LIST) && (wildcard.fType == WILDCARD_OTHER)) ) {
  +		
  +		int i=0;
  +		
  +		if (fType == WILDCARD_OTHER) {
  +			for (i=0; i<wildcard.fNamespaceList.length; i++)
  +				if (fNamespaceList[0] == wildcard.fNamespaceList[i]) {
  +					unionWildcard.fType = WILDCARD_ANY;
  +					break;
  +				}
  +			// Loop traversed completely. This means, negated namespace viz. tNS (here)
  +			// is not in the other list. So, union is other.
  +			if (i == wildcard.fNamespaceList.length)
  +				unionWildcard.fType = fType;
  +		}
  +		else {
  +			for (i=0; i<fNamespaceList.length; i++)
  +				if (wildcard.fNamespaceList[0] == fNamespaceList[i]) {
  +					unionWildcard.fType = WILDCARD_ANY;
  +					break;
  +				}
  +			// Loop traversed completely. This means, negated namespace viz. tNS (here)
  +			// is not in the other list. So, union is other.
  +			if (i == fNamespaceList.length)
  +				unionWildcard.fType = wildcard.fType;
  +		}
  +	}
  +
  +	unionWildcard.fProcessContents = fProcessContents;
  +	return unionWildcard;
  +    }
  +
  +
  +    public XSWildcardDecl performIntersectionWith(XSWildcardDecl wildcard) {
  +    	// For a wildcard's {namespace constraint} value to be the intensional intersection of two other 
  +    	// such values (call them O1 and O2): the appropriate case among the following must be true:
  +    	
  +	XSWildcardDecl intersectWildcard = new XSWildcardDecl();
  +        
  +        // 1 If O1 and O2 are the same value, then that value must be the value.     
  +	if (fType == wildcard.fType) {
  +		intersectWildcard.fType = fType;
  +	}
  +	// 2 If either O1 or O2 is any, then the other must be the value.
  +	else if ( (fType == WILDCARD_ANY) || (wildcard.fType == WILDCARD_ANY) ) {
  +		if (fType == WILDCARD_ANY)
  +			intersectWildcard.fType = wildcard.fType;
  +		else
  +			intersectWildcard.fType = fType;
  +	}
  +	// 3 If either O1 or O2 is a pair of not and a namespace name and the other is a set of 
  +	//   (namespace names or �absent�), then that set, minus the negated namespace name if it was in 
  +	//   the set, must be the value.
  +	else if ( ((fType == WILDCARD_OTHER) && (wildcard.fType == WILDCARD_LIST)) ||
  +	          ((fType == WILDCARD_LIST) && (wildcard.fType == WILDCARD_OTHER)) ) {
  +	        Vector intersect = new Vector(5,2);
  +	        if (fType == WILDCARD_OTHER) {
  +	        	for (int i=0; i<wildcard.fNamespaceList.length; i++)
  +	        		if (fNamespaceList[0] != wildcard.fNamespaceList[i])
  +	        			intersect.addElement(wildcard.fNamespaceList[i]);
  +	        }
  +	        else {
  +	        	for (int i=0; i<fNamespaceList.length; i++)
  +	        		if (wildcard.fNamespaceList[0] != fNamespaceList[i])
  +	        			intersect.addElement(fNamespaceList[i]);
  +	        }
  +		intersectWildcard.fType = WILDCARD_LIST;
  +        	// copy elements from vector to array
  +        	int size = intersect.size();
  +        	intersectWildcard.fNamespaceList = new String[size];
  +        	intersect.copyInto(intersectWildcard.fNamespaceList);
  +	}
  +	// 4 If both O1 and O2 are sets of (namespace names or �absent�), then the intersection of those 
  +	//   sets must be the value.
  +	else if ( (fType == WILDCARD_LIST) && (wildcard.fType == WILDCARD_LIST) ) {
  +		Vector intersect = new Vector(fNamespaceList.length,2);
  +		boolean found;
  +		
  +		for (int i=0; i<fNamespaceList.length; i++) {
  +			found = false;
  +			for (int j=0; j<wildcard.fNamespaceList.length; j++)
  +				if (fNamespaceList[i] == wildcard.fNamespaceList[j]) {
  +					found = true;
  +					break;
  +				}
  +			if (found)
  +				intersect.addElement(fNamespaceList[i]);
  +		}
  +
  +		intersectWildcard.fType = WILDCARD_LIST;
  +        	// copy elements from vector to array
  +        	int size = intersect.size();
  +        	intersectWildcard.fNamespaceList = new String[size];
  +        	intersect.copyInto(intersectWildcard.fNamespaceList);
  +	}
  +	// 5 If the two are negations of different namespace names, then the intersection is not expressible.
  +	
  +	intersectWildcard.fProcessContents = fProcessContents;
  +	return intersectWildcard;
  +    }
  +
   
       public String toString() {
           String ret = null;
  
  
  

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