You can subscribe to this list here.
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(71) |
Jun
(43) |
Jul
(9) |
Aug
(10) |
Sep
(21) |
Oct
(38) |
Nov
|
Dec
(11) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2012 |
Jan
|
Feb
(21) |
Mar
(9) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <pm_...@us...> - 2011-06-07 08:33:32
|
Revision: 4389
http://mxquery.svn.sourceforge.net/mxquery/?rev=4389&view=rev
Author: pm_fischer
Date: 2011-06-07 08:33:26 +0000 (Tue, 07 Jun 2011)
Log Message:
-----------
properly initialize iterators to access "body" content
Modified Paths:
--------------
trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-06-03 15:23:34 UTC (rev 4388)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-06-07 08:33:26 UTC (rev 4389)
@@ -888,7 +888,8 @@
ChildIterator bodyContentIt = new ChildIterator(childContext,
new TypeInfo(Type.NODE, Type.OCCURRENCE_IND_ZERO_OR_MORE), loc);
bodyContentIt.setSubIters(bodyIt);
-
+ bodyContentIt.staticInit();
+
String contentType = (String) hm.get("media-type");
if (!hm.containsKey("src")) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tim...@us...> - 2011-06-03 15:23:41
|
Revision: 4388
http://mxquery.svn.sourceforge.net/mxquery/?rev=4388&view=rev
Author: timchurch
Date: 2011-06-03 15:23:34 +0000 (Fri, 03 Jun 2011)
Log Message:
-----------
Mashup working fully from XQuery (no Java helper functions needed)
Modified Paths:
--------------
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/UserLocationOverlay.java
Added Paths:
-----------
trunk/MXQuery_Android_App/res/raw/mashup_without_helpers.xq
Added: trunk/MXQuery_Android_App/res/raw/mashup_without_helpers.xq
===================================================================
--- trunk/MXQuery_Android_App/res/raw/mashup_without_helpers.xq (rev 0)
+++ trunk/MXQuery_Android_App/res/raw/mashup_without_helpers.xq 2011-06-03 15:23:34 UTC (rev 4388)
@@ -0,0 +1,43 @@
+declare namespace m = "java:ch.ethz.mxquery.android.MXQuery";
+declare namespace map = "java:ch.ethz.mxquery.android.MyMap";
+declare namespace l = "java:android.location.Location";
+declare namespace g = "java:com.google.android.maps.GeoPoint";
+declare namespace oi = "java:com.google.android.maps.OverlayItem";
+declare namespace ulo = "java:ch.ethz.mxquery.android.UserLocationOverlay";
+declare namespace po = "java:ch.ethz.mxquery.android.PizzaOverlay";
+declare namespace mv = "java:com.google.android.maps.MapView";
+declare namespace mc = "java:com.google.android.maps.MapController";
+
+
+import module namespace http = "http://expath.org/ns/http-client";
+declare variable $activity := m:getActivity();
+declare variable $loc := m:getLocation();
+
+declare function local:createOverlayItem($lat as xs:double, $lng as xs:double, $name as xs:string) {
+ let $geopoint := g:new(($lat * 1e6) cast as xs:integer, ($lng * 1e6) cast as xs:integer)
+ let $overlayItem := oi:new($geopoint, $name, "")
+ return $overlayItem
+};
+
+declare function local:createOverlayItemFromLoc($loc) {
+ local:createOverlayItem(l:getLatitude($loc), l:getLongitude($loc), "")
+};
+
+
+ulo:addOverlay(map:userLocationOverlay($activity), local:createOverlayItemFromLoc($loc)),
+
+let $geopoint := g:new((l:getLatitude($loc) * 1e6) cast as xs:integer, (l:getLongitude($loc) * 1e6) cast as xs:integer)
+return mc:animateTo(mv:getController(map:mapView($activity)), $geopoint),
+
+let $baseUrl := "https://maps.googleapis.com/maps/api/place/search/xml?radius=50&types=food&name=pizza&sensor=false&key=AIzaSyAtNn71gfANF9KWPp0W_pEd1LHaxIux92g&location="
+let $url := fn:concat($baseUrl, l:getLatitude($loc), ",", l:getLongitude($loc))
+let $req := <http:request method="GET" href="{$url}" />
+let $result := http:send-request($req, ())[2]
+for $pizza in $result//result
+ let $name := $pizza/name/text()
+ let $lat := $pizza/geometry/location/lat cast as xs:double
+ let $lng := $pizza/geometry/location/lng cast as xs:double
+ return po:addOverlay(map:pizzaOverlay($activity), local:createOverlayItem($lat, $lng, $name)),
+
+mv:postInvalidate(map:mapView($activity))
+
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java 2011-06-03 15:21:55 UTC (rev 4387)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java 2011-06-03 15:23:34 UTC (rev 4388)
@@ -10,24 +10,21 @@
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.drawable.Drawable;
-import android.location.Location;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import ch.ethz.mxquery.android.MXQueryService.MXQueryServiceBinder;
-import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
-import com.google.android.maps.OverlayItem;
public class MyMap extends MapActivity {
- private MapView mapView;
+ public MapView mapView;
+ public UserLocationOverlay userLocationOverlay;
+ public PizzaOverlay pizzaOverlay;
private List<Overlay> mapOverlays;
- private UserLocationOverlay userLocationOverlay;
- private PizzaOverlay pizzaOverlay;
private Drawable pizzaDrawable;
protected MXQueryService mService;
protected boolean mIsBound = false;
@@ -50,6 +47,9 @@
pizzaOverlay = new PizzaOverlay(pizzaDrawable, this);
mapOverlays.add(pizzaOverlay);
+ userLocationOverlay = new UserLocationOverlay(this.getResources().getDrawable(R.drawable.marker));
+ mapOverlays.add(userLocationOverlay);
+
// start service
if (!mIsBound) {
doBindService();
@@ -85,7 +85,7 @@
Log.i(LOG_TAG, "MXQueryService Connected. Running queries...");
// show user location and nearby pizza places on map
- String showPizzasQuery = readXQueryFile(R.raw.mashup);
+ String showPizzasQuery = readXQueryFile(R.raw.mashup_without_helpers);
mService.runQuery(showPizzasQuery, queryListener);
}
@@ -120,21 +120,4 @@
return query;
}
- public void setUserLocation(Location userLocation) {
- Log.i(LOG_TAG, "Setting user location: (" + userLocation.getLatitude() + "," + userLocation.getLongitude() + ")");
- userLocationOverlay = new UserLocationOverlay(this.getResources().getDrawable(R.drawable.marker));
- GeoPoint userLocationGeoPoint = new GeoPoint((int) (userLocation.getLatitude()*1e6), (int) (userLocation.getLongitude()*1e6));
- OverlayItem userLocationOverlayItem = new OverlayItem(userLocationGeoPoint, "", "");
- userLocationOverlay.addOverlay(userLocationOverlayItem);
- mapOverlays.add(userLocationOverlay);
- mapView.getController().animateTo(userLocationGeoPoint);
- }
-
- public void addPlace(String name, double lat, double lng) {
- Log.i(LOG_TAG, "ADDING PLACE: " + name + ", " + Double.toString(lat) + ", " + Double.toString(lng));
- GeoPoint geoPoint = new GeoPoint((int) (lat*1e6), (int) (lng*1e6));
- OverlayItem overlayitem = new OverlayItem(geoPoint, name, "");
- pizzaOverlay.addOverlay(overlayitem);
- mapView.postInvalidate(); //updates UI
- }
}
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/UserLocationOverlay.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/UserLocationOverlay.java 2011-06-03 15:21:55 UTC (rev 4387)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/UserLocationOverlay.java 2011-06-03 15:23:34 UTC (rev 4388)
@@ -13,6 +13,7 @@
public UserLocationOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
+ populate(); // needed to prevent null pointer exception with empty list
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tim...@us...> - 2011-06-03 15:22:02
|
Revision: 4387
http://mxquery.svn.sourceforge.net/mxquery/?rev=4387&view=rev
Author: timchurch
Date: 2011-06-03 15:21:55 +0000 (Fri, 03 Jun 2011)
Log Message:
-----------
Bug fix for native java calls: Allow java objects to be passed as 1st parameter for constructors and static methods
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-06-03 14:08:07 UTC (rev 4386)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-06-03 15:21:55 UTC (rev 4387)
@@ -18,6 +18,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.Vector;
import ch.ethz.mxquery.contextConfig.Context;
@@ -99,7 +100,9 @@
case Type.ITEM:
if (tok instanceof WrappedObjectToken) {
WrappedObjectToken wrap = (WrappedObjectToken) tok;
- if(i == 0) {
+ int mod = native_function.getModifiers();
+
+ if (i == 0 && !methodName.equals("new") && !Modifier.isStatic(mod)) {
instanceToCall = wrap.getWrappedObject();
} else {
invocationParams[i] = wrap.getWrappedObject();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tim...@us...> - 2011-06-03 14:08:15
|
Revision: 4386
http://mxquery.svn.sourceforge.net/mxquery/?rev=4386&view=rev
Author: timchurch
Date: 2011-06-03 14:08:07 +0000 (Fri, 03 Jun 2011)
Log Message:
-----------
Moved XQuery query to separate file
Modified Paths:
--------------
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java
Added Paths:
-----------
trunk/MXQuery_Android_App/res/raw/mashup.xq
Added: trunk/MXQuery_Android_App/res/raw/mashup.xq
===================================================================
--- trunk/MXQuery_Android_App/res/raw/mashup.xq (rev 0)
+++ trunk/MXQuery_Android_App/res/raw/mashup.xq 2011-06-03 14:08:07 UTC (rev 4386)
@@ -0,0 +1,16 @@
+declare namespace m = "java:ch.ethz.mxquery.android.MXQuery";
+declare namespace map = "java:ch.ethz.mxquery.android.MyMap";
+declare namespace l = "java:android.location.Location";
+import module namespace http = "http://expath.org/ns/http-client";
+declare variable $activity := m:getActivity();
+declare variable $loc := m:getLocation();
+map:setUserLocation($activity, $loc),
+let $baseUrl := "https://maps.googleapis.com/maps/api/place/search/xml?radius=50&types=food&name=pizza&sensor=false&key=AIzaSyAtNn71gfANF9KWPp0W_pEd1LHaxIux92g&location="
+let $url := fn:concat($baseUrl, l:getLatitude($loc), ",", l:getLongitude($loc))
+let $req := <http:request method="GET" href="{$url}" />
+let $result := http:send-request($req, ())[2]
+for $pizza in $result//result
+ let $name := $pizza/name/text()
+ let $lat := $pizza/geometry/location/lat cast as xs:double
+ let $lng := $pizza/geometry/location/lng cast as xs:double
+ return map:addPlace($activity, $name, $lat, $lng)
\ No newline at end of file
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java 2011-06-03 13:21:13 UTC (rev 4385)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java 2011-06-03 14:08:07 UTC (rev 4386)
@@ -1,5 +1,8 @@
package ch.ethz.mxquery.android;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.List;
import android.content.ComponentName;
@@ -82,23 +85,7 @@
Log.i(LOG_TAG, "MXQueryService Connected. Running queries...");
// show user location and nearby pizza places on map
- String showPizzasQuery =
- "declare namespace m = \"java:ch.ethz.mxquery.android.MXQuery\"; " +
- "declare namespace map = \"java:ch.ethz.mxquery.android.MyMap\"; " +
- "declare namespace l = \"java:android.location.Location\"; " +
- "import module namespace http = \"http://expath.org/ns/http-client\"; " +
- "declare variable $activity := m:getActivity(); " +
- "declare variable $loc := m:getLocation(); " +
- "map:setUserLocation($activity, $loc), " +
- "let $baseUrl := \"https://maps.googleapis.com/maps/api/place/search/xml?radius=50&types=food&name=pizza&sensor=false&key=AIzaSyAtNn71gfANF9KWPp0W_pEd1LHaxIux92g&location=\" " +
- "let $url := fn:concat($baseUrl, l:getLatitude($loc), \",\", l:getLongitude($loc)) " +
- "let $req := <http:request method=\"GET\" href=\"{$url}\" /> " +
- "let $result := http:send-request($req, ())[2] " +
- "for $pizza in $result//result " +
- " let $name := $pizza/name/text() " +
- " let $lat := $pizza/geometry/location/lat cast as xs:double " +
- " let $lng := $pizza/geometry/location/lng cast as xs:double " +
- " return map:addPlace($activity, $name, $lat, $lng)";
+ String showPizzasQuery = readXQueryFile(R.raw.mashup);
mService.runQuery(showPizzasQuery, queryListener);
}
@@ -117,6 +104,22 @@
}
};
+ public String readXQueryFile(int rawResourceId) {
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader( getResources().openRawResource(rawResourceId) ) );
+ String query = "";
+ String line;
+
+ try {
+ while ((line = in.readLine()) != null) {
+ query += line;
+ }
+ } catch (IOException e) {
+ Log.e(LOG_TAG, e.getMessage(), e);
+ }
+ return query;
+ }
+
public void setUserLocation(Location userLocation) {
Log.i(LOG_TAG, "Setting user location: (" + userLocation.getLatitude() + "," + userLocation.getLongitude() + ")");
userLocationOverlay = new UserLocationOverlay(this.getResources().getDrawable(R.drawable.marker));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tim...@us...> - 2011-06-03 13:21:19
|
Revision: 4385
http://mxquery.svn.sourceforge.net/mxquery/?rev=4385&view=rev
Author: timchurch
Date: 2011-06-03 13:21:13 +0000 (Fri, 03 Jun 2011)
Log Message:
-----------
Combined 2 queries into 1 for mashup demo
Modified Paths:
--------------
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java 2011-06-03 13:03:30 UTC (rev 4384)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java 2011-06-03 13:21:13 UTC (rev 4385)
@@ -79,34 +79,26 @@
mService = binder.getService();
mIsBound = true;
- // show user location on map
Log.i(LOG_TAG, "MXQueryService Connected. Running queries...");
- String showUserLocationQuery =
- "declare namespace m = \"java:ch.ethz.mxquery.android.MXQuery\";\n" +
- "declare namespace map = \"java:ch.ethz.mxquery.android.MyMap\";\n" +
- "declare namespace l = \"java:android.location.Location\";\n" +
- "let $loc := m:getLocation()\n" +
- "let $activity := m:getActivity()\n" +
- "return map:setUserLocation($activity, $loc)";
- mService.runQuery(showUserLocationQuery, queryListener);
- // show nearby pizza places on map
+ // show user location and nearby pizza places on map
String showPizzasQuery =
"declare namespace m = \"java:ch.ethz.mxquery.android.MXQuery\"; " +
"declare namespace map = \"java:ch.ethz.mxquery.android.MyMap\"; " +
"declare namespace l = \"java:android.location.Location\"; " +
"import module namespace http = \"http://expath.org/ns/http-client\"; " +
- "let $activity := m:getActivity() " +
- "let $loc := m:getLocation() " +
+ "declare variable $activity := m:getActivity(); " +
+ "declare variable $loc := m:getLocation(); " +
+ "map:setUserLocation($activity, $loc), " +
"let $baseUrl := \"https://maps.googleapis.com/maps/api/place/search/xml?radius=50&types=food&name=pizza&sensor=false&key=AIzaSyAtNn71gfANF9KWPp0W_pEd1LHaxIux92g&location=\" " +
"let $url := fn:concat($baseUrl, l:getLatitude($loc), \",\", l:getLongitude($loc)) " +
"let $req := <http:request method=\"GET\" href=\"{$url}\" /> " +
"let $result := http:send-request($req, ())[2] " +
"for $pizza in $result//result " +
- "let $name := $pizza/name/text() " +
- "let $lat := $pizza/geometry/location/lat/text() cast as xs:double " +
- "let $lng := $pizza/geometry/location/lng/text() cast as xs:double " +
- "return map:addPlace($activity, $name, $lat, $lng)";
+ " let $name := $pizza/name/text() " +
+ " let $lat := $pizza/geometry/location/lat cast as xs:double " +
+ " let $lng := $pizza/geometry/location/lng cast as xs:double " +
+ " return map:addPlace($activity, $name, $lat, $lng)";
mService.runQuery(showPizzasQuery, queryListener);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tim...@us...> - 2011-06-03 13:03:39
|
Revision: 4384
http://mxquery.svn.sourceforge.net/mxquery/?rev=4384&view=rev
Author: timchurch
Date: 2011-06-03 13:03:30 +0000 (Fri, 03 Jun 2011)
Log Message:
-----------
Android map mashup working from XQuery :)
Modified Paths:
--------------
trunk/MXQuery_Android_App/res/values/strings.xml
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/PizzaOverlay.java
Modified: trunk/MXQuery_Android_App/res/values/strings.xml
===================================================================
--- trunk/MXQuery_Android_App/res/values/strings.xml 2011-06-03 12:57:07 UTC (rev 4383)
+++ trunk/MXQuery_Android_App/res/values/strings.xml 2011-06-03 13:03:30 UTC (rev 4384)
@@ -102,8 +102,12 @@
fn:put(<test><put/></test>, \"test2.xml\")
</string>
<string name="webservice_xquery">
- import module namespace http = \"http://expath.org/ns/http-client\";
- http:send-request(<http:request method=\'get\'/>,\'http://www.google.com\')[1]/data(@status)
+ import module namespace http = \"http://expath.org/ns/http-client\";\n
+ \n
+ let $req := <http:request method=\"GET\"\n
+ \thref=\"https://maps.googleapis.com/maps/api/place/search/xml?location=47.37642,8.54799&amp;radius=50&amp;types=food&amp;name=pizza&amp;sensor=false&amp;key=AIzaSyAtNn71gfANF9KWPp0W_pEd1LHaxIux92g\"/>\n
+ let $res := http:send-request($req, ())\n
+ return $res[2]
</string>
<string name="android_location_xquery">
declare namespace m = \"java:ch.ethz.mxquery.android.MXQuery\";\n
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java 2011-06-03 12:57:07 UTC (rev 4383)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java 2011-06-03 13:03:30 UTC (rev 4384)
@@ -1,40 +1,17 @@
package ch.ethz.mxquery.android;
-import java.io.BufferedInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URLEncoder;
-import java.util.ArrayList;
import java.util.List;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.HttpVersion;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.conn.scheme.PlainSocketFactory;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
+import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
import android.graphics.drawable.Drawable;
import android.location.Location;
-import android.location.LocationManager;
import android.os.Bundle;
+import android.os.IBinder;
import android.util.Log;
-import android.widget.Toast;
+import ch.ethz.mxquery.android.MXQueryService.MXQueryServiceBinder;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
@@ -49,15 +26,10 @@
private UserLocationOverlay userLocationOverlay;
private PizzaOverlay pizzaOverlay;
private Drawable pizzaDrawable;
- private HttpClient mClient;
+ protected MXQueryService mService;
+ protected boolean mIsBound = false;
private static final String LOG_TAG = "MXQuery.MyMap";
- private static final String GOOGLE_PLACES_API_KEY = "AIzaSyAtNn71gfANF9KWPp0W_pEd1LHaxIux92g";
- private static final String GOOGLE_PLACES_SEARCH_URL = "https://maps.googleapis.com/maps/api/place/search/%s?location=%.5f,%.5f&radius=%d&types=%s&name=%s&sensor=false&key=%s";
- private static final String OUTPUT_FORMAT = "json";
- private static final String SEARCH_KEYWORDS = "pizza";
- private static final String SEARCH_TYPES = "food|restaurant|establishment";
- private static final Integer SEARCH_RADIUS = 50;
@Override
@@ -65,29 +37,20 @@
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
+ MXQuery.init(this);
+
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapOverlays = mapView.getOverlays();
- this.initHttp();
-
- //Load last known user location
- Location userLocation = getCachedLocation();
- GeoPoint userLocationGeoPoint = new GeoPoint((int) (userLocation.getLatitude()*1e6), (int) (userLocation.getLongitude()*1e6));
- OverlayItem userLocationOverlayItem = new OverlayItem(userLocationGeoPoint, "", "");
- userLocationOverlay = new UserLocationOverlay(this.getResources().getDrawable(R.drawable.marker));
- userLocationOverlay.addOverlay(userLocationOverlayItem);
- mapView.getController().animateTo(userLocationGeoPoint);
-
- //Load nearby places from web service
- List<Place> pizzaRestaurants = searchGooglePlaces(userLocation);
pizzaDrawable = this.getResources().getDrawable(R.drawable.pizza);
pizzaOverlay = new PizzaOverlay(pizzaDrawable, this);
- pizzaOverlay.setPizzas(pizzaRestaurants);
-
- // add overlays to mapView list of overlays
mapOverlays.add(pizzaOverlay);
- mapOverlays.add(userLocationOverlay);
+
+ // start service
+ if (!mIsBound) {
+ doBindService();
+ }
}
@Override
@@ -95,124 +58,88 @@
return false;
}
- /**
- * Returns the last cached location value on the phone.
- * If none found, a default location is returned (ETH).
- */
- private Location getCachedLocation() {
- Location lastKnownLocation = null;
- LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
-
- // First try for cached GPS location data
- if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
- lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
- if(lastKnownLocation != null) {
- return lastKnownLocation;
- }
- }
-
- // Then try cached network location data
- if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
- lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
- if(lastKnownLocation != null) {
- return lastKnownLocation;
- }
- }
-
- // No cached location found. Use ETH as default location for demo...
- Toast.makeText(this, "No cached location found. Using default location (ETH)...", Toast.LENGTH_SHORT).show();
- Location defaultLocation = new Location("default");
- defaultLocation.setLatitude(47.37642);
- defaultLocation.setLongitude(8.54799);
- return defaultLocation;
+ void doBindService() {
+ // Establish a connection with the service. We use an explicit
+ // class name because we want a specific service implementation that
+ // we know will be running in our own process (and thus won't be
+ // supporting component replacement by other applications).
+ bindService(new Intent(MyMap.this, MXQueryService.class), mConnection,
+ Context.BIND_AUTO_CREATE);
+ mIsBound = true;
}
- /**
- * Initializes the HttpClient. This must be called before executeRequest().
- */
- private void initHttp() {
- final HttpParams params = new BasicHttpParams();
- HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
- HttpProtocolParams.setContentCharset(params, "UTF-8");
- final SchemeRegistry registry = new SchemeRegistry();
- registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
- registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
-
- final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
- mClient = new DefaultHttpClient(manager, params);
- }
- /**
- * Returns a list of pizza places that are near userLocation
- */
- public List<Place> searchGooglePlaces(Location userLocation) {
- List<Place> places = new ArrayList<Place>();
-
- //fetch data from web service
- try {
- final String url = String.format(GOOGLE_PLACES_SEARCH_URL, OUTPUT_FORMAT, userLocation.getLatitude(), userLocation.getLongitude(), SEARCH_RADIUS, URLEncoder.encode(SEARCH_TYPES, "UTF-8"), SEARCH_KEYWORDS, GOOGLE_PLACES_API_KEY);
- String result = executeRequest(url);
- JSONObject json = new JSONObject(result);
- JSONArray results = json.getJSONArray("results");
- for (int i = 0; i < results.length(); i++) {
- JSONObject location = results.getJSONObject(i).getJSONObject("geometry").getJSONObject("location");
- Double lat = location.getDouble("lat");
- Double lng = location.getDouble("lng");
- String name = results.getJSONObject(i).getString("name");
- Place pizzaPlace = new Place(lat, lng, name);
- places.add(pizzaPlace);
- }
- } catch (IOException e) {
- Log.e(LOG_TAG, e.getMessage(), e);
- } catch (JSONException e) {
- Log.e(LOG_TAG, "Error parsing JSON", e);
+ /** Defines callbacks for service binding, passed to bindService() */
+ private ServiceConnection mConnection = new ServiceConnection() {
+
+ public void onServiceConnected(ComponentName className, IBinder service) {
+ // We've bound to MXQueryService, cast the IBinder and get MXQueryService instance
+ MXQueryServiceBinder binder = (MXQueryServiceBinder) service;
+ mService = binder.getService();
+ mIsBound = true;
+
+ // show user location on map
+ Log.i(LOG_TAG, "MXQueryService Connected. Running queries...");
+ String showUserLocationQuery =
+ "declare namespace m = \"java:ch.ethz.mxquery.android.MXQuery\";\n" +
+ "declare namespace map = \"java:ch.ethz.mxquery.android.MyMap\";\n" +
+ "declare namespace l = \"java:android.location.Location\";\n" +
+ "let $loc := m:getLocation()\n" +
+ "let $activity := m:getActivity()\n" +
+ "return map:setUserLocation($activity, $loc)";
+ mService.runQuery(showUserLocationQuery, queryListener);
+
+ // show nearby pizza places on map
+ String showPizzasQuery =
+ "declare namespace m = \"java:ch.ethz.mxquery.android.MXQuery\"; " +
+ "declare namespace map = \"java:ch.ethz.mxquery.android.MyMap\"; " +
+ "declare namespace l = \"java:android.location.Location\"; " +
+ "import module namespace http = \"http://expath.org/ns/http-client\"; " +
+ "let $activity := m:getActivity() " +
+ "let $loc := m:getLocation() " +
+ "let $baseUrl := \"https://maps.googleapis.com/maps/api/place/search/xml?radius=50&types=food&name=pizza&sensor=false&key=AIzaSyAtNn71gfANF9KWPp0W_pEd1LHaxIux92g&location=\" " +
+ "let $url := fn:concat($baseUrl, l:getLatitude($loc), \",\", l:getLongitude($loc)) " +
+ "let $req := <http:request method=\"GET\" href=\"{$url}\" /> " +
+ "let $result := http:send-request($req, ())[2] " +
+ "for $pizza in $result//result " +
+ "let $name := $pizza/name/text() " +
+ "let $lat := $pizza/geometry/location/lat/text() cast as xs:double " +
+ "let $lng := $pizza/geometry/location/lng/text() cast as xs:double " +
+ "return map:addPlace($activity, $name, $lat, $lng)";
+ mService.runQuery(showPizzasQuery, queryListener);
}
-
- return places;
- }
+
+ public void onServiceDisconnected(ComponentName arg0) {
+ mIsBound = false;
+ }
+ };
- /**
- * Executes an HTTP request and returns the result as a string
- */
- public String executeRequest(String url) throws IOException {
- final HttpGet get = new HttpGet(url);
- HttpEntity entity = null;
- try {
- final HttpResponse response = mClient.execute(get);
- if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
- entity = response.getEntity();
- final InputStream in = entity.getContent();
- String result = convertStreamToString(in);
- in.close();
- return result;
- }
- } catch (ClientProtocolException e) {
- Log.e(LOG_TAG, e.getMessage(), e);
- } catch (IOException e) {
- Log.e(LOG_TAG, e.getMessage(), e);
- } finally {
- if (entity != null) {
- entity.consumeContent();
- }
+ protected XQueryListener queryListener = new XQueryListener() {
+ public void queryResult(final String result) {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ Log.i(LOG_TAG, "QUERY RESULT: " + result);
+ }
+ });
}
- return null;
+ };
+
+ public void setUserLocation(Location userLocation) {
+ Log.i(LOG_TAG, "Setting user location: (" + userLocation.getLatitude() + "," + userLocation.getLongitude() + ")");
+ userLocationOverlay = new UserLocationOverlay(this.getResources().getDrawable(R.drawable.marker));
+ GeoPoint userLocationGeoPoint = new GeoPoint((int) (userLocation.getLatitude()*1e6), (int) (userLocation.getLongitude()*1e6));
+ OverlayItem userLocationOverlayItem = new OverlayItem(userLocationGeoPoint, "", "");
+ userLocationOverlay.addOverlay(userLocationOverlayItem);
+ mapOverlays.add(userLocationOverlay);
+ mapView.getController().animateTo(userLocationGeoPoint);
}
- /**
- * Converts an InputStream to a String
- */
- public String convertStreamToString(InputStream in) throws IOException {
- BufferedInputStream bis = new BufferedInputStream(in);
- ByteArrayOutputStream buf = new ByteArrayOutputStream();
- int result = bis.read();
- while(result != -1) {
- byte b = (byte) result;
- buf.write(b);
- result = bis.read();
- }
- bis.close();
- return buf.toString();
-
+ public void addPlace(String name, double lat, double lng) {
+ Log.i(LOG_TAG, "ADDING PLACE: " + name + ", " + Double.toString(lat) + ", " + Double.toString(lng));
+ GeoPoint geoPoint = new GeoPoint((int) (lat*1e6), (int) (lng*1e6));
+ OverlayItem overlayitem = new OverlayItem(geoPoint, name, "");
+ pizzaOverlay.addOverlay(overlayitem);
+ mapView.postInvalidate(); //updates UI
}
}
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/PizzaOverlay.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/PizzaOverlay.java 2011-06-03 12:57:07 UTC (rev 4383)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/PizzaOverlay.java 2011-06-03 13:03:30 UTC (rev 4384)
@@ -19,6 +19,7 @@
public PizzaOverlay(Drawable defaultMarker, Activity activity) {
super(boundCenterBottom(defaultMarker));
this.mActivity = activity;
+ populate(); // needed to prevent null pointer exception with empty list
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tim...@us...> - 2011-06-03 12:57:13
|
Revision: 4383
http://mxquery.svn.sourceforge.net/mxquery/?rev=4383&view=rev
Author: timchurch
Date: 2011-06-03 12:57:07 +0000 (Fri, 03 Jun 2011)
Log Message:
-----------
Removed the rest of the (no longer used) updating flags
Modified Paths:
--------------
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java 2011-06-01 19:44:09 UTC (rev 4382)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java 2011-06-03 12:57:07 UTC (rev 4383)
@@ -39,8 +39,8 @@
}
/** public method for clients */
- public void runQuery(String query, XQueryListener listener, boolean updating) {
- QueryThread queryThread = new QueryThread(query, listener, updating);
+ public void runQuery(String query, XQueryListener listener) {
+ QueryThread queryThread = new QueryThread(query, listener);
queryThread.start();
}
@@ -51,7 +51,7 @@
private String query;
private XQueryListener listener;
- public QueryThread(String query, XQueryListener listener, boolean updating) {
+ public QueryThread(String query, XQueryListener listener) {
this.query = query;
this.listener = listener;
}
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java 2011-06-01 19:44:09 UTC (rev 4382)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java 2011-06-03 12:57:07 UTC (rev 4383)
@@ -58,7 +58,6 @@
protected TextView mResultView;
protected MXQueryService mService;
protected boolean mIsBound = false;
- protected boolean mUpdating = false;
protected ProgressDialog mDialog;
protected XQDataSource xqjd = new MXQueryXQDataSource();
@@ -134,8 +133,6 @@
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
String item = parent.getItemAtPosition(pos).toString();
-
- mUpdating = false;
if (item.equals(getString(R.string.hello_world))) {
mInputView.setText(getString(R.string.hello_world_xquery));
@@ -159,10 +156,8 @@
mInputView.setText(getString(R.string.fn_doc2_xquery));
} else if (item.equals(getString(R.string.updating))) {
mInputView.setText(getString(R.string.updating_xquery));
-// mUpdating = true;
} else if (item.equals(getString(R.string.updating2))) {
mInputView.setText(getString(R.string.updating2_xquery));
-// mUpdating = true;
} else if (item.equals(getString(R.string.put))) {
mInputView.setText(getString(R.string.put_xquery));
} else if (item.equals(getString(R.string.webservice))) {
@@ -259,7 +254,7 @@
doBindService();
}
- mService.runQuery(query, queryListener, mUpdating);
+ mService.runQuery(query, queryListener);
}
void doBindService() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-06-01 19:44:16
|
Revision: 4382
http://mxquery.svn.sourceforge.net/mxquery/?rev=4382&view=rev
Author: pm_fischer
Date: 2011-06-01 19:44:09 +0000 (Wed, 01 Jun 2011)
Log Message:
-----------
added missing HOF forward support iterator
Added Paths:
-----------
trunk/MXQuery/src/ch/ethz/mxquery/iterators/DelayedLiteralFunctionItemIterator.java
Added: trunk/MXQuery/src/ch/ethz/mxquery/iterators/DelayedLiteralFunctionItemIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/DelayedLiteralFunctionItemIterator.java (rev 0)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/DelayedLiteralFunctionItemIterator.java 2011-06-01 19:44:09 UTC (rev 4382)
@@ -0,0 +1,74 @@
+/* Copyright 2006 - 2009 ETH Zurich
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.ethz.mxquery.iterators;
+
+/**
+ * User defined function where the actual binding happens at runtime, not at compile time
+ * Needed to support forward references in function declarations and recursive calls
+ */
+
+import java.util.Vector;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.QName;
+import ch.ethz.mxquery.datamodel.xdm.FunctionItemToken;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.StaticException;
+import ch.ethz.mxquery.functions.Function;
+import ch.ethz.mxquery.model.TokenBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.LogLevel;
+
+public class DelayedLiteralFunctionItemIterator extends TokenBasedIterator {
+
+
+ public DelayedLiteralFunctionItemIterator(Context ctx, QName name, int ar) throws MXQueryException {
+ funcName = name;
+ arity = ar;
+ context = ctx;
+ }
+
+ QName funcName;
+ int arity;
+ FunctionItemToken func;
+
+ protected void init() throws MXQueryException {
+ currentToken = func;
+ }
+
+
+ protected XDMIterator copy(Context context, XDMIterator[] subIters, Vector nestedPredCtxStack) throws MXQueryException {
+ DelayedLiteralFunctionItemIterator copy = new DelayedLiteralFunctionItemIterator(context, funcName, arity);
+ copy.setSubIters(subIters);
+ copy.func = this.func;
+ return copy;
+
+ }
+ public XDMIterator staticInit() throws MXQueryException {
+ logger.log(LogLevel.INFO, "Static Init of Delayed Literal Function Items");
+ super.staticInit();
+ if (func == null) {
+ Function f = context.getFunction(funcName, arity);
+
+ if (f==null)
+ throw new StaticException(ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,"Function "+funcName+" with arity"+arity+" not available",loc);
+ func = new FunctionItemToken(f);
+ }
+ return this;
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tim...@us...> - 2011-06-01 16:59:49
|
Revision: 4381
http://mxquery.svn.sourceforge.net/mxquery/?rev=4381&view=rev
Author: timchurch
Date: 2011-06-01 16:59:42 +0000 (Wed, 01 Jun 2011)
Log Message:
-----------
- Allow java objects to be passed as params in native function calls from xquery
- Commented out println for void types on native function calls
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-06-01 15:44:14 UTC (rev 4380)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-06-01 16:59:42 UTC (rev 4381)
@@ -207,7 +207,7 @@
return new TypeInfo(Type.INT,Type.OCCURRENCE_IND_EXACTLY_ONE);
if (class1.getName().equals("boolean"))
return new TypeInfo(Type.BOOLEAN,Type.OCCURRENCE_IND_EXACTLY_ONE);
- System.out.println(class1.getPackage()+" "+class1.getName());
+ //System.out.println(class1.getPackage()+" "+class1.getName());
return new TypeInfo(Type.UNTYPED_ATOMIC,Type.OCCURRENCE_IND_EXACTLY_ONE);
}
if (class1.getName().equals("java.lang.String"))
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-06-01 15:44:14 UTC (rev 4380)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-06-01 16:59:42 UTC (rev 4381)
@@ -97,9 +97,14 @@
invocationParamsTypes[i] = invocationParams[i].getClass();
break;
case Type.ITEM:
- if (i==0 && tok instanceof WrappedObjectToken) {
+ if (tok instanceof WrappedObjectToken) {
WrappedObjectToken wrap = (WrappedObjectToken) tok;
- instanceToCall = wrap.getWrappedObject();
+ if(i == 0) {
+ instanceToCall = wrap.getWrappedObject();
+ } else {
+ invocationParams[i] = wrap.getWrappedObject();
+ invocationParamsTypes[i] = invocationParams[i].getClass();
+ }
} else
throw new DynamicException(ErrorCodes.A0002_EC_NOT_SUPPORTED, "Type "+Type.getTypeQName(tok.getEventType(), Context.getDictionary())+" not implemented in Java calls", loc);
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-06-01 15:44:20
|
Revision: 4380
http://mxquery.svn.sourceforge.net/mxquery/?rev=4380&view=rev
Author: pm_fischer
Date: 2011-06-01 15:44:14 +0000 (Wed, 01 Jun 2011)
Log Message:
-----------
fix some XQJ problems
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQConnection.java
trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQExpression.java
trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQForwardSequence.java
trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQPreparedExpression.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQConnection.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQConnection.java 2011-06-01 15:42:25 UTC (rev 4379)
+++ trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQConnection.java 2011-06-01 15:44:14 UTC (rev 4380)
@@ -26,6 +26,7 @@
import ch.ethz.mxquery.query.PreparedStatement;
import ch.ethz.mxquery.query.impl.CompilerImpl;
import ch.ethz.mxquery.util.PlatformDependentUtils;
+import ch.ethz.mxquery.xdmio.StoreSet;
import ch.ethz.mxquery.contextConfig.CompilerOptions;
import ch.ethz.mxquery.contextConfig.Context;
import ch.ethz.mxquery.exceptions.MXQueryException;
@@ -176,6 +177,15 @@
throw new XQException("Static context is null");
try {
XQCompiler compiler = new CompilerImpl();
+ if (languageLevel == MXQueryXQDataSource.XQJ_UPDATE_MODE) {
+ co.setUpdate(true);
+ StoreSet ss = runtime.getEngineContext().getStores();
+ ss.setSerializeStores(true);
+ } else if (languageLevel == MXQueryXQDataSource.XQJ_SCRIPTING_MODE) {
+ co.setUpdate(true);
+ StoreSet ss = runtime.getEngineContext().getStores();
+ ss.setSerializeStores(true);
+ }
PreparedStatement statement = compiler.compile(ctx.runtime, xquery,co, null, null);
MXQueryXQPreparedExpression mxPreExp = new MXQueryXQPreparedExpression(this, statement);
this.expStore.add(mxPreExp);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQExpression.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQExpression.java 2011-06-01 15:42:25 UTC (rev 4379)
+++ trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQExpression.java 2011-06-01 15:44:14 UTC (rev 4380)
@@ -117,13 +117,10 @@
ss.setSerializeStores(true);
}
PreparedStatement statement = compiler.compile(runtime.getEngineContext(), expr,co, null, null);
- XDMIterator iter;
if(this.cancel){
this.cancel = false;
throw new XQException("Expression has been closed");
- } else {
- iter = statement.evaluate();
- }
+ }
if(this.cancel){
this.cancel = false;
throw new XQException("Expression has been closed");
Modified: trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQForwardSequence.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQForwardSequence.java 2011-06-01 15:42:25 UTC (rev 4379)
+++ trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQForwardSequence.java 2011-06-01 15:44:14 UTC (rev 4380)
@@ -295,44 +295,50 @@
public void writeSequence(OutputStream os, Properties props)
throws XQException {
checkNotClosed();
+ boolean hasNext = true;
if(this.position == 0)
- this.next();
- do {
+ hasNext = this.next();
+ while (hasNext){
getCurrentXQItem(true).writeItem(os, props);
try {
os.write(' ');
} catch (IOException e) {
throw new XQQueryException("Could not write sequence "+e);
}
- } while(next());
+ hasNext = next();
+ };
}
public void writeSequence(Writer ow, Properties props) throws XQException {
checkNotClosed();
+ boolean hasNext = true;
if(this.position == 0)
- this.next();
- do {
+ hasNext = this.next();
+ while (hasNext){
getCurrentXQItem(true).writeItem(ow, props);
try {
ow.write(' ');
} catch (IOException e) {
throw new XQQueryException("Could not write sequence "+e);
}
- } while(next());
+ hasNext = next();
+ };
}
public void writeSequenceToSAX(ContentHandler saxhdlr) throws XQException {
checkNotClosed();
+ boolean hasNext = true;
if (position == 0) {
- next();
+ hasNext = this.next();
}
if (position < 0) {
throw new XQException("The XQSequence is positioned after the last item");
}
- do {
+ while (hasNext){
checkAndSetRetrieved();
resultItem.writeItemToSAX(saxhdlr);
- } while(next());
+ hasNext = next();
+ };
}
protected void checkNotClosed() throws XQException {
if (connection.isClosed()) {
@@ -371,16 +377,18 @@
public void writeSequenceToResult(Result result) throws XQException {
checkNotClosed();
+ boolean hasNext = true;
if (position == 0) {
- next();
+ hasNext = this.next();
}
if (position < 0) {
throw new XQException("The XQSequence is positioned after the last item");
}
- do {
+ while (hasNext){
checkAndSetRetrieved();
resultItem.writeItemToResult(result);
- } while(next());
+ hasNext = next();
+ };
}
public XMLStreamReader getItemAsStream() throws XQException {
Modified: trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQPreparedExpression.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQPreparedExpression.java 2011-06-01 15:42:25 UTC (rev 4379)
+++ trunk/MXQuery/src/ch/ethz/mxquery/xqj/MXQueryXQPreparedExpression.java 2011-06-01 15:44:14 UTC (rev 4380)
@@ -86,22 +86,22 @@
public XQResultSequence executeQuery() throws XQException {
checkNotClosed();
- try {
- XDMIterator iter = exp.evaluate();
- exp = pristineCopy.copy();
+ //try {
+ //XDMIterator iter = exp.evaluate();
+ //exp = pristineCopy.copy();
if(connection.getStaticContext().getScrollability() == XQConstants.SCROLLTYPE_FORWARD_ONLY)
- return new MXQueryXQForwardSequence(iter, connection,this);
+ return new MXQueryXQForwardSequence(exp, connection,this);
Vector store = new Vector();
int i = 0;
- MXQueryXQForwardSequence mSeq = new MXQueryXQForwardSequence(iter, connection,this);
+ MXQueryXQForwardSequence mSeq = new MXQueryXQForwardSequence(exp, connection,this);
while(mSeq.next()){
store.add(i++,mSeq.getItem());
}
this.seq = new MXQueryXQSequence(store, connection);
return seq;
- } catch (MXQueryException de) {
- throw new XQQueryException(de.toString(),PlatformDependentUtils.getJavaxQName(de.getErrorCode()));
- }
+// } catch (MXQueryException de) {
+// throw new XQQueryException(de.toString(),PlatformDependentUtils.getJavaxQName(de.getErrorCode()));
+// }
}
public QName[] getAllExternalVariables() throws XQException {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-06-01 15:42:33
|
Revision: 4379
http://mxquery.svn.sourceforge.net/mxquery/?rev=4379&view=rev
Author: pm_fischer
Date: 2011-06-01 15:42:25 +0000 (Wed, 01 Jun 2011)
Log Message:
-----------
- HOF can now contain forward references
- XQIB uses HOF for callback functions
- updated XQIB samples
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
trunk/MXQuery/xqib_samples/BGColors.html
trunk/MXQuery/xqib_samples/Delete.html
trunk/MXQuery/xqib_samples/DeleteInsert.html
trunk/MXQuery/xqib_samples/DragAndDrop.html
trunk/MXQuery/xqib_samples/EventLocation.html
trunk/MXQuery/xqib_samples/MouseButton.html
trunk/MXQuery/xqib_samples/MultiplicationTable.html
trunk/MXQuery/xqib_samples/OnClickEvent.html
trunk/MXQuery/xqib_samples/OnmouseoverEvent.html
trunk/MXQuery/xqib_samples/OnmouseoverEvent_source.html
trunk/MXQuery/xqib_samples/RESTCallCourses.html
trunk/MXQuery/xqib_samples/RESTCallCourses_source.html
trunk/MXQuery/xqib_samples/SetStyle.html
trunk/MXQuery/xqib_samples/SetStyle_source.html
trunk/MXQuery/xqib_samples/Update.html
trunk/MXQuery/xqib_samples/Update_source.html
trunk/MXQuery/xqib_samples/WeatherREST.html
trunk/MXQuery/xqib_samples/WeatherREST_source.html
trunk/MXQuery/xqib_samples/WeatherRESTasync.html
trunk/MXQuery/xqib_samples/WeatherRESTasyncSlow.html
trunk/MXQuery/xqib_samples/WeatherRESTasyncSlowCached.html
trunk/MXQuery/xqib_samples/WeatherRESTread.html
trunk/MXQuery/xqib_samples/cookies.html
trunk/MXQuery/xqib_samples/log.htm
trunk/MXQuery/xqib_samples/removeEventListener.html
trunk/MXQuery/xqib_samples/textarea.htm
trunk/MXQuery/xqib_samples/tidy.html
trunk/MXQuery/xqib_samples/timer.html
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddEventListener.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveEventListener.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/Timer.java
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/xq11streaming/MiscTests.java
Added Paths:
-----------
trunk/MXQuery_Testing/XQTests/Queries/xquery11/hof-forward-samefunc.xq
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-06-01 15:42:25 UTC (rev 4379)
@@ -71,6 +71,7 @@
import ch.ethz.mxquery.iterators.ComputedCommentConstrIterator;
import ch.ethz.mxquery.iterators.ComputedPIConstrIterator;
import ch.ethz.mxquery.iterators.ComputedTextConstrIterator;
+import ch.ethz.mxquery.iterators.DelayedLiteralFunctionItemIterator;
import ch.ethz.mxquery.iterators.DescendantOrSelfIterator;
import ch.ethz.mxquery.iterators.DocOrderIterator;
import ch.ethz.mxquery.iterators.ExceptIterator;
@@ -642,6 +643,8 @@
// This is only possible once all "forward/late" functions are available
for (int i = 0; i < addedFunctions.size(); i++) {
XDMIterator funcToCheck = (XDMIterator) addedFunctions.elementAt(i);
+ funcToCheck.staticInit();
+ funcToCheck.require(0);
funcToCheck.getExpressionCategoryType(co.isScripting());
}
@@ -1983,13 +1986,15 @@
funcCallIter = new UserdefFuncCall(getCurrentContext(),
qname, paramArr, arrParamTypes, body, returnType,
seqTypeIt, exprCategory, getCurrentLoc());
- funcCallIter.staticInit();
- funcCallIter = (UserdefFuncCall)funcCallIter.require(0);
+// funcCallIter.staticInit();
+// funcCallIter = (UserdefFuncCall)funcCallIter.require(0);
if (!allowExternal) {
// if inline function
// compute the closure
// all variable references which are not resolved within the
// context
+ funcCallIter.staticInit();
+ funcCallIter = (UserdefFuncCall)funcCallIter.require(0);
Vector subs = funcCallIter.getAllSubItersRecursive();
Vector closure = new Vector();
for (int i=0;i<subs.size();i++) {
@@ -6618,7 +6623,10 @@
Function f = getCurrentContext().getFunction(qn, arity);
if (f==null)
- throw new StaticException(ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,"Function "+qn+" with arity"+arity+" not available",getCurrentLoc());
+ if (!inProlog)
+ throw new StaticException(ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,"Function "+qn+" with arity"+arity+" not available",getCurrentLoc());
+ else
+ return new DelayedLiteralFunctionItemIterator(getCurrentContext(), qn, arity);
FunctionItemToken lit = new FunctionItemToken(f);
return new TokenIterator(getCurrentContext(), lit, getCurrentLoc(),false);
Modified: trunk/MXQuery/xqib_samples/BGColors.html
===================================================================
--- trunk/MXQuery/xqib_samples/BGColors.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/BGColors.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -12,7 +12,7 @@
for $button in b:dom()//input[@type="button"]
return
- b:addEventListener($button, "onclick", xs:QName("local:set"))
+ b:addEventListener($button, "onclick", local:set#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/Delete.html
===================================================================
--- trunk/MXQuery/xqib_samples/Delete.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/Delete.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -10,7 +10,7 @@
delete node b:dom()//input
};
- b:addEventListener(b:dom()//input, "onclick", xs:QName("local:onclick"))
+ b:addEventListener(b:dom()//input, "onclick", local:onclick#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/DeleteInsert.html
===================================================================
--- trunk/MXQuery/xqib_samples/DeleteInsert.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/DeleteInsert.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -10,7 +10,7 @@
delete node b:dom()//input, insert node <hr color="red"/> as last into b:dom()//body
};
- b:addEventListener(b:dom()//input, "onclick", xs:QName("local:onclick"))
+ b:addEventListener(b:dom()//input, "onclick", local:onclick#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/DragAndDrop.html
===================================================================
--- trunk/MXQuery/xqib_samples/DragAndDrop.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/DragAndDrop.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -25,9 +25,9 @@
declare sequential function local:onmousedown($loc, $evt) {
- b:addEventListener(b:dom()//body, "onmousemove", xs:QName("local:onmousemove"));
+ b:addEventListener(b:dom()//body, "onmousemove", local:onmousemove#2);
- b:addEventListener(b:dom()//body, "onmouseup", xs:QName("local:onmouseup"));
+ b:addEventListener(b:dom()//body, "onmouseup", local:onmouseup#2);
replace node b:dom()//div[@name="offsetx"] with <div name="offsetx">{$evt/clientX - local:getValuePx(b:getStyle($loc, "left"))}</div>;
@@ -48,16 +48,16 @@
declare sequential function local:onmouseup($loc, $evt) {
- b:removeEventListener(b:dom()//body, "onmouseup", xs:QName("local:onmouseup"));
+ b:removeEventListener(b:dom()//body, "onmouseup", local:onmouseup#2);
- b:removeEventListener(b:dom()//body, "onmousemove", xs:QName("local:onmousemove"));
+ b:removeEventListener(b:dom()//body, "onmousemove", local:onmousemove#2);
replace value of node b:dom()//div[@id="up_counter"] with xs:int(b:dom()//div[@id="up_counter"]) + 1;
};
- b:addEventListener(b:dom()//div[@id="mydiv"], "onmousedown", xs:QName("local:onmousedown"));
+ b:addEventListener(b:dom()//div[@id="mydiv"], "onmousedown", local:onmousedown#2);
Modified: trunk/MXQuery/xqib_samples/EventLocation.html
===================================================================
--- trunk/MXQuery/xqib_samples/EventLocation.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/EventLocation.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -11,7 +11,7 @@
};
for $d in b:dom()//div
- return b:addEventListener($d, "onclick", xs:QName("local:listener"))
+ return b:addEventListener($d, "onclick", local:listener#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/MouseButton.html
===================================================================
--- trunk/MXQuery/xqib_samples/MouseButton.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/MouseButton.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -17,7 +17,7 @@
b:alert("Unknown button")
};
- b:addEventListener(b:dom()//div[@id = "clickHere"], "onmouseup", xs:QName("local:listener"))
+ b:addEventListener(b:dom()//div[@id = "clickHere"], "onmouseup", local:listener#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/MultiplicationTable.html
===================================================================
--- trunk/MXQuery/xqib_samples/MultiplicationTable.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/MultiplicationTable.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -29,7 +29,7 @@
for $i in b:dom()//input[@type='button']
return
- b:addEventListener($i, "onclick", xs:QName("local:generateTable"));
+ b:addEventListener($i, "onclick", local:generateTable#2);
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/OnClickEvent.html
===================================================================
--- trunk/MXQuery/xqib_samples/OnClickEvent.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/OnClickEvent.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -10,7 +10,7 @@
b:alert("Hello, World")
};
- b:addEventListener(b:dom()//input[@id = "myButton"], "onclick", xs:QName ('local:listener'))
+ b:addEventListener(b:dom()//input[@id = "myButton"], "onclick", local:listener#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/OnmouseoverEvent.html
===================================================================
--- trunk/MXQuery/xqib_samples/OnmouseoverEvent.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/OnmouseoverEvent.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -10,7 +10,7 @@
b:alert("Mouse Over!")
};
- b:addEventListener(b:dom()//h1, "onmouseover", xs:QName("local:listener"))
+ b:addEventListener(b:dom()//h1, "onmouseover", local:listener#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/OnmouseoverEvent_source.html
===================================================================
--- trunk/MXQuery/xqib_samples/OnmouseoverEvent_source.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/OnmouseoverEvent_source.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -19,7 +19,7 @@
<span class="functiondeclare">};</span>
<span class="browserfunction">b:addEventListener</span>
- (<span class="browserfunction">b:dom()</span><span class="enhance1">//h1</span>, "onmouseover", "local:listener")
+ (<span class="browserfunction">b:dom()</span><span class="enhance1">//h1</span>, "onmouseover", local:listener#2)
<span class="scripttag"></script></span>
</head>
<body>
Modified: trunk/MXQuery/xqib_samples/RESTCallCourses.html
===================================================================
--- trunk/MXQuery/xqib_samples/RESTCallCourses.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/RESTCallCourses.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -18,7 +18,7 @@
}</p> as last into b:dom()//body
};
- b:addEventListener(b:dom()//input[@name="click"], "onclick", xs:QName("local:clickListener"))
+ b:addEventListener(b:dom()//input[@name="click"], "onclick", local:clickListener#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/RESTCallCourses_source.html
===================================================================
--- trunk/MXQuery/xqib_samples/RESTCallCourses_source.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/RESTCallCourses_source.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -31,7 +31,7 @@
<span class="functiondeclare">};</span>
<span class="browserfunction">b:addEventListener</span>
- (<span class="enhance2">b:dom()//input[@name="click"]</span>, "onclick", "<span class="enhance1">local:clickListener</span>")
+ (<span class="enhance2">b:dom()//input[@name="click"]</span>, "onclick", "<span class="enhance1">local:clickListener#2</span>")
<span class="scripttag"></script></span>
</head>
<body>
Modified: trunk/MXQuery/xqib_samples/SetStyle.html
===================================================================
--- trunk/MXQuery/xqib_samples/SetStyle.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/SetStyle.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -14,7 +14,7 @@
b:setStyle(b:dom()//body, "color", "blue")
};
- b:addEventListener(b:dom()//input, "onclick", xs:QName("local:listener"))
+ b:addEventListener(b:dom()//input, "onclick", local:listener#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/SetStyle_source.html
===================================================================
--- trunk/MXQuery/xqib_samples/SetStyle_source.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/SetStyle_source.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -24,7 +24,7 @@
<span class="functiondeclare">};</span>
<span class="browserfunction">b:addEventListener</span>
- (<span class="enhance2"><span class="browserfunction">b:dom()</span><span class="enhance1">//input</span>, "onclick", "local:listener")
+ (<span class="enhance2"><span class="browserfunction">b:dom()</span><span class="enhance1">//input</span>, "onclick", local:listener#2)
<span class="scripttag"></script></span>
</head>
<span class="enhance1"><body style="color: red"></span>
Modified: trunk/MXQuery/xqib_samples/Update.html
===================================================================
--- trunk/MXQuery/xqib_samples/Update.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/Update.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -10,7 +10,7 @@
insert node <hr color="red"/> as last into b:dom()//body
};
- b:addEventListener(b:dom()//input, "onclick", xs:QName("local:onclick"))
+ b:addEventListener(b:dom()//input, "onclick", local:onclick#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/Update_source.html
===================================================================
--- trunk/MXQuery/xqib_samples/Update_source.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/Update_source.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -21,7 +21,7 @@
<span class="functiondeclare">};</span>
<span class="browserfunction">b:addEventListener</span>
- (<span class="browserfunction">b:dom()</span><span class="enhance2">//input</span>, "onclick", "<span class="enhance3">local:onclick</span>")
+ (<span class="browserfunction">b:dom()</span><span class="enhance2">//input</span>, "onclick", "<span class="enhance3">local:onclick#2</span>")
<span class="scripttag"></script></span>
</head>
<span class="enhance1"><body></span>
Modified: trunk/MXQuery/xqib_samples/WeatherREST.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherREST.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/WeatherREST.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -46,7 +46,7 @@
};
- b:addEventListener(b:dom()//input[@name="button"], "onclick", xs:QName("local:getWeather"))
+ b:addEventListener(b:dom()//input[@name="button"], "onclick", local:getWeather#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/WeatherREST_source.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherREST_source.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/WeatherREST_source.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -53,7 +53,7 @@
<span class="functiondeclare">};</span>
<span class="browserfunction">b:addEventListener</span>
- (<span class="enhance4">b:dom()//input[@name="button"]</span>, "onclick", "<span class="enhance1">local:getWeather</span>")
+ (<span class="enhance4">b:dom()//input[@name="button"]</span>, "onclick", "<span class="enhance1">local:getWeather#2</span>")
<span class="scripttag"></script></span>
</head>
<span class="enhance3"><body></span>
Modified: trunk/MXQuery/xqib_samples/WeatherRESTasync.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherRESTasync.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/WeatherRESTasync.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -45,12 +45,12 @@
declare updating function local:getWeather($loc, $evtObj) {
http-client:async-request(<http-client:request href="forecast2.xml" method="get"/>,
- xs:QName('local:weatherResult')
+ local:weatherResult#1
)
};
- b:addEventListener(b:dom()//input[@name="button"], "onclick", xs:QName("local:getWeather"))
+ b:addEventListener(b:dom()//input[@name="button"], "onclick", local:getWeather#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/WeatherRESTasyncSlow.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherRESTasyncSlow.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/WeatherRESTasyncSlow.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -45,7 +45,7 @@
declare updating function local:getWeather($loc, $evtObj) {
(
- http-client:async-request( <http-client:request href="http://n.ethz.ch/~etterth/slowserver.php?file=forecast2.xml" method="get"/>, xs:QName('local:weatherResult')),
+ http-client:async-request( <http-client:request href="http://n.ethz.ch/~etterth/slowserver.php?file=forecast2.xml" method="get"/>, local:weatherResult#1),
insert node
<div>Loading:
<img src="img/Loading_2_transparent.gif" />
@@ -56,7 +56,7 @@
};
- b:addEventListener(b:dom()//input[@name="button"], "onclick", xs:QName("local:getWeather"))
+ b:addEventListener(b:dom()//input[@name="button"], "onclick", local:getWeather#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/WeatherRESTasyncSlowCached.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherRESTasyncSlowCached.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/WeatherRESTasyncSlowCached.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -45,7 +45,7 @@
declare updating function local:getWeather($loc, $evtObj) {
(
- http-client:async-read("http://n.ethz.ch/~etterth/slowserver.php?file=forecast2.xml",xs:QName('local:weatherResult')),
+ http-client:async-read("http://n.ethz.ch/~etterth/slowserver.php?file=forecast2.xml",local:weatherResult#1),
insert node
<div>Loading:
<img src="img/Loading_2_transparent.gif" />
@@ -56,7 +56,7 @@
};
- b:addEventListener(b:dom()//input[@name="button"], "onclick", xs:QName("local:getWeather"))
+ b:addEventListener(b:dom()//input[@name="button"], "onclick", local:getWeather#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/WeatherRESTread.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherRESTread.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/WeatherRESTread.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -44,13 +44,12 @@
};
declare updating function local:getWeather($loc, $evtObj) {
- http-client:async-read("forecast2.xml",
-xs:QName('local:weatherResult')
+ http-client:async-read("forecast2.xml",local:weatherResult#1)
)
};
- b:addEventListener(b:dom()//input[@name="button"], "onclick", xs:QName("local:getWeather"))
+ b:addEventListener(b:dom()//input[@name="button"], "onclick", local:getWeather#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/cookies.html
===================================================================
--- trunk/MXQuery/xqib_samples/cookies.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/cookies.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -24,8 +24,8 @@
};
- b:addEventListener(b:dom()//input[@id="getbutton"], "onclick", xs:QName("local:getCookie")),
- b:addEventListener(b:dom()//input[@id="setbutton"], "onclick", xs:QName("local:setCookie"))
+ b:addEventListener(b:dom()//input[@id="getbutton"], "onclick", local:getCookie#2),
+ b:addEventListener(b:dom()//input[@id="setbutton"], "onclick", local:setCookie#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/log.htm
===================================================================
--- trunk/MXQuery/xqib_samples/log.htm 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/log.htm 2011-06-01 15:42:25 UTC (rev 4379)
@@ -7,7 +7,7 @@
<script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
<script type="application/xquery">
- b:log(b:getStyle(b:dom()//body, "color"))
+ trace(b:getStyle(b:dom()//body, "color"))
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/removeEventListener.html
===================================================================
--- trunk/MXQuery/xqib_samples/removeEventListener.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/removeEventListener.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -26,7 +26,7 @@
<script type="application/xquery">
declare sequential function local:listener($loc, $evtObj) {
- b:removeEventListener($loc, "onclick", xs:QName("local:listener")),
+ b:removeEventListener($loc, "onclick", local:listener#2),
b:alert($loc);
};
Modified: trunk/MXQuery/xqib_samples/textarea.htm
===================================================================
--- trunk/MXQuery/xqib_samples/textarea.htm 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/textarea.htm 2011-06-01 15:42:25 UTC (rev 4379)
@@ -1,28 +1,28 @@
-<!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:onclick($loc, $evtObj) {
- let $textarea := b:dom()//textarea[@id='ta1']
-return (
- insert node ' appended text' as last into $textarea,
- insert node <div>{fn:concat('The value in ta1 was "', $textarea/text(),'"')}</div> after $textarea
-)
- };
-
- b:addEventListener(b:dom()//input, "onclick", xs:QName("local:onclick"))
-
- </script>
- </head>
- <body>
- <a href="index.html"><< Index</a>
- <h1>Insert</h1>
- <div><a href="Update.html">Page</a> | <a href="Update_source.html">Source</a></div>
- <p><textarea id="ta1"></textarea></p>
- <input type="button" value="test textarea"/>
- </body>
-</html>
+<!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:onclick($loc, $evtObj) {
+ let $textarea := b:dom()//textarea[@id='ta1']
+return (
+ insert node ' appended text' as last into $textarea,
+ insert node <div>{fn:concat('The value in ta1 was "', $textarea/text(),'"')}</div> after $textarea
+)
+ };
+
+ b:addEventListener(b:dom()//input, "onclick", local:onclick#2)
+
+ </script>
+ </head>
+ <body>
+ <a href="index.html"><< Index</a>
+ <h1>Insert</h1>
+ <div><a href="Update.html">Page</a> | <a href="Update_source.html">Source</a></div>
+ <p><textarea id="ta1"></textarea></p>
+ <input type="button" value="test textarea"/>
+ </body>
+</html>
Modified: trunk/MXQuery/xqib_samples/tidy.html
===================================================================
--- trunk/MXQuery/xqib_samples/tidy.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/tidy.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -22,7 +22,7 @@
};
- b:addEventListener(b:dom()//input[@name="button"], "onclick", xs:QName("local:getWeather"))
+ b:addEventListener(b:dom()//input[@name="button"], "onclick", local:getWeather#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/timer.html
===================================================================
--- trunk/MXQuery/xqib_samples/timer.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/timer.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -7,11 +7,11 @@
<script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
<script type="application/xquery">
declare updating function local:listener() {
- b:timer(1000, xs:QName('local:listener')),
+ (:b:timer(1000, local:listener#0),:)
insert node <div>{fn:current-time()}</div> as last into b:dom()//body
};
- b:timer(1000, xs:QName('local:listener'))
+ b:timer(1000, local:listener#0)
</script>
</head>
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-06-01 15:42:25 UTC (rev 4379)
@@ -7,9 +7,11 @@
import ch.ethz.mxquery.contextConfig.CompilerOptions;
import ch.ethz.mxquery.contextConfig.Context;
import ch.ethz.mxquery.datamodel.QName;
+import ch.ethz.mxquery.datamodel.xdm.FunctionItemToken;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
import ch.ethz.mxquery.functions.Function;
+import ch.ethz.mxquery.functions.FunctionGallery;
import ch.ethz.mxquery.iterators.browser.EventIterator;
import ch.ethz.mxquery.iterators.browser.ListBasedIterator;
import ch.ethz.mxquery.iterators.browser.SingleNodeIterator;
@@ -35,9 +37,9 @@
public class Environment {
- static Hashtable<NodeAndEventName, List<QnameAndArity>> handlers;
+ static Hashtable<NodeAndEventName, List<FunctionItemToken>> handlers;
static Hashtable<String, Context> modules = new Hashtable<String, Context>();
- static Context modCtx;
+ static Context modCtx = new Context();
static CompilerOptions co;
static int contextcounter = 0;
@@ -90,41 +92,41 @@
}
public static void reset() {
- modCtx = null;
+ //modCtx = null;
co = null;
handlers = null;
}
public static void addEventListener(Element el, String eventName,
- QName functionname, int arity, Context ctx) {
+ FunctionItemToken fi, Context ctx) {
if (eventName.startsWith("on"))
eventName = eventName.substring(2);
if (handlers == null)
- handlers = new Hashtable<NodeAndEventName, List<QnameAndArity>>();
+ handlers = new Hashtable<NodeAndEventName, List<FunctionItemToken>>();
NodeAndEventName test = new NodeAndEventName(el, eventName);
- List<QnameAndArity> lst = handlers.get(test);
+ List<FunctionItemToken> lst = handlers.get(test);
if (lst == null) {
- lst = new ArrayList<QnameAndArity>();
+ lst = new ArrayList<FunctionItemToken>();
handlers.put(test, lst);
}
- lst.add(new QnameAndArity(functionname, arity, ctx));
+ lst.add(fi);
nativeAddEventListener(el, eventName);
}
public static void removeEventListener(Element el, String eventName,
- QName functionname, int arity, Context ctx) throws MXQueryException {
+ FunctionItemToken fi, Context ctx) throws MXQueryException {
if (eventName.startsWith("on"))
eventName = eventName.substring(2);
if (handlers == null)
throw new MXQueryException("Eventlistener cannot be removed",
"handler to remove cannot be found", null);
NodeAndEventName test = new NodeAndEventName(el, eventName);
- List<QnameAndArity> lst = handlers.get(test);
+ List<FunctionItemToken> lst = handlers.get(test);
if (lst == null) {
throw new MXQueryException("Eventlistener cannot be removed",
"handler to remove cannot be found", null);
}
- lst.remove(new QnameAndArity(functionname, arity, ctx));
+ lst.remove(fi);
if (lst.isEmpty()) {
handlers.put(test, null);
nativeRemoveEventListener(el, eventName);
@@ -144,22 +146,20 @@
while (test.node.getParentElement()!= null && handlers.get(test) == null){
test.node = test.node.getParentElement();
}
- for (QnameAndArity functionname : handlers.get(test)) {
+ for (FunctionItemToken fi : handlers.get(test)) {
SingleNodeIterator nodeiter = new SingleNodeIterator(
test.node);
try {
- log.log(LogLevel.FINER, "Calling eventcallback " + functionname.qname.toString());
+ //TODO: remove name reference - inline functions don't have a name
+ log.log(LogLevel.FINER, "Calling eventcallback " + fi.getFunction().getFunctionSignature().getName().toString());
ListBasedIterator eventiter = new EventIterator(event);
eventiter.setContext(new Context(), true);
Iterator[] subiterators = { nodeiter, eventiter };
- QName qn = functionname.qname;
- qn.setNamespaceURI(functionname.context.getNamespace(
- qn.getNamespacePrefix()).getURI());
- Environment.invokeModule(functionname, subiterators);
- log.log(LogLevel.FINER, "Eventcallback " + functionname.qname.toString() + " done");
+
+ Environment.invokeModule(fi, subiterators);
+ log.log(LogLevel.FINER, "Eventcallback " + fi.getFunction().getFunctionSignature().getName().toString() + " done");
eventiter = null;
subiterators = null;
- qn = null;
nodeiter = null;
} catch (MXQueryException e) {
// TODO Auto-generated catch block
@@ -174,26 +174,35 @@
event.preventDefault();
}
- public static void invokeModule(QnameAndArity functionname, XDMIterator[] subiterators)
+ public static void invokeModule(FunctionItemToken ft, XDMIterator[] subiterators)
throws MXQueryException {
preProcessDocument();
// try {
if (subiterators == null) {
subiterators = new XDMIterator[0];
}
+
+ Logger log = Logger.getLogger("Environment");
+ log.log(LogLevel.FINER, "Invoke 'module'");
+
+
+ Function f = ft.getFunction();
+ log.log(LogLevel.FINER, "Got function");
+
+ //set currenttime
+ modCtx.setCurrentTime(null);
+ log.log(LogLevel.FINER, "Set time");
+ XDMIterator func = f.getFunctionImplementation(modCtx);
+
for (XDMIterator iter : subiterators) {
iter.staticInit();
}
- int arity = subiterators.length;
- Function function = functionname.context.getFunction(functionname.qname, arity);
- //set currenttime
- functionname.context.setCurrentTime(null);
- XDMIterator func = function.getFunctionImplementation(new Context(functionname.context));
+
func.setSubIters(subiterators);
// func.setContext(getContext(), true);
PreparedStatement prep = new PreparedStatementImpl(
- Environment.createContext(), func,
+ modCtx, func,
Environment.getCompilerOptions(), null);
// NodeStore nodestore = new NodeStore(Document.get());
// prep.addExternalResource(Context.CONTEXT_ITEM,
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-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-06-01 15:42:25 UTC (rev 4379)
@@ -35,6 +35,7 @@
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.datamodel.xdm.ElementToken;
+import ch.ethz.mxquery.datamodel.xdm.FunctionItemToken;
import ch.ethz.mxquery.datamodel.xdm.NamedToken;
import ch.ethz.mxquery.datamodel.xdm.TextToken;
import ch.ethz.mxquery.datamodel.xdm.Token;
@@ -164,24 +165,18 @@
protected boolean statusOnly = false;
protected boolean async;
protected boolean readonly;
- protected QName asynchandlername;
+ protected FunctionItemToken fi;
protected XmlHttpRequestWrappedHandler asynchandler;
private boolean received;
private void init() throws MXQueryException {
if (async) {
- XDMIterator handleriter = subIters[subIters.length - 1];
- this.asynchandlername = handleriter.next().getQNameTokenValue();
- if (asynchandlername != null) {
- if (this.getContext().getRootContext()
- .getFunction(asynchandlername, 1) == null) {
- throw new MXQueryException(
- ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,
- "the eventhandler with the name "
- + asynchandlername.toString()
- + " is not available in an asynchronous expath call",
- loc);
- }
+
+ TokenInterface fTok = subIters[subIters.length - 1].next();
+ if (fTok.getEventType() != Type.FUNCTION_ITEM && subIters[subIters.length - 1].next().getEventType() != Type.END_SEQUENCE)
+ throw new MXQueryException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "FunctionItem expected", getLoc());
+ fi = (FunctionItemToken)fTok;
+
final HttpIO thisobj = this;
asynchandler = new XmlHttpRequestWrappedHandler() {
@@ -192,25 +187,18 @@
thisobj.getResponse(req);
Logger log = Logger.getLogger(this.getClass().getName());
log.log(LogLevel.FINER, "Retrieved asynchronously: " + thisobj.uri);
- log.log(LogLevel.FINER, "Invoking the EventHandler " + thisobj.asynchandlername.toString());
- QnameAndArity qa = new QnameAndArity(
- thisobj.asynchandlername, 1, thisobj.getContext()
- .getRootContext());
- Environment.invokeModule(qa,
+ log.log(LogLevel.FINER, "Invoking the EventHandler ");
+ Environment.invokeModule(fi,
new XDMIterator[] { thisobj });
- log.log(LogLevel.FINER, "EventHandler " + thisobj.asynchandlername.toString() + " done");
+ log.log(LogLevel.FINER, "EventHandler done");
}
};
- }
- 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 = 0; i < oldsubiters.length-1; i++) {
subIters[i] = oldsubiters[i];
}
- }
+ };
Context childContext = new Context(context);
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java 2011-06-01 15:42:25 UTC (rev 4379)
@@ -71,7 +71,7 @@
"xs:integer",ctx),FunctionGallery.getOccur("xs:integer"),null);
paramTypes[1] = new TypeInfo(FunctionGallery.getType(
- "QName",ctx),FunctionGallery.getOccur("QName"),null);
+ "function()",ctx),FunctionGallery.getOccur("function()"),null);
signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
@@ -386,39 +386,6 @@
"http://xqib.org",
"b",
"addEventListener");
- paramTypes = new TypeInfo[4];
-
- paramTypes[0] = new TypeInfo(FunctionGallery.getType(
- "node()+",ctx),FunctionGallery.getOccur("node()+"),null);
-
- paramTypes[1] = new TypeInfo(FunctionGallery.getType(
- "xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
-
- paramTypes[2] = new TypeInfo(FunctionGallery.getType(
- "QName",ctx),FunctionGallery.getOccur("QName"),null);
-
- paramTypes[3] = new TypeInfo(FunctionGallery.getType(
- "xs:integer",ctx),FunctionGallery.getOccur("xs:integer"),null);
-
- signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
-
-
- {
- ch.ethz.mxquery.functions.b.AddEventListener iter = new ch.ethz.mxquery.functions.b.AddEventListener();
- iter.setContext(context, false);
-
- type = null;
-
- function = new Function(
- null,signature,
- iter, null, type );
- fg.add(function);
- }
-
- qn = new QName(
- "http://xqib.org",
- "b",
- "addEventListener");
paramTypes = new TypeInfo[3];
paramTypes[0] = new TypeInfo(FunctionGallery.getType(
@@ -428,7 +395,7 @@
"xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
paramTypes[2] = new TypeInfo(FunctionGallery.getType(
- "QName",ctx),FunctionGallery.getOccur("QName"),null);
+ "function()",ctx),FunctionGallery.getOccur("function()"),null);
signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
@@ -445,39 +412,8 @@
fg.add(function);
}
- qn = new QName(
- "http://xqib.org",
- "b",
- "removeEventListener");
- paramTypes = new TypeInfo[4];
-
- paramTypes[0] = new TypeInfo(FunctionGallery.getType(
- "node()+",ctx),FunctionGallery.getOccur("node()+"),null);
-
- paramTypes[1] = new TypeInfo(FunctionGallery.getType(
- "xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
-
- paramTypes[2] = new TypeInfo(FunctionGallery.getType(
- "QName",ctx),FunctionGallery.getOccur("QName"),null);
-
- paramTypes[3] = new TypeInfo(FunctionGallery.getType(
- "xs:integer",ctx),FunctionGallery.getOccur("xs:integer"),null);
-
- signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
-
-
- {
- ch.ethz.mxquery.functions.b.RemoveEventListener iter = new ch.ethz.mxquery.functions.b.RemoveEventListener();
- iter.setContext(context, false);
-
- type = null;
-
- function = new Function(
- null,signature,
- iter, null, type );
- fg.add(function);
- }
+
qn = new QName(
"http://xqib.org",
"b",
@@ -491,7 +427,7 @@
"xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
paramTypes[2] = new TypeInfo(FunctionGallery.getType(
- "QName",ctx),FunctionGallery.getOccur("QName"),null);
+ "function()",ctx),FunctionGallery.getOccur("function()"),null);
signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
@@ -5957,7 +5893,7 @@
"item()*",ctx),FunctionGallery.getOccur("item()*"),null);
paramTypes[3] = new TypeInfo(FunctionGallery.getType(
- "QName",ctx),FunctionGallery.getOccur("QName"),null);
+ "function()",ctx),FunctionGallery.getOccur("QName"),null);
signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
@@ -6018,7 +5954,7 @@
"element()?",ctx),FunctionGallery.getOccur("element()?"),null);
paramTypes[1] = new TypeInfo(FunctionGallery.getType(
- "QName",ctx),FunctionGallery.getOccur("QName"),null);
+ "function()",ctx),FunctionGallery.getOccur("function()"),null);
signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
@@ -6073,7 +6009,7 @@
"xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
paramTypes[1] = new TypeInfo(FunctionGallery.getType(
- "QName",ctx),FunctionGallery.getOccur("QName"),null);
+ "function()",ctx),FunctionGallery.getOccur("function()"),null);
signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddEventListener.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddEventListener.java 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddEventListener.java 2011-06-01 15:42:25 UTC (rev 4379)
@@ -10,6 +10,7 @@
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.FunctionItemToken;
import ch.ethz.mxquery.datamodel.xdm.Token;
import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.DynamicException;
@@ -28,23 +29,15 @@
@Override
protected void init() throws MXQueryException {
currentToken = Token.END_SEQUENCE_TOKEN;
- if (subIters[0] == null) {
- throw new IllegalArgumentException("no argument given for b:addEventListener");
- }
String eventname;
- QName qfunctionname;
- XDMIterator nameiter = subIters[1];
+
+ eventname = getStringValue(subIters[1]);
XDMIterator functioniter = subIters[2];
- int arity = 2;
- if (subIters.length >3){
- arity = Integer.parseInt(subIters[3].toString());
- }
- TokenInterface nametoken = nameiter.next();
TokenInterface functiontoken = functioniter.next();
- eventname = nametoken.getValueAsString();
- qfunctionname = functiontoken.getQNameTokenValue();
- if (eventname == null || qfunctionname == null)
- throw new IllegalArgumentException("The third argument for b:addEventListener has to be a QName");
+
+ if (functiontoken.getEventType() != Type.FUNCTION_ITEM || functioniter.next().getEventType() != Type.END_SEQUENCE)
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Function Item expected", loc);
+
XDMIterator iter = subIters[0];
//if (iter instanceof DataValuesIterator) ((DataValuesIterator)iter).setFnData(true);
TokenInterface tok;
@@ -59,13 +52,7 @@
throw new DynamicException(ErrorCodes.F0023_INVALID_VALUE_FOR_CAST_CONSTRUCTOR,de.getMessage(), loc);
else throw de;
}
-
- type = Type.getEventTypeSubstituted(tok.getEventType(), Context.getDictionary());
-
- if ( Type.isAttribute(type) ){
- type = Type.getAttributeValueType(type);
- }
-
+ type = tok.getEventType();
switch (type) {
case Type.END_SEQUENCE:
break;
@@ -76,18 +63,16 @@
case Type.END_TAG:
level--;
break;
- default:
-
-
+ default:
}
} while (type != Type.END_SEQUENCE);
for (TokenInterface token:tokens){
- addEventHandler(token, eventname, qfunctionname, arity);
+ addEventHandler(token, eventname, (FunctionItemToken)functiontoken);
}
}
private void addEventHandler(TokenInterface tok, String eventname,
- QName qfunctionname, int arity) throws MXQueryException {
+ FunctionItemToken fi) throws MXQueryException {
if (!(tok instanceof ElementNodeToken)){
return;
}
@@ -97,11 +82,11 @@
// QName qfunctionname = new QName(functionname);
// qfunctionname.setNamespaceURI(this.getContext().getNamespace(qfunctionname.getNamespacePrefix()).getURI());
Context ctx = this.getContext().getRootContext();//Environment.getContext();
- if (this.getContext().getRootContext().getFunction(qfunctionname, arity) == null){
- throw new MXQueryException(ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,
- "function not available in addEventListener", getLoc());
- }
- Environment.addEventListener(el, eventname, qfunctionname, arity,ctx);
+ //if (this.getContext().getRootContext().getFunction(qfunctionname, arity) == null){
+ // throw new MXQueryException(ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,
+ // "function not available in addEventListener", getLoc());
+ //}
+ Environment.addEventListener(el, eventname, fi,ctx);
}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveEventListener.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveEventListener.java 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveEventListener.java 2011-06-01 15:42:25 UTC (rev 4379)
@@ -8,6 +8,7 @@
import ch.ethz.mxquery.contextConfig.Context;
import ch.ethz.mxquery.datamodel.QName;
import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.xdm.FunctionItemToken;
import ch.ethz.mxquery.datamodel.xdm.Token;
import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.DynamicException;
@@ -28,20 +29,12 @@
if (subIters[0] == null) {
throw new IllegalArgumentException();
}
- String eventname;
- QName qfunctionname;
- XDMIterator nameiter = subIters[1];
- XDMIterator functioniter = subIters[2];
- int arity = 2;
- if (subIters.length >3){
- arity = Integer.parseInt(subIters[3].toString());
- }
- TokenInterface nametoken = nameiter.next();
- TokenInterface functiontoken = functioniter.next();
- eventname = nametoken.getValueAsString();
- qfunctionname = functiontoken.getQNameTokenValue();
- if (eventname == null || qfunctionname == null)
- throw new MXQueryException("b:addEventListener", "invalid arguments", loc);
+ String eventname = getStringValue(subIters[1]);
+
+ TokenInterface functiontoken = subIters[2].next();
+ if (functiontoken.getEventType() != Type.FUNCTION_ITEM && subIters[2].next().getEventType() != Type.END_SEQUENCE)
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Function Item expected", loc);
+
XDMIterator iter = subIters[0];
//if (iter instanceof DataValuesIterator) ((DataValuesIterator)iter).setFnData(true);
TokenInterface tok;
@@ -49,42 +42,28 @@
int level = 0;
LinkedList<TokenInterface> tokens = new LinkedList<TokenInterface>();
do {
- try {
- tok = iter.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;
- }
-
- type = Type.getEventTypeSubstituted(tok.getEventType(), Context.getDictionary());
-
- if ( Type.isAttribute(type) ){
- type = Type.getAttributeValueType(type);
- }
-
- switch (type) {
- case Type.END_SEQUENCE:
- break;
- case Type.START_TAG:
- if (level++ == 0)
- tokens.add(tok);
- break;
- case Type.END_TAG:
- level--;
- break;
- default:
-
-
- }
+ tok = iter.next();
+ type = tok.getEventType();
+ switch (type) {
+ case Type.END_SEQUENCE:
+ break;
+ case Type.START_TAG:
+ if (level++ == 0)
+ tokens.add(tok);
+ break;
+ case Type.END_TAG:
+ level--;
+ break;
+ default:
+ }
} while (type != Type.END_SEQUENCE);
for (TokenInterface token:tokens){
- removeEventHandler(token, eventname, qfunctionname, arity);
+ removeEventHandler(token, eventname, (FunctionItemToken)functiontoken);
}
}
private void removeEventHandler(TokenInterface tok, String eventname,
- QName qfunctionname, int arity) throws MXQueryException {
+ FunctionItemToken fi) throws MXQueryException {
if (!(tok instanceof ElementNodeToken)){
return;
}
@@ -94,11 +73,7 @@
//resolve functionname
// qfunctionname.setNamespaceURI(this.getContext().getNamespace(qfunctionname.getNamespacePrefix()).getURI());
Context ctx = this.getContext().getParent();//Environment.getContext();
- if (this.getContext().getRootContext().getFunction(qfunctionname, arity) == null){
- throw new MXQueryException(ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,
- "function not available in addEventListener", getLoc());
- }
- Environment.removeEventListener(el, eventname, qfunctionname, arity, ctx);
+ Environment.removeEventListener(el, eventname, fi, ctx);
}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/Timer.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/Timer.java 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/Timer.java 2011-06-01 15:42:25 UTC (rev 4379)
@@ -7,16 +7,10 @@
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.FunctionItemToken;
import ch.ethz.mxquery.datamodel.xdm.LongToken;
import ch.ethz.mxquery.datamodel.xdm.Token;
import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
@@ -35,72 +29,26 @@
import ch.ethz.mxquery.util.browser.XmlHttpRequestWrapper;
public class Timer extends TokenBasedIterator {
-
- protected QName asynchandlername;
-
+
+ FunctionItemToken fi;
+
@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;
- }
+
+ TokenInterface fTok = subIters[1].next();
+ if (fTok.getEventType() != Type.FUNCTION_ITEM || subIters[1].next().getEventType() != Type.END_SEQUENCE)
+ throw new MXQueryException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "FunctionItem expected", getLoc());
+ fi = (FunctionItemToken)fTok;
+ TokenInterface tok = subIters[0].next();
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);
- }
+ if (type != Type.INTEGER && subIters[0].next().getEventType() != Type.END_SEQUENCE)
+ throw new MXQueryException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Single xs:integer expected", getLoc());
+
+ int time = (int) tok.getLong();
final Timer thisobj = this;
com.google.gwt.user.client.Timer timerobj = new com.google.gwt.user.client.Timer() {
@@ -109,12 +57,9 @@
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());
+ log.log(LogLevel.FINER, "Invoking the TimerHandler ");
try {
- Environment.invokeModule(qa,
+ Environment.invokeModule(fi,
new XDMIterator[] { });
} catch (MXQueryException e) {
// TODO Auto-generated catch block
@@ -123,12 +68,12 @@
false);
e.printStackTrace();
}
- log.log(LogLevel.FINER, "TimerHandler " + thisobj.asynchandlername.toString() + " done");
+ log.log(LogLevel.FINER, "TimerHandler done");
}
};
timerobj.schedule(time);
+ logger.log(LogLevel.FINER, "Invoking the Timer setup function");
-
}
@Override
Added: trunk/MXQuery_Testing/XQTests/Queries/xquery11/hof-forward-samefunc.xq
===================================================================
--- trunk/MXQuery_Testing/XQTests/Queries/xquery11/hof-forward-samefunc.xq (rev 0)
+++ trunk/MXQuery_Testing/XQTests/Queries/xquery11/hof-forward-samefunc.xq 2011-06-01 15:42:25 UTC (rev 4379)
@@ -0,0 +1,12 @@
+declare function local:hof($func as function(*), $par as xs:integer) {
+$func($par)
+};
+
+declare function local:fwtest($param as xs:integer) {
+ if ($param gt 0) then
+ local:hof(local:fwtest#1,$param - 1)
+ else
+ 1
+ };
+
+local:hof(local:fwtest#1,42)
\ No newline at end of file
Modified: trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/xq11streaming/MiscTests.java
===================================================================
--- trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/xq11streaming/MiscTests.java 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/xq11streaming/MiscTests.java 2011-06-01 15:42:25 UTC (rev 4379)
@@ -650,4 +650,12 @@
// check for sequential, give updating
// check for sequential, give sequential
+ public void test_hof_forward_samefunc() throws Exception {
+ String name = "hof-forward-samefunc";
+ String query = UriToString(QUERIES + name + ".xq");
+ doQuery(prepareQuery(query, false ,false, false, true, false));
+ }
+
+
}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tim...@us...> - 2011-05-31 12:53:52
|
Revision: 4378
http://mxquery.svn.sourceforge.net/mxquery/?rev=4378&view=rev
Author: timchurch
Date: 2011-05-31 12:53:45 +0000 (Tue, 31 May 2011)
Log Message:
-----------
Removed separate doUpdatingQuery() function - no longer needed
Modified Paths:
--------------
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java 2011-05-31 10:39:22 UTC (rev 4377)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java 2011-05-31 12:53:45 UTC (rev 4378)
@@ -1,23 +1,12 @@
package ch.ethz.mxquery.android;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
-import ch.ethz.mxquery.contextConfig.CompilerOptions;
-import ch.ethz.mxquery.contextConfig.Context;
-import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.model.XDMIterator;
-import ch.ethz.mxquery.query.PreparedStatement;
-import ch.ethz.mxquery.query.XQCompiler;
-import ch.ethz.mxquery.query.impl.CompilerImpl;
-import ch.ethz.mxquery.xdmio.XDMSerializer;
import ch.ethz.mxquery.xqj.MXQueryXQDataSource;
import ch.ethz.repackaged.xquery.XQConnection;
import ch.ethz.repackaged.xquery.XQDataSource;
@@ -61,17 +50,14 @@
private class QueryThread extends Thread {
private String query;
private XQueryListener listener;
- private boolean updating;
public QueryThread(String query, XQueryListener listener, boolean updating) {
this.query = query;
this.listener = listener;
- this.updating = updating;
}
public void run() {
- String result = updating ? doUpdatingQuery(this.query)
- : doQuery(this.query);
+ String result = doQuery(this.query);
lastResult = result;
System.out.println("QueryThread - saving result: " + result);
listener.queryResult(result);
@@ -95,43 +81,5 @@
}
return result.toString();
}
-
- protected String doUpdatingQuery(String query) {
- Context ctx = new Context();
- CompilerOptions co = new CompilerOptions();
- XQCompiler comp = new CompilerImpl();
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- String s = new String();
-
- ctx.getStores().setSerializeStores(true);
- co.setUpdate(true);
-
- try {
- PreparedStatement statement = comp.compile(ctx, query, co, null, null);
- XDMIterator result = statement.evaluate();
- XDMSerializer ser = new XDMSerializer();
-
- ser.eventsToXML(out, result);
- statement.applyPUL();
- statement.serializeStores(false);
- result.close(false);
- statement.close();
- } catch (MXQueryException err) {
- MXQueryException.printErrorPosition(query, err.getLocation());
- err.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- ctx.getStores().freeRessources();
-
- try {
- s = out.toString("utf-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
-
- return s;
- }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <max...@us...> - 2011-05-31 10:39:28
|
Revision: 4377
http://mxquery.svn.sourceforge.net/mxquery/?rev=4377&view=rev
Author: maxspeicher
Date: 2011-05-31 10:39:22 +0000 (Tue, 31 May 2011)
Log Message:
-----------
- modified XQJ invocation to support updating queries
- added fn:put() to sample queries
Modified Paths:
--------------
trunk/MXQuery_Android_App/res/values/strings.xml
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java
Modified: trunk/MXQuery_Android_App/res/values/strings.xml
===================================================================
--- trunk/MXQuery_Android_App/res/values/strings.xml 2011-05-31 08:56:18 UTC (rev 4376)
+++ trunk/MXQuery_Android_App/res/values/strings.xml 2011-05-31 10:39:22 UTC (rev 4377)
@@ -27,6 +27,7 @@
<item>@string/fn_doc2</item>
<item>@string/updating</item>
<item>@string/updating2</item>
+ <item>@string/put</item>
<item>@string/webservice</item>
<item>@string/android_location</item>
</string-array>
@@ -43,6 +44,7 @@
<string name="fn_doc2">fn:doc() - Internet</string>
<string name="updating">Updating 1</string>
<string name="updating2">Updating 2</string>
+ <string name="put">fn:put()</string>
<string name="webservice">Web Service</string>
<string name="android_location">android:location()</string>
@@ -96,6 +98,9 @@
<string name="updating2_xquery">
insert node <update2/> as last into fn:doc(\"test.xml\")/test
</string>
+ <string name="put_xquery">
+ fn:put(<test><put/></test>, \"test2.xml\")
+ </string>
<string name="webservice_xquery">
import module namespace http = \"http://expath.org/ns/http-client\";
http:send-request(<http:request method=\'get\'/>,\'http://www.google.com\')[1]/data(@status)
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java 2011-05-31 08:56:18 UTC (rev 4376)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java 2011-05-31 10:39:22 UTC (rev 4377)
@@ -26,7 +26,7 @@
import ch.ethz.repackaged.xquery.XQSequence;
public class MXQueryService extends Service {
- private XQDataSource xqjd = new MXQueryXQDataSource();
+ private XQDataSource xqjd = new MXQueryXQDataSource(MXQueryXQDataSource.XQJ_UPDATE_MODE);
public static String lastResult = null;
private static final String LOG_TAG = "MXQuery.MXQueryService";
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java 2011-05-31 08:56:18 UTC (rev 4376)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java 2011-05-31 10:39:22 UTC (rev 4377)
@@ -159,10 +159,12 @@
mInputView.setText(getString(R.string.fn_doc2_xquery));
} else if (item.equals(getString(R.string.updating))) {
mInputView.setText(getString(R.string.updating_xquery));
- mUpdating = true;
+// mUpdating = true;
} else if (item.equals(getString(R.string.updating2))) {
mInputView.setText(getString(R.string.updating2_xquery));
- mUpdating = true;
+// mUpdating = true;
+ } else if (item.equals(getString(R.string.put))) {
+ mInputView.setText(getString(R.string.put_xquery));
} else if (item.equals(getString(R.string.webservice))) {
mInputView.setText(getString(R.string.webservice_xquery));
} else if (item.equals(getString(R.string.android_location))) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tim...@us...> - 2011-05-31 08:56:24
|
Revision: 4376
http://mxquery.svn.sourceforge.net/mxquery/?rev=4376&view=rev
Author: timchurch
Date: 2011-05-31 08:56:18 +0000 (Tue, 31 May 2011)
Log Message:
-----------
- Added sample query for web service calls
- Added sample query for Android location
- Changed values for local file updates (to make it easier to understand)
- Better error handling on queries (return error message)
Modified Paths:
--------------
trunk/MXQuery_Android_App/res/values/strings.xml
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java
Modified: trunk/MXQuery_Android_App/res/values/strings.xml
===================================================================
--- trunk/MXQuery_Android_App/res/values/strings.xml 2011-05-31 08:52:59 UTC (rev 4375)
+++ trunk/MXQuery_Android_App/res/values/strings.xml 2011-05-31 08:56:18 UTC (rev 4376)
@@ -27,6 +27,8 @@
<item>@string/fn_doc2</item>
<item>@string/updating</item>
<item>@string/updating2</item>
+ <item>@string/webservice</item>
+ <item>@string/android_location</item>
</string-array>
<string name="hello_world">Hello World</string>
@@ -41,6 +43,8 @@
<string name="fn_doc2">fn:doc() - Internet</string>
<string name="updating">Updating 1</string>
<string name="updating2">Updating 2</string>
+ <string name="webservice">Web Service</string>
+ <string name="android_location">android:location()</string>
<string name="hello_world_xquery">\"Hello World\"</string>
<string name="addition_xquery">5+5</string>
@@ -86,11 +90,21 @@
</string>
<string name="updating_xquery">
copy $x := <test></test>\n
- modify( insert node <bla/> into $x )\n
+ modify( insert node <update1/> into $x )\n
return $x
</string>
<string name="updating2_xquery">
- insert node <blub/> as last into fn:doc(\"test.xml\")/test
+ insert node <update2/> as last into fn:doc(\"test.xml\")/test
</string>
+ <string name="webservice_xquery">
+ import module namespace http = \"http://expath.org/ns/http-client\";
+ http:send-request(<http:request method=\'get\'/>,\'http://www.google.com\')[1]/data(@status)
+ </string>
+ <string name="android_location_xquery">
+ declare namespace m = \"java:ch.ethz.mxquery.android.MXQuery\";\n
+ declare namespace l = \"java:android.location.Location\";\n
+ let $loc := m:getLocation()\n
+ return fn:concat(l:getLatitude($loc), \", \", l:getLongitude($loc))
+ </string>
</resources>
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java 2011-05-31 08:52:59 UTC (rev 4375)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MXQueryService.java 2011-05-31 08:56:18 UTC (rev 4376)
@@ -9,6 +9,7 @@
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
+import android.util.Log;
import ch.ethz.mxquery.contextConfig.CompilerOptions;
import ch.ethz.mxquery.contextConfig.Context;
import ch.ethz.mxquery.exceptions.MXQueryException;
@@ -27,6 +28,7 @@
public class MXQueryService extends Service {
private XQDataSource xqjd = new MXQueryXQDataSource();
public static String lastResult = null;
+ private static final String LOG_TAG = "MXQuery.MXQueryService";
// Binder given to clients
private final IBinder mBinder = new MXQueryServiceBinder();
@@ -87,9 +89,10 @@
xqjs.writeSequence(result, null);
xqjc.close();
} catch (XQException xqe) {
- xqe.printStackTrace();
+ //xqe.printStackTrace();
+ Log.e(LOG_TAG, xqe.getMessage(), xqe);
+ return xqe.getMessage();
}
-
return result.toString();
}
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java 2011-05-31 08:52:59 UTC (rev 4375)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java 2011-05-31 08:56:18 UTC (rev 4376)
@@ -57,7 +57,7 @@
private static final String OUTPUT_FORMAT = "json";
private static final String SEARCH_KEYWORDS = "pizza";
private static final String SEARCH_TYPES = "food|restaurant|establishment";
- private static final Integer SEARCH_RADIUS = 20;
+ private static final Integer SEARCH_RADIUS = 50;
@Override
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java 2011-05-31 08:52:59 UTC (rev 4375)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java 2011-05-31 08:56:18 UTC (rev 4376)
@@ -110,7 +110,7 @@
BufferedWriter save = new BufferedWriter(new OutputStreamWriter(openFileOutput("test.xml", 0)));
save.write(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<test><bla/></test>"
+ "<test><default/></test>"
);
save.close();
} catch (Exception e) {
@@ -163,6 +163,10 @@
} else if (item.equals(getString(R.string.updating2))) {
mInputView.setText(getString(R.string.updating2_xquery));
mUpdating = true;
+ } else if (item.equals(getString(R.string.webservice))) {
+ mInputView.setText(getString(R.string.webservice_xquery));
+ } else if (item.equals(getString(R.string.android_location))) {
+ mInputView.setText(getString(R.string.android_location_xquery));
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tim...@us...> - 2011-05-31 08:53:05
|
Revision: 4375
http://mxquery.svn.sourceforge.net/mxquery/?rev=4375&view=rev
Author: timchurch
Date: 2011-05-31 08:52:59 +0000 (Tue, 31 May 2011)
Log Message:
-----------
Added function to retrieve Android location
Modified Paths:
--------------
trunk/MXQuery/android/src/ch/ethz/mxquery/android/MXQuery.java
Modified: trunk/MXQuery/android/src/ch/ethz/mxquery/android/MXQuery.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/android/MXQuery.java 2011-05-31 00:30:44 UTC (rev 4374)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/android/MXQuery.java 2011-05-31 08:52:59 UTC (rev 4375)
@@ -7,6 +7,8 @@
import android.app.Activity;
import android.content.Context;
+import android.location.Location;
+import android.location.LocationManager;
import android.widget.Button;
import android.widget.TextView;
@@ -56,4 +58,30 @@
return (TextView) act.findViewById(id);
}
+ public static Location getLocation() {
+ Location lastKnownLocation = null;
+ LocationManager locationManager = (LocationManager) act.getSystemService(Context.LOCATION_SERVICE);
+
+ // First try for cached GPS location data
+ if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
+ lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+ if(lastKnownLocation != null) {
+ return lastKnownLocation;
+ }
+ }
+
+ // Then try cached network location data
+ if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
+ lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
+ if(lastKnownLocation != null) {
+ return lastKnownLocation;
+ }
+ }
+
+ // No cached location found. Use ETH as default location for demo...
+ Location defaultLocation = new Location("default");
+ defaultLocation.setLatitude(47.37642);
+ defaultLocation.setLongitude(8.54799);
+ return defaultLocation;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-05-31 00:30:51
|
Revision: 4374
http://mxquery.svn.sourceforge.net/mxquery/?rev=4374&view=rev
Author: etterth
Date: 2011-05-31 00:30:44 +0000 (Tue, 31 May 2011)
Log Message:
-----------
- Basic (incomplete) API for calling an XQIB function from JS added
Modified Paths:
--------------
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/MXQueryJS.java
Added Paths:
-----------
trunk/MXQuery/xqib_samples/jsapi1.html
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/JsApi.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/JavaScriptArrayIterator.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/JsToMxQuery.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/MxQueryToJs.java
Removed Paths:
-------------
trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleElementIterator.java
Added: trunk/MXQuery/xqib_samples/jsapi1.html
===================================================================
--- trunk/MXQuery/xqib_samples/jsapi1.html (rev 0)
+++ trunk/MXQuery/xqib_samples/jsapi1.html 2011-05-31 00:30:44 UTC (rev 4374)
@@ -0,0 +1,34 @@
+<!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" >
+ module namespace m = "http://www.XQIB.org/module";
+
+ declare function m:generateDiv($node as node()+) {
+ for $x in $node/text()
+ return
+ <div>{concat('div generated by XQIB with "',$x,'" which was passed from JS')}</div>
+ };
+ </script>
+ <script type="text/javascript" >
+ handle = function () {
+ var output = xqib.call('http://www.XQIB.org/module','generateDiv',document.getElementsByTagName('h1'))
+ for (i=0;i<output.length;i++){
+ document.getElementById('output').appendChild(output[i]);
+ }
+ };
+ </script>
+ </head>
+ <body>
+ <a href="index.html"><< Index</a>
+ <h1>Some Text</h1>
+ <h1>Some more text</h1>
+ <div><a href="ModuleImport_new.html">Page</a> | <a href="ModuleImport_new_source.html">Source</a></div>
+ <input type='button' value='Test calling XQIB' onclick='handle()' />
+<div id='output' />
+ </body>
+</html>
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-05-30 13:49:59 UTC (rev 4373)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -12,7 +12,7 @@
import ch.ethz.mxquery.functions.Function;
import ch.ethz.mxquery.iterators.browser.EventIterator;
import ch.ethz.mxquery.iterators.browser.ListBasedIterator;
-import ch.ethz.mxquery.iterators.browser.SingleElementIterator;
+import ch.ethz.mxquery.iterators.browser.SingleNodeIterator;
import ch.ethz.mxquery.model.Iterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.query.PreparedStatement;
@@ -145,7 +145,7 @@
test.node = test.node.getParentElement();
}
for (QnameAndArity functionname : handlers.get(test)) {
- SingleElementIterator nodeiter = new SingleElementIterator(
+ SingleNodeIterator nodeiter = new SingleNodeIterator(
test.node);
try {
log.log(LogLevel.FINER, "Calling eventcallback " + functionname.qname.toString());
@@ -219,7 +219,6 @@
// }
NodeStoreSet.resetStoreSet();
-
// prep = null;
// ip = null;
// function = null;
Added: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/JsApi.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/JsApi.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/JsApi.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -0,0 +1,112 @@
+package ch.ethz.mxqjs.client;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.QName;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.functions.Function;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.query.PreparedStatement;
+import ch.ethz.mxquery.query.impl.PreparedStatementImpl;
+import ch.ethz.mxquery.util.LogLevel;
+import ch.ethz.mxquery.util.Logger;
+import ch.ethz.mxquery.util.browser.JsToMxQuery;
+import ch.ethz.mxquery.util.browser.MxQueryToJs;
+import ch.ethz.mxquery.xdmio.XDMSerializer;
+import ch.ethz.mxquery.xdmio.XDMSerializerSettings;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+
+public class JsApi {
+ public static Logger lg = Logger.getLogger(JsApi.class.getName());
+ //this does not work
+// static {
+// register();
+// }
+ public static native void register()/*-{
+ if ($wnd.xqib == undefined){
+ $wnd.xqib = {};
+ }
+ $wnd.xqib.__executeWithArray = @ch.ethz.mxqjs.client.JsApi::n_ExecuteFunction(Lcom/google/gwt/core/client/JsArray;);
+ $wnd.eval ('xqib.call = function () {return xqib.__executeWithArray(arguments);}');
+ }-*/;
+
+ public static JsArray<JavaScriptObject> call(JsArray<JavaScriptObject> args){
+ int arity = args.length() -2;
+ if (arity < 0){
+ lg.log(LogLevel.WARNING, "You need at least a namespace and a function name to call an XQuery function");
+ return null;
+ }
+
+ String nsUri = asString(args,0);
+ String local = asString(args,1);
+ QName qname = new QName(nsUri, null, local);
+ QnameAndArity functionname;
+ try {
+ Context context = Environment.createContext().getModule(nsUri);
+ if (context == null) {
+ context = Environment.createContext();
+ }
+ functionname = new QnameAndArity(qname, arity, context);
+
+
+
+ XDMIterator[] subiterators = new XDMIterator[arity];
+ for (int i=0;i<arity;i++){
+ subiterators[i] = JsToMxQuery.getIterator(args.get(i + 2));
+ }
+
+
+ //XDMIterator result = Environment.invokeModule(nameAndArity, subiterators);
+ Environment.preProcessDocument();
+ // try {
+ if (subiterators == null) {
+ subiterators = new XDMIterator[0];
+ }
+ for (XDMIterator iter : subiterators) {
+ iter.staticInit();
+ }
+ Function function = functionname.context.getFunction(functionname.qname, arity);
+ //set currenttime
+ functionname.context.setCurrentTime(null);
+ XDMIterator func = function.getFunctionImplementation(new Context(functionname.context));
+ func.setSubIters(subiterators);
+ // func.setContext(getContext(), true);
+
+ PreparedStatement prep = new PreparedStatementImpl(
+ context, func,
+ Environment.getCompilerOptions(), null);
+ // NodeStore nodestore = new NodeStore(Document.get());
+ // prep.addExternalResource(Context.CONTEXT_ITEM,
+ // nodestore.getIterator(Environment.getContext()));
+
+ XDMIterator result = prep.evaluate();
+ result.staticInit();
+ // result.setContext(getContext(), true);
+ // TODO is this right
+ // ((UserdefFuncCall)result).getFunction().setContext(getContext(),
+ // true);
+
+ final JsArray<JavaScriptObject> ret = MxQueryToJs.getAsJavaScriptObject(result);
+ prep.applyPUL();
+ Environment.postProcessDocument();
+
+ lg.log(LogLevel.FINER, "got " + args.length() + " arguments");
+ return ret;
+ } catch (MXQueryException e) {
+ Environment.displayErrorMessage(null, null, e, true);
+ return null;
+ }
+
+ }
+
+ private static native JsArray<JavaScriptObject> n_ExecuteFunction(JsArray<JavaScriptObject> arguments)/*-{
+
+ return @ch.ethz.mxqjs.client.JsApi::call(Lcom/google/gwt/core/client/JsArray;)(arguments);
+ }-*/;
+
+ private static native String asString(JsArray<JavaScriptObject> arr, int i)/*-{
+ return arr[i];
+ }-*/;
+
+}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/MXQueryJS.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/MXQueryJS.java 2011-05-30 13:49:59 UTC (rev 4373)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/MXQueryJS.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -62,6 +62,7 @@
* This is the entry point method.
*/
public void onModuleLoad() {
+ JsApi.register();
NodeList<Element> scripts = Document.get().getElementsByTagName(
"script");
int scriptlen = scripts.getLength();
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/JavaScriptArrayIterator.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/JavaScriptArrayIterator.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/JavaScriptArrayIterator.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -0,0 +1,59 @@
+package ch.ethz.mxquery.iterators.browser;
+
+import java.util.Vector;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.model.CurrentBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.browser.JsToMxQuery;
+
+public class JavaScriptArrayIterator extends CurrentBasedIterator {
+
+ JsArray<JavaScriptObject> arr;
+ int index;
+
+ public JavaScriptArrayIterator(JsArray<JavaScriptObject> arr) {
+ this.arr = arr;
+ }
+
+ @Override
+ public TokenInterface next() throws MXQueryException {
+ if (current == null) {
+ if (arr.length() == 0)
+ return Token.END_SEQUENCE_TOKEN;
+ current = JsToMxQuery.getIterator(arr.get(0));
+ }
+ TokenInterface ret = current.next();
+ if (ret.getEventType() == Type.END_SEQUENCE) {
+ index++;
+ if (index >= arr.length())
+ return Token.END_SEQUENCE_TOKEN;
+ current = JsToMxQuery.getIterator(arr.get(index));
+ ret = current.next();
+ }
+ return ret;
+ }
+
+ @Override
+ protected void resetImpl() throws MXQueryException {
+ super.resetImpl();
+ index = 0;
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ JavaScriptArrayIterator iter = new JavaScriptArrayIterator(arr);
+ iter.setContext(context, true);
+ iter.setSubIters(subIters);
+ return iter;
+ }
+
+}
Deleted: trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleElementIterator.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleElementIterator.java 2011-05-30 13:49:59 UTC (rev 4373)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleElementIterator.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -1,65 +0,0 @@
-package ch.ethz.mxquery.iterators.browser;
-
-
-
-import java.util.Vector;
-
-import ch.ethz.mxquery.contextConfig.Context;
-import ch.ethz.mxquery.datamodel.types.Type;
-import ch.ethz.mxquery.datamodel.xdm.Token;
-import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
-import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.model.Window;
-import ch.ethz.mxquery.model.XDMIterator;
-import ch.ethz.mxquery.update.store.domImpl.NodeToken;
-import ch.ethz.mxquery.util.browser.dom.Node;
-
-
-public class SingleElementIterator extends NodeStoreIterator {
- boolean finished = false;
- public SingleElementIterator(Node store) {
- super(store);
- }
-
- @Override
- public TokenInterface next() throws MXQueryException {
- if (finished)
- return Token.END_SEQUENCE_TOKEN;
- TokenInterface tok = super.next();
-
- if (tok.getEventType() == Type.END_TAG){
- NodeToken nt = (NodeToken) tok;
- finished = nt.getNode() == this.store;
- }
- return tok;
- }
-
- @Override
- protected void resetImpl() throws MXQueryException {
- super.resetImpl();
- finished = false;
- }
-
- @Override
- public Window getNewWindow(int startPosition, int endPosition)
- throws MXQueryException {
- if (startPosition == 1
- && endPosition == Window.END_OF_STREAM_POSITION) {
- Window ret = new SingleElementIterator(store);
- ret.setContext(context,false);
- return ret;
- } else {
- throw new MXQueryException("dont use window with integer parameters", "", null);
- }
- }
-
- @Override
- protected XDMIterator copy(Context context, XDMIterator[] subIters,
- Vector nestedPredCtxStack) throws MXQueryException {
- SingleElementIterator ret = new SingleElementIterator(this.store);
- ret.setContext(context, true);
- ret.setContext(context, true);
- ret.setSubIters(subIters);
- return ret;
- }
-}
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -0,0 +1,72 @@
+package ch.ethz.mxquery.iterators.browser;
+
+
+
+import java.util.Vector;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.model.Window;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.update.store.domImpl.NodeToken;
+import ch.ethz.mxquery.util.browser.dom.Node;
+
+
+public class SingleNodeIterator extends NodeStoreIterator {
+ boolean finished = false;
+ boolean multipletokens;
+ public SingleNodeIterator(Node store) {
+ super(store);
+ short nt = store.getNodeType();
+ multipletokens = nt == Node.ELEMENT_NODE
+ || nt == Node.DOCUMENT_NODE;
+ }
+
+ @Override
+ public TokenInterface next() throws MXQueryException {
+ if (finished)
+ return Token.END_SEQUENCE_TOKEN;
+
+ if (!multipletokens && called >= 1)
+ return Token.END_SEQUENCE_TOKEN;
+ TokenInterface tok = super.next();
+
+ if (tok.getEventType() == Type.END_TAG){
+ NodeToken nt = (NodeToken) tok;
+ finished = nt.getNode() == this.store;
+ }
+ return tok;
+ }
+
+ @Override
+ protected void resetImpl() throws MXQueryException {
+ super.resetImpl();
+ finished = false;
+
+ }
+
+ @Override
+ public Window getNewWindow(int startPosition, int endPosition)
+ throws MXQueryException {
+ if (startPosition == 1
+ && endPosition == Window.END_OF_STREAM_POSITION) {
+ Window ret = new SingleNodeIterator(store);
+ ret.setContext(context,false);
+ return ret;
+ } else {
+ throw new MXQueryException("dont use window with integer parameters", "", null);
+ }
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ SingleNodeIterator ret = new SingleNodeIterator(this.store);
+ ret.setContext(context, true);
+ ret.setSubIters(subIters);
+ return ret;
+ }
+}
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/JsToMxQuery.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/JsToMxQuery.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/JsToMxQuery.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -0,0 +1,129 @@
+package ch.ethz.mxquery.util.browser;
+
+import ch.ethz.mxquery.datamodel.MXQueryDouble;
+import ch.ethz.mxquery.datamodel.xdm.BooleanToken;
+import ch.ethz.mxquery.datamodel.xdm.DoubleToken;
+import ch.ethz.mxquery.datamodel.xdm.TextToken;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.iterators.browser.JavaScriptArrayIterator;
+import ch.ethz.mxquery.iterators.browser.SingleNodeIterator;
+import ch.ethz.mxquery.model.EmptySequenceIterator;
+import ch.ethz.mxquery.model.Iterator;
+import ch.ethz.mxquery.model.TokenSequenceIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.browser.dom.Node;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+
+public class JsToMxQuery {
+
+ public static XDMIterator getIterator(JavaScriptObject obj) {
+ TokenInterface tok = convertSingleValue(obj);
+ if (tok != null) {
+ return new TokenSequenceIterator(new TokenInterface[] { tok });
+ }
+ XDMIterator iter = convertArray(obj);
+ if (iter != null) {
+ return iter;
+ }
+ iter = convertNode(obj);
+ if (iter != null) {
+ return iter;
+ }
+ return new EmptySequenceIterator(null, null);
+ }
+
+ private static XDMIterator convertNode(JavaScriptObject obj) {
+ if (!isNode(obj))
+ return null;
+ return new SingleNodeIterator((Node) obj);
+ }
+
+ @SuppressWarnings("unchecked")
+ private static XDMIterator convertArray(JavaScriptObject obj) {
+ if (!isNonEmptyArrayLike(obj))
+ return null;
+ return new JavaScriptArrayIterator((JsArray<JavaScriptObject>) obj);
+ }
+
+ private static TokenInterface convertSingleValue(JavaScriptObject obj) {
+ if (isBoolean(obj)) {
+ TokenInterface valuetoken;
+ if (booleanValue(obj)) {
+ valuetoken = BooleanToken.TRUE_TOKEN;
+ } else {
+ valuetoken = BooleanToken.FALSE_TOKEN;
+ }
+ return valuetoken;
+ }
+
+ if (isNumber(obj)) {
+ TokenInterface valuetoken = new DoubleToken(null,
+ new MXQueryDouble(numberValue(obj)));
+ return valuetoken;
+ }
+ if (isString(obj)) {
+ TokenInterface valuetoken = new TextToken(null, stringValue(obj));
+ return valuetoken;
+ }
+ return null;
+ }
+
+ private static boolean isBoolean(JavaScriptObject obj) {
+ return typeOf(obj).equals("boolean");
+ };
+
+ private static native boolean booleanValue(JavaScriptObject obj) /*-{
+ return obj == true;
+ }-*/;
+
+ private static native double numberValue(JavaScriptObject obj) /*-{
+ return obj;
+ }-*/;
+
+ private static native boolean hasNodeType(JavaScriptObject obj) /*-{
+ return 'nodeType' in obj;
+ }-*/;
+
+ private static boolean isNode(JavaScriptObject obj) {
+ if (!isObject(obj))
+ return false;
+ return hasNodeType(obj);
+ };
+
+ private static boolean isNumber(JavaScriptObject obj) {
+ return typeOf(obj).equals("number");
+ };
+
+ private static boolean isString(JavaScriptObject obj) {
+ return typeOf(obj).equals("string");
+ };
+
+ private static native String stringValue(JavaScriptObject obj) /*-{
+ return obj;
+ }-*/;
+
+ private static boolean isObject(JavaScriptObject obj) {
+ return typeOf(obj).equals("object");
+ };
+
+ private static native boolean isNonEmptyArrayLike(JavaScriptObject obj) /*-{
+ try { // don't bother with `typeof` - just access `length` and `catch`
+ return obj.length > 0 && '0' in Object(obj);
+ } catch (e) {
+ return false;
+ }
+ }-*/;
+
+ private static native String typeOf(JavaScriptObject obj) /*-{
+ return typeof obj;
+ }-*/;
+
+ private static native Node node(JavaScriptObject obj) /*-{
+ if (obj != null && obj.nodeType)
+ return obj;
+ return null;
+ }-*/;
+
+}
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/MxQueryToJs.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/MxQueryToJs.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/MxQueryToJs.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -0,0 +1,150 @@
+package ch.ethz.mxquery.util.browser;
+
+import java.util.ArrayList;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.Identifier;
+import ch.ethz.mxquery.datamodel.types.Type;
+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.TypeException;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.update.store.domImpl.NodeToken;
+import ch.ethz.mxquery.util.browser.dom.Document;
+import ch.ethz.mxquery.util.browser.dom.Element;
+import ch.ethz.mxquery.util.browser.dom.Node;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+
+public class MxQueryToJs {
+ public static JsArray<JavaScriptObject> getAsJavaScriptObject(
+ XDMIterator iter) {
+ @SuppressWarnings("unchecked")
+ JsArray<JavaScriptObject> ret = (JsArray<JavaScriptObject>) JsArray
+ .createArray();
+
+ try {
+ TokenInterface tok = iter.next();
+ for (; tok.getEventType() != Type.END_SEQUENCE; tok = iter.next()) {
+ if (Type.isNode(tok.getEventType())) {
+ ret.push(consumeAndProduceNode(tok, iter));
+ } else {
+ ret.push(convertToken(tok));
+ }
+ }
+ } catch (MXQueryException e) {
+ // TODO: handle exception
+ }
+ return ret;
+ }
+
+ /**
+ *
+ * @param tok
+ * @param iter
+ * @return a node that is equal to the input (if it already is a
+ * materialized node, the node itself will be given
+ * @throws MXQueryException
+ */
+ private static JavaScriptObject consumeAndProduceNode(TokenInterface tok,
+ XDMIterator iter) throws MXQueryException {
+ final Document theDocument = Document
+ .createFromGwtNode(com.google.gwt.dom.client.Document.get());
+ int type = tok.getEventType();
+ if (Type.isStartType(type)) {// we have to consume
+ // ArrayList<TokenInterface> tokens = new
+ // ArrayList<TokenInterface>();
+ // tokens.add(tok);
+ Identifier startid = tok.getNodeId();
+ if (tok instanceof NodeToken) {
+ NodeToken nt = (NodeToken) tok;
+ Node node = nt.getNode();
+
+ int level = 1;
+ do {
+ tok = iter.next();
+
+ type = Type.getEventTypeSubstituted(tok.getEventType(),
+ Context.getDictionary());
+
+ switch (type) {
+ case Type.END_SEQUENCE:
+ break;
+ case Type.START_TAG:
+ level++;
+ break;
+ case Type.END_TAG:
+ level--;
+ break;
+ default:
+
+ }
+ } while (level != 0 && type != Type.END_SEQUENCE);
+ return node;
+ }
+
+ // we need to create a new node
+ Element ret = theDocument.createElementNS(tok.getNS(),
+ tok.getLocal());
+ tok = iter.next();
+ while (Type.isAttribute(tok.getEventType())) {
+ ret.setAttributeNS(tok.getNS(), tok.getLocal(),
+ tok.getValueAsString());
+ tok = iter.next();
+ }
+ while (!Type.isEndType(tok.getEventType())) {
+ if (Type.isTextNode(tok.getEventType())) {
+ ret.appendChild(Node.createFromGwtNode(theDocument
+ .getAsGwtDocument().createTextNode(tok.getText())));
+ } else if (Type.isStartType(tok.getEventType())) {
+ ret.appendChild((Node) consumeAndProduceNode(tok, iter));
+ } else {
+ // TODO: does this happen?
+ }
+ tok = iter.next();
+
+ }
+
+ // tok must be END_TAG
+ return ret;
+
+ } else {
+ if (tok instanceof NodeToken) {
+ NodeToken nt = (NodeToken) tok;
+ return nt.getNode();
+ }
+ return createJavaScriptString(tok.getValueAsString());
+ }
+
+ }
+
+ private static JavaScriptObject convertToken(TokenInterface tok) {
+ int type = tok.getTypeAnnotation();
+ if (type == Type.BOOLEAN) {
+ return createJavaScriptBoolean(tok.getBoolean());
+ } else if (Type.isNumericPrimitiveType(type)) {
+ return createJavaScriptNumber(tok.getDouble().getValue());
+ }
+ // TODO more distinctions
+ else {
+ return createJavaScriptString(tok.getValueAsString());
+ }
+ }
+
+ private static native JavaScriptObject createJavaScriptBoolean(
+ boolean boolean1) /*-{
+ return boolean1;
+ }-*/;
+
+ private static native JavaScriptObject createJavaScriptNumber(double d) /*-{
+ return d;
+ }-*/;
+
+ private static native JavaScriptObject createJavaScriptString(String str) /*-{
+ return str;
+ }-*/;
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tim...@us...> - 2011-05-30 13:50:10
|
Revision: 4373
http://mxquery.svn.sourceforge.net/mxquery/?rev=4373&view=rev
Author: timchurch
Date: 2011-05-30 13:49:59 +0000 (Mon, 30 May 2011)
Log Message:
-----------
Code cleanup - removed old/unused code for clarity
Modified Paths:
--------------
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java 2011-05-30 13:37:38 UTC (rev 4372)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java 2011-05-30 13:49:59 UTC (rev 4373)
@@ -46,7 +46,6 @@
private MapView mapView;
private List<Overlay> mapOverlays;
- //private MyLocationOverlay myLocationOverlay;
private UserLocationOverlay userLocationOverlay;
private PizzaOverlay pizzaOverlay;
private Drawable pizzaDrawable;
@@ -55,7 +54,6 @@
private static final String LOG_TAG = "MXQuery.MyMap";
private static final String GOOGLE_PLACES_API_KEY = "AIzaSyAtNn71gfANF9KWPp0W_pEd1LHaxIux92g";
private static final String GOOGLE_PLACES_SEARCH_URL = "https://maps.googleapis.com/maps/api/place/search/%s?location=%.5f,%.5f&radius=%d&types=%s&name=%s&sensor=false&key=%s";
- private static final String GOOGLE_PLACES_SEARCH_URL_BASE = "maps.googleapis.com/maps/api/place/search/json";
private static final String OUTPUT_FORMAT = "json";
private static final String SEARCH_KEYWORDS = "pizza";
private static final String SEARCH_TYPES = "food|restaurant|establishment";
@@ -73,29 +71,6 @@
this.initHttp();
-// myLocationOverlay = new MyLocationOverlay(MyMap.this, mapView);
-// myLocationOverlay.enableMyLocation();
-// myLocationOverlay.runOnFirstFix(new Runnable() {
-// public void run() {
-// Log.i(LOG_TAG, "Found location");
-// myLocationOverlay.disableMyLocation();
-// mapView.getController().animateTo(myLocationOverlay.getMyLocation());
-// }
-// });
-
-
-
- //test a static overlay item
-// pizzaDrawable = this.getResources().getDrawable(R.drawable.pizza);
-// pizzaOverlay = new PizzaOverlay(pizzaDrawable);
-// GeoPoint point = new GeoPoint(47374710, 8529110);
-// OverlayItem overlayitem = new OverlayItem(point, "Don Leone", "");
-// pizzaOverlay.addOverlay(overlayitem);
-// GeoPoint point2 = new GeoPoint(47378510, 8547970);
-// OverlayItem overlayitem2 = new OverlayItem(point2, "Domino's Pizza", "");
-// pizzaOverlay.addOverlay(overlayitem2);
-
-
//Load last known user location
Location userLocation = getCachedLocation();
GeoPoint userLocationGeoPoint = new GeoPoint((int) (userLocation.getLatitude()*1e6), (int) (userLocation.getLongitude()*1e6));
@@ -113,9 +88,6 @@
// add overlays to mapView list of overlays
mapOverlays.add(pizzaOverlay);
mapOverlays.add(userLocationOverlay);
- //mapOverlays.add(myLocationOverlay);
-
-
}
@Override
@@ -243,78 +215,4 @@
return buf.toString();
}
-
-
-
-// Location getLocation(Flickr.Photo photo) {
-// final Uri.Builder uri = buildGetMethod(API_PEOPLE_GET_LOCATION);
-// uri.appendQueryParameter(PARAM_PHOTO_ID, photo.mId);
-//
-// final HttpGet get = new HttpGet(uri.build().toString());
-// final Location location = new Location(0.0f, 0.0f);
-//
-// try {
-// executeRequest(get, new ResponseHandler() {
-// public void handleResponse(InputStream in) throws IOException {
-// parseResponse(in, new ResponseParser() {
-// public void parseResponse(XmlPullParser parser)
-// throws XmlPullParserException, IOException {
-// parsePhotoLocation(parser, location);
-// }
-// });
-// }
-// });
-// return location;
-// } catch (IOException e) {
-// android.util.Log.e(LOG_TAG, "Could not find location for photo: " + photo);
-// }
-//
-// return null;
-// }
-//
-// void downloadPhoto(Photo photo, PhotoSize size, OutputStream destination) throws IOException {
-// final BufferedOutputStream out = new BufferedOutputStream(destination, IO_BUFFER_SIZE);
-// final String url = photo.getUrl(size);
-// final HttpGet get = new HttpGet(url);
-//
-// HttpEntity entity = null;
-// try {
-// final HttpResponse response = mClient.execute(get);
-// if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
-// entity = response.getEntity();
-// entity.writeTo(out);
-// out.flush();
-// }
-// } finally {
-// if (entity != null) {
-// entity.consumeContent();
-// }
-// }
-// }
-//
-// private void executeRequest(HttpGet get, ResponseHandler handler) throws IOException {
-// HttpEntity entity = null;
-// HttpHost host = new HttpHost(API_REST_HOST, 80, "http");
-// try {
-// final HttpResponse response = mClient.execute(host, get);
-// if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
-// entity = response.getEntity();
-// final InputStream in = entity.getContent();
-// handler.handleResponse(in);
-// }
-// } finally {
-// if (entity != null) {
-// entity.consumeContent();
-// }
-// }
-// }
-//
-// private static Uri.Builder buildGetMethod(String method) {
-// final Uri.Builder builder = new Uri.Builder();
-// builder.path(API_REST_URL).appendQueryParameter(PARAM_API_KEY, API_KEY);
-// builder.appendQueryParameter(PARAM_METHOD, method);
-// return builder;
-// }
-
-
}
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java 2011-05-30 13:37:38 UTC (rev 4372)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java 2011-05-30 13:49:59 UTC (rev 4373)
@@ -22,9 +22,6 @@
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.database.Cursor;
-import android.location.Location;
-import android.location.LocationListener;
-import android.location.LocationManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
@@ -59,7 +56,6 @@
protected Spinner mSpinner;
protected EditText mInputView;
protected TextView mResultView;
- // private XQueryAsyncTask mTask;
protected MXQueryService mService;
protected boolean mIsBound = false;
protected boolean mUpdating = false;
@@ -70,7 +66,6 @@
public static final String STATE_CHANGE_SETTINGS = "STATE_CHANGE_SETTINGS";
public static final int QUERY_RUNNING_DIALOG = 1;
public static final int GENERATING_CONTACTS_XML_DIALOG = 2;
- public static final int LOCATION_DIALOG = 3;
public static final String UNDEFINED_LABEL = "Undefined";
private static final String LOG_TAG = "MXQuery.Start";
@@ -87,11 +82,6 @@
mDialog.setMessage("Generating Contacts XML...");
mDialog.setCancelable(true);
return mDialog;
- case LOCATION_DIALOG:
- mDialog = new ProgressDialog(mActivity);
- mDialog.setMessage("Finding Location...");
- mDialog.setCancelable(true);
- return mDialog;
default:
return null;
}
@@ -101,8 +91,6 @@
switch(id) {
case QUERY_RUNNING_DIALOG:
return;
- case LOCATION_DIALOG:
- return;
case GENERATING_CONTACTS_XML_DIALOG:
int numContacts = getContactsCount();
mDialog.setMax(numContacts);
@@ -110,35 +98,6 @@
}
}
- /*
- * protected class XQueryAsyncTask extends AsyncTask<String, Integer,
- * String> {
- *
- * @Override protected void onPreExecute() { //clear results
- * mResultView.setText(""); mActivity.showDialog(1); }
- *
- * @Override protected void onPostExecute(String result) {
- * mResultView.setText(result); mActivity.removeDialog(1); //Note: don't use
- * dismissDialog or progress spinner will not spin on subsequent runs }
- *
- * protected String doInBackground(String... query) { String output = new
- * String(); try { output = runQuery(query[0]); } catch (MXQueryException e)
- * { e.printStackTrace(); output = "Error: " + e.toString(); } return
- * output; }
- *
- * private String runQuery(String query) throws MXQueryException {
- * StringWriter result = new StringWriter();
- *
- * try { XQDataSource xqjd = new MXQueryXQDataSource(); XQConnection xqjc =
- * xqjd.getConnection(); XQExpression xqje = xqjc.createExpression();
- * XQSequence xqjs = xqje.executeQuery(query);
- *
- * xqjs.writeSequence(result, null); xqjc.close(); } catch (XQException xqe)
- * { xqe.printStackTrace(); }
- *
- * return result.toString(); } }
- */
-
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -225,11 +184,6 @@
mButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
- // run query with ASyncTask
- // new
- // XQueryAsyncTask().execute(mInputView.getText().toString());
-
- // run query with Service
runQueryOnService(mInputView.getText().toString());
}
});
@@ -429,8 +383,6 @@
new GenerateContactsXMLAsyncTask().execute();
return true;
case R.id.location:
- //new ShowLocationAsyncTask().execute();
- //item.setIntent(new Intent(this, MyMap.class));
Intent i = new Intent(this, MyMap.class);
startActivity(i);
return true;
@@ -439,102 +391,12 @@
}
}
- protected class ShowLocationAsyncTask extends AsyncTask<Void, Void, Location> {
- Location mLocation = null;
- LocationManager locationManager = null;
-
- @Override
- protected void onPreExecute() {
- mActivity.showDialog(LOCATION_DIALOG);
-
- // Start listeners to find location
- locationManager = (LocationManager) mActivity.getSystemService(Context.LOCATION_SERVICE);
- if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
- Log.d(LOG_TAG, "GPS_PROVIDER is enabled");
- locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
- }
- if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
- Log.d(LOG_TAG, "NETWORK_PROVIDER is enabled");
- locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
- }
- }
-
- @Override
- protected void onPostExecute(Location l) {
- mActivity.removeDialog(LOCATION_DIALOG);
- String locationString = "Unable to determine location";
- if(l != null) {
- locationString = "(" + l.getLatitude() + ", " + l.getLongitude() + ")";
- }
- mResultView.setText(locationString);
- locationManager.removeUpdates(locationListener);
- }
-
- @Override
- protected void onCancelled() {
- if(mDialog.isShowing())
- mActivity.removeDialog(LOCATION_DIALOG);
- }
-
- @Override
- protected Location doInBackground(Void... v) {
- Location lastKnownLocation = null;
-
- // First try for cached GPS location data
- if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
- lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
- if(lastKnownLocation != null) {
- return lastKnownLocation;
- }
- }
-
- // Then try cached network location data
- if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
- lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
- if(lastKnownLocation != null) {
- return lastKnownLocation;
- }
- }
-
- // Wait for updated location
- Location location = null;
- try {
- location = getLocation();
- } catch (InterruptedException e) {
- Log.e(LOG_TAG, e.getMessage(), e);
- }
-
- return location;
- }
-
- protected synchronized Location getLocation() throws InterruptedException {
- if(mLocation == null) {
- this.wait();
- }
- return mLocation;
- }
-
- protected synchronized void setLocation(Location location) {
- mLocation = location;
- notify();
- }
-
- LocationListener locationListener = new LocationListener() {
- public void onLocationChanged(Location location) {
- setLocation(location);
- }
-
- public void onStatusChanged(String provider, int status, Bundle extras) {}
-
- public void onProviderEnabled(String provider) {}
-
- public void onProviderDisabled(String provider) {}
- };
-
- }
+
+
+
/**
* Serializes all Android contacts to an XML file
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tim...@us...> - 2011-05-30 13:37:45
|
Revision: 4372
http://mxquery.svn.sourceforge.net/mxquery/?rev=4372&view=rev
Author: timchurch
Date: 2011-05-30 13:37:38 +0000 (Mon, 30 May 2011)
Log Message:
-----------
Added location mashup demo implemented only in normal Android/java (for now)
Modified Paths:
--------------
trunk/MXQuery_Android_App/AndroidManifest.xml
trunk/MXQuery_Android_App/default.properties
trunk/MXQuery_Android_App/res/menu/menu.xml
trunk/MXQuery_Android_App/res/values/strings.xml
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java
Added Paths:
-----------
trunk/MXQuery_Android_App/res/drawable-hdpi/ic_menu_location.png
trunk/MXQuery_Android_App/res/drawable-hdpi/marker.png
trunk/MXQuery_Android_App/res/drawable-hdpi/pizza.png
trunk/MXQuery_Android_App/res/drawable-ldpi/ic_menu_location.png
trunk/MXQuery_Android_App/res/drawable-ldpi/marker.png
trunk/MXQuery_Android_App/res/drawable-ldpi/pizza.png
trunk/MXQuery_Android_App/res/drawable-mdpi/ic_menu_location.png
trunk/MXQuery_Android_App/res/drawable-mdpi/marker.png
trunk/MXQuery_Android_App/res/drawable-mdpi/pizza.png
trunk/MXQuery_Android_App/res/layout/map.xml
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/PizzaOverlay.java
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Place.java
trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/UserLocationOverlay.java
Modified: trunk/MXQuery_Android_App/AndroidManifest.xml
===================================================================
--- trunk/MXQuery_Android_App/AndroidManifest.xml 2011-05-27 13:42:20 UTC (rev 4371)
+++ trunk/MXQuery_Android_App/AndroidManifest.xml 2011-05-30 13:37:38 UTC (rev 4372)
@@ -5,14 +5,19 @@
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"></uses-sdk>
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
- <application android:icon="@drawable/xquery_icon" android:label="@string/app_name" android:permission="android.permission.READ_CONTACTS" android:debuggable="true">
+ <application android:icon="@drawable/xquery_icon" android:label="@string/app_name" android:debuggable="true">
+ <uses-library android:name="com.google.android.maps" />
<activity android:name="Start">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
+
+ <activity android:name="MyMap"></activity>
<service android:name="MXQueryService"/>
</application>
Modified: trunk/MXQuery_Android_App/default.properties
===================================================================
--- trunk/MXQuery_Android_App/default.properties 2011-05-27 13:42:20 UTC (rev 4371)
+++ trunk/MXQuery_Android_App/default.properties 2011-05-30 13:37:38 UTC (rev 4372)
@@ -8,4 +8,4 @@
# project structure.
# Project target.
-target=android-8
+target=Google Inc.:Google APIs:8
Added: trunk/MXQuery_Android_App/res/drawable-hdpi/ic_menu_location.png
===================================================================
(Binary files differ)
Property changes on: trunk/MXQuery_Android_App/res/drawable-hdpi/ic_menu_location.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/MXQuery_Android_App/res/drawable-hdpi/marker.png
===================================================================
(Binary files differ)
Property changes on: trunk/MXQuery_Android_App/res/drawable-hdpi/marker.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/MXQuery_Android_App/res/drawable-hdpi/pizza.png
===================================================================
(Binary files differ)
Property changes on: trunk/MXQuery_Android_App/res/drawable-hdpi/pizza.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/MXQuery_Android_App/res/drawable-ldpi/ic_menu_location.png
===================================================================
(Binary files differ)
Property changes on: trunk/MXQuery_Android_App/res/drawable-ldpi/ic_menu_location.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/MXQuery_Android_App/res/drawable-ldpi/marker.png
===================================================================
(Binary files differ)
Property changes on: trunk/MXQuery_Android_App/res/drawable-ldpi/marker.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/MXQuery_Android_App/res/drawable-ldpi/pizza.png
===================================================================
(Binary files differ)
Property changes on: trunk/MXQuery_Android_App/res/drawable-ldpi/pizza.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/MXQuery_Android_App/res/drawable-mdpi/ic_menu_location.png
===================================================================
(Binary files differ)
Property changes on: trunk/MXQuery_Android_App/res/drawable-mdpi/ic_menu_location.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/MXQuery_Android_App/res/drawable-mdpi/marker.png
===================================================================
(Binary files differ)
Property changes on: trunk/MXQuery_Android_App/res/drawable-mdpi/marker.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/MXQuery_Android_App/res/drawable-mdpi/pizza.png
===================================================================
(Binary files differ)
Property changes on: trunk/MXQuery_Android_App/res/drawable-mdpi/pizza.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/MXQuery_Android_App/res/layout/map.xml
===================================================================
--- trunk/MXQuery_Android_App/res/layout/map.xml (rev 0)
+++ trunk/MXQuery_Android_App/res/layout/map.xml 2011-05-30 13:37:38 UTC (rev 4372)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<com.google.android.maps.MapView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/mapview"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:clickable="true"
+ android:apiKey="0UZG-wPw80641BcuDMz_RYS6__LEd1cM72xBpAg"
+/>
Modified: trunk/MXQuery_Android_App/res/menu/menu.xml
===================================================================
--- trunk/MXQuery_Android_App/res/menu/menu.xml 2011-05-27 13:42:20 UTC (rev 4371)
+++ trunk/MXQuery_Android_App/res/menu/menu.xml 2011-05-30 13:37:38 UTC (rev 4372)
@@ -3,4 +3,7 @@
<item android:id="@+id/generate_contacts_XML"
android:icon="@drawable/ic_menu_contacts"
android:title="@string/menu_generate_contacts_xml" />
+ <item android:id="@+id/location"
+ android:icon="@drawable/ic_menu_location"
+ android:title="@string/menu_location" />
</menu>
\ No newline at end of file
Modified: trunk/MXQuery_Android_App/res/values/strings.xml
===================================================================
--- trunk/MXQuery_Android_App/res/values/strings.xml 2011-05-27 13:42:20 UTC (rev 4371)
+++ trunk/MXQuery_Android_App/res/values/strings.xml 2011-05-30 13:37:38 UTC (rev 4372)
@@ -4,6 +4,7 @@
<!-- Menu Strings -->
<string name="menu_generate_contacts_xml">Generate Contacts XML</string>
+ <string name="menu_location">My Location</string>
<!-- End Menu Strings -->
<!-- UI Strings -->
Added: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java (rev 0)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/MyMap.java 2011-05-30 13:37:38 UTC (rev 4372)
@@ -0,0 +1,320 @@
+package ch.ethz.mxquery.android;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.location.Location;
+import android.location.LocationManager;
+import android.os.Bundle;
+import android.util.Log;
+import android.widget.Toast;
+
+import com.google.android.maps.GeoPoint;
+import com.google.android.maps.MapActivity;
+import com.google.android.maps.MapView;
+import com.google.android.maps.Overlay;
+import com.google.android.maps.OverlayItem;
+
+public class MyMap extends MapActivity {
+
+ private MapView mapView;
+ private List<Overlay> mapOverlays;
+ //private MyLocationOverlay myLocationOverlay;
+ private UserLocationOverlay userLocationOverlay;
+ private PizzaOverlay pizzaOverlay;
+ private Drawable pizzaDrawable;
+ private HttpClient mClient;
+
+ private static final String LOG_TAG = "MXQuery.MyMap";
+ private static final String GOOGLE_PLACES_API_KEY = "AIzaSyAtNn71gfANF9KWPp0W_pEd1LHaxIux92g";
+ private static final String GOOGLE_PLACES_SEARCH_URL = "https://maps.googleapis.com/maps/api/place/search/%s?location=%.5f,%.5f&radius=%d&types=%s&name=%s&sensor=false&key=%s";
+ private static final String GOOGLE_PLACES_SEARCH_URL_BASE = "maps.googleapis.com/maps/api/place/search/json";
+ private static final String OUTPUT_FORMAT = "json";
+ private static final String SEARCH_KEYWORDS = "pizza";
+ private static final String SEARCH_TYPES = "food|restaurant|establishment";
+ private static final Integer SEARCH_RADIUS = 20;
+
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.map);
+
+ mapView = (MapView) findViewById(R.id.mapview);
+ mapView.setBuiltInZoomControls(true);
+ mapOverlays = mapView.getOverlays();
+
+ this.initHttp();
+
+// myLocationOverlay = new MyLocationOverlay(MyMap.this, mapView);
+// myLocationOverlay.enableMyLocation();
+// myLocationOverlay.runOnFirstFix(new Runnable() {
+// public void run() {
+// Log.i(LOG_TAG, "Found location");
+// myLocationOverlay.disableMyLocation();
+// mapView.getController().animateTo(myLocationOverlay.getMyLocation());
+// }
+// });
+
+
+
+ //test a static overlay item
+// pizzaDrawable = this.getResources().getDrawable(R.drawable.pizza);
+// pizzaOverlay = new PizzaOverlay(pizzaDrawable);
+// GeoPoint point = new GeoPoint(47374710, 8529110);
+// OverlayItem overlayitem = new OverlayItem(point, "Don Leone", "");
+// pizzaOverlay.addOverlay(overlayitem);
+// GeoPoint point2 = new GeoPoint(47378510, 8547970);
+// OverlayItem overlayitem2 = new OverlayItem(point2, "Domino's Pizza", "");
+// pizzaOverlay.addOverlay(overlayitem2);
+
+
+ //Load last known user location
+ Location userLocation = getCachedLocation();
+ GeoPoint userLocationGeoPoint = new GeoPoint((int) (userLocation.getLatitude()*1e6), (int) (userLocation.getLongitude()*1e6));
+ OverlayItem userLocationOverlayItem = new OverlayItem(userLocationGeoPoint, "", "");
+ userLocationOverlay = new UserLocationOverlay(this.getResources().getDrawable(R.drawable.marker));
+ userLocationOverlay.addOverlay(userLocationOverlayItem);
+ mapView.getController().animateTo(userLocationGeoPoint);
+
+ //Load nearby places from web service
+ List<Place> pizzaRestaurants = searchGooglePlaces(userLocation);
+ pizzaDrawable = this.getResources().getDrawable(R.drawable.pizza);
+ pizzaOverlay = new PizzaOverlay(pizzaDrawable, this);
+ pizzaOverlay.setPizzas(pizzaRestaurants);
+
+ // add overlays to mapView list of overlays
+ mapOverlays.add(pizzaOverlay);
+ mapOverlays.add(userLocationOverlay);
+ //mapOverlays.add(myLocationOverlay);
+
+
+ }
+
+ @Override
+ protected boolean isRouteDisplayed() {
+ return false;
+ }
+
+ /**
+ * Returns the last cached location value on the phone.
+ * If none found, a default location is returned (ETH).
+ */
+ private Location getCachedLocation() {
+ Location lastKnownLocation = null;
+ LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
+
+ // First try for cached GPS location data
+ if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
+ lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+ if(lastKnownLocation != null) {
+ return lastKnownLocation;
+ }
+ }
+
+ // Then try cached network location data
+ if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
+ lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
+ if(lastKnownLocation != null) {
+ return lastKnownLocation;
+ }
+ }
+
+ // No cached location found. Use ETH as default location for demo...
+ Toast.makeText(this, "No cached location found. Using default location (ETH)...", Toast.LENGTH_SHORT).show();
+ Location defaultLocation = new Location("default");
+ defaultLocation.setLatitude(47.37642);
+ defaultLocation.setLongitude(8.54799);
+ return defaultLocation;
+ }
+
+ /**
+ * Initializes the HttpClient. This must be called before executeRequest().
+ */
+ private void initHttp() {
+ final HttpParams params = new BasicHttpParams();
+ HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
+ HttpProtocolParams.setContentCharset(params, "UTF-8");
+
+ final SchemeRegistry registry = new SchemeRegistry();
+ registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
+
+ final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
+ mClient = new DefaultHttpClient(manager, params);
+ }
+
+ /**
+ * Returns a list of pizza places that are near userLocation
+ */
+ public List<Place> searchGooglePlaces(Location userLocation) {
+ List<Place> places = new ArrayList<Place>();
+
+ //fetch data from web service
+ try {
+ final String url = String.format(GOOGLE_PLACES_SEARCH_URL, OUTPUT_FORMAT, userLocation.getLatitude(), userLocation.getLongitude(), SEARCH_RADIUS, URLEncoder.encode(SEARCH_TYPES, "UTF-8"), SEARCH_KEYWORDS, GOOGLE_PLACES_API_KEY);
+ String result = executeRequest(url);
+ JSONObject json = new JSONObject(result);
+ JSONArray results = json.getJSONArray("results");
+ for (int i = 0; i < results.length(); i++) {
+ JSONObject location = results.getJSONObject(i).getJSONObject("geometry").getJSONObject("location");
+ Double lat = location.getDouble("lat");
+ Double lng = location.getDouble("lng");
+ String name = results.getJSONObject(i).getString("name");
+ Place pizzaPlace = new Place(lat, lng, name);
+ places.add(pizzaPlace);
+ }
+ } catch (IOException e) {
+ Log.e(LOG_TAG, e.getMessage(), e);
+ } catch (JSONException e) {
+ Log.e(LOG_TAG, "Error parsing JSON", e);
+ }
+
+ return places;
+ }
+
+ /**
+ * Executes an HTTP request and returns the result as a string
+ */
+ public String executeRequest(String url) throws IOException {
+ final HttpGet get = new HttpGet(url);
+ HttpEntity entity = null;
+ try {
+ final HttpResponse response = mClient.execute(get);
+ if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+ entity = response.getEntity();
+ final InputStream in = entity.getContent();
+ String result = convertStreamToString(in);
+ in.close();
+ return result;
+ }
+ } catch (ClientProtocolException e) {
+ Log.e(LOG_TAG, e.getMessage(), e);
+ } catch (IOException e) {
+ Log.e(LOG_TAG, e.getMessage(), e);
+ } finally {
+ if (entity != null) {
+ entity.consumeContent();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Converts an InputStream to a String
+ */
+ public String convertStreamToString(InputStream in) throws IOException {
+ BufferedInputStream bis = new BufferedInputStream(in);
+ ByteArrayOutputStream buf = new ByteArrayOutputStream();
+ int result = bis.read();
+ while(result != -1) {
+ byte b = (byte) result;
+ buf.write(b);
+ result = bis.read();
+ }
+ bis.close();
+ return buf.toString();
+
+ }
+
+
+
+// Location getLocation(Flickr.Photo photo) {
+// final Uri.Builder uri = buildGetMethod(API_PEOPLE_GET_LOCATION);
+// uri.appendQueryParameter(PARAM_PHOTO_ID, photo.mId);
+//
+// final HttpGet get = new HttpGet(uri.build().toString());
+// final Location location = new Location(0.0f, 0.0f);
+//
+// try {
+// executeRequest(get, new ResponseHandler() {
+// public void handleResponse(InputStream in) throws IOException {
+// parseResponse(in, new ResponseParser() {
+// public void parseResponse(XmlPullParser parser)
+// throws XmlPullParserException, IOException {
+// parsePhotoLocation(parser, location);
+// }
+// });
+// }
+// });
+// return location;
+// } catch (IOException e) {
+// android.util.Log.e(LOG_TAG, "Could not find location for photo: " + photo);
+// }
+//
+// return null;
+// }
+//
+// void downloadPhoto(Photo photo, PhotoSize size, OutputStream destination) throws IOException {
+// final BufferedOutputStream out = new BufferedOutputStream(destination, IO_BUFFER_SIZE);
+// final String url = photo.getUrl(size);
+// final HttpGet get = new HttpGet(url);
+//
+// HttpEntity entity = null;
+// try {
+// final HttpResponse response = mClient.execute(get);
+// if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+// entity = response.getEntity();
+// entity.writeTo(out);
+// out.flush();
+// }
+// } finally {
+// if (entity != null) {
+// entity.consumeContent();
+// }
+// }
+// }
+//
+// private void executeRequest(HttpGet get, ResponseHandler handler) throws IOException {
+// HttpEntity entity = null;
+// HttpHost host = new HttpHost(API_REST_HOST, 80, "http");
+// try {
+// final HttpResponse response = mClient.execute(host, get);
+// if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+// entity = response.getEntity();
+// final InputStream in = entity.getContent();
+// handler.handleResponse(in);
+// }
+// } finally {
+// if (entity != null) {
+// entity.consumeContent();
+// }
+// }
+// }
+//
+// private static Uri.Builder buildGetMethod(String method) {
+// final Uri.Builder builder = new Uri.Builder();
+// builder.path(API_REST_URL).appendQueryParameter(PARAM_API_KEY, API_KEY);
+// builder.appendQueryParameter(PARAM_METHOD, method);
+// return builder;
+// }
+
+
+}
Added: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/PizzaOverlay.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/PizzaOverlay.java (rev 0)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/PizzaOverlay.java 2011-05-30 13:37:38 UTC (rev 4372)
@@ -0,0 +1,57 @@
+package ch.ethz.mxquery.android;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.app.Activity;
+import android.graphics.drawable.Drawable;
+import android.widget.Toast;
+
+import com.google.android.maps.GeoPoint;
+import com.google.android.maps.ItemizedOverlay;
+import com.google.android.maps.OverlayItem;
+
+public class PizzaOverlay extends ItemizedOverlay<OverlayItem> {
+
+ private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
+ private Activity mActivity;
+
+ public PizzaOverlay(Drawable defaultMarker, Activity activity) {
+ super(boundCenterBottom(defaultMarker));
+ this.mActivity = activity;
+ }
+
+ @Override
+ protected OverlayItem createItem(int i) {
+ return mOverlays.get(i);
+ }
+
+ @Override
+ public int size() {
+ return mOverlays.size();
+ }
+
+ public void addOverlay(OverlayItem overlay) {
+ mOverlays.add(overlay);
+ //setLastFocusedIndex(-1);
+ populate();
+ }
+
+ public void setPizzas(List<Place> places) {
+ mOverlays.clear();
+ for(Place place: places){
+ GeoPoint geoPoint = new GeoPoint((int) (place.getLatitude()*1e6), (int) (place.getLongitude()*1e6));
+ OverlayItem overlayitem = new OverlayItem(geoPoint, place.getName(), "");
+ addOverlay(overlayitem);
+ }
+ }
+
+ @Override
+ protected boolean onTap(int index) {
+ OverlayItem overlayItem = mOverlays.get(index);
+
+ Toast.makeText(this.mActivity, overlayItem.getTitle(), Toast.LENGTH_SHORT).show();
+
+ return true;
+ }
+}
Added: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Place.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Place.java (rev 0)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Place.java 2011-05-30 13:37:38 UTC (rev 4372)
@@ -0,0 +1,36 @@
+package ch.ethz.mxquery.android;
+
+public class Place {
+ private Double latitude;
+ private Double longitude;
+ private String name;
+
+ public Place() {}
+
+ public Place(Double latitude, Double longitude, String name) {
+ this.latitude = latitude;
+ this.longitude = longitude;
+ this.name = name;
+ }
+
+ public Double getLatitude() {
+ return latitude;
+ }
+ public void setLatitude(Double latitude) {
+ this.latitude = latitude;
+ }
+ public Double getLongitude() {
+ return longitude;
+ }
+ public void setLongitude(Double longitude) {
+ this.longitude = longitude;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+}
Modified: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java 2011-05-27 13:42:20 UTC (rev 4371)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/Start.java 2011-05-30 13:37:38 UTC (rev 4372)
@@ -22,6 +22,9 @@
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.database.Cursor;
+import android.location.Location;
+import android.location.LocationListener;
+import android.location.LocationManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
@@ -67,6 +70,7 @@
public static final String STATE_CHANGE_SETTINGS = "STATE_CHANGE_SETTINGS";
public static final int QUERY_RUNNING_DIALOG = 1;
public static final int GENERATING_CONTACTS_XML_DIALOG = 2;
+ public static final int LOCATION_DIALOG = 3;
public static final String UNDEFINED_LABEL = "Undefined";
private static final String LOG_TAG = "MXQuery.Start";
@@ -83,6 +87,11 @@
mDialog.setMessage("Generating Contacts XML...");
mDialog.setCancelable(true);
return mDialog;
+ case LOCATION_DIALOG:
+ mDialog = new ProgressDialog(mActivity);
+ mDialog.setMessage("Finding Location...");
+ mDialog.setCancelable(true);
+ return mDialog;
default:
return null;
}
@@ -92,6 +101,8 @@
switch(id) {
case QUERY_RUNNING_DIALOG:
return;
+ case LOCATION_DIALOG:
+ return;
case GENERATING_CONTACTS_XML_DIALOG:
int numContacts = getContactsCount();
mDialog.setMax(numContacts);
@@ -417,13 +428,116 @@
case R.id.generate_contacts_XML:
new GenerateContactsXMLAsyncTask().execute();
return true;
+ case R.id.location:
+ //new ShowLocationAsyncTask().execute();
+ //item.setIntent(new Intent(this, MyMap.class));
+ Intent i = new Intent(this, MyMap.class);
+ startActivity(i);
+ return true;
default:
return super.onOptionsItemSelected(item);
}
}
+ protected class ShowLocationAsyncTask extends AsyncTask<Void, Void, Location> {
+ Location mLocation = null;
+ LocationManager locationManager = null;
+
+ @Override
+ protected void onPreExecute() {
+ mActivity.showDialog(LOCATION_DIALOG);
+
+ // Start listeners to find location
+ locationManager = (LocationManager) mActivity.getSystemService(Context.LOCATION_SERVICE);
+ if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
+ Log.d(LOG_TAG, "GPS_PROVIDER is enabled");
+ locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
+ }
+ if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
+ Log.d(LOG_TAG, "NETWORK_PROVIDER is enabled");
+ locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
+ }
+ }
+
+ @Override
+ protected void onPostExecute(Location l) {
+ mActivity.removeDialog(LOCATION_DIALOG);
+ String locationString = "Unable to determine location";
+ if(l != null) {
+ locationString = "(" + l.getLatitude() + ", " + l.getLongitude() + ")";
+ }
+ mResultView.setText(locationString);
+ locationManager.removeUpdates(locationListener);
+ }
+
+ @Override
+ protected void onCancelled() {
+ if(mDialog.isShowing())
+ mActivity.removeDialog(LOCATION_DIALOG);
+ }
+
+ @Override
+ protected Location doInBackground(Void... v) {
+ Location lastKnownLocation = null;
+
+ // First try for cached GPS location data
+ if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
+ lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+ if(lastKnownLocation != null) {
+ return lastKnownLocation;
+ }
+ }
+
+ // Then try cached network location data
+ if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
+ lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
+ if(lastKnownLocation != null) {
+ return lastKnownLocation;
+ }
+ }
+
+ // Wait for updated location
+ Location location = null;
+ try {
+ location = getLocation();
+ } catch (InterruptedException e) {
+ Log.e(LOG_TAG, e.getMessage(), e);
+ }
+
+ return location;
+ }
+
+ protected synchronized Location getLocation() throws InterruptedException {
+ if(mLocation == null) {
+ this.wait();
+ }
+ return mLocation;
+ }
+
+ protected synchronized void setLocation(Location location) {
+ mLocation = location;
+ notify();
+ }
+
+ LocationListener locationListener = new LocationListener() {
+ public void onLocationChanged(Location location) {
+ setLocation(location);
+ }
+
+ public void onStatusChanged(String provider, int status, Bundle extras) {}
+
+ public void onProviderEnabled(String provider) {}
+
+ public void onProviderDisabled(String provider) {}
+ };
+
+ }
+
+ /**
+ * Serializes all Android contacts to an XML file
+ */
protected class GenerateContactsXMLAsyncTask extends AsyncTask<Void, Integer, String> {
Integer numContacts = 100;
final String[] phoneProjection = new String[] {
@@ -439,26 +553,12 @@
@Override
protected void onPreExecute() {
mActivity.showDialog(GENERATING_CONTACTS_XML_DIALOG);
- /*
- numContacts = getContactsCount();
-
- mDialog = new ProgressDialog(mActivity);
- mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- mDialog.setMessage("Generating Contacts XML...");
- mDialog.setCancelable(true);
- mDialog.setMax(numContacts);
- mDialog.setProgress(0);
- mDialog.show();
- */
}
@Override
protected void onPostExecute(String s) {
mActivity.removeDialog(GENERATING_CONTACTS_XML_DIALOG);
- /*
- if(mDialog.isShowing())
- mDialog.dismiss();
- */
+
//printContactsXML();
mResultView.setText(s);
}
@@ -741,6 +841,10 @@
}
}
+ /**
+ * Only needed for serializing Android contacts to XML
+ * @return
+ */
private int getContactsCount() {
//for testing
//return 300;
Added: trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/UserLocationOverlay.java
===================================================================
--- trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/UserLocationOverlay.java (rev 0)
+++ trunk/MXQuery_Android_App/src/ch/ethz/mxquery/android/UserLocationOverlay.java 2011-05-30 13:37:38 UTC (rev 4372)
@@ -0,0 +1,32 @@
+package ch.ethz.mxquery.android;
+
+import java.util.ArrayList;
+
+import android.graphics.drawable.Drawable;
+
+import com.google.android.maps.ItemizedOverlay;
+import com.google.android.maps.OverlayItem;
+
+public class UserLocationOverlay extends ItemizedOverlay<OverlayItem> {
+
+ private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
+
+ public UserLocationOverlay(Drawable defaultMarker) {
+ super(boundCenterBottom(defaultMarker));
+ }
+
+ @Override
+ protected OverlayItem createItem(int i) {
+ return mOverlays.get(i);
+ }
+
+ @Override
+ public int size() {
+ return mOverlays.size();
+ }
+
+ public void addOverlay(OverlayItem overlay) {
+ mOverlays.add(overlay);
+ populate();
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-05-27 13:42:27
|
Revision: 4371
http://mxquery.svn.sourceforge.net/mxquery/?rev=4371&view=rev
Author: pm_fischer
Date: 2011-05-27 13:42:20 +0000 (Fri, 27 May 2011)
Log Message:
-----------
next step towards non-linear patterns:
- use a state stack
- all existing tests working again
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/iterators/pattern/PatternNaiveIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/PatternDataHelper.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/pattern/PatternNaiveIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/pattern/PatternNaiveIterator.java 2011-05-26 08:04:15 UTC (rev 4370)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/pattern/PatternNaiveIterator.java 2011-05-27 13:42:20 UTC (rev 4371)
@@ -109,8 +109,17 @@
if(initanyPatternMatch){
anyPatternFirstMatch = 1;
initanyPatternMatch = false;
+ statesStack = new Vector();
+ PatternDataHelper.PatternVarHelper [] cands = patternDef.getInitialCandidates();
+ Vector curStates = new Vector(cands.length);
+ for (int v=0;v<cands.length;v++) {
+ curStates.addElement(new PatternState(cands[v],null,initialFirstPosition));
+ }
+ statesStack.addElement(curStates);
}
+
+
while(!endofSequence(startTumblingIncremental)) {
if(prevState != SLIDEPARTITIONMATCH)
@@ -194,8 +203,17 @@
if(initanyPatternMatch){
anyPatternFirstMatch = 1;
initanyPatternMatch = false;
+ statesStack = new Vector();
+ PatternDataHelper.PatternVarHelper [] cands = patternDef.getInitialCandidates();
+ Vector curStates = new Vector(cands.length);
+ for (int v=0;v<cands.length;v++) {
+ curStates.addElement(new PatternState(cands[v],null,initialFirstPosition));
+ }
+ statesStack.addElement(curStates);
}
+
+
while(!endofSequence(startTumblingIncremental)) {
if(!forceReset){
prevState = typeOfMatch(endTumblingIncremental, prevState);
@@ -323,111 +341,95 @@
protected int typeOfMatch(int end, int execState) throws MXQueryException {
- if(statesStack.size() == 1) {
- Vector curStates = (Vector)statesStack.elementAt(0);
- if (stateToContinue == -1) {
- for (int i=0;i<curStates.size();i++) {
- PatternState curState = (PatternState)curStates.elementAt(i);
- int occurID = curState.cur.getTypeOcc().getOccurID();
- if(occurID == Type.OCCURRENCE_IND_ONE_OR_MORE && plusOperatorFlag) {
- anyPatternFirstMatch = startTumblingIncremental;
- if(checkPatternExpr(end, 0, curState.cur)) {
- plusOperatorFlag = false;
- if(curState.cur.isAccepting()) {
- curState.achievedExecutionState = CONTINUOUSMATCH;
- } else
- curState.achievedExecutionState = PARTIALMATCH;
- } else {
- plusOperatorFlag = true;
- }
- }
- }
- if (curStates.size() > 0) {
- stateToContinue = 0;
- return ((PatternState)curStates.elementAt(0)).achievedExecutionState;
- }
- } else {
- if (stateToContinue > -1 && stateToContinue < curStates.size()) {
- stateToContinue++;
- return ((PatternState)curStates.elementAt(stateToContinue-1)).achievedExecutionState;
- }
- else {
- stateToContinue = -1;
- return NONMATCH;
- }
- }
-
- }
Vector curStates = (Vector)statesStack.elementAt(statesStack.size()-1);
+ Vector nextStates = new Vector();
+
+ int summaryState = NONMATCH;
- if (stateToContinue == -1) {
-
- Vector nextStates = new Vector();
for (int s=0;s<curStates.size();s++) {
+ PatternState nextState = null;
PatternState curState = (PatternState)curStates.elementAt(s);
- // Get list of clauses from ArrayList
- PatternVarHelper [] states = curState.cur.getListMatches();
- // decide prevState on the basis of
- for (int i=0;i<states.length;i++) {
- PatternVarHelper patternDefClause = states[i];
- int occurID = patternDefClause.getTypeOcc().getOccurID();
- if(checkPatternExpr(end, 0, patternDefClause)) {
- //Check here if pat is non-grouping variable
- if(patternDefClause.isAccepting()) {
- // case of OpenFullMatch
- if(occurID == Type.OCCURRENCE_IND_EXACTLY_ONE){
- PatternDataHelper.PatternVarHelper [] cands = patternDef.getInitialCandidates();
- for (int v=0;v<cands.length;v++) {
- nextStates.addElement(new PatternState(cands[v],curState,currentPosition));
+ int curOccurID = curState.cur.getTypeOcc().getOccurID();
+ if(curOccurID == Type.OCCURRENCE_IND_ONE_OR_MORE && !curState.alreadyMatchedOnce) {
+ anyPatternFirstMatch = startTumblingIncremental;
+ if(checkPatternExpr(end, 0, curState.cur)) {
+// plusOperatorFlag = false;
+ nextState = new PatternState(curState.cur,curState,currentPosition);
+ nextState.alreadyMatchedOnce = true;
+ nextStates.addElement(nextState);
+
+ if(curState.cur.isAccepting()) {
+ nextState.achievedExecutionState = CONTINUOUSMATCH; // it is matching according to rules
+ summaryState = CONTINUOUSMATCH;
+ } else
+ nextState.achievedExecutionState = PARTIALMATCH; // it is matching according to rules
+ if (summaryState != CONTINUOUSMATCH)
+ summaryState = PARTIALMATCH;
+ }
+ } else {
+ // Get reachable states
+ PatternVarHelper [] states = curState.cur.getListMatches();
+ for (int i=0;i<states.length;i++) {
+ PatternVarHelper patternDefClause = states[i];
+ int occurID = patternDefClause.getTypeOcc().getOccurID();
+ if(checkPatternExpr(end, 0, patternDefClause)) {
+ //Check here if pat is non-grouping variable
+ if(patternDefClause.isAccepting()) {
+ // case of OpenFullMatch
+ if(occurID == Type.OCCURRENCE_IND_EXACTLY_ONE){
+ PatternDataHelper.PatternVarHelper [] cands = patternDef.getInitialCandidates();
+ for (int v=0;v<cands.length;v++) {
+ nextState = new PatternState(cands[v],curState,currentPosition);
+ nextStates.addElement(nextState);
+ }
+ occurenceIndicatorOne = true;
+ }else {
+ nextState = new PatternState(patternDefClause,curState,currentPosition);
+ nextState.alreadyMatchedOnce = true;
+ nextStates.addElement(nextState);
}
- occurenceIndicatorOne = true;
- }else {
- nextStates.addElement(new PatternState(patternDefClause,curState,currentPosition));
+ nextState.achievedExecutionState = CONTINUOUSMATCH; // it is matching according to rules
+ summaryState = CONTINUOUSMATCH;
+ } else {
+ if(occurID == Type.OCCURRENCE_IND_EXACTLY_ONE) {
+ PatternDataHelper.PatternVarHelper [] cands = patternDefClause.getNextCandidates();
+ for (int v=0;v<cands.length;v++) {
+ nextState = new PatternState(cands[v],curState,currentPosition);
+ nextStates.addElement(nextState);
+ }
+ }else {
+ nextState = new PatternState(patternDefClause,curState,currentPosition);
+ nextState.alreadyMatchedOnce = true;
+ nextStates.addElement(nextState);
+ }
+ // check for the last satisfying clause
+
+ nextState.achievedExecutionState = PARTIALMATCH; // it is matching according to rules
+ if (summaryState != CONTINUOUSMATCH)
+ summaryState = PARTIALMATCH;
}
- return CONTINUOUSMATCH; // it is vaild match
+ break;
}
- if(occurID == Type.OCCURRENCE_IND_EXACTLY_ONE) {
- PatternDataHelper.PatternVarHelper [] cands = patternDef.getInitialCandidates();
- for (int v=0;v<cands.length;v++) {
- nextStates.addElement(new PatternState(cands[v],curState,currentPosition));
- }
- }else {
- nextStates.addElement(new PatternState(patternDefClause,curState,currentPosition));
- }
- // check for the last satisfying clause
+ anyPatternFirstMatch = endTumblingIncremental;
- curState.achievedExecutionState = PARTIALMATCH; // it is matching according to rules
}
- anyPatternFirstMatch = endTumblingIncremental;
-
}
// Does not match with any of the clauses
- if(selectionType == INCREMENTAL_SELECTION) {
+ if(selectionType == INCREMENTAL_SELECTION && summaryState == NONMATCH) {
if(prevState == CONTINUOUSMATCH)
- curState.achievedExecutionState =SLIDEPARTITIONMATCH;
+ summaryState =SLIDEPARTITIONMATCH;
else if(prevState == PARTIALMATCH)
- curState.achievedExecutionState = SLIDEPARTITIONMATCH; // purposely distinguished
+ summaryState = SLIDEPARTITIONMATCH; // purposely distinguished
else if(prevState == NONMATCH)
- curState.achievedExecutionState = NONMATCH;
+ summaryState = NONMATCH;
else if(prevState == SLIDEPARTITIONMATCH)
- curState.achievedExecutionState = NONMATCH;
+ summaryState = NONMATCH;
}
}
- statesStack.addElement(nextStates);
- if (curStates.size() > 0) {
- stateToContinue = 0;
- return ((PatternState)curStates.elementAt(0)).achievedExecutionState;
- }
- }else {
- if (stateToContinue < curStates.size()) {
- stateToContinue++;
- return ((PatternState)curStates.elementAt(stateToContinue-1)).achievedExecutionState;
- }
- else {
- return NONMATCH;
- }
- }
- return NONMATCH;
+ if (nextStates.size() > 0) {
+ statesStack.addElement(nextStates);
+ }
+ return summaryState;
}
@@ -758,6 +760,7 @@
cur = curState;
prev = prevState;
startPos = start;
+
}
@@ -765,7 +768,12 @@
PatternState prev;
int startPos;
int endPos;
+ boolean alreadyMatchedOnce = false;
int achievedExecutionState = NONMATCH;
+
+ PatternState copy(PatternState prev) {
+ return new PatternState(cur, this, startPos);
+ }
}
public XDMIterator staticInit() throws MXQueryException {
@@ -779,6 +787,5 @@
}
return this;
}
-
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/parser/PatternDataHelper.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/parser/PatternDataHelper.java 2011-05-26 08:04:15 UTC (rev 4370)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/parser/PatternDataHelper.java 2011-05-27 13:42:20 UTC (rev 4371)
@@ -303,7 +303,7 @@
if (!var.contains(v1))
var.add(v1);
else
- throw new StaticException(ErrorCodes.A0018_Missing_Pattern_Var_Decl, "Variable "+v1+" is used multiple times in the pattern", QueryLocation.OUTSIDE_QUERY_LOC);
+ throw new StaticException(ErrorCodes.A0017_Duplicate_Pattern_Var, "Variable "+v1+" is used multiple times in the pattern", QueryLocation.OUTSIDE_QUERY_LOC);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-05-26 08:04:22
|
Revision: 4370
http://mxquery.svn.sourceforge.net/mxquery/?rev=4370&view=rev
Author: pm_fischer
Date: 2011-05-26 08:04:15 +0000 (Thu, 26 May 2011)
Log Message:
-----------
- fixes on detection of sequential annotation
- cleanup on namespace scope processing
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/XDMScope.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/NSScopeChange.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/update/StripTypeIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
trunk/MXQuery_Testing/XQTests/Queries/try_zorba_3.xq
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/WebService/WSMXQImportTest.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/XDMScope.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/XDMScope.java 2011-05-25 18:40:36 UTC (rev 4369)
+++ trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/XDMScope.java 2011-05-26 08:04:15 UTC (rev 4370)
@@ -144,7 +144,7 @@
uri = (Namespace) c.prefixNamespaceMap.get(prefix);
else
uri = (Namespace) prefixNamespaceMap.get(prefix);
- if (uri!= null)
+ if (uri!= null && !"".equals(uri.getURI()))
return uri.getURI();
else return null;
}
@@ -226,7 +226,7 @@
}
}
// Undeclare default NS if construction around uses it, but inner content does not
- if ((ns.getNamespace("") == null || ns.getNamespace("").getURI() == null) && curScope.getNamespace("")!=null) {
+ if ((ns.getNamespace("") == null || ns.getNamespace("").getURI() == null) && requiredNS.contains(new Namespace("", ""))) {
nsNew.addNamespace("", "");
newNamespaces++;
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/NSScopeChange.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/NSScopeChange.java 2011-05-25 18:40:36 UTC (rev 4369)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/NSScopeChange.java 2011-05-26 08:04:15 UTC (rev 4370)
@@ -131,9 +131,10 @@
}
if (ev == Type.END_TAG) {
if (next instanceof NamedToken
- && !scopeDepth.empty() && depth == scopeDepth.peek()) {
+ && !scopeDepth.empty() && depth == scopeDepth.peek()-1) {
curNsScope = curNsScope.getParent();
scopeDepth.pop();
+ oldParentNs = null;
}
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/update/StripTypeIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/update/StripTypeIterator.java 2011-05-25 18:40:36 UTC (rev 4369)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/update/StripTypeIterator.java 2011-05-26 08:04:15 UTC (rev 4370)
@@ -55,7 +55,7 @@
seenAttrPos++;
}
else
- cur = current.next();
+ cur = getNext();
if (Type.isAttribute(cur.getEventType())) {
NamedToken nm = ((NamedToken)cur).copyStrip();
nm.setIDREFS(null);
@@ -64,7 +64,7 @@
if (cur.getEventType() == Type.START_TAG) {
NamedToken nm = ((NamedToken)cur).copyStrip();
boolean hasNamedIDAttribute = false;
- TokenInterface nextTok = current.next();
+ TokenInterface nextTok = getNext();
if (collectedAttributes.size() > 0)
collectedAttributes = new Vector();
collectedAttributes.addElement(nextTok);
@@ -80,7 +80,7 @@
requiredNS.add(new Namespace(nm.getPrefix(), nm.getNS()));
}
// if attribute, check if id
- nextTok = current.next();
+ nextTok = getNext();
collectedAttributes.addElement(nextTok);
}
nm.setIDREFS(null);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-05-25 18:40:36 UTC (rev 4369)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-05-26 08:04:15 UTC (rev 4370)
@@ -635,7 +635,7 @@
throw new StaticException(
ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,
"Function named " + funcToCheck.funcName.toString()
- + " not available", getCurrentLoc());
+ + " with arity "+funcToCheck.arity+" not available", getCurrentLoc());
}
}
// Check if the expression type is consistent
@@ -1957,7 +1957,7 @@
paramAnnotations.put(VariableHolder.ASSIGNABLE_ANNOTATION, new XDMIterator[]{});
getCurrentContext().registerVariable(
(QName) paramNames.elementAt(i), false,
- seqTypeIt, annotations);
+ seqTypeIt, paramAnnotations);
}
Iterator body;
@@ -2040,9 +2040,10 @@
annotations.put(FunctionSignature.UPDATING_ANNOTATION, new XDMIterator[]{});
} else if (co.isScripting() && parseKeyword("sequential")) {
checkExprTypeAnnotation(annotations);
+ annotations.put(FunctionSignature.SEQUENTIAL_ANNOTATION, new XDMIterator[]{});
} else if (parseKeyword("simple")) {
checkExprTypeAnnotation(annotations);
- annotations.put(FunctionSignature.SEQUENTIAL_ANNOTATION, new XDMIterator[]{});
+ annotations.put(FunctionSignature.SIMPLE_ANNOTATION, new XDMIterator[]{});
} else if (co.isXquery11() && parseKeyword("private")) {
checkVisibilityAnnotation(annotations);
annotations.put(FunctionSignature.PRIVATE_ANNOTATION, new XDMIterator[]{});
Modified: trunk/MXQuery_Testing/XQTests/Queries/try_zorba_3.xq
===================================================================
--- trunk/MXQuery_Testing/XQTests/Queries/try_zorba_3.xq 2011-05-25 18:40:36 UTC (rev 4369)
+++ trunk/MXQuery_Testing/XQTests/Queries/try_zorba_3.xq 2011-05-26 08:04:15 UTC (rev 4370)
@@ -2,5 +2,5 @@
try {
2 + "3"
} catch * ($ecode, $desc) {
- string-join(($ecode, $desc), " ")
+ string-join((xs:string($ecode), $desc), " ")
}
Modified: trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/WebService/WSMXQImportTest.java
===================================================================
--- trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/WebService/WSMXQImportTest.java 2011-05-25 18:40:36 UTC (rev 4369)
+++ trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/WebService/WSMXQImportTest.java 2011-05-26 08:04:15 UTC (rev 4370)
@@ -36,7 +36,7 @@
String query = UriToString(queries + "Q13_MXQuery_Node_Sequence_Result_Function.xq");
PreparedStatement expr = prepareQuery(query, false, true, false, false, false);
doQuery(expr);
- assertEquals(UriToString(expected_results+"Q13_MXQuery_Node_Sequence_Result_Function.xml"),resultBuffer.toString().trim());
+ assertXMLEqual(UriToString(expected_results+"Q13_MXQuery_Node_Sequence_Result_Function.xml"),resultBuffer.toString().trim());
}
public void test_14() throws Exception{
String query = UriToString(queries + "Q14_MXQuery_Atomic_Sequence_Result_Function.xq");
@@ -72,7 +72,7 @@
String query = UriToString(queries + "Q19_MXQuery_Element_Mapping_Function.xq");
PreparedStatement expr = prepareQuery(query, false, true, false, false, false);
doQuery(expr);
- assertEquals(UriToString(expected_results+"Q19_MXQuery_Element_Mapping_Function.xml"),resultBuffer.toString().trim());
+ assertXMLEqual(UriToString(expected_results+"Q19_MXQuery_Element_Mapping_Function.xml"),resultBuffer.toString().trim());
}
// public void test_multi() throws Exception {
// String query = UriToString(queries + "Q20_Import_Multiple_WSDL.xq");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-05-25 18:40:42
|
Revision: 4369
http://mxquery.svn.sourceforge.net/mxquery/?rev=4369&view=rev
Author: pm_fischer
Date: 2011-05-25 18:40:36 +0000 (Wed, 25 May 2011)
Log Message:
-----------
- fix nested module import problem on XQIB
- reStore building on Java 1.4
Modified Paths:
--------------
trunk/MXQuery/build.xml
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/Function.java
Modified: trunk/MXQuery/build.xml
===================================================================
--- trunk/MXQuery/build.xml 2011-05-24 13:54:45 UTC (rev 4368)
+++ trunk/MXQuery/build.xml 2011-05-25 18:40:36 UTC (rev 4369)
@@ -217,7 +217,7 @@
<copy file="${altsrc.dir}/ch/ethz/mxquery/query/impl/CompilerImpl.java" todir="${customtmp.dir}/ch/ethz/mxquery/query/impl" overwrite="yes" />
<copy file="${altsrc.dir}/ch/ethz/mxquery/xdmio/xmlAdapters/NonValidatingDOMAdapter.java" todir="${customtmp.dir}/ch/ethz/mxquery/xdmio/xmlAdapters/" overwrite="yes" />
<copy file="${altsrc.dir}/ch/ethz/mxquery/functions/math/TransMath.java" todir="${customtmp.dir}/ch/ethz/mxquery/functions/math" overwrite="yes" />
- <copy file="${altsrc.dir}/ch/ethz/mxquery/functions/Matches.java" todir="${customtmp.dir}/ch/ethz/mxquery/functions/" overwrite="yes" />
+ <copy file="${altsrc.dir}/ch/ethz/mxquery/functions/fn/Matches.java" todir="${customtmp.dir}/ch/ethz/mxquery/functions/fn/" overwrite="yes" />
<depend srcdir="${customtmp.dir}"
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/Function.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/Function.java 2011-05-24 13:54:45 UTC (rev 4368)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/Function.java 2011-05-25 18:40:36 UTC (rev 4369)
@@ -27,6 +27,7 @@
import ch.ethz.mxquery.functions.FunctionSignature;
import ch.ethz.mxquery.iterators.UserdefFuncCall;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
/**
* Holds information on the function metadata and methods to retrieve the
@@ -80,9 +81,10 @@
public Function getAsExternalFunction(String prefix) {
QName fName = new QName(signature.getName().getNamespaceURI(), prefix,
signature.getName().getLocalPart());
+ Hashtable annotations = signature.getAllAnnotations();
+ annotations.put(FunctionSignature.PRIVATE_ANNOTATION,new XDMIterator[]{});
FunctionSignature newSig = new FunctionSignature(fName, signature.paramTypes
- , FunctionSignature.EXTERNAL_FUNCTION,
- signature.getAllAnnotations());
+ , FunctionSignature.EXTERNAL_FUNCTION,annotations);
Function func = new Function(className, newSig, iter, operation, returnType);
return func;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-05-24 13:54:51
|
Revision: 4368
http://mxquery.svn.sourceforge.net/mxquery/?rev=4368&view=rev
Author: pm_fischer
Date: 2011-05-24 13:54:45 +0000 (Tue, 24 May 2011)
Log Message:
-----------
adapt build.xml for Java 1.4 matches
Modified Paths:
--------------
trunk/MXQuery/build.xml
Modified: trunk/MXQuery/build.xml
===================================================================
--- trunk/MXQuery/build.xml 2011-05-24 13:34:09 UTC (rev 4367)
+++ trunk/MXQuery/build.xml 2011-05-24 13:54:45 UTC (rev 4368)
@@ -217,6 +217,7 @@
<copy file="${altsrc.dir}/ch/ethz/mxquery/query/impl/CompilerImpl.java" todir="${customtmp.dir}/ch/ethz/mxquery/query/impl" overwrite="yes" />
<copy file="${altsrc.dir}/ch/ethz/mxquery/xdmio/xmlAdapters/NonValidatingDOMAdapter.java" todir="${customtmp.dir}/ch/ethz/mxquery/xdmio/xmlAdapters/" overwrite="yes" />
<copy file="${altsrc.dir}/ch/ethz/mxquery/functions/math/TransMath.java" todir="${customtmp.dir}/ch/ethz/mxquery/functions/math" overwrite="yes" />
+ <copy file="${altsrc.dir}/ch/ethz/mxquery/functions/Matches.java" todir="${customtmp.dir}/ch/ethz/mxquery/functions/" overwrite="yes" />
<depend srcdir="${customtmp.dir}"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-05-24 13:34:15
|
Revision: 4367
http://mxquery.svn.sourceforge.net/mxquery/?rev=4367&view=rev
Author: pm_fischer
Date: 2011-05-24 13:34:09 +0000 (Tue, 24 May 2011)
Log Message:
-----------
- fn:matches should work on Java 1.4 again
- all errors are thrown (and not just logged) for NativeFunctionCalls
- use string, not URI for file I/O
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
trunk/MXQuery/src/ch/ethz/mxquery/util/IOLib.java
Added Paths:
-----------
trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/fn/
trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/fn/Matches.java
Added: trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/fn/Matches.java
===================================================================
--- trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/fn/Matches.java (rev 0)
+++ trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/fn/Matches.java 2011-05-24 13:34:09 UTC (rev 4367)
@@ -0,0 +1,148 @@
+/* Copyright 2006 - 2009 ETH Zurich
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ch.ethz.mxquery.functions.fn;
+
+import java.util.Vector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.thaiopensource.datatype.xsd.regex.jdk1_4.Translator;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.types.TypeInfo;
+import ch.ethz.mxquery.datamodel.xdm.BooleanToken;
+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.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
+import ch.ethz.mxquery.model.TokenBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class Matches extends TokenBasedIterator {
+
+ protected void init() throws MXQueryException {
+ String text = getStringValueOrEmpty(subIters[0]);
+ if (text == null)
+ text = "";
+
+ int f = computeFlags(subIters, 3, loc);
+
+ String pat = getStringValue(subIters[1]);
+
+ if (pat.equals("")) {
+ throw new DynamicException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Pattern must be a String value!", loc);
+ }
+
+
+ if ((f & Pattern.COMMENTS) != 0) {
+ pat = removeWsFromPattern(pat);
+ f = f ^ Pattern.COMMENTS;
+ }
+
+ Pattern p = null;
+ try {
+ String toMatch = pat;
+// if ((f & Pattern.LITERAL) == 0)
+ toMatch = Translator.translate(pat);
+ p = Pattern.compile(toMatch, f);
+ } catch (Exception e) {
+ throw new DynamicException(ErrorCodes.F0032_INVALID_REGULAR_EXPRESSION, "Invalid regular expression!", loc);
+ }
+
+ if ((f & Pattern.CASE_INSENSITIVE) != 0)
+ text = text.toLowerCase();
+ Matcher m = p.matcher(text);
+ if (m.find())
+ currentToken = BooleanToken.TRUE_TOKEN;
+ else
+ currentToken = BooleanToken.FALSE_TOKEN;
+ }
+
+ private static String removeWsFromPattern(String pattern) {
+ StringBuffer res = new StringBuffer(pattern.length());
+ boolean inCharClass = false;
+ // Simplified version of WS stripping, does not take [] into account
+ for (int i=0;i<pattern.length();i++) {
+ char chr = pattern.charAt(i);
+ if (!Character.isWhitespace(chr) || inCharClass)
+ res.append(chr);
+ if (chr == '[')
+ inCharClass = true;
+ if (chr == ']')
+ inCharClass = false;
+ }
+ return res.toString();
+ }
+
+ /**
+ * Extract and compute the flags for the regexp-based functions
+ * @param subIters
+ * @param pos: Position of the flags parameter, counting as in XQuery (1...)
+ * @param loc: QueryLocation for error reporting
+ * @return
+ * @throws MXQueryException
+ */
+
+ static int computeFlags(XDMIterator [] subIters, int pos, QueryLocation loc) throws MXQueryException {
+ int f = 0;
+ if (subIters.length == pos) {
+
+ TokenInterface flags = subIters[pos-1].next();
+ String theFlags = flags.getText();
+
+ if (theFlags == null) {
+ throw new DynamicException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Regex Flags must be a String value!", loc);
+ }
+
+ if (!theFlags.equals("")) { // if flags are empty, skip
+ if (!theFlags.matches("[smixq]+")) {
+ throw new DynamicException(ErrorCodes.F0031_INVALID_REGULAR_EXPRESSION_FLAGS, "Invalid regular expression flags!", loc);
+ }
+
+ if (theFlags.indexOf("s") >= 0) {
+ f += Pattern.DOTALL;
+ }
+ if (theFlags.indexOf('m') >= 0) {
+ f += Pattern.MULTILINE;
+ }
+ if (theFlags.indexOf("i") >= 0) {
+ f += Pattern.CASE_INSENSITIVE;
+ }
+ if (theFlags.indexOf("x") >= 0) {
+ f += Pattern.COMMENTS;
+ }
+ if (theFlags.indexOf("q") >= 0) {
+ throw new StaticException(ErrorCodes.A0002_EC_NOT_SUPPORTED, "'q' flag/literal matches not supported on Java 1.4", loc);
+ }
+
+ }
+ }
+ return f;
+ }
+
+ public TypeInfo getStaticType() {
+ return new TypeInfo(Type.BOOLEAN,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ }
+
+ protected XDMIterator copy(Context context, XDMIterator[] subIters, Vector nestedPredCtxStack) throws MXQueryException {
+ XDMIterator copy = new Matches();
+ copy.setContext(context, true);
+ copy.setSubIters(subIters);
+ return copy;
+ }
+}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-05-24 13:32:19 UTC (rev 4366)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-05-24 13:34:09 UTC (rev 4367)
@@ -149,19 +149,19 @@
this.current = new TokenIterator(context, wrap, loc, false);
}
} catch (SecurityException e) {
- e.printStackTrace();
+ throw new DynamicException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Native call failed: "+e.getMessage(), loc);
} catch (NoSuchFieldException e) {
- e.printStackTrace();
+ throw new DynamicException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Native call failed: "+e.getMessage(), loc);
} catch (NoSuchMethodException e) {
- e.printStackTrace();
+ throw new DynamicException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Native call failed: "+e.getMessage(), loc);
} catch (IllegalArgumentException e) {
- e.printStackTrace();
+ throw new DynamicException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Native call failed: "+e.getMessage(), loc);
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ throw new DynamicException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Native call failed: "+e.getMessage(), loc);
} catch (InvocationTargetException e) {
- e.printStackTrace();
+ throw new DynamicException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Native call failed: "+e.getMessage(), loc);
} catch (InstantiationException e) {
- e.printStackTrace();
+ throw new DynamicException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Native call failed: "+e.getMessage(), loc);
}
//this.current = new TokenIterator(context, 42,Type.INT, loc);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/util/IOLib.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/util/IOLib.java 2011-05-24 13:32:19 UTC (rev 4366)
+++ trunk/MXQuery/src/ch/ethz/mxquery/util/IOLib.java 2011-05-24 13:34:09 UTC (rev 4367)
@@ -201,7 +201,7 @@
throw new DynamicException(ErrorCodes.F0014_ERROR_RETRIEVING_RESOURCE, "I/O Error - Remote Data cannot be accessed: " + e, loc);
}
} else {
- File xml = new File(uri);
+ File xml = new File(toOpen);
if (xml.exists()) {
try {
ins = new FileInputStream(xml);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-05-24 13:32:31
|
Revision: 4366
http://mxquery.svn.sourceforge.net/mxquery/?rev=4366&view=rev
Author: pm_fischer
Date: 2011-05-24 13:32:19 +0000 (Tue, 24 May 2011)
Log Message:
-----------
annotation (e..g, %private, %updating) support: definitions, tests and helper structures
Modified Paths:
--------------
trunk/MXQuery/android/src/ch/ethz/mxquery/query/parser/SchemaParser.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/query/webservice/WSDLHandler.java
trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java
trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/XQStaticContext.java
trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/TypeInfo.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/FGPopulator.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/Function.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionSignature.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Filter.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Fold.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Map.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/MapPairs.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/SequenceTypeIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/model/VariableHolder.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/SchemaParser.java
trunk/MXQuery/src/ch/ethz/mxquery/query/webservice/WSDLHandler.java
trunk/MXQuery/src/examples/ExternalFunctionExample.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/Function.java
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/xq11streaming/MiscTests.java
Added Paths:
-----------
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-func.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-import-default.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-import-defaultvar.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-import-private.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-import-privatevar.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-import-public.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-import-publicvar.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-missing-literal.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-module.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-nondet-UDT.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-nondet-func.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-nondet-sequential-func.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-privateprivatefunc.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-privatepublicfunc.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-publicpublicfunc.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-unknown-namespace.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-var.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/functest-deterministic-builtin.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/functest-deterministic-external-nondet-coercion.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/functest-deterministic-external-nondet-partial.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/functest-deterministic-external-nondet.xq
Modified: trunk/MXQuery/android/src/ch/ethz/mxquery/query/parser/SchemaParser.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/query/parser/SchemaParser.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/query/parser/SchemaParser.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -48,6 +48,7 @@
import ch.ethz.mxquery.functions.xs.XSConstructorIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.URIUtils;
+import ch.ethz.mxquery.util.Hashtable;
public class SchemaParser implements DOMErrorHandler {
/**
@@ -287,7 +288,7 @@
Type.OCCURRENCE_IND_ZERO_OR_MORE);
FunctionSignature signature = new FunctionSignature(qn, paramTypes,
FunctionSignature.SYSTEM_FUNCTION,
- XDMIterator.EXPR_CATEGORY_SIMPLE, false, true);
+ new Hashtable());
XDMIterator it = XSConstructorIterator.getBaseTypeConstructor(ctx, Type.getTypeFootprint(
qn, dict), dict);
if (it != null) {
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/query/webservice/WSDLHandler.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/query/webservice/WSDLHandler.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/query/webservice/WSDLHandler.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -200,7 +200,9 @@
// only function name and arity
params[i] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE);
}
- FunctionSignature signature = new FunctionSignature(functionName,params,FunctionSignature.EXTERNAL_FUNCTION,XDMIterator.EXPR_CATEGORY_SEQUENTIAL,true,false);
+ Hashtable annotations = new Hashtable();
+ annotations.put(FunctionSignature.NONDETERMINISTIC_ANNOTATION, new XDMIterator[]{});
+ FunctionSignature signature = new FunctionSignature(functionName,params,FunctionSignature.EXTERNAL_FUNCTION,annotations);
Function function = new Function(null,signature,wf,null,null);
context.addFunction(function, true, true);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -395,33 +395,33 @@
public void registerVariable(QName qname, boolean isFFLWOR)
throws MXQueryException {
- registerVariable(qname, false, isFFLWOR, null, false);
+ registerVariable(qname, false, isFFLWOR, null, new Hashtable());
}
public void registerVariable(QName qname, boolean isFFLWOR,
- XDMIterator seqTypeIter, boolean assignable)
+ XDMIterator seqTypeIter, Hashtable annotations)
throws MXQueryException {
- registerVariable(qname, false, isFFLWOR, seqTypeIter, assignable);
+ registerVariable(qname, false, isFFLWOR, seqTypeIter, annotations);
}
public void registerNewContextItem() throws MXQueryException {
- registerVariable(CONTEXT_ITEM, false, null, false);
+ registerVariable(CONTEXT_ITEM, false, null, new Hashtable());
}
public void registerNewContextItem(XDMIterator seqTypeIter) throws MXQueryException {
- registerVariable(CONTEXT_ITEM, false, seqTypeIter, false);
+ registerVariable(CONTEXT_ITEM, false, seqTypeIter, new Hashtable());
}
public void registerVariable(QName qname, boolean external,
- boolean isFFLWOR, XDMIterator seqTypeIter, boolean assignable)
+ boolean isFFLWOR, XDMIterator seqTypeIter, Hashtable annotations)
throws MXQueryException {
registerVariable(qname, external, isFFLWOR, seqTypeIter, true,
- assignable, true);
+ annotations, true);
}
public void registerVariable(QName qname, boolean external,
boolean isFFLWOR, XDMIterator seqTypeIter, boolean resolve,
- boolean assignable, boolean declared) throws MXQueryException {
+ Hashtable annotations, boolean declared) throws MXQueryException {
XQName resolvedQName = qname;
if (resolve && qname.getNamespaceURI() == null)
resolvedQName = qname.resolveQNameNamespace(this, false);
@@ -442,18 +442,17 @@
holder.setDeclared(declared);
}
} else {
- holder = new VariableHolder(this, external,variableMap.size());
+ holder = new VariableHolder(this, external,variableMap.size(),annotations);
holder.setDeclared(declared);
variableMap.put(resolvedQName, holder);
}
holder.setSeqTypeIt(seqTypeIter);
- holder.setAssignable(assignable);
}
public QName registerAnonymousVariable() {
QName qname = new QName(ANONYM_VARIABLE_PREFIX, ANONYM_VARIABLE_PREFIX
+ ++anonymVariableCounter);
- variableMap.put(qname, new VariableHolder(this, false,variableMap.size()));
+ variableMap.put(qname, new VariableHolder(this, false,variableMap.size(),new Hashtable()));
return qname;
}
@@ -522,7 +521,7 @@
throws MXQueryException {
VariableHolder holder = getVariable(qname);
if (holder == null) {
- registerVariable(qname, true,false,null,true,false,false);
+ registerVariable(qname, true,false,null,true,new Hashtable(),false);
holder = getVariable(qname);
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/XQStaticContext.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/XQStaticContext.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/XQStaticContext.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -458,11 +458,11 @@
* @param qname
* @param isFFLWOR
* @param seqTypeIter
- * @param assignable
+ * @param annotations
* @throws MXQueryException
*/
public void registerVariable(QName qname, boolean isFFLWOR, XDMIterator seqTypeIter,
- boolean assignable) throws MXQueryException;
+ Hashtable annotations) throws MXQueryException;
/**
* Registers a new context item in this scope
* @throws MXQueryException
@@ -483,11 +483,11 @@
* @param external
* @param isFFLWOR
* @param seqTypeIter
- * @param assignable
+ * @param annotations
* @throws MXQueryException
*/
public void registerVariable(QName qname, boolean external, boolean isFFLWOR,
- XDMIterator seqTypeIter, boolean assignable) throws MXQueryException;
+ XDMIterator seqTypeIter, Hashtable annotations) throws MXQueryException;
/**
* Registers a new variable. If the variable already exists, an error is thrown.
@@ -496,12 +496,12 @@
* @param isFFLWOR
* @param seqTypeIter
* @param resolve
- * @param assignable
+ * @param annotations
* @param declared TODO
* @throws MXQueryException
*/
public void registerVariable(QName qname, boolean external, boolean isFFLWOR,
- XDMIterator seqTypeIter, boolean resolve, boolean assignable, boolean declared) throws MXQueryException;
+ XDMIterator seqTypeIter, boolean resolve, Hashtable annotations, boolean declared) throws MXQueryException;
/**
* Registers a new "anonymous" (=internal) variable
* @return the QName of the registered variable
Modified: trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/TypeInfo.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/TypeInfo.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/TypeInfo.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -20,6 +20,7 @@
package ch.ethz.mxquery.datamodel.types;
import ch.ethz.mxquery.datamodel.XQName;
+import ch.ethz.mxquery.util.Hashtable;
/** Some of node kind types (e.g. element, attribute, PI) might have name part in the type definition.
* It's not possible to represent type with integer number in these cases.
@@ -33,6 +34,7 @@
private int typeAnnotation =UNDEFINED;
private TypeInfo [] paramTypes = null;
private TypeInfo returnType=null;
+ private Hashtable annotations=null;
private final static int MASK_GET_START_TAG = Integer.parseInt("0001100000000000000000000000000", 2);
private final static int MASK_CLEAN_START_TAG = Integer.parseInt("1110011111111111111111111111111", 2);
@@ -59,11 +61,12 @@
this.typeAnnotation = typeAn;
}
- public TypeInfo(int type, int occurIndID, TypeInfo[] params,TypeInfo retType) {
+ public TypeInfo(int type, int occurIndID, TypeInfo[] params,TypeInfo retType, Hashtable annotations) {
this.type = type;
this.occurID = occurIndID;
this.paramTypes = params;
this.returnType = retType;
+ this.annotations = annotations;
}
@@ -164,11 +167,15 @@
return returnType;
}
+ public Hashtable getAnnotations() {
+ return annotations;
+ }
+
public TypeInfo copy() {
if (typeAnnotation != UNDEFINED)
return new TypeInfo(type,occurID,qn,typeAnnotation);
else if (type ==Type.FUNCTION_ITEM)
- return new TypeInfo(type, occurID, paramTypes, returnType);
+ return new TypeInfo(type, occurID, paramTypes, returnType,annotations);
else
return new TypeInfo(type, occurID,qn);
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/FGPopulator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/FGPopulator.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/FGPopulator.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -16,7 +16,7 @@
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
-import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
import ch.ethz.mxquery.util.IOLib;
class FGPopulator {
@@ -133,7 +133,7 @@
for (int i=0;i<paramTypes.length;i++)
paramTypes[i] = new TypeInfo(FunctionGallery.getType(parameters[i],ctx),FunctionGallery.getOccur(parameters[i]));
- FunctionSignature signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+ FunctionSignature signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
Function function = new Function(baseLoc+loc+"."+funcDesc[2],signature, null, operation, type );
fg.add(function);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/Function.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/Function.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/Function.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -26,6 +26,7 @@
import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.iterators.UserdefFuncCall;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
/**
* Holds information on the function metadata and methods to retrieve the
@@ -79,9 +80,10 @@
public Function getAsExternalFunction(String prefix) {
QName fName = new QName(signature.getName().getNamespaceURI(), prefix,
signature.getName().getLocalPart());
+ Hashtable annotations = signature.getAllAnnotations();
+ annotations.put(FunctionSignature.PRIVATE_ANNOTATION,new XDMIterator[]{});
FunctionSignature newSig = new FunctionSignature(fName, signature.paramTypes
- , FunctionSignature.EXTERNAL_FUNCTION,
- signature.getExpressionCategory(), false, true);
+ , FunctionSignature.EXTERNAL_FUNCTION,annotations);
Function func = new Function(className, newSig, iter, operation, returnType);
return func;
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionSignature.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionSignature.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionSignature.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -15,12 +15,15 @@
package ch.ethz.mxquery.functions;
+import java.util.Enumeration;
+
import ch.ethz.mxquery.contextConfig.XQStaticContext;
import ch.ethz.mxquery.datamodel.QName;
import ch.ethz.mxquery.datamodel.XQName;
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
/**
* Holds information on the signature (Name, parameters, classification) of an XQuery function
@@ -30,6 +33,14 @@
public class FunctionSignature {
+ public static final QName PRIVATE_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","private");
+ public static final QName PUBLIC_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","public");
+ public static final QName DETERMINISTIC_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","deterministic");
+ public static final QName NONDETERMINISTIC_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","nondeterministic");
+ public static final QName SIMPLE_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","simple");
+ public static final QName UPDATING_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","updating");
+ public static final QName SEQUENTIAL_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","sequential");
+
protected QName qname;
TypeInfo [] paramTypes;
@@ -37,13 +48,9 @@
int arity = 0;
protected int type;
-
- protected int expressionType;
-
- protected boolean nondet;
-
- protected boolean privateScope;
-
+
+ Hashtable annotations;
+
//Undefined is just for locking up values
private static final int UNDEFINED_TYPE=0;
@@ -53,18 +60,16 @@
//public static final int LOCAL_SCOPE_FUNCTION=4;
FunctionSignature(QName qname, TypeInfo [] parameterType){
- this(qname, parameterType, UNDEFINED_TYPE, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+ this(qname, parameterType, UNDEFINED_TYPE, new Hashtable());
}
- public FunctionSignature(QName qname, TypeInfo[] parameterType, int type, int exprType, boolean nondeterministic, boolean isPrivate){
+ public FunctionSignature(QName qname, TypeInfo[] parameterType, int type, Hashtable annotations){
this.qname = qname;
this.paramTypes = parameterType;
this.type = type;
- expressionType = exprType;
- nondet = nondeterministic;
- privateScope = isPrivate;
if (this.paramTypes != null)
arity = paramTypes.length;
+ this.annotations = annotations;
}
/**
* Checks the equality of Function Signatures.
@@ -128,28 +133,43 @@
* @return The expression type of this function: SIMPLE, UPDATING, SCRIPTING
*/
public int getExpressionCategory() {
- return expressionType;
+ if (annotations.containsKey(UPDATING_ANNOTATION))
+ return XDMIterator.EXPR_CATEGORY_UPDATING;
+ if (annotations.containsKey(SEQUENTIAL_ANNOTATION))
+ return XDMIterator.EXPR_CATEGORY_SEQUENTIAL;
+ return XDMIterator.EXPR_CATEGORY_SIMPLE;
}
/**
* Is this a deterministic or non-deterministic functions (as defined in XQuery 1.1)
* @return true if the function is non-deterministic
*/
public boolean isNonDeterministic() {
- return nondet;
+ return annotations.containsKey(NONDETERMINISTIC_ANNOTATION);
}
/**
* Is this a private function (XQuery 1.1, exempt from module import)
* @return true if this is a private function
*/
public boolean isPrivateFunction() {
- return privateScope;
+ return annotations.containsKey(PRIVATE_ANNOTATION);
}
+ public Hashtable getAllAnnotations() {
+ Hashtable ht = new Hashtable();
+ Enumeration keys = annotations.keys();
+ while (keys.hasMoreElements()) {
+ Object key = keys.nextElement();
+ Object val = annotations.get(key);
+ ht.put(key, val);
+ }
+ return ht;
+ }
+
public FunctionSignature copy() {
QName qn = null;
if (qname != null)
qn = qname.copy();
- FunctionSignature fs = new FunctionSignature(qn, paramTypes, type, expressionType, nondet, privateScope);
+ FunctionSignature fs = new FunctionSignature(qn, paramTypes, type, annotations);
fs.arity = arity;
return fs;
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -17,6 +17,7 @@
import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.iterators.NativeFuncCall;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
public class NativeFunctionImporter {
@@ -181,7 +182,10 @@
while (allFuncts.hasNext()) {
MethodData md = (MethodData)allFuncts.next();
QName qn = new QName("java:"+className,"javamethod",md.methodName);
- FunctionSignature fs = new FunctionSignature(qn, md.paramTypes,FunctionSignature.EXTERNAL_FUNCTION,XDMIterator.EXPR_CATEGORY_SEQUENTIAL,true,false);
+ Hashtable annotations = new Hashtable();
+ annotations.put(FunctionSignature.SEQUENTIAL_ANNOTATION,new XDMIterator[]{});
+ annotations.put(FunctionSignature.NONDETERMINISTIC_ANNOTATION,new XDMIterator[]{});
+ FunctionSignature fs = new FunctionSignature(qn, md.paramTypes,FunctionSignature.EXTERNAL_FUNCTION,annotations);
Function fn = new Function(null, fs, new NativeFuncCall(ctx, md.paramTypes, toImport, md.methodName, md.returnType, null, XDMIterator.EXPR_CATEGORY_SIMPLE, QueryLocation.OUTSIDE_QUERY_LOC), null, null);
ctx.addFunction(fn);
}
@@ -220,4 +224,4 @@
public static boolean isNativeUri(String uri) {
return uri.startsWith("java:");
}
-}
\ No newline at end of file
+}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Filter.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Filter.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Filter.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -15,6 +15,7 @@
import ch.ethz.mxquery.model.CurrentBasedIterator;
import ch.ethz.mxquery.model.Iterator;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
public class Filter extends CurrentBasedIterator {
@@ -31,7 +32,7 @@
// if (!(predicate instanceof FFLWORIterator))
TypeInfo [] params = new TypeInfo[1];
params[0] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
- TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.BOOLEAN,Type.OCCURRENCE_IND_EXACTLY_ONE));
+ TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.BOOLEAN,Type.OCCURRENCE_IND_EXACTLY_ONE), new Hashtable());
SequenceTypeIterator st = new SequenceTypeIterator(tInfo, true, true, context, loc, true);
st.setSubIters(subIters[0]);
Iterator[] its = null;
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Fold.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Fold.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Fold.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -20,6 +20,7 @@
import ch.ethz.mxquery.model.VariableHolder;
import ch.ethz.mxquery.model.Window;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
public class Fold extends CurrentBasedIterator implements RequestTypeMulti{
@@ -38,7 +39,7 @@
TypeInfo [] params = new TypeInfo[2];
params[0] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE);
params[1] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE);
- TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE));
+ TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE), new Hashtable());
SequenceTypeIterator st = new SequenceTypeIterator(tInfo, true, true, context, loc, true);
st.setSubIters(subIters[0]);
st.setResettable(true);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Map.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Map.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Map.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -15,6 +15,7 @@
import ch.ethz.mxquery.model.CurrentBasedIterator;
import ch.ethz.mxquery.model.Iterator;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
public class Map extends CurrentBasedIterator {
@@ -31,7 +32,7 @@
// if (!(predicate instanceof FFLWORIterator))
TypeInfo [] params = new TypeInfo[1];
params[0] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE);
- TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE));
+ TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE), new Hashtable());
SequenceTypeIterator st = new SequenceTypeIterator(tInfo, true, true, context, loc, true);
st.setSubIters(subIters[0]);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/MapPairs.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/MapPairs.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/MapPairs.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -18,6 +18,7 @@
import ch.ethz.mxquery.model.VariableHolder;
import ch.ethz.mxquery.model.Window;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
public class MapPairs extends CurrentBasedIterator {
Window wnd1, wnd2;
@@ -34,7 +35,7 @@
params[0] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
params[1] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
- TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE));
+ TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE), new Hashtable());
st = new SequenceTypeIterator(tInfo, true, true, context, loc, true);
st.setSubIters(subIters[0]);
st.setResettable(true);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/SequenceTypeIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/SequenceTypeIterator.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/SequenceTypeIterator.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -39,6 +39,7 @@
import ch.ethz.mxquery.model.CurrentBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.Hashtable;
public class SequenceTypeIterator extends CurrentBasedIterator {
@@ -343,8 +344,8 @@
if (tok.getEventType()!=Type.FUNCTION_ITEM)
return false;
TypeInfo [] params = tInfo.getParameterTypes();
+ FunctionSignature fs = ((FunctionItemToken)tok).getFunction().getFunctionSignature();
if (params != null) {
- FunctionSignature fs = ((FunctionItemToken)tok).getFunction().getFunctionSignature();
if (fs.getArity() != params.length)
return false;
for (int i=0;i<params.length;i++) {
@@ -359,6 +360,21 @@
!Type.isOccCompatible(retType.getOccurID(),tInfo.getReturnType().getOccurID()))
return false;
}
+ if (tInfo.getAnnotations().size() > 0) {
+ Hashtable annToCheck = tInfo.getAnnotations();
+ if (annToCheck.containsKey(FunctionSignature.DETERMINISTIC_ANNOTATION) &&
+ fs.isNonDeterministic())
+ return false;
+ if (annToCheck.containsKey(FunctionSignature.SIMPLE_ANNOTATION) &&
+ fs.getExpressionCategory() != XDMIterator.EXPR_CATEGORY_SIMPLE)
+ return false;
+ if (annToCheck.contains(FunctionSignature.UPDATING_ANNOTATION) &&
+ fs.getExpressionCategory() != XDMIterator.EXPR_CATEGORY_SEQUENTIAL)
+ return false;
+ if (annToCheck.contains(FunctionSignature.SEQUENTIAL_ANNOTATION) &&
+ fs.getExpressionCategory() != XDMIterator.EXPR_CATEGORY_UPDATING)
+ return false;
+ }
return true;
}
@@ -391,7 +407,7 @@
FunctionSignature origSig = tok.getFunction().getFunctionSignature();
if (origSig.getArity() != targetType.getParameterTypes().length)
throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Wrong arity for function item",loc);
- FunctionSignature fs = new FunctionSignature(tok.getQNameTokenValue(), targetType.getParameterTypes(), FunctionSignature.USER_DEFINED_FUNCTION, origSig.getExpressionCategory(), origSig.isNonDeterministic(), origSig.isPrivateFunction());
+ FunctionSignature fs = new FunctionSignature(tok.getQNameTokenValue(), targetType.getParameterTypes(), FunctionSignature.USER_DEFINED_FUNCTION, origSig.getAllAnnotations());
Function fun = new Function(null,fs,tok.getFunction().getFunctionImplementation(getContext()),null,targetType.getReturnType());
return tok.coerce(fun);
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/model/VariableHolder.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/model/VariableHolder.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/model/VariableHolder.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -21,6 +21,7 @@
import ch.ethz.mxquery.bindings.WindowFactory;
import ch.ethz.mxquery.contextConfig.Context;
import ch.ethz.mxquery.contextConfig.XQStaticContext;
+import ch.ethz.mxquery.datamodel.QName;
import ch.ethz.mxquery.datamodel.Source;
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
@@ -29,14 +30,19 @@
import ch.ethz.mxquery.exceptions.QueryLocation;
import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.iterators.VariableIterator;
+import ch.ethz.mxquery.util.Hashtable;
public class VariableHolder {
+
+ public static final QName ASSIGNABLE_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","assignable");
+ public static final QName UNASSIGNABLE_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","assignable");
+
private XDMIterator iter;
private boolean external;
private boolean declared=false;
private int useCounter=0;
private boolean resetable=false;
- private boolean assignable=true;
+ private Hashtable annotations;
private int requriedOptions = 0;
private int contextPos;
private Context ctx;
@@ -48,19 +54,20 @@
this.seqTypeIt = seqTypeIt;
}
- public VariableHolder(Context ctx, boolean external, int pos){
- this(ctx, null, external,pos);
+ public VariableHolder(Context ctx, boolean external, int pos, Hashtable ann){
+ this(ctx, null, external,pos, ann);
}
// public VariableHolder(Context ctx, XDMIterator iter){
// this(ctx, iter, false);
// }
- public VariableHolder(Context ctx, XDMIterator iter, boolean external, int pos){
+ public VariableHolder(Context ctx, XDMIterator iter, boolean external, int pos, Hashtable ann){
this.external = external;
this.iter = iter;
this.ctx = ctx;
contextPos = pos;
+ annotations = ann;
}
public void setIter(XDMIterator iter) throws MXQueryException {
@@ -113,13 +120,12 @@
}
public boolean isAssignable() {
- return assignable;
+ if (annotations.containsKey(ASSIGNABLE_ANNOTATION))
+ return true;
+ else
+ return false;
}
- public void setAssignable(boolean assignable) {
- this.assignable = assignable;
- }
-
public TypeInfo getType() {
if (seqTypeIt != null)
return seqTypeIt.getStaticType();
@@ -196,7 +202,7 @@
VariableHolder copy = new VariableHolder(
context,
iter==null?null:iter.copy(context, null, false, nestedPredCtxStack),
- external,contextPos);
+ external,contextPos, annotations);
copy.setResetable(resetable);
copy.useCounter = useCounter;
if (seqTypeIt != null)
@@ -242,5 +248,7 @@
return requriedOptions;
}
-
+ public Hashtable getAnnotations(){
+ return annotations;
+ }
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -294,30 +294,30 @@
Set pendingVars;
}
- private class FunctionOptions {
+// private class FunctionOptions {
+//
+// public FunctionOptions(int expCategory, int visbility, int execution) {
+// super();
+// this.expCategory = expCategory;
+// if (visbility == VISIBILITY_PRIVATE)
+// this.privateVisbility = true;
+// else
+// privateVisbility = false;
+// if (execution == EXECUTION_NONDET)
+// this.nondeterministic = true;
+// else
+// this.nondeterministic = false;
+// }
+//
+// public static final int VISIBILITY_PUBLIC = 0;
+// public static final int VISIBILITY_PRIVATE = 1;
+// public static final int EXECUTION_DET = 0;
+// public static final int EXECUTION_NONDET = 1;
+// int expCategory;
+// boolean privateVisbility;
+// boolean nondeterministic;
+// }
- public FunctionOptions(int expCategory, int visbility, int execution) {
- super();
- this.expCategory = expCategory;
- if (visbility == VISIBILITY_PRIVATE)
- this.privateVisbility = true;
- else
- privateVisbility = false;
- if (execution == EXECUTION_NONDET)
- this.nondeterministic = true;
- else
- this.nondeterministic = false;
- }
-
- public static final int VISIBILITY_PUBLIC = 0;
- public static final int VISIBILITY_PRIVATE = 1;
- public static final int EXECUTION_DET = 0;
- public static final int EXECUTION_NONDET = 1;
- int expCategory;
- boolean privateVisbility;
- boolean nondeterministic;
- }
-
/**
* Used for static checking of continue and break<br/>
* They can only appear in loop => during parsing of a break/coninue must be
@@ -1498,6 +1498,8 @@
continue;
VariableHolder vh = (VariableHolder) ht.get(qn);
+ if (vh.getAnnotations().containsKey(FunctionSignature.PRIVATE_ANNOTATION))
+ continue;
if (!vh.isExternal()) {
// all variables need to be in the
// target namespace of the module
@@ -1510,8 +1512,10 @@
// getCurrentContext().registerExternalVariable(qn,
// vh.getIter(), false);
QName newQn = new QName(ns_uri, temp, qn.getLocalPart());
+ Hashtable annotations = new Hashtable();
+ annotations.put(FunctionSignature.PRIVATE_ANNOTATION, new XDMIterator[]{});
getCurrentContext().registerVariable(newQn, true, false, null,
- false, false, true);
+ false, annotations, true);
XDMIterator varVal;
if (!(vh.getIter() instanceof Window)) {
varVal = vh.getIter().copy(vh.getIter().getContext(),vh.getIter().getContext(),false,new Vector());
@@ -1539,10 +1543,75 @@
// boolean isCopy = false;
if (parseKeyword("declare")) {
int declareIndex = index;
- boolean assignable = false;
boolean expectVar = false;
+ if (co.isXquery11()
+ && (parseStringGetResult("context", true)) != null) {
+
+ if (!parseString("item", true, false)) {
+ generateStaticError(
+ ErrorCodes.E0003_STATIC_NOT_A_VALID_GRAMMAR_ELEMENT,
+ "Error while parsing: 'item' expected (for context item)!");
+ }
+
+ TypeInfo typeInfo = new TypeInfo();
+ if (parseKeyword("as")) {
+ typeInfo = SequenceType();
+ seqTypeIt = new SequenceTypeIterator(typeInfo, true, false,
+ getCurrentContext(), getCurrentLoc(), false);
+ }
+
+ boolean external = false;
+ Iterator expr = null;
+ if (parseKeyword("external")) {
+ external = true;
+ }
+
+ if (parseString(":=", true, false)) {
+ createNewContextScope();
+ expr = ExprSingle();
+ checkingPrologInitializer(expr, Context.CONTEXT_ITEM);
+ removeContextScope();
+ } else if (!external)
+ generateStaticError(
+ ErrorCodes.E0003_STATIC_NOT_A_VALID_GRAMMAR_ELEMENT,
+ "Variable declared in a prolog need to either have an initializing expression or marked external");
+
+ if (!parseString(";", true, false)) {
+ generateStaticError(
+ ErrorCodes.E0003_STATIC_NOT_A_VALID_GRAMMAR_ELEMENT,
+ "Error while parsing: ';' expected!");
+ }
+
+ if (contextItemDefined)
+ generateStaticError(
+ ErrorCodes.E0099_STATIC_CTXITEM_LATE_DUPLICATE,
+ "Duplicate context item definition");
+ else
+ contextItemDefined = true;
+
+ if (!getCurrentContext().checkVariableLocal(
+ Context.CONTEXT_ITEM))
+ getCurrentContext().registerNewContextItem();
+
+ VariableHolder vh = getCurrentContext().getVariable(
+ Context.CONTEXT_ITEM);
+ if (seqTypeIt != null) {
+ vh.setSeqTypeIt(seqTypeIt);
+ }
+
+ if (expr != null) {
+ getCurrentContext().setVariableValue(Context.CONTEXT_ITEM,
+ expr);
+ }
+ return true;
+ } else {
+ index = declareIndex;
+ }
+
+ Hashtable annotations = Annotation();
+ declareIndex = index;
if (parseKeyword("assignable")) {
- assignable = true;
+ annotations.put(VariableHolder.ASSIGNABLE_ANNOTATION, new XDMIterator[]{});
expectVar = true;
} else if (parseKeyword("unassignable")) {
expectVar = true;
@@ -1560,9 +1629,7 @@
// skippingAllowed = true;
if (qname == null) {
- generateStaticError(
- ErrorCodes.E0003_STATIC_NOT_A_VALID_GRAMMAR_ELEMENT,
- "Error while parsing: 'QName' expected!");
+ generateParseError("QName");
}
TypeInfo typeInfo = new TypeInfo();
@@ -1597,10 +1664,10 @@
}
if (external) {
getCurrentContext().registerVariable(qname, external,
- false, seqTypeIt, assignable);
+ false, seqTypeIt, annotations);
} else {
getCurrentContext().registerVariable(qname, external,
- false, null, assignable);
+ false, null, annotations);
}
// In the web service case: exposing the global variables
@@ -1612,9 +1679,10 @@
qname.getNamespacePrefix(), "get"
+ qname.getLocalPart());
TypeInfo getterTypeInfo[] = new TypeInfo[0];
+ annotations.put(FunctionSignature.NONDETERMINISTIC_ANNOTATION, new XDMIterator[]{});
getterSignature = new FunctionSignature(getterFunctionName,
getterTypeInfo, FunctionSignature.SYSTEM_FUNCTION,
- XDMIterator.EXPR_CATEGORY_SIMPLE, true, false);
+ annotations);
VariableIterator vIter = new VariableIterator(
getCurrentContext(), qname, false, getCurrentLoc());
vIter.setReturnType(typeInfo.getType());
@@ -1648,71 +1716,8 @@
index = declareIndex;
}
- if (co.isXquery11()
- && (parseStringGetResult("context", true)) != null) {
- if (!parseString("item", true, false)) {
- generateStaticError(
- ErrorCodes.E0003_STATIC_NOT_A_VALID_GRAMMAR_ELEMENT,
- "Error while parsing: 'item' expected (for context item)!");
- }
-
- TypeInfo typeInfo = new TypeInfo();
- if (parseKeyword("as")) {
- typeInfo = SequenceType();
- seqTypeIt = new SequenceTypeIterator(typeInfo, true, false,
- getCurrentContext(), getCurrentLoc(), false);
- }
-
- boolean external = false;
- Iterator expr = null;
- if (parseKeyword("external")) {
- external = true;
- }
-
- if (parseString(":=", true, false)) {
- createNewContextScope();
- expr = ExprSingle();
- checkingPrologInitializer(expr, Context.CONTEXT_ITEM);
- removeContextScope();
- } else if (!external)
- generateStaticError(
- ErrorCodes.E0003_STATIC_NOT_A_VALID_GRAMMAR_ELEMENT,
- "Variable declared in a prolog need to either have an initializing expression or marked external");
-
- if (!parseString(";", true, false)) {
- generateStaticError(
- ErrorCodes.E0003_STATIC_NOT_A_VALID_GRAMMAR_ELEMENT,
- "Error while parsing: ';' expected!");
- }
-
- if (contextItemDefined)
- generateStaticError(
- ErrorCodes.E0099_STATIC_CTXITEM_LATE_DUPLICATE,
- "Duplicate context item definition");
- else
- contextItemDefined = true;
-
- if (!getCurrentContext().checkVariableLocal(
- Context.CONTEXT_ITEM))
- getCurrentContext().registerNewContextItem();
-
- VariableHolder vh = getCurrentContext().getVariable(
- Context.CONTEXT_ITEM);
- if (seqTypeIt != null) {
- vh.setSeqTypeIt(seqTypeIt);
- }
-
- if (expr != null) {
- getCurrentContext().setVariableValue(Context.CONTEXT_ITEM,
- expr);
- }
- return true;
- } else {
- index = declareIndex;
- }
-
- FunctionOptions funOpts = functionOptions();
+ annotations = functionOptions(annotations);
if (parseKeyword("function")) {
@@ -1731,7 +1736,7 @@
.getDefaultFunctionNamespace());
// skippingAllowed = true;
- Function fn = parseFunctionDef(funOpts, qname,true);
+ Function fn = parseFunctionDef(annotations, qname,true);
if (!parseString(";", true, false)) {
generateStaticError(
ErrorCodes.E0003_STATIC_NOT_A_VALID_GRAMMAR_ELEMENT,
@@ -1803,7 +1808,68 @@
return false;
}
- private Function parseFunctionDef(FunctionOptions funOpts, QName qname, boolean allowExternal)
+ private Hashtable Annotation() throws MXQueryException {
+ Hashtable annotations = new Hashtable();
+ while (co.isXquery30() && parseString("%",true,false)) {
+ QName annName = EQName();
+ if (annName == null)
+ generateParseError("EQName");
+
+ if (annName.getNamespaceURI() == null)
+ if (annName.getNamespacePrefix() == null
+ || annName.getNamespacePrefix().equals("")) {
+ annName.setNamespaceURI(getCurrentContext()
+ .getDefaultFunctionNamespace());
+ } else {
+ annName = (QName)annName.resolveQNameNamespace(getCurrentContext(),
+ false);
+ }
+ Vector literals = new Vector();
+ if (parseString("(",true,false)) {
+ XDMIterator lit = Literal();
+ if (lit == null)
+ generateParseError("Literal");
+ else
+ literals.addElement(lit);
+ while (parseString(",", true, false)) {
+ lit = Literal();
+ if (lit == null)
+ generateParseError("Literal");
+ literals.addElement(lit);
+ }
+ parseKeywordYieldError(")");
+
+ }
+ XDMIterator [] annotationLiterals = new XDMIterator[literals.size()];
+ literals.copyInto(annotationLiterals);
+ if (annotations.containsKey(annName)) {
+ if (annName.equals(FunctionSignature.DETERMINISTIC_ANNOTATION)||
+ annName.equals(FunctionSignature.NONDETERMINISTIC_ANNOTATION)||
+ annName.equals(FunctionSignature.PRIVATE_ANNOTATION)||
+ annName.equals(FunctionSignature.PUBLIC_ANNOTATION))
+ generateStaticError(ErrorCodes.E0106_STATIC_MULTIPLE_PRIVATE_NONDET_FUNCTION,
+ "Duplicate annotation "+annName);
+ else
+ generateStaticError(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE,
+ "Duplicate annotation "+annName);
+ }
+ if (annName.equals(FunctionSignature.PRIVATE_ANNOTATION)||
+ annName.equals(FunctionSignature.PUBLIC_ANNOTATION))
+ checkVisibilityAnnotation(annotations);
+ if (annName.equals(FunctionSignature.DETERMINISTIC_ANNOTATION)||
+ annName.equals(FunctionSignature.NONDETERMINISTIC_ANNOTATION))
+ checkDeterministicAnnotation(annotations);
+ if (annName.equals(FunctionSignature.SIMPLE_ANNOTATION)||
+ annName.equals(FunctionSignature.UPDATING_ANNOTATION)||
+ annName.equals(FunctionSignature.SEQUENTIAL_ANNOTATION))
+ checkExprTypeAnnotation(annotations);
+
+ annotations.put(annName, annotationLiterals);
+ }
+ return annotations;
+ }
+
+ private Function parseFunctionDef(Hashtable annotations, QName qname, boolean allowExternal)
throws StaticException, MXQueryException {
Iterator seqTypeIt;
if (!parseString("(", true, false)) {
@@ -1856,7 +1922,7 @@
if (!returnType.isUndefined()
&& !co.isScripting()
- && funOpts.expCategory == XDMIterator.EXPR_CATEGORY_UPDATING)
+ && annotations.containsKey(FunctionSignature.UPDATING_ANNOTATION))
throw new StaticException(
ErrorCodes.U0028_UPDATE_STATIC_FUNCTION_UPDATING_RETURNTYPE,
"'updating' function must not specify a return type",
@@ -1868,7 +1934,7 @@
external = true;
// TODO: Insert runtime PUL checking for external functions
} else {
- if (funOpts.nondeterministic)
+ if (annotations.containsKey(FunctionSignature.NONDETERMINISTIC_ANNOTATION))
generateStaticError(
ErrorCodes.E0106_STATIC_MULTIPLE_PRIVATE_NONDET_FUNCTION,
"A UDF cannot be specified as nondeterminitic");
@@ -1886,13 +1952,16 @@
true, true, getCurrentContext(),
getCurrentLoc(), true); // streaming
}
+ Hashtable paramAnnotations = new Hashtable();
+ if (annotations.containsKey(FunctionSignature.SEQUENTIAL_ANNOTATION))
+ paramAnnotations.put(VariableHolder.ASSIGNABLE_ANNOTATION, new XDMIterator[]{});
getCurrentContext().registerVariable(
(QName) paramNames.elementAt(i), false,
- seqTypeIt, false);
+ seqTypeIt, annotations);
}
Iterator body;
- if (funOpts.expCategory == XDMIterator.EXPR_CATEGORY_SEQUENTIAL) {
+ if (annotations.containsKey(FunctionSignature.SEQUENTIAL_ANNOTATION)) {
body = Block();
} else {
body = EnclosedExpr(false);
@@ -1905,15 +1974,22 @@
seqTypeIt = null;
}
+ int exprCategory = XDMIterator.EXPR_CATEGORY_SIMPLE;
+ if (annotations.containsKey(FunctionSignature.UPDATING_ANNOTATION))
+ exprCategory = XDMIterator.EXPR_CATEGORY_UPDATING;
+ if (annotations.containsKey(FunctionSignature.SEQUENTIAL_ANNOTATION))
+ exprCategory = XDMIterator.EXPR_CATEGORY_SEQUENTIAL;
+
funcCallIter = new UserdefFuncCall(getCurrentContext(),
qname, paramArr, arrParamTypes, body, returnType,
- seqTypeIt, funOpts.expCategory, getCurrentLoc());
+ seqTypeIt, exprCategory, getCurrentLoc());
funcCallIter.staticInit();
funcCallIter = (UserdefFuncCall)funcCallIter.require(0);
if (!allowExternal) {
// if inline function
// compute the closure
// all variable references which are not resolved within the
+ // context
Vector subs = funcCallIter.getAllSubItersRecursive();
Vector closure = new Vector();
for (int i=0;i<subs.size();i++) {
@@ -1942,8 +2018,7 @@
fs = new FunctionSignature(qname,
arrParamTypes,
FunctionSignature.USER_DEFINED_FUNCTION,
- funOpts.expCategory, !funOpts.nondeterministic,
- funOpts.privateVisbility);
+ annotations);
// Check if the category can be resolved now
funcCallIter.getExpressionCategoryType(co.isScripting());
addedFunctions.addElement(funcCallIter);
@@ -1951,80 +2026,67 @@
} else {
fs = new FunctionSignature(qname,
arrParamTypes, FunctionSignature.EXTERNAL_FUNCTION,
- funOpts.expCategory, !funOpts.nondeterministic,
- !funOpts.privateVisbility);
+ annotations);
}
- Function fn = new Function(null, fs, funcCallIter, null, null);
+ Function fn = new Function(null, fs, funcCallIter, null, returnType);
return fn;
}
- private FunctionOptions functionOptions() throws MXQueryException {
-
- int expressionCategory = -1;
- int visibilityMode = -1;
- int deterministicMode = -1;
-
+ private Hashtable functionOptions(Hashtable annotations) throws MXQueryException {
while (true) {
int oldPos = index;
if (co.isUpdate() && parseKeyword("updating")) {
- if (expressionCategory != -1)
- generateStaticError(
- ErrorCodes.E0003_STATIC_NOT_A_VALID_GRAMMAR_ELEMENT,
- "Only a one of 'updating','sequential','simple' allowed");
- expressionCategory = XDMIterator.EXPR_CATEGORY_UPDATING;
+ checkExprTypeAnnotation(annotations);
+ annotations.put(FunctionSignature.UPDATING_ANNOTATION, new XDMIterator[]{});
} else if (co.isScripting() && parseKeyword("sequential")) {
- if (expressionCategory != -1)
- generateStaticError(
- ErrorCodes.E0003_STATIC_NOT_A_VALID_GRAMMAR_ELEMENT,
- "Only a one of 'updating','sequential','simple' allowed");
- expressionCategory = XDMIterator.EXPR_CATEGORY_SEQUENTIAL;
+ checkExprTypeAnnotation(annotations);
} else if (parseKeyword("simple")) {
- if (expressionCategory != -1)
- generateStaticError(
- ErrorCodes.E0003_STATIC_NOT_A_VALID_GRAMMAR_ELEMENT,
- "Only a one of 'updating','sequential','simple' allowed");
+ checkExprTypeAnnotation(annotations);
+ annotations.put(FunctionSignature.SEQUENTIAL_ANNOTATION, new XDMIterator[]{});
} else if (co.isXquery11() && parseKeyword("private")) {
- if (visibilityMode != -1)
- generateStaticError(
- ErrorCodes.E0106_STATIC_MULTIPLE_PRIVATE_NONDET_FUNCTION,
- "Only a one of 'private','public'allowed");
- visibilityMode = FunctionOptions.VISIBILITY_PRIVATE;
+ checkVisibilityAnnotation(annotations);
+ annotations.put(FunctionSignature.PRIVATE_ANNOTATION, new XDMIterator[]{});
} else if (co.isXquery11() && parseKeyword("public")) {
- if (visibilityMode != -1)
- generateStaticError(
- ErrorCodes.E0106_STATIC_MULTIPLE_PRIVATE_NONDET_FUNCTION,
- "Only a one of 'private','public'allowed");
- visibilityMode = FunctionOptions.VISIBILITY_PUBLIC;
+ checkVisibilityAnnotation(annotations);
+ annotations.put(FunctionSignature.PUBLIC_ANNOTATION, new XDMIterator[]{});
} else if (co.isXquery11() && parseKeyword("nondeterministic")) {
- if (deterministicMode != -1)
- generateStaticError(
- ErrorCodes.E0106_STATIC_MULTIPLE_PRIVATE_NONDET_FUNCTION,
- "Only a one of 'deterministic','nondeterministic'allowed");
- deterministicMode = FunctionOptions.EXECUTION_NONDET;
+ checkDeterministicAnnotation(annotations);
+ annotations.put(FunctionSignature.NONDETERMINISTIC_ANNOTATION, new XDMIterator[]{});
} else if (co.isXquery11() && parseKeyword("deterministic")) {
- if (deterministicMode != -1)
- generateStaticError(
- ErrorCodes.E0106_STATIC_MULTIPLE_PRIVATE_NONDET_FUNCTION,
- "Only a one of 'deterministic','nondeterministic'allowed");
- deterministicMode = FunctionOptions.EXECUTION_DET;
+ checkDeterministicAnnotation(annotations);
+ annotations.put(FunctionSignature.DETERMINISTIC_ANNOTATION, new XDMIterator[]{});
} else {
index = oldPos;
break;
}
}
+ return annotations;
+ }
- if (expressionCategory == -1)
- expressionCategory = XDMIterator.EXPR_CATEGORY_SIMPLE;
- if (visibilityMode == -1)
- visibilityMode = FunctionOptions.VISIBILITY_PUBLIC; // public
- if (deterministicMode == -1)
- deterministicMode = FunctionOptions.EXECUTION_DET;
+ void checkDeterministicAnnotation(Hashtable annotations)
+ throws StaticException {
+ if (annotations.containsKey(FunctionSignature.DETERMINISTIC_ANNOTATION) || annotations.containsKey(FunctionSignature.NONDETERMINISTIC_ANNOTATION))
+ generateStaticError(
+ ErrorCodes.E0106_STATIC_MULTIPLE_PRIVATE_NONDET_FUNCTION,
+ "Only a one of 'deterministic','nondeterministic'allowed");
+ }
- FunctionOptions fo = new FunctionOptions(expressionCategory,
- visibilityMode, deterministicMode);
+ void checkVisibilityAnnotation(Hashtable annotations)
+ throws StaticException {
+ if (annotations.containsKey(FunctionSignature.PUBLIC_ANNOTATION) || annotations.containsKey(FunctionSignature.PRIVATE_ANNOTATION))
+ generateStaticError(
+ ErrorCodes.E0106_STATIC_MULTIPLE_PRIVATE_NONDET_FUNCTION,
+ "Only a one of 'private','public'allowed");
+ }
- return fo;
+ void checkExprTypeAnnotation(Hashtable annotations) throws StaticException {
+ if (annotations.containsKey(FunctionSignature.SEQUENTIAL_ANNOTATION) ||
+ annotations.containsKey(FunctionSignature.SIMPLE_ANNOTATION) ||
+ annotations.containsKey(FunctionSignature.UPDATING_ANNOTATION))
+ generateStaticError(
+ ErrorCodes.E0003_STATIC_NOT_A_VALID_GRAMMAR_ELEMENT,
+ "Only a one of 'updating','sequential','simple' allowed");
}
private void checkingPrologInitializer(Iterator expr, QName varname)
@@ -2637,7 +2699,7 @@
extendCurrentContextScope();
getCurrentContext().registerVariable(varQName, true, seqTypeIt,
- false);
+ new Hashtable());
Context current = getCurrentContext();
return generatePatternIterator(varQName, qType, seq,
windowType, selectionType, current, outerContext, pat);
@@ -2910,7 +2972,7 @@
}
}
getCurrentContext().registerVariable(varQName, true, seqTypeIt,
- false);
+ new Hashtable());
return generateForseqIterator(varQName, qType, seq, windowType,
outerContext, startVars, startExpr, forceEnd, endVars,
@@ -2973,7 +3035,7 @@
}
if (windowType == 0) {
getCurrentContext().registerVariable(varQName, true, seqTypeIt,
- false);
+ new Hashtable());
return new ForseqGeneralIterator(getCurrentContext(),
windowType, varQName, qType, seq,
ForseqIterator.ORDER_MODE_END, getCurrentLoc());
@@ -3045,7 +3107,7 @@
resolveVarsOnReset = false;
getCurrentContext().registerVariable(varQName, true, seqTypeIt,
- false);
+ new Hashtable());
return generateForseqIterator(varQName, qType, seq, windowType,
outerContext, startVars, startExpr, forceEnd, endVars,
@@ -3248,7 +3310,7 @@
if ((inIt = ExprSingle()) != null) {
// wait with the new context until in is parsed
extendCurrentContextScope().registerVariable(q, true,
- seqTypeIt, false);
+ seqTypeIt, new Hashtable());
if (p != null) {
getCurrentContext().registerVariable(p, true);
@@ -3302,7 +3364,7 @@
// parsed
extendCurrentContextScope()
.registerVariable(qname, false,
- seqTypeIt, false);
+ seqTypeIt, new Hashtable());
if (p1 != null) {
getCurrentContext().registerVariable(
p1, true);
@@ -3452,7 +3514,7 @@
if (score) {
useFTScoring = false;
extendCurrentContextScope().registerVariable(q,
- false, seqTypeIt, false);
+ false, seqTypeIt, new Hashtable());
Score s = new Score(inIt, getCurrentContext(),
getCurrentLoc());
its.insertElementAt(new LetIterator(
@@ -3461,7 +3523,7 @@
} else {
extendCurrentContextScope().registerVariable(q,
- false, seqTypeIt, false);
+ false, seqTypeIt, new Hashtable());
its.insertElementAt(new LetIterator(
getCurrentContext(),
new Iterator[] { inIt }, q, t,
@@ -3506,7 +3568,7 @@
if ((inIt1 = ExprSingle()) != null) {
extendCurrentContextScope()
.registerVariable(qname, false,
- seqTypeIt, false);
+ seqTypeIt, new Hashtable());
its.insertElementAt(new LetIterator(
getCurrentContext(),
new Iterator[] { inIt1 }, qname,
@@ -3680,11 +3742,12 @@
}
private TypeInfo FunctionTest() throws MXQueryException {
+ Hashtable annotations = Annotation();
if (parseKeyword("function"))
if (parseString("(",true,false)) {
if (parseString("*",true,false)) {
parseKeywordYieldError(")");
- return new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE);
+ return new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE,null,null,annotations);
} else {
Vector params = new Vector();
TypeInfo param;
@@ -3709,7 +3772,7 @@
TypeInfo returnType = TypeDeclaration();
TypeInfo [] paramTypes = new TypeInfo[params.size()];
params.copyInto(paramTypes);
- return new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE,paramTypes,returnType);
+ return new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE,paramTypes,returnType,annotations);
}
}
@@ -3986,7 +4049,7 @@
createNewContextScope();
inIt.setContext(getCurrentContext(), true);
getCurrentContext().registerVariable(q, false,
- seqTypeIt, false);
+ seqTypeIt, new Hashtable());
inIt = new ForIterator(getCurrentContext(),
new Iterator[] { inIt }, q, t, null,
getCurrentLoc(), false);
@@ -4014,7 +4077,7 @@
if ((inIt1 = ExprSingle()) != null) {
extendCurrentContextScope()
.registerVariable(qname, false,
- seqTypeIt, false);
+ seqTypeIt, new Hashtable());
inIt1 = new ForIterator(
getCurrentContext(),
new Iterator[] { inIt1 },
@@ -6517,7 +6580,7 @@
private Iterator InlineFunction() throws MXQueryException {
int startIndex = index;
if (parseKeyword("function")) {
- Function fn = parseFunctionDef(new FunctionOptions(XDMIterator.EXPR_CATEGORY_SIMPLE, FunctionOptions.VISIBILITY_PUBLIC, FunctionOptions.EXECUTION_DET), null, false);
+ Function fn = parseFunctionDef(new Hashtable(), null, false);
if (fn == null) {
index = startIndex;
return null;
@@ -7135,7 +7198,7 @@
}
TypeInfo [] wType = new TypeInfo[types.size()];
types.copyInto(wType);
- FunctionSignature fs = new FunctionSignature(null,wType,FunctionSignature.USER_DEFINED_FUNCTION,sig.getExpressionCategory(),sig.isNonDeterministic(),sig.isPrivateFunction());
+ FunctionSignature fs = new FunctionSignature(null,wType,FunctionSignature.USER_DEFINED_FUNCTION,sig.getAllAnnotations());
FunctionItemWrapperIterator fi = new FunctionItemWrapperIterator(getCurrentContext(),it, placeHolders, applied,getCurrentLoc());
Function fu = new Function(null,fs,fi,null,null);
FunctionItemToken ft = new FunctionItemToken(fu);
@@ -8648,8 +8711,10 @@
getCurrentContext(), getCurrentLoc(), false);
}
try {
+ Hashtable annotations = new Hashtable();
+ annotations.put(VariableHolder.ASSIGNABLE_ANNOTATION, new XDMIterator[]{});
getCurrentContext().registerVariable(varName, false,
- seqTypeIt, true);
+ seqTypeIt, annotations);
} catch (StaticException se) {
if (se.getErrorCode()
.equals(ErrorCodes.E0049_STATIC_MODULE_DUPLICATE_VARIABLE_NAMES))
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/parser/SchemaParser.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/parser/SchemaParser.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/parser/SchemaParser.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -48,6 +48,7 @@
import ch.ethz.mxquery.functions.FunctionSignature;
import ch.ethz.mxquery.functions.xs.XSConstructorIterator;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
import ch.ethz.mxquery.util.URIUtils;
public class SchemaParser implements DOMErrorHandler {
@@ -288,9 +289,10 @@
TypeInfo[] paramTypes = new TypeInfo[1];
paramTypes[0] = new TypeInfo(Type.ITEM,
Type.OCCURRENCE_IND_ZERO_OR_MORE);
+ Hashtable annotations = new Hashtable();
+ annotations.put(FunctionSignature.PRIVATE_ANNOTATION, new XDMIterator[]{});
FunctionSignature signature = new FunctionSignature(qn, paramTypes,
- FunctionSignature.SYSTEM_FUNCTION,
- XDMIterator.EXPR_CATEGORY_SIMPLE, false, true);
+ FunctionSignature.SYSTEM_FUNCTION,annotations);
XDMIterator it = XSConstructorIterator.getBaseTypeConstructor(ctx, Type.getTypeFootprint(
qn, dict), dict);
if (it != null) {
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/webservice/WSDLHandler.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/webservice/WSDLHandler.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/webservice/WSDLHandler.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -314,7 +314,10 @@
// only function name and arity
params[i] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE);
}
- FunctionSignature signature = new FunctionSignature(functionName,params,FunctionSignature.EXTERNAL_FUNCTION,XDMIterator.EXPR_CATEGORY_SEQUENTIAL,true, false);
+ Hashtable annotations = new Hashtable();
+ annotations.put(FunctionSignature.SEQUENTIAL_ANNOTATION,new XDMIterator[]{});
+ annotations.put(FunctionSignature.NONDETERMINISTIC_ANNOTATION,new XDMIterator[]{});
+ FunctionSignature signature = new FunctionSignature(functionName,params,FunctionSignature.EXTERNAL_FUNCTION,annotations);
Function function = new Function(null,signature,wf, null, null);
context.addFunction(function, true, true);
}
Modified: trunk/MXQuery/src/examples/ExternalFunctionExample.java
======================================...
[truncated message content] |
|
From: <et...@us...> - 2011-05-23 09:59:14
|
Revision: 4365
http://mxquery.svn.sourceforge.net/mxquery/?rev=4365&view=rev
Author: etterth
Date: 2011-05-23 09:59:07 +0000 (Mon, 23 May 2011)
Log Message:
-----------
- fixed Java Import (broke it in revision #4361)
Revision Links:
--------------
http://mxquery.svn.sourceforge.net/mxquery/?rev=4361&view=rev
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-23 07:03:46 UTC (rev 4364)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-23 09:59:07 UTC (rev 4365)
@@ -1,21 +1,223 @@
package ch.ethz.mxquery.functions;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.QName;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
+import ch.ethz.mxquery.iterators.NativeFuncCall;
+import ch.ethz.mxquery.model.XDMIterator;
public class NativeFunctionImporter {
-
+ static class MethodData {
+ Class baseClass;
+ String methodName;
+ TypeInfo [] paramTypes;
+ TypeInfo returnType;
+
+ public MethodData(Class baseClass, String methodName,
+ TypeInfo[] paramTypes, TypeInfo returnType) {
+ super();
+ this.baseClass = baseClass;
+ this.methodName = methodName;
+ this.paramTypes = paramTypes;
+ this.returnType = returnType;
+ }
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((baseClass == null) ? 0 : baseClass.hashCode());
+ result = prime * result
+ + ((methodName == null) ? 0 : methodName.hashCode());
+ result = prime * result + paramTypes.length;
+ return result;
+ }
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ MethodData other = (MethodData) obj;
+ if (baseClass == null) {
+ if (other.baseClass != null)
+ return false;
+ } else if (!baseClass.equals(other.baseClass))
+ return false;
+ if (methodName == null) {
+ if (other.methodName != null)
+ return false;
+ } else if (!methodName.equals(other.methodName))
+ return false;
+ if (paramTypes == null) {
+ if (other.paramTypes != null)
+ return false;
+ }else if (paramTypes.length != other.paramTypes.length)
+ return false;
+ return true;
+ }
+
+ }
+
public static Context getNativeMethods(String uri) throws MXQueryException{
String className = uri.substring(5);
Context ctx = new Context();
- throw new MXQueryException(ErrorCodes.A0002_EC_NOT_SUPPORTED, "Import of native methods not supported", QueryLocation.OUTSIDE_QUERY_LOC);
+
+ try {
+ Class toImport = Class.forName(className);
+
+ Map functions = new HashMap();
+
+ Constructor [] constructors = toImport.getConstructors();
+ for (int i=0;i<constructors.length;i++) {
+ Constructor cur = constructors[i];
+ int mod = cur.getModifiers();
+ if (Modifier.isPublic(mod)) {
+ TypeInfo [] params;
+ Class [] paramTypes = cur.getParameterTypes();
+ params = new TypeInfo[paramTypes.length];
+ for (int j=0;j<params.length;j++) {
+ params[j] = getXQueryType(paramTypes[j]);
+ }
+ MethodData md = new MethodData(toImport, "new", params, new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE));
+ if (!functions.containsKey(md))
+ functions.put(md,md);
+ else {
+ MethodData existingMd = (MethodData)functions.get(md);
+ for (int j=0;j<existingMd.paramTypes.length;j++) {
+ if (!params[j].equals(existingMd.paramTypes [j])) {
+ if (Type.isNumericPrimitiveType(params[j].getType()) && Type.isNumericPrimitiveType(existingMd.paramTypes[j].getType()))
+ existingMd.paramTypes[j] = new TypeInfo(Type.NUMBER,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ else
+ if (Type.isAtomicType(params[j].getType(), Context.getDictionary()) && Type.isAtomicType(existingMd.paramTypes[j].getType(),Context.getDictionary()))
+ existingMd.paramTypes[j] = new TypeInfo(Type.ANY_ATOMIC_TYPE,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ else
+ existingMd.paramTypes[j] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ }
+ }
+ }
+
+ }
+ }
+
+ Method [] methods = toImport.getMethods();
+
+ for (int i=0;i<methods.length;i++) {
+ Method cur = methods[i];
+ int mod = cur.getModifiers();
+ if (Modifier.isPublic(mod)) {
+ String name = cur.getName();
+ Class [] paramTypes = cur.getParameterTypes();
+ TypeInfo [] params = new TypeInfo[paramTypes.length];
+ if (Modifier.isStatic(mod)) {
+ params = new TypeInfo[paramTypes.length];
+ for (int j=0;j<params.length;j++) {
+ params[j] = getXQueryType(paramTypes[j]);
+ }
+ }
+ else {
+ params = new TypeInfo[paramTypes.length+1];
+ params[0] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ for (int j=1;j<params.length;j++) {
+ params[j] = getXQueryType(paramTypes[j-1]);
+ }
+ }
+ TypeInfo resultType = getXQueryType(cur.getReturnType());
+ MethodData md = new MethodData(toImport, name, params, resultType);
+ if (!functions.containsKey(md))
+ functions.put(md,md);
+ else {
+ MethodData existingMd = (MethodData)functions.get(md);
+ for (int j=0;j<existingMd.paramTypes.length;j++) {
+ if (!params[j].equals(existingMd.paramTypes [j])) {
+ if (Type.isNumericPrimitiveType(params[j].getType()) && Type.isNumericPrimitiveType(existingMd.paramTypes[j].getType()))
+ existingMd.paramTypes[j] = new TypeInfo(Type.NUMBER,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ else
+ existingMd.paramTypes[j] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ //throw new StaticException(ErrorCodes.A0020_Incompatible_Overload, "Overloaded Java Function "+className+"."+name+" could not be mapped", QueryLocation.OUTSIDE_QUERY_LOC);
+ }
+ }
+ }
+
+ }
+ }
+
+ Field [] fields = toImport.getFields();
+
+ for (int i=0;i<fields.length;i++) {
+ Field cur = fields[i];
+ int mod = cur.getModifiers();
+ if (Modifier.isPublic(mod)) {
+ String name = cur.getName();
+ TypeInfo[] params;
+ if (Modifier.isStatic(mod)) {
+ params = new TypeInfo[0];
+ }
+ else {
+ params = new TypeInfo[1];
+ params[0] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ }
+ TypeInfo resultType = getXQueryType(cur.getType());
+ MethodData md = new MethodData(toImport, name, params, resultType);
+ if (!functions.containsKey(md))
+ functions.put(md,md);
+ }
+ }
+
+ java.util.Iterator allFuncts = functions.values().iterator();
+ while (allFuncts.hasNext()) {
+ MethodData md = (MethodData)allFuncts.next();
+ QName qn = new QName("java:"+className,"javamethod",md.methodName);
+ FunctionSignature fs = new FunctionSignature(qn, md.paramTypes,FunctionSignature.EXTERNAL_FUNCTION,XDMIterator.EXPR_CATEGORY_SEQUENTIAL,true,false);
+ Function fn = new Function(null, fs, new NativeFuncCall(ctx, md.paramTypes, toImport, md.methodName, md.returnType, null, XDMIterator.EXPR_CATEGORY_SIMPLE, QueryLocation.OUTSIDE_QUERY_LOC), null, null);
+ ctx.addFunction(fn);
+ }
+ } catch (ClassNotFoundException e) {
+ throw new StaticException(ErrorCodes.A0019_Unknown_Class, "Class "+className+" could not be found", QueryLocation.OUTSIDE_QUERY_LOC);
+ }
+ return ctx;
}
+ private static TypeInfo getXQueryType(Class class1) {
+
+ if (class1.isPrimitive()) {
+ if (class1.getName().equals("long"))
+ return new TypeInfo(Type.LONG,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ if (class1.getName().equals("double"))
+ return new TypeInfo(Type.DOUBLE,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ if (class1.getName().equals("float"))
+ return new TypeInfo(Type.FLOAT,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ if (class1.getName().equals("int"))
+ return new TypeInfo(Type.INT,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ if (class1.getName().equals("boolean"))
+ return new TypeInfo(Type.BOOLEAN,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ System.out.println(class1.getPackage()+" "+class1.getName());
+ return new TypeInfo(Type.UNTYPED_ATOMIC,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ }
+ if (class1.getName().equals("java.lang.String"))
+ return new TypeInfo(Type.STRING,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ if (class1.getName().equals("java.lang.CharSequence"))
+ return new TypeInfo(Type.STRING,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ if (class1.getName().equals("java.lang.Double"))
+ return new TypeInfo(Type.DOUBLE,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ if (class1.getName().equals("java.lang.Float"))
+ return new TypeInfo(Type.FLOAT,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ return new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE);
+ }
public static boolean isNativeUri(String uri) {
return uri.startsWith("java:");
}
-}
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|