|
From: <et...@us...> - 2011-05-06 22:35:18
|
Revision: 4324
http://mxquery.svn.sourceforge.net/mxquery/?rev=4324&view=rev
Author: etterth
Date: 2011-05-06 22:35:11 +0000 (Fri, 06 May 2011)
Log Message:
-----------
- Added Timer
- Fixed Timezone-related bug, which caused a wrong time to be returned in fn:currenttime()
Modified Paths:
--------------
trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryDateTime.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/PlatformDependentUtils.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/Calendar.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/TimeZone.java
Added Paths:
-----------
trunk/MXQuery/xqib_samples/timer.html
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/Timer.java
Added: trunk/MXQuery/xqib_samples/timer.html
===================================================================
--- trunk/MXQuery/xqib_samples/timer.html (rev 0)
+++ trunk/MXQuery/xqib_samples/timer.html 2011-05-06 22:35:11 UTC (rev 4324)
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>XQIB: Sample page</title>
+ <meta charset="UTF-8"/>
+ <link href="style.css" rel="stylesheet" type="text/css">
+ <script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
+ <script type="application/xquery">
+ declare updating function local:listener() {
+ insert node <div>{fn:current-time()}</div> as last into b:dom()//body
+, b:timer(1000, xs:QName('local:listener'))
+ };
+
+ b:timer(1000, xs:QName('local:listener'))
+
+ </script>
+ </head>
+ <body>
+ <h1>timer</h1>
+
+ </body>
+</html>
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryDateTime.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryDateTime.java 2011-05-06 10:18:30 UTC (rev 4323)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryDateTime.java 2011-05-06 22:35:11 UTC (rev 4324)
@@ -897,7 +897,7 @@
// int offset = new GregorianCalendar().get(Calendar.ZONE_OFFSET);
// int offset = Calendar.getInstance().get(Calendar.ZONE_OFFSET);
// return getNewCalendar(offset);
- return getNewCalendar(0);
+ return getNewCalendar(TimeZone.getDefault().getRawOffset());
}
private static TimeZone getNewTimeZone(int zone_offset) {
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-05-06 10:18:30 UTC (rev 4323)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-05-06 22:35:11 UTC (rev 4324)
@@ -211,6 +211,9 @@
}
};
}
+ else {
+ throw new MXQueryException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "a qname has to be provided in an async expath function", getLoc());
+ }
XDMIterator[] oldsubiters = subIters;
subIters = new XDMIterator[oldsubiters.length - 1];
for (int i = 1; i < oldsubiters.length; i++) {
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java 2011-05-06 10:18:30 UTC (rev 4323)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java 2011-05-06 22:35:11 UTC (rev 4324)
@@ -454,6 +454,33 @@
qn = new QName(
"http://xqib.org",
"b",
+ "timer");
+ paramTypes = new TypeInfo[2];
+
+ paramTypes[0] = new TypeInfo(getType(
+ "numeric",ctx),getOccur("numeric"),null);
+
+ paramTypes[1] = new TypeInfo(getType(
+ "QName",ctx),getOccur("QName"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.Timer iter = new ch.ethz.mxquery.functions.b.Timer();
+ iter.setContext(context, false);
+
+ type = -1;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
"pageURI");
paramTypes = new TypeInfo[0];
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/Timer.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/Timer.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/Timer.java 2011-05-06 22:35:11 UTC (rev 4324)
@@ -0,0 +1,148 @@
+package ch.ethz.mxquery.functions.b;
+
+import java.util.Vector;
+
+import com.google.gwt.user.client.Window;
+
+import ch.ethz.mxqjs.client.Environment;
+import ch.ethz.mxqjs.client.QnameAndArity;
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.MXQueryBigDecimal;
+import ch.ethz.mxquery.datamodel.MXQueryDouble;
+import ch.ethz.mxquery.datamodel.MXQueryFloat;
+import ch.ethz.mxquery.datamodel.MXQueryNumber;
+import ch.ethz.mxquery.datamodel.QName;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.types.TypeInfo;
+import ch.ethz.mxquery.datamodel.xdm.DecimalToken;
+import ch.ethz.mxquery.datamodel.xdm.DoubleToken;
+import ch.ethz.mxquery.datamodel.xdm.FloatToken;
+import ch.ethz.mxquery.datamodel.xdm.LongToken;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.DynamicException;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.StaticException;
+import ch.ethz.mxquery.exceptions.TypeException;
+import ch.ethz.mxquery.extensionsModules.expathhttp.HttpIO;
+import ch.ethz.mxquery.functions.fn.Abs;
+import ch.ethz.mxquery.model.TokenBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.LogLevel;
+import ch.ethz.mxquery.util.Logger;
+import ch.ethz.mxquery.util.browser.XmlHttpRequestWrappedHandler;
+import ch.ethz.mxquery.util.browser.XmlHttpRequestWrapper;
+
+public class Timer extends TokenBasedIterator {
+
+ protected QName asynchandlername;
+
+ @Override
+ protected void init() throws MXQueryException {
+ // TODO integer and timer
+ currentToken = Token.END_SEQUENCE_TOKEN;
+ if (subIters[0] == null) {
+ throw new IllegalArgumentException();
+ }
+ XDMIterator handleriter = subIters[1];
+ asynchandlername = handleriter.next().getQNameTokenValue();
+ if (asynchandlername == null) {
+ throw new MXQueryException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "a qname has to be provided in b:timer", getLoc());
+ }
+ XDMIterator timeiter = subIters[0];
+ TokenInterface tok;
+ try {
+ tok = timeiter.next();
+ } catch (TypeException de) {
+ if (de.getErrorCode().equals(
+ ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE))
+ throw new DynamicException(
+ ErrorCodes.F0023_INVALID_VALUE_FOR_CAST_CONSTRUCTOR,
+ de.getMessage(), loc);
+ else
+ throw de;
+ }
+
+ int type = Type.getEventTypeSubstituted(tok.getEventType(),
+ Context.getDictionary());
+
+ if (Type.isAttribute(type)) {
+ type = Type.getAttributeValueType(type);
+ }
+
+ if (!Type.isNumericPrimitiveType(type)){
+ throw new MXQueryException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "a numeric value has to be provided in b:timer", getLoc());
+ }
+
+ int time;
+ switch(type){
+ case Type.INTEGER:
+ time = (int) tok.getLong();
+ break;
+ case Type.DOUBLE:
+ case Type.FLOAT:
+ case Type.DECIMAL:
+ time = (int) tok.getNumber().getLongValue();
+ break;
+ case Type.UNTYPED_ATOMIC:
+ case Type.UNTYPED:
+ time = new MXQueryDouble(tok.getValueAsString()).getIntValue();
+ break;
+ default:
+ throw new TypeException(ErrorCodes.F0028_INVALID_ARGUMENT_TYPE, "Invalid argument type "+Type.getTypeQName(type, Context.getDictionary()), loc);
+}//switch
+ if (this.getContext().getRootContext()
+ .getFunction(asynchandlername, 0) == null) {
+ throw new MXQueryException(
+ ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,
+ "the eventhandler with the name "
+ + asynchandlername.toString()
+ + " is not available in a timer call",
+ loc);
+ }
+ final Timer thisobj = this;
+
+ com.google.gwt.user.client.Timer timerobj = new com.google.gwt.user.client.Timer() {
+
+ @Override
+ public void run() {
+
+ Logger log = Logger.getLogger(this.getClass().getName());
+ log.log(LogLevel.FINER, "Invoking the TimerHandler " + thisobj.asynchandlername.toString());
+ QnameAndArity qa = new QnameAndArity(
+ thisobj.asynchandlername, 0, thisobj.getContext()
+ .getRootContext());
+ try {
+ Environment.invokeModule(qa,
+ new XDMIterator[] { });
+ } catch (MXQueryException e) {
+ // TODO Auto-generated catch block
+
+ Environment.displayErrorMessage(new StringBuffer(), null, e,
+ false);
+ e.printStackTrace();
+ }
+ log.log(LogLevel.FINER, "TimerHandler " + thisobj.asynchandlername.toString() + " done");
+ }
+ };
+ timerobj.schedule(time);
+
+
+ }
+
+ @Override
+ public TypeInfo getStaticType() {
+ return new TypeInfo();
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ XDMIterator copy = new Timer();
+ copy.setContext(context, true);
+ copy.setSubIters(subIters);
+ return copy;
+ }
+
+}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/PlatformDependentUtils.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/PlatformDependentUtils.java 2011-05-06 10:18:30 UTC (rev 4323)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/PlatformDependentUtils.java 2011-05-06 22:35:11 UTC (rev 4324)
@@ -93,7 +93,7 @@
public static int getCurrentTimezoneOffset(){
Calendar cal = MXQueryDateTime.getNewCalendar();
TimeZone tz = cal.getTimeZone();
- return tz.getStandardOffset() / (1000 * 60);
+ return tz.getRawOffset() / (1000 * 60);
}
/**
* Provide access to the current time
@@ -105,7 +105,7 @@
TimeZone tz = cal.getTimeZone();
return new MXQueryDateTime(cal,
- tz.getStandardOffset() , MXQueryDateTime.VALUE_TYPE_DATE_TIME);
+ tz.getRawOffset() / (1000 * 60) , MXQueryDateTime.VALUE_TYPE_DATE_TIME);
}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/Calendar.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/Calendar.java 2011-05-06 10:18:30 UTC (rev 4323)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/Calendar.java 2011-05-06 22:35:11 UTC (rev 4324)
@@ -437,7 +437,7 @@
}
else
{
- return timeZone.getStandardOffset();
+ return timeZone.getRawOffset();
}
// case DST_OFFSET:
// //TODO, fix
@@ -805,16 +805,29 @@
// }
- Date date = new Date(
- localDateTime.year,
- localDateTime.month,
- localDateTime.date,
- localDateTime.hourOfDay,
- localDateTime.minutes,
- localDateTime.seconds);
+ Date datewithoutms = new Date(
+ localDateTime.year,
+ localDateTime.month,
+ localDateTime.date,
+ localDateTime.hourOfDay,
+ localDateTime.minutes,
+ localDateTime.seconds);
- // Date class does not have milliseconds manipulation.
- date.setTime(date.getTime() + localDateTime.milliseconds);
+
+ // Date class does not have milliseconds manipulation.
+ Date datewithms = new Date(datewithoutms.getTime() + localDateTime.milliseconds);
+ localDateTime.year = datewithms.getYear();
+ localDateTime.month = datewithms.getMonth();
+ localDateTime.date = datewithms.getDate();
+ localDateTime.hourOfDay = datewithms.getHours();
+ localDateTime.minutes = datewithms.getMinutes();
+ localDateTime.seconds = datewithms.getSeconds();
+ localDateTime.milliseconds = (int) (datewithms.getTime() - datewithoutms.getTime());
+ //milliseconds might have been negative
+ if (localDateTime.milliseconds < 0){
+ localDateTime.milliseconds = - localDateTime.milliseconds;
+ }
+ localDateTime.milliseconds = localDateTime.milliseconds % 1000;
// Store the rolled up fields back in the original LocalDateTime object.
// setValuesFromDate(this.date);
@@ -943,8 +956,8 @@
// Console.log("GWTDate createDate " + d);
- int offsetConversion = d.getTimezoneOffset() - timeZone2.getStandardOffset();
- d.setMinutes(d.getMinutes() - offsetConversion);
+ int offsetConversion = -d.getTimezoneOffset()*60*1000 - timeZone2.getRawOffset();
+ d.setTime(d.getTime() + offsetConversion);
// d.setMinutes(d.getMinutes() - timeZone.timeZoneContainer.getTimeZone().getDaylightAdjustment(d));
return d;
}
@@ -954,7 +967,7 @@
return this.getTime().getTime();
}
public static Calendar getInstance() {
- return getInstance(new Date().getTimezoneOffset());
+ return getInstance(TimeZone.getDefault().getRawOffset());
}
public static Calendar getInstance(int zone_offset) {
// TODO Auto-generated method stub
@@ -968,8 +981,9 @@
}
public void setTimeZone(TimeZone newTimeZone) {
- this.localDateTime.minutes += this.timeZone.getStandardOffset()- newTimeZone.getStandardOffset() ;
+ this.localDateTime.milliseconds -= this.timeZone.getRawOffset()- newTimeZone.getRawOffset() ;
this.timeZone = newTimeZone;
+ this.needsCalculation = true;
}
public TimeZone getTimeZone() {
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/TimeZone.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/TimeZone.java 2011-05-06 10:18:30 UTC (rev 4323)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/TimeZone.java 2011-05-06 22:35:11 UTC (rev 4324)
@@ -5,19 +5,19 @@
public class TimeZone {
- private int minutes_offset = 0;
+ private int milliseconds_offset = 0;
public TimeZone(int zone_offset) {
- minutes_offset = zone_offset;
+ milliseconds_offset = zone_offset;
}
public static TimeZone getDefault() {
- return new TimeZone(new Date().getTimezoneOffset());
+ return new TimeZone(-new Date().getTimezoneOffset()*1000*60);
}
/**
- * @return the offset in minutes
+ * @return the offset in milliseconds
*/
- public int getStandardOffset() {
- return minutes_offset;
+ public int getRawOffset() {
+ return milliseconds_offset;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|