diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2008-10-01 18:38:28 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2008-10-01 18:38:28 +0000 |
commit | a1f3b4775ee817492c6d4e4d6930ddca2b57facb (patch) | |
tree | c2bfc1cf09269bf2ebfb520725c7c17753e9e9c5 /java/sca/modules/databinding-jaxb/src/main | |
parent | ce12a414db052fb2d37ec5f80e1e4507f9e8a8f3 (diff) |
Adding more XmlJavaTypeAdapter support
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@700861 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/databinding-jaxb/src/main')
3 files changed, 96 insertions, 26 deletions
diff --git a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/AnyTypeXmlAdapter.java b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/AnyTypeXmlAdapter.java new file mode 100644 index 0000000000..57922e1c89 --- /dev/null +++ b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/AnyTypeXmlAdapter.java @@ -0,0 +1,39 @@ +/* + * 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.jaxb; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +/** + * This special XmlAdapter can be used by JAXB classes to annotate the references to java interfaces + */ +public class AnyTypeXmlAdapter extends XmlAdapter<Object, Object> { + + @Override + public Object marshal(Object v) throws Exception { + return v; + } + + @Override + public Object unmarshal(Object v) throws Exception { + return v; + } + +} diff --git a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DOMElementXmlAdapter.java b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DOMElementXmlAdapter.java new file mode 100644 index 0000000000..91cb39b0f2 --- /dev/null +++ b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DOMElementXmlAdapter.java @@ -0,0 +1,57 @@ +/* + * 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.jaxb; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.w3c.dom.Element; + +/** + * A generic XmlAdapter for JAXB to marshal/unmarshal between the java objects and DOM elements + */ +public class DOMElementXmlAdapter extends XmlAdapter<Element, Object> { + private Mediator mediator; + private DataType dataType; + private DataType domType; + + public DOMElementXmlAdapter(Mediator mediator, DataType dataType) { + this.mediator = mediator; + this.dataType = dataType; + this.domType = new DataTypeImpl(DOMDataBinding.NAME, Element.class, dataType.getLogical()); + } + + @Override + public Element marshal(Object value) throws Exception { + return (Element) mediator.mediate(value, dataType, domType, null); + } + + @Override + public Object unmarshal(Element element) throws Exception { + return mediator.mediate(element, domType, dataType, null); + } + + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } +} diff --git a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java index 7297399f5e..5265184ba6 100644 --- a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java +++ b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java @@ -18,7 +18,6 @@ */ package org.apache.tuscany.sca.databinding.jaxb; -import java.io.IOException; import java.lang.reflect.GenericArrayType; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -34,15 +33,12 @@ import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBIntrospector; import javax.xml.bind.Marshaller; -import javax.xml.bind.SchemaOutputResolver; import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSchema; import javax.xml.bind.annotation.XmlType; import javax.xml.namespace.QName; -import javax.xml.transform.Result; -import javax.xml.transform.dom.DOMResult; import org.apache.tuscany.sca.databinding.TransformationContext; import org.apache.tuscany.sca.databinding.TransformationException; @@ -53,7 +49,6 @@ import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; import org.apache.tuscany.sca.interfacedef.util.XMLType; -import org.w3c.dom.Node; /** * @@ -444,25 +439,4 @@ public class JAXBContextHelper { return name.substring(0, decap).toLowerCase() + name.substring(decap); } - public static Node generateSchema(JAXBContext context) throws Exception { - SchemaOutputResolverImpl resolver = new SchemaOutputResolverImpl(); - context.generateSchema(resolver); - return resolver.getSchema(); - } - - public static class SchemaOutputResolverImpl extends SchemaOutputResolver { - private DOMResult result = new DOMResult(); - - @Override - public Result createOutput(String ns, String file) throws IOException { - result.setSystemId("sca:dom"); - return result; - } - - public Node getSchema() { - return result != null ? result.getNode() : null; - } - - } - } |