summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/databinding-saxon/src
diff options
context:
space:
mode:
authoradrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68>2008-07-02 04:53:50 +0000
committeradrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68>2008-07-02 04:53:50 +0000
commit76718176b0a45f28c5e22a9f72371958ead27559 (patch)
treefe10f6d2af91f4597ea28599f1f748fac55cd9c6 /java/sca/modules/databinding-saxon/src
parent58a3413067277196f2aa5bb298b59b87f9f7481b (diff)
-adding support to implementation.xquery for xquery execution results that returns only one value but the caller is expecting one array
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@673278 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/databinding-saxon/src')
-rw-r--r--java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/ItemList2ObjectTransformer.java4
-rw-r--r--java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2JavaArrayTransformer.java76
-rw-r--r--java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2JavaArray.java78
-rw-r--r--java/sca/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer2
4 files changed, 158 insertions, 2 deletions
diff --git a/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/ItemList2ObjectTransformer.java b/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/ItemList2ObjectTransformer.java
index 5f7c7ed858..bfd41d5557 100644
--- a/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/ItemList2ObjectTransformer.java
+++ b/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/ItemList2ObjectTransformer.java
@@ -109,7 +109,7 @@ public class ItemList2ObjectTransformer extends
.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 @@ public class ItemList2ObjectTransformer extends
} else {
try {
- return Value.convert(item);
+ return Value.convertToJava(item);
} catch (XPathException e) {
throw new TransformationException(e);
diff --git a/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2JavaArrayTransformer.java b/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2JavaArrayTransformer.java
new file mode 100644
index 0000000000..36ebac3aea
--- /dev/null
+++ b/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2JavaArrayTransformer.java
@@ -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;
+
+ }
+
+}
diff --git a/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2JavaArray.java b/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2JavaArray.java
new file mode 100644
index 0000000000..c3365c49bb
--- /dev/null
+++ b/java/sca/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2JavaArray.java
@@ -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());
+ }
+
+ }
+
+}
diff --git a/java/sca/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/java/sca/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
index 829a01b896..4d927ce53d 100644
--- a/java/sca/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
+++ b/java/sca/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
@@ -30,3 +30,5 @@ org.apache.tuscany.sca.databinding.saxon.ItemList2ObjectTransformer;source=org.a
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