mmidy 2002/09/06 08:06:08 Modified: java/src/org/apache/xml/utils Tag: xslt20 DateTimeObj.java java/src/org/apache/xpath/axes Tag: xslt20 FilterExprIteratorSimple.java UnionPathIterator.java java/src/org/apache/xpath/parser Tag: xslt20 SimpleNode.java java/src/org/apache/xpath/quantified Tag: xslt20 Every.java Some.java Added: java/src/org/apache/xpath/axes Tag: xslt20 ExceptPathIterator.java InterceptPathIterator.java java/src/org/apache/xpath/functions Tag: xslt20 FuncAddTZToDT.java FuncAddTZToDate.java FuncAddTZToTime.java FuncRemoveTZFromDT.java FuncRemoveTZFromTime.java Log: This is a commit includes: - Add/remove timezone functions - Misc fixes to dateTime and duration - Implement Every and Some - Fix bug in Union iterator - Implement Intercept/Except - Misc fixes in SimpleNode, FilterExprIteratorSimple Revision Changes Path No revision No revision 1.1.2.1.2.1 +280 -4 xml-xalan/java/src/org/apache/xml/utils/Attic/DateTimeObj.java Index: DateTimeObj.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/Attic/DateTimeObj.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.1.2.1 diff -u -r1.1.2.1 -r1.1.2.1.2.1 --- DateTimeObj.java 14 Aug 2002 19:45:36 -0000 1.1.2.1 +++ DateTimeObj.java 6 Sep 2002 15:06:05 -0000 1.1.2.1.2.1 @@ -64,6 +64,7 @@ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.TimeZone; import javax.xml.transform.TransformerException; import org.apache.xml.dtm.XType; @@ -78,6 +79,7 @@ // Datetime formats (era and zone handled separately). public static final String dt1 = "yyyy-MM-dd'T'HH:mm:ss.ss"; public static final String dt2 = "yyyy-MM-dd'T'HH:mm:ss"; + public static final String dt3 = "yyyy-MM-dd'T'HH:mm"; public static final String d = "yyyy-MM-dd"; public static final String gym = "yyyy-MM"; public static final String gy = "yyyy"; @@ -111,7 +113,7 @@ */ public DateTimeObj(String dateTimeIn) throws TransformerException { - this(dateTimeIn, new String[]{dt2}); + this(dateTimeIn, new String[]{dt1, dt2, dt3}); } public DateTimeObj(String dateTimeIn, String[] formatsIn) throws TransformerException @@ -161,7 +163,10 @@ dateFormat.setLenient(false); m_dateTime = dateFormat.format(date); m_date = date; - + m_size = m_dateTime.length(); + // Remember our Time separator + m_T = (m_T = m_dateTime.indexOf("T")) != -1 ? m_T : m_size ; + Calendar cal = Calendar.getInstance(); cal.setLenient(false); cal.setTime(date); @@ -311,6 +316,8 @@ if (z > 0) { zone = datetime.substring(z); + if(datetime.charAt(z-1) == 'T') + z--; datetime = datetime.substring(0, z); } else if (z == -2) @@ -456,7 +463,7 @@ public static DateTimeObj time(Date timeIn) throws TransformerException { - DateTimeObj dt = new DateTimeObj (timeIn, t1); + DateTimeObj dt = new DateTimeObj (timeIn, t2); return dt; } @@ -598,6 +605,27 @@ } /** + * Return the hours from a given timezone. + * @param timezone string + * @return hours from timezone + */ + private static int getHrsFromZone(String zone) + { + if (zone.equals("Z")) + return 0; + int sign = 1; + if (zone.startsWith("-")) + { + sign = -1; + } + int index = zone.indexOf(":"); + int hr = sign * (Integer.parseInt(zone.substring(1, index))); + int min = sign * (Integer.parseInt(zone.substring(index+1))); + return hr; + } + + + /** * The duration function returns the duration specified in the duration * string given as the argument.. * The duration string that's returned must be a string in the format defined as the @@ -1011,6 +1039,252 @@ return dt; } + public DateTimeObj addTZToDateTime(Duration tz) throws TransformerException + { + if(tz == null) + { + if (m_zone.equals("z")) + return this; + Date date; + if (m_zone== null || m_zone.length()==0) + { + Calendar cal = Calendar.getInstance(); + int offset = TimeZone.getDefault().getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), + cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.DAY_OF_WEEK),Math.abs(TimeZone.getDefault().getRawOffset())); + int tZone = offset/(60*60*1000); + // ...but without daylight saving: + //int tZone = TimeZone.getDefault().getRawOffset()/(60*60*1000); + cal.setTime(m_date); + cal.add(Calendar.HOUR,-tZone); + //String dateTime = m_dateTime.substring(0,m_dateTime.indexOf("T")); + //dateTime = dateTime + formatDigits(hrs) + ":" + formatDigits(m_minute) + ":" + m_second; + date = cal.getTime(); + DateTimeObj datetime = new DateTimeObj(date, dt2); + datetime.setZone("Z"); + return datetime; + } + else + { + Calendar cal = Calendar.getInstance(); + int tZone = getHrsFromZone(m_zone); + cal.setTime(m_date); + cal.add(Calendar.HOUR,-tZone); + date = cal.getTime(); + DateTimeObj datetime = new DateTimeObj(date, dt2); + datetime.setZone("Z"); + return datetime; + } + } + else + { + Calendar cal = Calendar.getInstance(); + int offset = TimeZone.getDefault().getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), + cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.DAY_OF_WEEK),Math.abs(TimeZone.getDefault().getRawOffset())); + int tZone = tz.getSigned() ? tz.getHours() * -1 : tz.getHours(); + // need to handle m_zone!!! + cal.setTime(m_date); + cal.add(Calendar.HOUR,-tZone); + if(m_zone != null && m_zone.length()>0) + { + tZone = getHrsFromZone(m_zone); + tZone = tZone - (offset/(60*60*1000)); + cal.add(Calendar.HOUR,-tZone); + } + //String dateTime = m_dateTime.substring(0,m_dateTime.indexOf("T")); + //dateTime = dateTime + formatDigits(hrs) + ":" + formatDigits(m_minute) + ":" + m_second; + Date date = cal.getTime(); + DateTimeObj datetime = new DateTimeObj(date, dt2); + datetime.setZone("Z"); + return datetime; + } + } + + public DateTimeObj addTZToDate(Duration tz) throws TransformerException + { + if(tz == null) + { + if (m_zone== null || m_zone.length()==0) + { + Calendar cal = Calendar.getInstance(); + int offset = TimeZone.getDefault().getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), + cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.DAY_OF_WEEK),Math.abs(TimeZone.getDefault().getRawOffset())); + int tZone = offset/(60*60*1000); + boolean signed = tZone < 0; + DateTimeObj dateTime = date(m_dateTime); + dateTime.setZone((signed?"-" : "") + formatDigits(tZone) + ":00"); + return dateTime; + } + else + return this; + } + else + { + int tZone = tz.getHours(); + // need to handle m_zone!!! + DateTimeObj dateTime = date(m_dateTime); + dateTime.setZone((tz.getSigned() ? "-" + formatDigits(tZone) : formatDigits(tZone)) + ":00"); + return dateTime; + } + } + + public DateTimeObj addTZToTime(Duration tz) throws TransformerException + { + if(tz == null) + { + if (m_zone.equals("z")) + return this; + Date date; + if (m_zone== null || m_zone.length()==0) + { + Calendar cal = Calendar.getInstance(); + int offset = TimeZone.getDefault().getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), + cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.DAY_OF_WEEK),Math.abs(TimeZone.getDefault().getRawOffset())); + int tZone = offset/(60*60*1000); + cal.setTime(m_date); + cal.add(Calendar.HOUR,tZone); + //String dateTime = m_dateTime.substring(0,m_dateTime.indexOf("T")); + //dateTime = dateTime + formatDigits(hrs) + ":" + formatDigits(m_minute) + ":" + m_second; + date = cal.getTime(); + DateTimeObj time = time(date); + time.setZone("Z"); + return time; + } + else + { + Calendar cal = Calendar.getInstance(); + int tZone = getHrsFromZone(m_zone); + cal.setTime(m_date); + cal.add(Calendar.HOUR,-tZone); + date = cal.getTime(); + DateTimeObj time = time(date); + time.setZone("Z"); + return time; + } + } + else + { + Calendar cal = Calendar.getInstance(); + int offset = TimeZone.getDefault().getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), + cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.DAY_OF_WEEK),Math.abs(TimeZone.getDefault().getRawOffset())); + int tZone = tz.getSigned() ? tz.getHours() * -1 : tz.getHours(); + // need to handle m_zone!!! + cal.setTime(m_date); + cal.add(Calendar.HOUR,-tZone); + if(m_zone != null && m_zone.length()>0) + { + tZone = getHrsFromZone(m_zone); + tZone = tZone - (offset/(60*60*1000)); + cal.add(Calendar.HOUR,-tZone); + } + //String dateTime = m_dateTime.substring(0,m_dateTime.indexOf("T")); + //dateTime = dateTime + formatDigits(hrs) + ":" + formatDigits(m_minute) + ":" + m_second; + Date date = cal.getTime(); + DateTimeObj time = time(date); + time.setZone("Z"); + return time; + } + } + + public DateTimeObj removeTZFromDateTime(Duration tz) throws TransformerException + { + if(tz == null) + { + if (m_zone.equals("z") || m_zone== null || m_zone.length()==0) + return this; + + Date date; + Calendar cal = Calendar.getInstance(); + int offset = TimeZone.getDefault().getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), + cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.DAY_OF_WEEK),Math.abs(TimeZone.getDefault().getRawOffset())); + + int tZone = getHrsFromZone(m_zone); + tZone = (offset/(60*60*1000)) - tZone; + cal.setTime(m_date); + cal.add(Calendar.HOUR,tZone); + date = cal.getTime(); + DateTimeObj datetime = new DateTimeObj(date, dt2); + datetime.setZone("Z"); + return datetime; + } + else + { + Calendar cal = Calendar.getInstance(); + int offset = TimeZone.getDefault().getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), + cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.DAY_OF_WEEK),Math.abs(TimeZone.getDefault().getRawOffset())); + + int tZone = tz.getSigned() ? tz.getHours() * -1 : tz.getHours(); + tZone = tZone - (offset/(60*60*1000)); + // need to handle m_zone!!! + cal.setTime(m_date); + cal.add(Calendar.HOUR,tZone); + if(m_zone != null && m_zone.length()>0) + { + tZone = getHrsFromZone(m_zone); + tZone = (offset/(60*60*1000)) - tZone; + cal.add(Calendar.HOUR,tZone); + } + //String dateTime = m_dateTime.substring(0,m_dateTime.indexOf("T")); + //dateTime = dateTime + formatDigits(hrs) + ":" + formatDigits(m_minute) + ":" + m_second; + Date date = cal.getTime(); + DateTimeObj datetime = new DateTimeObj(date, dt2); + datetime.setZone("Z"); + return datetime; + } + } + /* Removed from spec... + public DateTimeObj removeTZFromDate(Duration tz) throws TransformerException + { + return new DateTimeObj(m_dateTime); + } + */ + + public DateTimeObj removeTZFromTime(Duration tz) throws TransformerException + { + if(tz == null) + { + if (m_zone.equals("z") || m_zone== null || m_zone.length()==0) + return this; + + Date date; + Calendar cal = Calendar.getInstance(); + int offset = TimeZone.getDefault().getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), + cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.DAY_OF_WEEK),Math.abs(TimeZone.getDefault().getRawOffset())); + + int tZone = getHrsFromZone(m_zone); + tZone = (offset/(60*60*1000)) - tZone; + cal.setTime(m_date); + cal.add(Calendar.HOUR,tZone); + date = cal.getTime(); + DateTimeObj time = time(date); + time.setZone("Z"); + return time; + } + else + { + Calendar cal = Calendar.getInstance(); + int offset = TimeZone.getDefault().getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), + cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.DAY_OF_WEEK),Math.abs(TimeZone.getDefault().getRawOffset())); + + int tZone = tz.getSigned() ? tz.getHours() * -1 : tz.getHours(); + tZone = tZone - (offset/(60*60*1000)); + // need to handle m_zone!!! + cal.setTime(m_date); + cal.add(Calendar.HOUR,tZone); + if(m_zone != null && m_zone.length()>0) + { + tZone = getHrsFromZone(m_zone); + tZone = (offset/(60*60*1000)) - tZone; + cal.add(Calendar.HOUR,tZone); + } + //String dateTime = m_dateTime.substring(0,m_dateTime.indexOf("T")); + //dateTime = dateTime + formatDigits(hrs) + ":" + formatDigits(m_minute) + ":" + m_second; + Date date = cal.getTime(); + DateTimeObj time = time(date); + time.setZone("Z"); + return time; + } + } + public void setYears(int years) @@ -1093,7 +1367,9 @@ public String toString() { - return (m_dateTime + (m_zone == null ? "" : m_zone)); + return (m_dateTime + + ((m_zone != null && m_zone.length()>0 && m_hour == 0) ? "T" : "" )+ + (m_zone == null ? "" : m_zone)); } No revision No revision 1.2.4.1.2.1 +1 -1 xml-xalan/java/src/org/apache/xpath/axes/FilterExprIteratorSimple.java Index: FilterExprIteratorSimple.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/axes/FilterExprIteratorSimple.java,v retrieving revision 1.2.4.1 retrieving revision 1.2.4.1.2.1 diff -u -r1.2.4.1 -r1.2.4.1.2.1 --- FilterExprIteratorSimple.java 14 Aug 2002 20:06:57 -0000 1.2.4.1 +++ FilterExprIteratorSimple.java 6 Sep 2002 15:06:06 -0000 1.2.4.1.2.1 @@ -112,7 +112,7 @@ vars.setStackFrame(savedStart); } else - result = (XNodeSet) expr.execute(xctxt); + result = (XSequence)expr.execute(xctxt); /* %REVIEW% %OPT% Unfortunately, not all variables can be statically resolved into either 1.26.4.1.2.1 +3 -1 xml-xalan/java/src/org/apache/xpath/axes/UnionPathIterator.java Index: UnionPathIterator.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/axes/UnionPathIterator.java,v retrieving revision 1.26.4.1 retrieving revision 1.26.4.1.2.1 diff -u -r1.26.4.1 -r1.26.4.1.2.1 --- UnionPathIterator.java 14 Aug 2002 20:06:57 -0000 1.26.4.1 +++ UnionPathIterator.java 6 Sep 2002 15:06:06 -0000 1.26.4.1.2.1 @@ -65,6 +65,8 @@ import org.apache.xpath.functions.Function; import org.apache.xpath.operations.Variable; import org.apache.xpath.parser.Node; +import org.apache.xpath.parser.SimpleNode; +import org.apache.xpath.seqctor.ExprSequence; /** * <meta name="usage" content="advanced"/> @@ -218,7 +220,7 @@ // we need to turn it back into a path expression here! There // might be a way to do this a bit earlier. -sb // if(!(((SimpleNode)n).isPathExpr())) - if(n instanceof Variable || n instanceof Function) + if(n instanceof Variable || n instanceof Function || n instanceof ExprSequence) { FilterExprIteratorSimple feis = new FilterExprIteratorSimple((Expression) n); No revision No revision 1.1.2.1 +232 -0 xml-xalan/java/src/org/apache/xpath/axes/Attic/ExceptPathIterator.java 1.1.2.1 +136 -0 xml-xalan/java/src/org/apache/xpath/axes/Attic/InterceptPathIterator.java No revision No revision 1.1.2.1 +127 -0 xml-xalan/java/src/org/apache/xpath/functions/Attic/FuncAddTZToDT.java 1.1.2.1 +127 -0 xml-xalan/java/src/org/apache/xpath/functions/Attic/FuncAddTZToDate.java 1.1.2.1 +127 -0 xml-xalan/java/src/org/apache/xpath/functions/Attic/FuncAddTZToTime.java 1.1.2.1 +127 -0 xml-xalan/java/src/org/apache/xpath/functions/Attic/FuncRemoveTZFromDT.java 1.1.2.1 +127 -0 xml-xalan/java/src/org/apache/xpath/functions/Attic/FuncRemoveTZFromTime.java No revision No revision 1.1.2.1.2.7 +18 -1 xml-xalan/java/src/org/apache/xpath/parser/Attic/SimpleNode.java Index: SimpleNode.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/parser/Attic/SimpleNode.java,v retrieving revision 1.1.2.1.2.6 retrieving revision 1.1.2.1.2.7 diff -u -r1.1.2.1.2.6 -r1.1.2.1.2.7 --- SimpleNode.java 27 Aug 2002 20:51:18 -0000 1.1.2.1.2.6 +++ SimpleNode.java 6 Sep 2002 15:06:07 -0000 1.1.2.1.2.7 @@ -9,6 +9,7 @@ import org.apache.xpath.Expression; import org.apache.xpath.ExpressionNode; import org.apache.xpath.axes.UnionPathIterator; +import org.apache.xpath.axes.ExceptPathIterator; import org.apache.xpath.axes.WalkerFactory; import org.apache.xpath.functions.*; import org.apache.xpath.objects.XDecimal; @@ -204,6 +205,21 @@ new QName("subtract-dayTimeDurationFromTime"), new FuncSubtractDTDurationFromTime()); m_builtInFunctions.put( + new QName("add-timezone-to-dateTime"), + new FuncAddTZToDT()); + m_builtInFunctions.put( + new QName("remove-timezone-from-dateTime"), + new FuncRemoveTZFromDT()); + m_builtInFunctions.put( + new QName("add-timezone-to-date"), + new FuncAddTZToDate()); + m_builtInFunctions.put( + new QName("add-timezone-to-time"), + new FuncAddTZToTime()); + m_builtInFunctions.put( + new QName("remove-timezone-from-time"), + new FuncRemoveTZFromTime()); + m_builtInFunctions.put( new QName("add-days"), new FuncAddDays()); m_builtInFunctions.put( @@ -597,7 +613,8 @@ newNode = new UnionPathIterator(); break; case XPathTreeConstants.JJTINTERSECTEXCEPTEXPR : - newNode = new NonExecutableExpression(p, "JJTUNIONEXPR"); + //newNode = new NonExecutableExpression(p, "JJTUNIONEXPR"); + newNode = new ExceptPathIterator(); break; // case XPathTreeConstants.JJTUNION: // newNode = new SimpleNode(); No revision No revision 1.1.2.1.2.1 +194 -1 xml-xalan/java/src/org/apache/xpath/quantified/Attic/Every.java Index: Every.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/quantified/Attic/Every.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.1.2.1 diff -u -r1.1.2.1 -r1.1.2.1.2.1 --- Every.java 14 Aug 2002 20:07:09 -0000 1.1.2.1 +++ Every.java 6 Sep 2002 15:06:08 -0000 1.1.2.1.2.1 @@ -7,10 +7,19 @@ import org.apache.xpath.Expression; import org.apache.xpath.ExpressionOwner; import org.apache.xpath.VariableComposeState; +import org.apache.xpath.VariableStack; import org.apache.xpath.XPathContext; import org.apache.xpath.XPathVisitor; import org.apache.xpath.objects.XObject; import org.apache.xpath.parser.XPath; +import org.apache.xpath.operations.Variable; +import org.apache.xpath.parser.Node; +import org.apache.xpath.parser.QuantifiedExpr; +import org.apache.xml.utils.QName; +import org.apache.xpath.objects.XBoolean; +import org.apache.xpath.objects.XSequence; +import org.apache.xpath.objects.XNodeSequenceSingleton; + public class Every extends Expression implements ExpressionOwner { @@ -18,6 +27,16 @@ public Every() { super(); } + + Expression m_test; + + Expression[] m_clauses; + + Expression[] m_vars; + + int m_evalPos = 0; + + XSequence[] m_evaluations; /** Accept the visitor. **/ public Object jjtAccept(org.apache.xpath.parser.XPathVisitor visitor, Object data) { @@ -25,6 +44,55 @@ } /** + * @see org.apache.xpath.parser.Node#jjtSetParent(Node) + */ + public void jjtSetParent(Node n) + { + super.jjtSetParent(n); + if (n instanceof QuantifiedExpr) // don't fix up if we're reducing + { + QuantifiedExpr qexpr = (QuantifiedExpr) n; + + // At this point all children should have been added except this node. + // This has a fixed number of children. + int i = qexpr.jjtGetNumChildren(); + m_test = (Expression) qexpr.jjtGetChild(--i); + m_test.jjtSetParent(this); + i-=2; + int count = (i)/3; + m_clauses = new Expression[count]; + m_vars = new Expression[count]; + m_evaluations = new XSequence[count--]; + //count = 0; + while(i>0) + { + m_clauses[count] = (Expression) qexpr.jjtGetChild(i); + m_clauses[count].jjtSetParent(this); + m_vars [count]= (Expression) qexpr.jjtGetChild(i-=2); + m_vars[count--].jjtSetParent(this); + i--; + } + + qexpr.m_exprs.setSize(1); + } + } + + /** + * @see org.apache.xpath.parser.Node#jjtGetChild(int) + */ + public Node jjtGetChild(int i) + { + if (i == this.jjtGetNumChildren() -1) + return m_test; + else if (i < m_vars.length) + return m_vars[i]; + else if (i < m_vars.length + m_clauses.length) + return m_clauses[i - m_vars.length]; + else + return null; + } + + /** * @see Expression#deepEquals(Expression) */ public boolean deepEquals(Expression expr) @@ -37,6 +105,65 @@ */ public void fixupVariables(VariableComposeState vcs) { + vcs.pushStackMark(); + int globalsSize = vcs.getGlobalsSize(); + for (int i = 0; i < m_vars.length; i++) + { + Variable var = (Variable)m_vars[i]; + QName varName = var.getQName(); + int index = vcs.addVariableName(varName) - globalsSize; + var.setIndex(index); + var.setFixUpWasCalled(true); + // var.fixupVariables(vcs); + } + m_test.fixupVariables(vcs); + vcs.popStackMark(); + } + + /** + * Bind the next tuple of values to the variables + * + * @return XObject The last evaluation found, or null if + * there's no more to evaluate. + */ + public XObject evalVars(XPathContext xctxt) throws TransformerException + { + //XObject var = m_var.execute(xctxt); + VariableStack vars = xctxt.getVarStack(); + XSequence xseq; + XObject xobj = null; + for (int i =m_evalPos; i < m_vars.length; i++) + { + if (m_evaluations[i] == null) + { + XObject clauseResult = m_clauses[i].execute(xctxt); + xseq = clauseResult.xseq(); + m_evaluations[i] = xseq; + } + else + xseq = m_evaluations[i]; + + xobj = xseq.next(); + if (null != xobj) + { + vars.setLocalVariable(((Variable)m_vars[i]).getIndex(), xobj); + m_evalPos = i; + } + else + { + if (i != 0) + { + m_evaluations[i] = null; + i -=2; + } + else + { + m_evalPos = m_vars.length; + break; + } + } + } + return xobj; } @@ -45,7 +172,73 @@ */ public XObject execute(XPathContext xctxt) throws TransformerException { - return null; + boolean testResult = true; + while (true) + { + XObject xobj; + xobj = evalVars(xctxt); + if (null != xobj) + { + testResult = m_test.execute(xctxt).bool(); + if(!testResult) + return new XBoolean(false); + } + else + return new XBoolean(true); + } + // + // XSequence xseq = clauseResult.xseq(); + + // VariableStack vars = xctxt.getVarStack(); + // int thisframe = vars.getStackFrame(); + +// XObject item; + // try{ + /* int[] currentExpressionNodes = xctxt.getCurrentExpressionNodeStack(); + int currentExpressionNodePos = + xctxt.getCurrentExpressionNodesFirstFree() - 1; + int argsFrame = -1; + argsFrame = vars.link(1); + vars.setStackFrame(thisframe); + while (null != (item = xseq.next())) + { + xctxt.setCurrentItem(item); + if(item instanceof XNodeSequenceSingleton) + { + XNodeSequenceSingleton xnss = (XNodeSequenceSingleton)item; + int nodeHandle = xnss.getNodeHandle(); + currentExpressionNodes[currentExpressionNodePos] = nodeHandle; + } + + // This code will create a section on the stack that is all the + // evaluated arguments. These will be copied into the real params + // section of each called template. + + vars.setLocalVariable(0, item, argsFrame); + vars.setStackFrame(argsFrame); + int len=0; + /* + for (int i =0; i < m_vars.length; i++) + { + XObject left = m_vars[i].execute(xctxt); + + if (left.isNodesetExpr()) + len += left.iter().getLength(); + else + len += 1; + } + // switch(type) + // { + // case + //m_test.m_left.execute() + XObject testResult = m_test.execute(xctxt); + XSequence xseq = testResult.xseq(); + if(xseq.next()== null) + return new XBoolean(true); + //if (xseq.getLength() == len) + // return new XBoolean(true); + //} + return new XBoolean(false);*/ } 1.1.2.1.2.1 +180 -1 xml-xalan/java/src/org/apache/xpath/quantified/Attic/Some.java Index: Some.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/quantified/Attic/Some.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.1.2.1 diff -u -r1.1.2.1 -r1.1.2.1.2.1 --- Some.java 14 Aug 2002 20:07:09 -0000 1.1.2.1 +++ Some.java 6 Sep 2002 15:06:08 -0000 1.1.2.1.2.1 @@ -7,13 +7,31 @@ import org.apache.xpath.Expression; import org.apache.xpath.ExpressionOwner; import org.apache.xpath.VariableComposeState; +import org.apache.xpath.VariableStack; import org.apache.xpath.XPathContext; import org.apache.xpath.XPathVisitor; import org.apache.xpath.objects.XObject; +import org.apache.xpath.operations.Variable; +import org.apache.xpath.parser.Node; +import org.apache.xpath.parser.QuantifiedExpr; +import org.apache.xml.utils.QName; +import org.apache.xpath.objects.XBoolean; +import org.apache.xpath.objects.XSequence; +import org.apache.xpath.objects.XNodeSequenceSingleton; public class Some extends Expression implements ExpressionOwner { + Expression m_test; + + Expression[] m_clauses; + + Expression[] m_vars; + + int m_evalPos = 0; + + XSequence[] m_evaluations; + public Some() { super(); } @@ -21,6 +39,56 @@ /** Accept the visitor. **/ public Object jjtAccept(org.apache.xpath.parser.XPathVisitor visitor, Object data) { return visitor.visit(this, data); + } + + + /** + * @see org.apache.xpath.parser.Node#jjtSetParent(Node) + */ + public void jjtSetParent(Node n) + { + super.jjtSetParent(n); + if (n instanceof QuantifiedExpr) // don't fix up if we're reducing + { + QuantifiedExpr qexpr = (QuantifiedExpr) n; + + // At this point all children should have been added except this node. + // This has a fixed number of children. + int i = qexpr.jjtGetNumChildren(); + m_test = (Expression) qexpr.jjtGetChild(--i); + m_test.jjtSetParent(this); + i-=2; + int count = (i)/3; + m_clauses = new Expression[count]; + m_vars = new Expression[count]; + m_evaluations = new XSequence[count]; + count = 0; + while(i>0) + { + m_clauses[count] = (Expression) qexpr.jjtGetChild(i); + m_clauses[count].jjtSetParent(this); + m_vars [count]= (Expression) qexpr.jjtGetChild(i-=2); + m_vars[count++].jjtSetParent(this); + i--; + } + + qexpr.m_exprs.setSize(1); + } + } + + /** + * @see org.apache.xpath.parser.Node#jjtGetChild(int) + */ + public Node jjtGetChild(int i) + { + if (i == this.jjtGetNumChildren() -1) + return m_test; + else if (i < m_vars.length) + return m_vars[i]; + else if (i < m_vars.length + m_clauses.length) + return m_clauses[i - m_vars.length]; + else + return null; } /** @@ -35,14 +103,125 @@ */ public void fixupVariables(VariableComposeState vcs) { + vcs.pushStackMark(); + int globalsSize = vcs.getGlobalsSize(); + for (int i = 0; i < m_vars.length; i++) + { + Variable var = (Variable)m_vars[i]; + QName varName = var.getQName(); + int index = vcs.addVariableName(varName) - globalsSize; + var.setIndex(index); + var.setFixUpWasCalled(true); + // var.fixupVariables(vcs); + } + m_test.fixupVariables(vcs); + vcs.popStackMark(); } /** + * Bind the next tuple of values to the variables + * + * @return XObject The last evaluation found, or null if + * there's no more to evaluate. + */ + public XObject evalVars(XPathContext xctxt) throws TransformerException + { + //XObject var = m_var.execute(xctxt); + VariableStack vars = xctxt.getVarStack(); + XSequence xseq; + XObject xobj = null; + for (int i =m_evalPos; i < m_vars.length; i++) + { + if (m_evaluations[i] == null) + { + XObject clauseResult = m_clauses[i].execute(xctxt); + xseq = clauseResult.xseq(); + m_evaluations[i] = xseq; + } + else + xseq = m_evaluations[i]; + + xobj = xseq.next(); + if (null != xobj) + { + vars.setLocalVariable(((Variable)m_vars[i]).getIndex(), xobj); + m_evalPos = i; + } + else + { + if (i != 0) + { + m_evaluations[i] = null; + i -=2; + } + else + { + m_evalPos = m_vars.length; + break; + } + } + } + return xobj; + } + + + /** * @see Expression#execute(XPathContext) */ public XObject execute(XPathContext xctxt) throws TransformerException { - return null; + boolean testResult = true; + while (true) + { + XObject xobj; + xobj = evalVars(xctxt); + if (null != xobj) + { + testResult = m_test.execute(xctxt).bool(); + if(testResult) + return new XBoolean(true); + } + else + break; + } + return new XBoolean(false); + // + // XSequence xseq = clauseResult.xseq(); + + // VariableStack vars = xctxt.getVarStack(); + // int thisframe = vars.getStackFrame(); + +// XObject item; + // try{ + /* int[] currentExpressionNodes = xctxt.getCurrentExpressionNodeStack(); + int currentExpressionNodePos = + xctxt.getCurrentExpressionNodesFirstFree() - 1; + int argsFrame = -1; + argsFrame = vars.link(1); + vars.setStackFrame(thisframe); + while (null != (item = xseq.next())) + { + xctxt.setCurrentItem(item); + if(item instanceof XNodeSequenceSingleton) + { + XNodeSequenceSingleton xnss = (XNodeSequenceSingleton)item; + int nodeHandle = xnss.getNodeHandle(); + currentExpressionNodes[currentExpressionNodePos] = nodeHandle; + } + + // This code will create a section on the stack that is all the + // evaluated arguments. These will be copied into the real params + // section of each called template. + + vars.setLocalVariable(0, item, argsFrame); + vars.setStackFrame(argsFrame); + + boolean testResult = m_test.execute(xctxt).bool(); + if(testResult) + return new XBoolean(true); + //} + return new XBoolean(false);*/ + } /**
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]