xalan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From santiag...@apache.org
Subject cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/dom NodeSortRecord.java
Date Tue, 26 Nov 2002 16:00:35 GMT
santiagopg    2002/11/26 08:00:35

  Modified:    java/src/org/apache/xalan/xsltc/compiler Constants.java
                        Sort.java
               java/src/org/apache/xalan/xsltc/dom NodeSortRecord.java
  Log:
  Changed the NodeSortRecord class to hold non-static references to
  instances of java.text.Collator and java.util.Locale. Updated the
  bytecode generation for NodeSortRecord subclasses to access the new
  variables correctly. When a stylesheet specifies a different language
  in xsl:sort, the protected references in NodeSortRecord will be
  updated by the subclass' constructor.
  
  Revision  Changes    Path
  1.29      +3 -1      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Constants.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- Constants.java	8 Oct 2002 21:44:13 -0000	1.28
  +++ Constants.java	26 Nov 2002 16:00:34 -0000	1.29
  @@ -165,6 +165,8 @@
   	= "Lorg/apache/xalan/xsltc/dom/NodeSortRecord;";
       public static final String NODE_SORT_FACTORY_SIG
   	= "Lorg/apache/xalan/xsltc/dom/NodeSortRecordFactory;";
  +    public static final String LOCALE_SIG 
  +	= "Ljava/util/Locale;";
       public static final String STRING_VALUE_HANDLER
   	= "org.apache.xalan.xsltc.runtime.StringValueHandler";
       public static final String STRING_VALUE_HANDLER_SIG 
  
  
  
  1.17      +38 -69    xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Sort.java
  
  Index: Sort.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Sort.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Sort.java	26 Aug 2002 16:03:00 -0000	1.16
  +++ Sort.java	26 Nov 2002 16:00:34 -0000	1.17
  @@ -560,46 +560,38 @@
   	    }
   	}
   
  -	Method clinit = compileClassInit(sortObjects, sortRecord,
  +	Method init = compileInit(sortObjects, sortRecord,
   					 cpg, className);
   	Method extract = compileExtract(sortObjects, sortRecord,
   					cpg, className);
  -	sortRecord.addMethod(clinit);
  -	sortRecord.addEmptyConstructor(ACC_PUBLIC);
  +	sortRecord.addMethod(init);
   	sortRecord.addMethod(extract);
   
  -	// Overload NodeSortRecord.getCollator() only if needed
  -	for (int i = 0; i < sortObjects.size(); i++) {
  -	    if (((Sort)(sortObjects.elementAt(i)))._lang != null) {
  -		sortRecord.addMethod(compileGetCollator(sortObjects,
  -							sortRecord,
  -							cpg,
  -							className));
  -		i = sortObjects.size();
  -	    }
  -	}
  -	
   	xsltc.dumpClass(sortRecord.getJavaClass());
   	return className;
       }
   
       /**
  -     * Create a class constructor for the new class. All this constructor does
  -     * is to initialize a couple of tables that contain information on sort
  -     * order and sort type. These static tables cannot be in the parent class.
  +     * Create a constructor for the new class. Updates the reference to the 
  +     * collator in the super calls only when the stylesheet specifies a new
  +     * language in xsl:sort.
        */
  -    private static Method compileClassInit(Vector sortObjects,
  +    private static Method compileInit(Vector sortObjects,
   					   NodeSortRecordGenerator sortRecord,
   					   ConstantPoolGen cpg,
  -					   String className) {
  -	// Class initializer - void NodeSortRecord.<clinit>();
  +					   String className) 
  +    {
   	final InstructionList il = new InstructionList();
  -	final CompareGenerator classInit =
  -	    new CompareGenerator(ACC_PUBLIC | ACC_STATIC,
  -				 org.apache.bcel.generic.Type.VOID, 
  -				 new org.apache.bcel.generic.Type[] { },
  -				 new String[] { },
  -				 "<clinit>", className, il, cpg);
  +	final MethodGenerator init = 
  +	    new MethodGenerator(ACC_PUBLIC, 
  +				org.apache.bcel.generic.Type.VOID, 
  +				null, null, "<init>", className, 
  +				il, cpg);
  +
  +	// Call the constructor in the NodeSortRecord superclass
  +	il.append(ALOAD_0);
  +	il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
  +						     "<init>", "()V")));
   
   	final int initLocale =  cpg.addMethodref("java/util/Locale",
   						 "<init>",
  @@ -628,41 +620,50 @@
   	Sort sort = (Sort)sortObjects.elementAt(0);
   
   	for (int level = 0; level < levels; level++) {
  -	    if (language == null && sort._lang != null)
  +	    if (language == null && sort._lang != null) {
   		language = sort._lang;
  -	    if (country == null && sort._country != null)
  +	    }
  +	    if (country == null && sort._country != null) {
   		country = sort._country;
  +	    }
   	}
   
  -	// Get index to private static reference in NodeSortRecrd
   	final int collator =
   	    cpg.addFieldref(className, "_collator", COLLATOR_SIG);
  +	final int locale =
  +	    cpg.addFieldref(className, "_locale", LOCALE_SIG);
   
   	if (language != null) {
   	    // Create new Locale object on stack
   	    il.append(new NEW(cpg.addClass("java/util/Locale")));
   	    il.append(DUP);
  +	    il.append(DUP);
   	    il.append(new PUSH(cpg, language));
   	    il.append(new PUSH(cpg, (country != null ? country : EMPTYSTRING)));
   	    il.append(new INVOKESPECIAL(initLocale));
  +	    il.append(ALOAD_0);
  +	    il.append(SWAP);
  +	    il.append(new PUTFIELD(locale));
   	    
   	    // Use that Locale object to get the required Collator object
   	    il.append(new INVOKESTATIC(getCollator));
  -	    il.append(new PUTSTATIC(collator));
  +	    il.append(ALOAD_0);
  +	    il.append(SWAP);
  +	    il.append(new PUTFIELD(collator));
   	}
   
  -	il.append(new GETSTATIC(collator));
  +	il.append(ALOAD_0);
  +	il.append(new GETFIELD(collator));
   	il.append(new ICONST(Collator.TERTIARY));
   	il.append(new INVOKEVIRTUAL(setStrength));
   
   	il.append(RETURN);
   
  -	classInit.stripAttributes(true);
  -	classInit.setMaxLocals();
  -	classInit.setMaxStack();
  -	classInit.removeNOPs();
  +	init.stripAttributes(true);
  +	init.setMaxLocals();
  +	init.setMaxStack();
   
  -	return classInit.getMethod();
  +	return init.getMethod();
       }
   
   
  @@ -732,37 +733,5 @@
   	extractMethod.removeNOPs();
   
   	return extractMethod.getMethod();
  -    }
  -
  -    /**
  -     * Compiles a method that overloads NodeSortRecord.getCollator()
  -     * This method is only compiled if the "lang" attribute is used.
  -     */
  -    private static Method compileGetCollator(Vector sortObjects,
  -					     NodeSortRecordGenerator sortRecord,
  -					     ConstantPoolGen cpg,
  -					     String className) {
  -	final InstructionList il = new InstructionList();
  -	// Collator NodeSortRecord.getCollator();
  -	final MethodGenerator getCollator =
  -	    new MethodGenerator(ACC_PUBLIC | ACC_FINAL,
  -				Util.getJCRefType(COLLATOR_SIG),
  -				new org.apache.bcel.generic.Type[] {},
  -				new String[] { },
  -				"getCollator", className, il, cpg);
  -
  -	// Get index to private static reference in NodeSortRecrd
  -	final int collator =
  -	    cpg.addFieldref(className, "collator", COLLATOR_SIG);
  -	// Feck the Collator object on the stack and return it
  -	il.append(new GETSTATIC(collator));
  -	il.append(ARETURN);
  -
  -	getCollator.stripAttributes(true);
  -	getCollator.setMaxLocals();
  -	getCollator.setMaxStack();
  -	getCollator.removeNOPs();
  -
  -	return getCollator.getMethod();
       }
   }
  
  
  
  1.9       +13 -2     xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecord.java
  
  Index: NodeSortRecord.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecord.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- NodeSortRecord.java	29 Nov 2001 09:49:35 -0000	1.8
  +++ NodeSortRecord.java	26 Nov 2002 16:00:35 -0000	1.9
  @@ -65,6 +65,7 @@
   package org.apache.xalan.xsltc.dom;
   
   import java.util.Vector;
  +import java.util.Locale;
   import java.text.Collator;
   import java.text.CollationKey;
   
  @@ -81,7 +82,17 @@
       public static int COMPARE_ASCENDING  = 0;
       public static int COMPARE_DESCENDING = 1;
   
  -    protected static Collator _collator = Collator.getInstance();
  +    /**
  +     * A reference to a locale. May be updated by subclass if the stylesheet
  +     * specifies a different language.
  +     */
  +    protected Locale _locale = Locale.getDefault();
  +
  +    /**
  +     * A reference to a collator. May be updated by subclass if the stylesheet
  +     * specifies a different language (will be updated iff _locale is updated).
  +     */
  +    protected Collator _collator = Collator.getInstance();
   
       protected int   _levels = 1;
       protected int[] _compareType;
  
  
  

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


Mime
View raw message