tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adrianocrest...@apache.org
Subject svn commit: r673278 - in /tuscany/java/sca/modules/databinding-saxon/src/main: java/org/apache/tuscany/sca/databinding/saxon/ resources/META-INF/services/
Date Wed, 02 Jul 2008 04:53:51 GMT
Author: adrianocrestani
Date: Tue Jul  1 21:53:50 2008
New Revision: 673278

URL: http://svn.apache.org/viewvc?rev=673278&view=rev
Log:
-adding support to implementation.xquery for xquery execution results that returns only one
value but the caller is expecting one array

Added:
    tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2JavaArrayTransformer.java
    tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2JavaArray.java
Modified:
    tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/ItemList2ObjectTransformer.java
    tuscany/java/sca/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer

Modified: tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/ItemList2ObjectTransformer.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/ItemList2ObjectTransformer.java?rev=673278&r1=673277&r2=673278&view=diff
==============================================================================
--- tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/ItemList2ObjectTransformer.java
(original)
+++ tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/ItemList2ObjectTransformer.java
Tue Jul  1 21:53:50 2008
@@ -109,7 +109,7 @@
 									.transform((NodeInfo) item, context);
 
 						} else if (item instanceof Value) {
-							result[i] = Value.convert(item);
+							result[i] = Value.convertToJava(item);
 
 						} else {
 							result[i] = item;
@@ -143,7 +143,7 @@
 			} else {
 
 				try {
-					return Value.convert(item);
+					return Value.convertToJava(item);
 
 				} catch (XPathException e) {
 					throw new TransformationException(e);

Added: tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2JavaArrayTransformer.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2JavaArrayTransformer.java?rev=673278&view=auto
==============================================================================
--- tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2JavaArrayTransformer.java
(added)
+++ tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2JavaArrayTransformer.java
Tue Jul  1 21:53:50 2008
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.tuscany.sca.databinding.saxon;
+
+import java.lang.reflect.Array;
+
+import net.sf.saxon.om.Item;
+import net.sf.saxon.om.NodeInfo;
+import net.sf.saxon.trans.XPathException;
+import net.sf.saxon.value.Value;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.apache.tuscany.sca.databinding.saxon.collection.ItemList;
+
+import commonj.sdo.DataObject;
+
+/**
+ * Transforms a NodeInfo object to a DataObject and return it in an array.
+ * 
+ * @version $Rev: 659284 $ $Date: 2008-05-22 14:26:18 -0800 (Thu, 22 May 2008) $
+ */
+public class NodeInfo2JavaArrayTransformer extends
+		BaseTransformer<NodeInfo, Object[]> implements
+		PullTransformer<NodeInfo, Object[]> {
+
+	private NodeInfo2DataObjectTransformer nodeInfo2DataObjectTransformer = new NodeInfo2DataObjectTransformer();
+
+	public NodeInfo2JavaArrayTransformer() {}
+
+	@Override
+	protected Class<NodeInfo> getSourceType() {
+		return NodeInfo.class;
+	}
+
+	@Override
+	protected Class<Object[]> getTargetType() {
+		return Object[].class;
+	}
+
+	@Override
+	public int getWeight() {
+		return 30 + nodeInfo2DataObjectTransformer.getWeight();
+	}
+
+	public Object[] transform(NodeInfo source, TransformationContext context) {
+		Object object = nodeInfo2DataObjectTransformer.transform(source, context);
+		
+		Class<?> componentClass = context.getTargetDataType().getPhysical().getComponentType();
+		Object[] result = (Object[]) Array.newInstance(componentClass, 1);
+		
+		result[0] = object;
+		
+		return result;
+
+	}
+
+}

Added: tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2JavaArray.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2JavaArray.java?rev=673278&view=auto
==============================================================================
--- tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2JavaArray.java
(added)
+++ tuscany/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2JavaArray.java
Tue Jul  1 21:53:50 2008
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.tuscany.sca.databinding.saxon;
+
+import java.lang.reflect.Array;
+
+import net.sf.saxon.om.Item;
+import net.sf.saxon.om.NodeInfo;
+import net.sf.saxon.trans.XPathException;
+import net.sf.saxon.value.Value;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.apache.tuscany.sca.databinding.saxon.collection.ItemList;
+
+/**
+ * Transforms a Value object to a Java Object and return it in an array.
+ * 
+ * @version $Rev: 659284 $ $Date: 2008-05-22 14:26:18 -0800 (Thu, 22 May 2008) $
+ */
+public class Value2JavaArray extends
+		BaseTransformer<Value, Object[]> implements
+		PullTransformer<Value, Object[]> {
+
+	public Value2JavaArray() {}
+
+	@Override
+	protected Class<Value> getSourceType() {
+		return Value.class;
+	}
+
+	@Override
+	protected Class<Object[]> getTargetType() {
+		return Object[].class;
+	}
+
+	@Override
+	public int getWeight() {
+		return super.getWeight() + 100;
+	}
+
+	public Object[] transform(Value source, TransformationContext context) {
+		
+		try {
+			Object object = Value.convertToJava(Value.asItem(source));
+			
+			Class<?> componentClass = context.getTargetDataType().getPhysical().getComponentType();
+			Object[] result = (Object[]) Array.newInstance(componentClass, 1);
+			
+			result[0] = object;
+			
+			return result;
+			
+		} catch (XPathException e) {
+			throw new TransformationException(e.getMessage());
+		}
+
+	}
+
+}

Modified: tuscany/java/sca/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer?rev=673278&r1=673277&r2=673278&view=diff
==============================================================================
--- tuscany/java/sca/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
(original)
+++ tuscany/java/sca/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
Tue Jul  1 21:53:50 2008
@@ -30,3 +30,5 @@
 org.apache.tuscany.sca.databinding.saxon.ItemList2ObjectTransformer;source=org.apache.tuscany.sca.databinding.saxon.collection.ItemList,target=java:complex,weight=1000
 org.apache.tuscany.sca.databinding.saxon.ItemList2ObjectTransformer;source=org.apache.tuscany.sca.databinding.saxon.collection.ItemList,target=java:simple,weight=1000
 org.apache.tuscany.sca.databinding.saxon.ItemList2ObjectTransformer;source=org.apache.tuscany.sca.databinding.saxon.collection.ItemList,target=java:array,weight=1000
+org.apache.tuscany.sca.databinding.saxon.NodeInfo2JavaArrayTransformer;source=net.sf.saxon.om.NodeInfo,target=java:array,weight=1000
+org.apache.tuscany.sca.databinding.saxon.Value2JavaArrayTransformer;source=net.sf.saxon.value.Value,target=java:array,weight=1000



Mime
View raw message