You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sa...@apache.org on 2002/10/25 23:26:04 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util NodeSetType.java ReferenceType.java ResultTreeType.java

santiagopg    2002/10/25 14:26:04

  Modified:    java/src/org/apache/xalan/xsltc/compiler FunctionCall.java
               java/src/org/apache/xalan/xsltc/compiler/util
                        NodeSetType.java ReferenceType.java
                        ResultTreeType.java
  Log:
  Fix for Bugzilla 13850 provided by Morris Kwan.
  
  Morris Kwan wrote:
  
  Changes in NodeSetType.java:
  Allow a org.w3c.dom.Node to be converted to a XSLTC internal nodeset
  
  Changes in ReferenceType.java:
  Allow conversions from Reference to Java String, double, w3c Node/NodeList
  
  Changes in ResultTreeType.java:
  The result tree when converted to a nodeset, should contain only one node
  starting from the root. If you replace <xsl:param> with <xsl:variable> in
  the attached testcase, you will see a problem in "ext:nodelistTest
  ($a)/h1/h2" because of this problem.
  
  Changes in BasisLibrary.java:
  Added interfaces referenceToNodeList, referenceToNode and node2Iterator.
  The changes in copyNodes() fix a problem with the document node. In the
  case of an RTF, the NodeList passed to nodeList2Iterator() contains only
  one Node, which is a Document Node. The changes try to create a dummy
  element for the Document and copy all Nodes under it.
  
  Revision  Changes    Path
  1.26      +14 -7     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionCall.java
  
  Index: FunctionCall.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionCall.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- FunctionCall.java	4 Oct 2002 20:03:41 -0000	1.25
  +++ FunctionCall.java	25 Oct 2002 21:26:04 -0000	1.26
  @@ -240,9 +240,10 @@
   	    _internal2Java.put(Type.NodeSet, new JavaType(nodeListClass,0)); 
   
   	    _internal2Java.put(Type.ResultTree, new JavaType(nodeClass, 1)); 
  -	    _internal2Java.put(Type.ResultTree, new JavaType(nodeListClass,0));
  -	    _internal2Java.put(Type.ResultTree, new JavaType(objectClass,2));
  -	    _internal2Java.put(Type.ResultTree, new JavaType(stringClass,3));
  +	    _internal2Java.put(Type.ResultTree, new JavaType(nodeListClass, 0));
  +	    _internal2Java.put(Type.ResultTree, new JavaType(objectClass, 2));
  +	    _internal2Java.put(Type.ResultTree, new JavaType(stringClass, 3));
  +	    _internal2Java.put(Type.ResultTree, new JavaType(Double.TYPE, 4));
   
   	    _internal2Java.put(Type.Reference, new JavaType(objectClass,0));
   
  @@ -261,9 +262,9 @@
   
   	    _java2Internal.put(objectClass, Type.Reference);
   
  -	    // Conversions from org.w3c.dom.Node/NodeList are not supported
  -	    // GTM
  +	    // Conversions from org.w3c.dom.Node/NodeList to internal NodeSet
   	    _java2Internal.put(nodeListClass, Type.NodeSet);
  +	    _java2Internal.put(nodeClass, Type.NodeSet);
   	    
   	    // Initialize the extension namespace table
   	    _extensionNamespaceTable.put(EXT_XALAN, "org.apache.xalan.lib.Extensions");
  @@ -602,7 +603,13 @@
   		}
   		else {
   		    // no mapping available
  -		    if (intType instanceof ObjectType) {
  +		    //
  +		    // Allow a Reference type to match any external (Java) type at
  +		    // the moment. The real type checking is performed at runtime.
  +		    if (intType instanceof ReferenceType) {
  +		       currMethodDistance += 1; 
  +		    }
  +		    else if (intType instanceof ObjectType) {
   		        ObjectType object = (ObjectType)intType;
   		        if (extType.getName().equals(object.getJavaClassName()))
   		            currMethodDistance += 0;
  
  
  
  1.12      +16 -1     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/NodeSetType.java
  
  Index: NodeSetType.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/NodeSetType.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- NodeSetType.java	16 Sep 2002 19:14:45 -0000	1.11
  +++ NodeSetType.java	25 Oct 2002 21:26:04 -0000	1.12
  @@ -148,6 +148,21 @@
   					 + ")" + NODE_ITERATOR_SIG );
   	   il.append(new INVOKESTATIC(convert));
   	}
  +	else if (clazz.getName().equals("org.w3c.dom.Node")) {
  +	   // w3c Node is on the stack from the external Java function call.
  +	   // call BasisLibrary.node2Iterator() to consume Node and leave 
  +	   // Iterator on the stack. 
  +	   il.append(classGen.loadTranslet());   // push translet onto stack
  +	   il.append(methodGen.loadDOM());   	 // push DOM onto stack
  +	   final int convert = cpg.addMethodref(BASIS_LIBRARY_CLASS,
  +					"node2Iterator",
  +					"("		
  +					 + "Lorg/w3c/dom/Node;"
  +					 + TRANSLET_INTF_SIG 
  +					 + DOM_INTF_SIG 
  +					 + ")" + NODE_ITERATOR_SIG );
  +	   il.append(new INVOKESTATIC(convert));
  +	}
   	else {
   	    ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
   		toString(), clazz.getName());
  
  
  
  1.12      +34 -3     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ReferenceType.java
  
  Index: ReferenceType.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ReferenceType.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ReferenceType.java	30 Jul 2002 18:30:28 -0000	1.11
  +++ ReferenceType.java	25 Oct 2002 21:26:04 -0000	1.12
  @@ -242,12 +242,43 @@
   
       /**
        * Translates a reference into the Java type denoted by <code>clazz</code>. 
  -     * Only conversion allowed is to java.lang.Object.
        */
       public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 
   			    Class clazz) {
  +	final ConstantPoolGen cpg = classGen.getConstantPool();
  +	final InstructionList il = methodGen.getInstructionList();
  +	
   	if (clazz.getName().equals("java.lang.Object")) {
  -	    methodGen.getInstructionList().append(NOP);	
  +	    il.append(NOP);	
  +	}
  +	else if (clazz == Double.TYPE) {
  +	    translateTo(classGen, methodGen, Type.Real);
  +	}
  +	else if (clazz.getName().equals("java.lang.String")) {
  +	    translateTo(classGen, methodGen, Type.String);
  +	}
  +	else if (clazz.getName().equals("org.w3c.dom.Node")) {
  +	    int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "referenceToNode", 
  +				         "(" 
  +				         + OBJECT_SIG 
  +				         + DOM_INTF_SIG 
  +				         + ")"
  +				         + "Lorg/w3c/dom/Node;");
  +	    il.append(methodGen.loadDOM());
  +	    il.append(new INVOKESTATIC(index));
  +	}
  +	else if (clazz.getName().equals("org.w3c.dom.NodeList")) {
  +	    int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "referenceToNodeList", 
  +				         "(" 
  +				         + OBJECT_SIG 
  +				         + DOM_INTF_SIG 
  +				         + ")"
  +				         + "Lorg/w3c/dom/NodeList;");
  +	    il.append(methodGen.loadDOM());
  +	    il.append(new INVOKESTATIC(index));
  +	}
  +	else if (clazz.getName().equals("org.apache.xalan.xsltc.DOM")) {
  +	    translateTo(classGen, methodGen, Type.ResultTree);
   	}
   	else {
   	    ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
  
  
  
  1.15      +8 -6      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ResultTreeType.java
  
  Index: ResultTreeType.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ResultTreeType.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ResultTreeType.java	16 Sep 2002 19:14:45 -0000	1.14
  +++ ResultTreeType.java	25 Oct 2002 21:26:04 -0000	1.15
  @@ -362,12 +362,11 @@
   	il.append(new INVOKEINTERFACE(mapping, 3));
   	il.append(DUP);
   
  -	// Create an iterator with all the nodes in the DOM adapter
  +	// Create an iterator for the root node of the DOM adapter
   	final int iter = cpg.addInterfaceMethodref(DOM_INTF,
  -						   "getChildren",
  -						   "(I)"+NODE_ITERATOR_SIG);
  -	il.append(new PUSH(cpg, DOM.ROOTNODE));
  -	il.append(new INVOKEINTERFACE(iter, 2));
  +						   "getIterator",
  +						   "()"+NODE_ITERATOR_SIG);
  +	il.append(new INVOKEINTERFACE(iter, 1));	
       }
   
       /**
  @@ -436,6 +435,9 @@
           else if (className.equals("java.lang.String")) {
               translateTo(classGen, methodGen, Type.String);
           }
  +        else if (clazz == Double.TYPE) {
  +            translateTo(classGen, methodGen, Type.Real);
  +        }        
   	else {
   	    ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
   					toString(), className);
  
  
  

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