You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mo...@apache.org on 2001/11/05 14:51:58 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/dom NodeSortRecord.java NodeSortRecordFactory.java
morten 01/11/05 05:51:58
Modified: java/src/org/apache/xalan/xsltc/compiler Sort.java
java/src/org/apache/xalan/xsltc/dom NodeSortRecord.java
NodeSortRecordFactory.java
Log:
Changed the 'order' and 'data-type' attributes of the <xsl:sort> element
from plain attributes to attribute value templates. This required a change
not inly in the way we interpret these attributes but also in the time at
which these attributes are intrepreted. Since these are not treated as AVTs
we need to wait until runtime before reading the values of the attributes.
PR: bugzilla 3835
Obtained from: n/a
Submitted by: morten@xml.apache.org
Reviewed by: morten@xml.apache.org
Revision Changes Path
1.9 +52 -55 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Sort.java 2001/11/01 15:10:29 1.8
+++ Sort.java 2001/11/05 13:51:58 1.9
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Sort.java,v 1.8 2001/11/01 15:10:29 morten Exp $
+ * @(#)$Id: Sort.java,v 1.9 2001/11/05 13:51:58 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -93,9 +93,6 @@
public String _lang;
public String _country;
- private final static String EMPTYSTRING =
- org.apache.xalan.xsltc.compiler.Constants.EMPTYSTRING;
-
/**
* Parse the attributes of the xsl:sort element
*/
@@ -105,16 +102,29 @@
// Get the sort order; default is 'ascending'
String val = getAttribute("order");
- _order = AttributeValue
- .create(this, val.length() > 0 ? val : "ascending", parser);
+ if (val.length() == 0) val = "ascending";
+ _order = AttributeValue.create(this, val, parser);
// Get the case order; default is language dependant
val = getAttribute("case-order");
- _caseOrder = AttributeValue
- .create(this, val.length() > 0 ? val : "upper-first", parser);
+ if (val.length() == 0) val = "upper-first";
+ _caseOrder = AttributeValue.create(this, val, parser);
// Get the sort data type; default is text
- _data = getAttribute("data-type");
+ val = getAttribute("data-type");
+ if (val.length() == 0) {
+ try {
+ final Type type = _select.typeCheck(parser.getSymbolTable());
+ if (type instanceof IntType)
+ val = "number";
+ else
+ val = "text";
+ }
+ catch (TypeCheckError e) {
+ val = "text";
+ }
+ }
+ _dataType = AttributeValue.create(this, val, parser);
// Get the language whose sort rules we will use; default is env.dep.
if ((val = getAttribute("lang")) != null) {
@@ -137,20 +147,10 @@
// If the sort data-type is not set we use the natural data-type
// of the data we will sort
- if (tselect instanceof IntType) {
+ if (!(tselect instanceof StringType)) {
_select = new CastExpr(_select, Type.String);
- if ((_data == null) || (_data.length() == 0)) _data = "number";
- }
- else if (tselect instanceof StringType) {
- if ((_data == null) || (_data.length() == 0)) _data = "text";
}
- else {
- _select = new CastExpr(_select, Type.String);
- if ((_data == null) || (_data.length() == 0)) _data = "text";
- }
- _dataType = AttributeValue.create(this, _data, getParser());
-
_order.typeCheck(stable);
_caseOrder.typeCheck(stable);
_dataType.typeCheck(stable);
@@ -161,12 +161,14 @@
* These two methods are needed in the static methods that compile the
* overloaded NodeSortRecord.compareType() and NodeSortRecord.sortOrder()
*/
- public String getSortType() {
- return _dataType.toString();
+ public void translateSortType(ClassGenerator classGen,
+ MethodGenerator methodGen) {
+ _dataType.translate(classGen, methodGen);
}
- public String getSortOrder() {
- return _order.toString();
+ public void translateSortOrder(ClassGenerator classGen,
+ MethodGenerator methodGen) {
+ _order.translate(classGen, methodGen);
}
/**
@@ -249,7 +251,8 @@
// NodeSortRecordFactory.NodeSortRecordFactory(dom,class,levels,trlet);
final String initParams =
- "("+DOM_INTF_SIG+STRING_SIG+ TRANSLET_INTF_SIG+")V";
+ "("+DOM_INTF_SIG+STRING_SIG+TRANSLET_INTF_SIG+
+ "["+STRING_SIG+"["+STRING_SIG+")V";
final int init = cpg.addMethodref(NODE_SORT_FACTORY,
"<init>", initParams);
@@ -264,6 +267,30 @@
il.append(methodGen.loadDOM());
il.append(new PUSH(cpg, className));
il.append(classGen.loadTranslet());
+
+ // Compile code that initializes the static _compareType array
+ final int levels = sortObjects.size();
+ // Compile code that initializes the static _sortOrder
+ il.append(new PUSH(cpg, levels));
+ il.append(new ANEWARRAY(cpg.addClass(STRING)));
+ for (int level = 0; level < levels; level++) {
+ final Sort sort = (Sort)sortObjects.elementAt(level);
+ il.append(DUP);
+ il.append(new PUSH(cpg, level));
+ sort.translateSortOrder(classGen, methodGen);
+ il.append(AASTORE);
+ }
+
+ il.append(new PUSH(cpg,levels));
+ il.append(new ANEWARRAY(cpg.addClass(STRING)));
+ for (int level = 0; level < levels; level++) {
+ final Sort sort = (Sort)sortObjects.elementAt(level);
+ il.append(DUP);
+ il.append(new PUSH(cpg, level));
+ sort.translateSortType(classGen, methodGen);
+ il.append(AASTORE);
+ }
+
il.append(new INVOKESPECIAL(init));
}
@@ -346,36 +373,6 @@
final int levelsField = cpg.addFieldref(className, "_levels", "I");
il.append(new PUSH(cpg, levels));
il.append(new PUTSTATIC(levelsField));
-
- // Compile code that initializes the static _compareType array
- final int ctype = cpg.addFieldref(className, "_compareType", "[I");
- il.append(new PUSH(cpg,levels));
- il.append(new NEWARRAY(de.fub.bytecode.Constants.T_INT));
- for (int level = 0; level < levels; level++) {
- final Sort sort = (Sort)sortObjects.elementAt(level);
- il.append(DUP);
- il.append(new PUSH(cpg, level));
- il.append(new PUSH(cpg, sort.getSortType().equals("number")
- ? NodeSortRecord.COMPARE_NUMERIC
- : NodeSortRecord.COMPARE_STRING));
- il.append(IASTORE);
- }
- il.append(new PUTSTATIC(ctype));
-
- // Compile code that initializes the static _sortOrder
- final int corder = cpg.addFieldref(className, "_sortOrder", "[I");
- il.append(new PUSH(cpg, levels));
- il.append(new NEWARRAY(de.fub.bytecode.Constants.T_INT));
- for (int level = 0; level < levels; level++) {
- final Sort sort = (Sort)sortObjects.elementAt(level);
- il.append(DUP);
- il.append(new PUSH(cpg, level));
- il.append(new PUSH(cpg, sort.getSortOrder().equals("descending")
- ? NodeSortRecord.COMPARE_DESCENDING
- : NodeSortRecord.COMPARE_ASCENDING));
- il.append(IASTORE);
- }
- il.append(new PUTSTATIC(corder));
// Compile code that initializes the locale
String language = null;
1.6 +9 -4 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- NodeSortRecord.java 2001/10/17 13:44:25 1.5
+++ NodeSortRecord.java 2001/11/05 13:51:58 1.6
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: NodeSortRecord.java,v 1.5 2001/10/17 13:44:25 morten Exp $
+ * @(#)$Id: NodeSortRecord.java,v 1.6 2001/11/05 13:51:58 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -82,10 +82,11 @@
public static int COMPARE_DESCENDING = 1;
protected static Collator _collator = Collator.getInstance();
- protected static int[] _compareType;
- protected static int[] _sortOrder;
protected static int _levels = 1;
+ protected int[] _compareType;
+ protected int[] _sortOrder;
+
private AbstractTranslet _translet = null;
private DOM _dom = null;
@@ -114,12 +115,16 @@
* to the default constructor.
*/
public final void initialize(int node, int last, DOM dom,
- AbstractTranslet translet) {
+ AbstractTranslet translet,
+ int[] order, int[] type) {
_dom = dom;
_node = node;
_last = last;
_translet = translet;
_scanned = 0;
+
+ _sortOrder = order;
+ _compareType = type;
_values = new Object[_levels];
}
1.6 +20 -4 xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecordFactory.java
Index: NodeSortRecordFactory.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecordFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- NodeSortRecordFactory.java 2001/10/30 14:57:54 1.5
+++ NodeSortRecordFactory.java 2001/11/05 13:51:58 1.6
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: NodeSortRecordFactory.java,v 1.5 2001/10/30 14:57:54 morten Exp $
+ * @(#)$Id: NodeSortRecordFactory.java,v 1.6 2001/11/05 13:51:58 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -70,10 +70,15 @@
import org.apache.xalan.xsltc.runtime.AbstractTranslet;
public class NodeSortRecordFactory {
+
+ private static int DESCENDING = "descending".length();
+ private static int NUMBER = "number".length();
+
private final DOM _dom;
private final String _className;
private Class _class;
-
+ private int _order[];
+ private int _type[];
private final AbstractTranslet _translet;
/**
@@ -83,7 +88,8 @@
* class), and the translet parameter is needed for methods called by
* this object.
*/
- public NodeSortRecordFactory(DOM dom, String className, Translet translet)
+ public NodeSortRecordFactory(DOM dom, String className, Translet translet,
+ String order[], String type[])
throws TransletException {
try {
_dom = dom;
@@ -91,6 +97,16 @@
_class = translet.getAuxiliaryClass(className);
if (_class == null) _class = Class.forName(className);
_translet = (AbstractTranslet)translet;
+
+ int levels = order.length;
+ _order = new int[levels];
+ _type = new int[levels];
+ for (int i = 0; i < levels; i++) {
+ if (order[i].length() == DESCENDING)
+ _order[i] = NodeSortRecord.COMPARE_DESCENDING;
+ if (type[i].length() == NUMBER)
+ _type[i] = NodeSortRecord.COMPARE_NUMERIC;
+ }
}
catch (ClassNotFoundException e) {
throw new TransletException(e);
@@ -111,7 +127,7 @@
final NodeSortRecord sortRecord =
(NodeSortRecord)_class.newInstance();
- sortRecord.initialize(node, last, _dom, _translet);
+ sortRecord.initialize(node, last, _dom, _translet, _order, _type);
return sortRecord;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org