summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/databinding/src/main
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-05-19 00:53:52 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-05-19 00:53:52 +0000
commitd683dc4b30c79348b5e73f0f11b1cfd8ce4b9812 (patch)
tree3b64741b708c3e13a6a301f7df21bec070547bfc /sca-java-2.x/trunk/modules/databinding/src/main
parenta0bfd24b7af22df3174e1c1e4e6d2eb913f41d2f (diff)
Merge branch 'jaxrs' into trunk
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@945980 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/databinding/src/main')
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingContext.java95
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java11
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java9
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java9
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java10
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java9
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java10
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java12
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2StringTransformer.java12
9 files changed, 164 insertions, 13 deletions
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingContext.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingContext.java
new file mode 100644
index 0000000000..c77d0ad0f6
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingContext.java
@@ -0,0 +1,95 @@
+/*
+ * 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;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+
+/**
+ * The context for databinding processing
+ */
+public class DataBindingContext {
+
+ private String contentType;
+ private Class<?> type;
+ private Type genericType;
+ private Annotation[] annotations;
+ private Operation operation;
+
+ public DataBindingContext(Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ Operation operation,
+ String contentType) {
+ super();
+ this.type = type;
+ this.genericType = genericType;
+ this.annotations = annotations;
+ this.operation = operation;
+ this.contentType = contentType;
+ }
+
+ public DataBindingContext(Class<?> type, Type genericType, Annotation[] annotations) {
+ super();
+ this.type = type;
+ this.genericType = genericType;
+ this.annotations = annotations;
+ }
+
+ public DataBindingContext(Class<?> type) {
+ super();
+ this.type = type;
+ this.genericType = type;
+ }
+
+ public Class<?> getType() {
+ return type;
+ }
+
+ public Type getGenericType() {
+ return genericType;
+ }
+
+ public Annotation[] getAnnotations() {
+ return annotations;
+ }
+
+ public Operation getOperation() {
+ return operation;
+ }
+
+ public <A extends Annotation> A getAnnotation(Class<A> type) {
+ if (annotations == null) {
+ return null;
+ }
+ for (Annotation a : annotations) {
+ if (a.annotationType() == type) {
+ return type.cast(a);
+ }
+ }
+ return null;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java
index 5333d8047a..0bb0513011 100644
--- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java
@@ -22,6 +22,7 @@ import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.stream.StreamSource;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.databinding.BaseTransformer;
import org.apache.tuscany.sca.databinding.PullTransformer;
import org.apache.tuscany.sca.databinding.TransformationContext;
@@ -36,8 +37,14 @@ import org.xml.sax.InputSource;
*/
public class InputSource2Node extends BaseTransformer<InputSource, Node> implements
PullTransformer<InputSource, Node> {
- private static final Source2ResultTransformer TRANSFORMER = new Source2ResultTransformer();
-
+
+ private final Source2ResultTransformer TRANSFORMER;
+
+ public InputSource2Node(ExtensionPointRegistry registry) {
+ super();
+ this.TRANSFORMER = new Source2ResultTransformer(registry);
+ }
+
public Node transform(InputSource source, TransformationContext context) {
try {
Source streamSource = new StreamSource(source.getCharacterStream());
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java
index 31254ff2c6..c9183c4cbf 100644
--- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java
@@ -24,6 +24,7 @@ import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXSource;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.databinding.BaseTransformer;
import org.apache.tuscany.sca.databinding.PullTransformer;
import org.apache.tuscany.sca.databinding.TransformationContext;
@@ -38,8 +39,14 @@ import org.xml.sax.InputSource;
*/
public class InputStream2Node extends BaseTransformer<InputStream, Node> implements
PullTransformer<InputStream, Node> {
- private static final Source2ResultTransformer TRANSFORMER = new Source2ResultTransformer();
+ private final Source2ResultTransformer TRANSFORMER;
+
+ public InputStream2Node(ExtensionPointRegistry registry) {
+ super();
+ this.TRANSFORMER = new Source2ResultTransformer(registry);
+ }
+
public Node transform(InputStream source, TransformationContext context) {
try {
Source streamSource = new SAXSource(new InputSource(source));
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java
index bf39509e35..25ed70dda5 100644
--- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java
@@ -25,6 +25,7 @@ import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.databinding.BaseTransformer;
import org.apache.tuscany.sca.databinding.PushTransformer;
import org.apache.tuscany.sca.databinding.TransformationContext;
@@ -38,8 +39,14 @@ import org.w3c.dom.Node;
*/
public class Node2OutputStream extends BaseTransformer<Node, OutputStream> implements
PushTransformer<Node, OutputStream> {
- private static final Source2ResultTransformer TRANSFORMER = new Source2ResultTransformer();
+ private final Source2ResultTransformer TRANSFORMER;
+
+ public Node2OutputStream(ExtensionPointRegistry registry) {
+ super();
+ this.TRANSFORMER = new Source2ResultTransformer(registry);
+ }
+
public void transform(Node source, OutputStream writer, TransformationContext context) {
try {
Source domSource = new DOMSource(source);
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java
index a43354e99c..fb3023345c 100644
--- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java
@@ -20,6 +20,7 @@ package org.apache.tuscany.sca.databinding.xml;
import java.io.StringWriter;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.databinding.BaseTransformer;
import org.apache.tuscany.sca.databinding.PullTransformer;
import org.apache.tuscany.sca.databinding.TransformationContext;
@@ -32,8 +33,13 @@ import org.w3c.dom.Node;
* @version $Rev$ $Date$
*/
public class Node2String extends BaseTransformer<Node, String> implements PullTransformer<Node, String> {
- private static final Node2Writer TRANSFORMER = new Node2Writer();
-
+ private final Node2Writer TRANSFORMER;
+
+ public Node2String(ExtensionPointRegistry registry) {
+ super();
+ this.TRANSFORMER = new Node2Writer(registry);
+ }
+
public String transform(Node source, TransformationContext context) {
try {
StringWriter writer = new StringWriter();
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java
index 18561d0eeb..6c1d241ce9 100644
--- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java
@@ -25,6 +25,7 @@ import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.databinding.BaseTransformer;
import org.apache.tuscany.sca.databinding.PushTransformer;
import org.apache.tuscany.sca.databinding.TransformationContext;
@@ -37,8 +38,14 @@ import org.w3c.dom.Node;
* @version $Rev$ $Date$
*/
public class Node2Writer extends BaseTransformer<Node, Writer> implements PushTransformer<Node, Writer> {
- private static final Source2ResultTransformer TRANSFORMER = new Source2ResultTransformer();
+ private final Source2ResultTransformer TRANSFORMER;
+
+ public Node2Writer(ExtensionPointRegistry registry) {
+ super();
+ this.TRANSFORMER = new Source2ResultTransformer(registry);
+ }
+
public void transform(Node source, Writer writer, TransformationContext context) {
try {
Source domSource = new DOMSource(source);
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java
index 31adea234d..1866f3864a 100644
--- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java
@@ -24,6 +24,7 @@ import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.stream.StreamSource;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.databinding.BaseTransformer;
import org.apache.tuscany.sca.databinding.PullTransformer;
import org.apache.tuscany.sca.databinding.TransformationContext;
@@ -36,8 +37,13 @@ import org.w3c.dom.Node;
* @version $Rev$ $Date$
*/
public class Reader2Node extends BaseTransformer<Reader, Node> implements PullTransformer<Reader, Node> {
- private static final Source2ResultTransformer TRANSFORMER = new Source2ResultTransformer();
-
+ private final Source2ResultTransformer TRANSFORMER;
+
+ public Reader2Node(ExtensionPointRegistry registry) {
+ super();
+ this.TRANSFORMER = new Source2ResultTransformer(registry);
+ }
+
public Node transform(Reader source, TransformationContext context) {
try {
Source streamSource = new StreamSource(source);
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java
index da78e6f9a6..dd69e3ea66 100644
--- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java
@@ -22,6 +22,8 @@ import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerFactory;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.databinding.BaseTransformer;
import org.apache.tuscany.sca.databinding.PushTransformer;
import org.apache.tuscany.sca.databinding.TransformationContext;
@@ -34,11 +36,17 @@ import org.apache.tuscany.sca.databinding.TransformationException;
*/
public class Source2ResultTransformer extends BaseTransformer<Source, Result> implements
PushTransformer<Source, Result> {
- private static final TransformerFactory FACTORY = TransformerFactory.newInstance();
+ private final TransformerFactory factory;
+ public Source2ResultTransformer(ExtensionPointRegistry registry) {
+ super();
+ FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ factory = factories.getFactory(TransformerFactory.class);
+ }
+
public void transform(Source source, Result result, TransformationContext context) {
try {
- javax.xml.transform.Transformer transformer = FACTORY.newTransformer();
+ javax.xml.transform.Transformer transformer = factory.newTransformer();
transformer.transform(source, result);
} catch (Exception e) {
throw new TransformationException(e);
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2StringTransformer.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2StringTransformer.java
index 5cf1867b96..0c3db2a477 100644
--- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2StringTransformer.java
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2StringTransformer.java
@@ -24,6 +24,8 @@ import javax.xml.transform.Source;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.databinding.BaseTransformer;
import org.apache.tuscany.sca.databinding.PullTransformer;
import org.apache.tuscany.sca.databinding.TransformationContext;
@@ -36,11 +38,17 @@ import org.apache.tuscany.sca.databinding.TransformationException;
*/
public class Source2StringTransformer extends BaseTransformer<Source, String> implements
PullTransformer<Source, String> {
- private static final TransformerFactory FACTORY = TransformerFactory.newInstance();
+ private final TransformerFactory factory;
+ public Source2StringTransformer(ExtensionPointRegistry registry) {
+ super();
+ FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ factory = factories.getFactory(TransformerFactory.class);
+ }
+
public String transform(Source source, TransformationContext context) {
try {
- javax.xml.transform.Transformer transformer = FACTORY.newTransformer();
+ javax.xml.transform.Transformer transformer = factory.newTransformer();
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
transformer.transform(source, result);