From d683dc4b30c79348b5e73f0f11b1cfd8ce4b9812 Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 19 May 2010 00:53:52 +0000 Subject: Merge branch 'jaxrs' into trunk git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@945980 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/databinding/DataBindingContext.java | 95 ++++++++++++++++++++++ .../sca/databinding/xml/InputSource2Node.java | 11 ++- .../sca/databinding/xml/InputStream2Node.java | 9 +- .../sca/databinding/xml/Node2OutputStream.java | 9 +- .../tuscany/sca/databinding/xml/Node2String.java | 10 ++- .../tuscany/sca/databinding/xml/Node2Writer.java | 9 +- .../tuscany/sca/databinding/xml/Reader2Node.java | 10 ++- .../databinding/xml/Source2ResultTransformer.java | 12 ++- .../databinding/xml/Source2StringTransformer.java | 12 ++- 9 files changed, 164 insertions(+), 13 deletions(-) create mode 100644 sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingContext.java (limited to 'sca-java-2.x/trunk/modules/databinding/src/main/java/org') 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 getAnnotation(Class 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 implements PullTransformer { - 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 implements PullTransformer { - 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 implements PushTransformer { - 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 implements PullTransformer { - 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 implements PushTransformer { - 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 implements PullTransformer { - 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 implements PushTransformer { - 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 implements PullTransformer { - 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); -- cgit v1.2.3