[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qexo-general] some contribution
From: |
Marco Vezzoli |
Subject: |
[Qexo-general] some contribution |
Date: |
Mon, 22 Jul 2002 13:28:28 +0200 |
I added four functions as defined in
http://www.w3.org/TR/xquery-operators/ these functions deal mainly with
date; for that type I used java.util.Date (maybe is not the best
solution).
Here is a very simple patch for the interpreter; I also attached a new
module.
*** gnu/xquery/lang/XQuery.java.sav Tue Jul 16 14:05:14 2002
--- gnu/xquery/lang/XQuery.java Wed Jul 17 08:25:00 2002
***************
*** 176,181 ****
--- 176,186 ----
define("concat", new kawa.standard.string_append());
define("write-to", gnu.kawa.xml.WriteTo.writeTo);
+
+ define("current-dateTime", gnu.xquery.util.Date.current);
+ define("dateTime", gnu.xquery.util.Date.dateTime);
+ define("date", gnu.xquery.util.Date.date);
+ define("time", gnu.xquery.util.Date.time);
}
public static XQuery getInstance()
--
(--cafe babe--)
Marco Vezzoli address@hidden
CR&D Intranet Developement STMicroelectronics
tel. +39 039 603 6852 fax. +39 039 603 5055
package gnu.xquery.util;
import gnu.mapping.*;
import gnu.lists.*;
import gnu.xml.*;
import java.util.*;
import java.text.*;
/**
* Date.java
*
*
* Created: Tue Jul 16 14:07:19 2002
*
* @author Marco Vezzoli
* @version
*/
public class Date extends Procedure{
static public final int CURRENTDATETIME=0;
static public final int DATETIME=1;
static public final int DATE=2;
static public final int TIME=3;
static public final String [] names={"current-dateTime","dateTime",
"date","time"};
static public final Date currentDateTime=new Date(CURRENTDATETIME);
static public final Date dateTime=new Date(DATETIME);
static public final Date date=new Date(DATE);
static public final Date time=new Date(TIME);
static final SimpleDateFormat xmlDateTimeFormat=new
SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
static final SimpleDateFormat xmlDateFormat=new
SimpleDateFormat("yyyy-MM-dd");
static final SimpleDateFormat xmlTimeFormat=new SimpleDateFormat("hh:mm:ss");
private int type=-1;
public Date(int type){
super(names[type]);
this.type=type;
}
public Object applyN (Object[] args) throws Throwable{
throw new WrongArguments(this,args.length);
}
public Object apply0 () throws Throwable{
switch (type){
case CURRENT:
return new java.util.Date();
}
throw new WrongArguments(this,0);
}
public Object apply1 (Object arg1) throws Throwable{
switch (type){
case DATETIME:
return xmlDateTimeFormat.parse(arg1.toString());
case DATE:
return xmlDateFormat.parse(arg1.toString());
case TIME:
return xmlTimeFormat.parse(arg1.toString());
}
throw new WrongArguments(this,1);
}
public Object apply2 (Object arg1,Object arg2) throws Throwable{
throw new WrongArguments(this,2);
}
public Object apply3 (Object arg1, Object arg2, Object arg3) throws Throwable{
throw new WrongArguments(this,3);
}
public Object apply4(Object arg1,Object arg2,
Object arg3,Object arg4) throws Throwable{
throw new WrongArguments(this,4);
}
} // Date
- [Qexo-general] some contribution,
Marco Vezzoli <=