diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-18 22:16:59 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-18 22:16:59 +0000 |
commit | d66ee8eaa28332cd66237e9cfd588254c346802f (patch) | |
tree | 0a9d44d770aae09a063fc80c5eaedbdd284e3137 /java/sca/modules | |
parent | 3f213f98b66f3f57e6a061fc63cc5ae35adafe1b (diff) |
Fix a regression caused by r755474
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@755756 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules')
3 files changed, 127 insertions, 74 deletions
diff --git a/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java b/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java index 12a2c6feb8..de861103c4 100644 --- a/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java +++ b/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java @@ -23,6 +23,7 @@ import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.ModuleActivator; import org.apache.tuscany.sca.core.databinding.processor.DataBindingJavaInterfaceProcessor; +import org.apache.tuscany.sca.core.databinding.processor.WrapperJavaInterfaceProcessor; import org.apache.tuscany.sca.core.databinding.transformers.Array2ArrayTransformer; import org.apache.tuscany.sca.core.databinding.transformers.CallableReferenceXMLAdapter; import org.apache.tuscany.sca.core.databinding.transformers.Exception2ExceptionTransformer; @@ -86,7 +87,7 @@ public class DataBindingModuleActivator implements ModuleActivator { // Introspect the data types javaFactory.addInterfaceVisitor(new DataBindingJavaInterfaceProcessor(dataBindings)); javaFactory.addInterfaceVisitor(new JAXWSJavaInterfaceProcessor(dataBindings, faultExceptionMapper, xmlAdapterExtensionPoint)); - + javaFactory.addInterfaceVisitor(new WrapperJavaInterfaceProcessor(dataBindings)); RuntimeWireProcessorExtensionPoint wireProcessorExtensionPoint = registry.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class); if (wireProcessorExtensionPoint != null) { diff --git a/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java b/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java index e182b472d4..53a4aeca00 100644 --- a/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java +++ b/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java @@ -22,24 +22,17 @@ package org.apache.tuscany.sca.core.databinding.processor; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Set; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.WrapperHandler; import org.apache.tuscany.sca.databinding.annotation.DataBinding; -import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; -import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.java.JavaOperation; import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; -import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; /** * The databinding annotation processor for java interfaces @@ -47,7 +40,6 @@ import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; * @version $Rev$ $Date$ */ public class DataBindingJavaInterfaceProcessor implements JavaInterfaceVisitor { - private static final String JAXB_DATABINDING = "javax.xml.bind.JAXBElement"; private DataBindingExtensionPoint dataBindingRegistry; public DataBindingJavaInterfaceProcessor(DataBindingExtensionPoint dataBindingRegistry) { @@ -140,71 +132,6 @@ public class DataBindingJavaInterfaceProcessor implements JavaInterfaceVisitor { // TODO: Handle exceptions dataBindingRegistry.introspectType(d, operation); } - - // JIRA: TUSCANY-842 - String db = operation.getDataBinding(); - if (db == null || JAXB_DATABINDING.equals(db)) { - assignOperationDataBinding(operation); - db = operation.getDataBinding(); - } - - // Introspect the wrapper data type - if (operation.getWrapper() != null) { - org.apache.tuscany.sca.databinding.DataBinding dbObj = - dataBindingRegistry.getDataBinding(db); - WrapperHandler handler = dbObj == null ? null : dbObj.getWrapperHandler(); - if (handler != null) { - WrapperInfo wrapper = operation.getWrapper(); - wrapper.setInputWrapperType(handler.getWrapperType(operation, true)); - wrapper.setOutputWrapperType(handler.getWrapperType(operation, false)); - } - if (dbObj != null && handler == null) { - // To avoid JAXB wrapper bean generation - WrapperInfo wrapper = operation.getWrapper(); - wrapper.setInputWrapperType(null); - wrapper.setOutputWrapperType(null); - } - } - } - } - - /* - * Assigns an operation DB if one of the input types, output type, fault types has a non-default DB. - * However, if two of the input types, output type, fault types have two different non-default DBs - * ( e.g. SDO and JAXB), then we do nothing to the operation DB. - * - * The method logic assumes the JavaBeans DataBinding is the default - */ - private void assignOperationDataBinding(Operation operation) { - - Set<String> dbs = new HashSet<String>(); - - // Can't use DataType<?> since operation.getInputType() returns: DataType<List<DataType>> - List<DataType> opDataTypes = new LinkedList<DataType>(); - - opDataTypes.addAll(operation.getInputType().getLogical()); - opDataTypes.add(operation.getOutputType()); - for (DataType<DataType> ft : operation.getFaultTypes()) { - opDataTypes.add(ft.getLogical()); - } - - for (DataType<?> d : opDataTypes) { - if (d != null) { - String dataBinding = d.getDataBinding(); - if ("java:array".equals(dataBinding)) { - dataBinding = ((DataType)d.getLogical()).getDataBinding(); - } - if (dataBinding != null) { - dbs.add(dataBinding); - } - } - } - - dbs.remove(JavaBeansDataBinding.NAME); - dbs.remove(SimpleJavaDataBinding.NAME); - - if (dbs.size() == 1) { - operation.setDataBinding(dbs.iterator().next()); } } } diff --git a/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/WrapperJavaInterfaceProcessor.java b/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/WrapperJavaInterfaceProcessor.java new file mode 100644 index 0000000000..7f2e3fa23d --- /dev/null +++ b/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/WrapperJavaInterfaceProcessor.java @@ -0,0 +1,125 @@ +/* + * 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.core.databinding.processor; + +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; +import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; + +/** + * The databinding annotation processor for java interfaces + * + * @version $Rev$ $Date$ + */ +public class WrapperJavaInterfaceProcessor implements JavaInterfaceVisitor { + private static final String JAXB_DATABINDING = "javax.xml.bind.JAXBElement"; + private DataBindingExtensionPoint dataBindingRegistry; + + public WrapperJavaInterfaceProcessor(DataBindingExtensionPoint dataBindingRegistry) { + super(); + this.dataBindingRegistry = dataBindingRegistry; + } + + public void visitInterface(JavaInterface javaInterface) throws InvalidInterfaceException { + if (!javaInterface.isRemotable()) { + return; + } + for (Operation operation : javaInterface.getOperations()) { + WrapperInfo wrapper = operation.getWrapper(); + if (wrapper == null) { + continue; + } + // JIRA: TUSCANY-842 + String db = wrapper.getDataBinding(); + if (db == null || JAXB_DATABINDING.equals(db)) { + db = assignOperationDataBinding(operation); + } + + // Introspect the wrapper data type + org.apache.tuscany.sca.databinding.DataBinding dbObj = dataBindingRegistry.getDataBinding(db); + WrapperHandler handler = dbObj == null ? null : dbObj.getWrapperHandler(); + if (handler != null) { + wrapper.setInputWrapperType(handler.getWrapperType(operation, true)); + wrapper.setOutputWrapperType(handler.getWrapperType(operation, false)); + } + if (dbObj != null && handler == null) { + // To avoid JAXB wrapper bean generation + wrapper.setInputWrapperType(null); + wrapper.setOutputWrapperType(null); + } + } + } + + /* + * Assigns an operation DB if one of the input types, output type, fault types has a non-default DB. + * However, if two of the input types, output type, fault types have two different non-default DBs + * ( e.g. SDO and JAXB), then we do nothing to the operation DB. + * + * The method logic assumes the JavaBeans DataBinding is the default + */ + private String assignOperationDataBinding(Operation operation) { + + Set<String> dbs = new HashSet<String>(); + + // Can't use DataType<?> since operation.getInputType() returns: DataType<List<DataType>> + List<DataType> opDataTypes = new LinkedList<DataType>(); + + opDataTypes.addAll(operation.getInputType().getLogical()); + opDataTypes.add(operation.getOutputType()); + for (DataType<DataType> ft : operation.getFaultTypes()) { + opDataTypes.add(ft.getLogical()); + } + + for (DataType<?> d : opDataTypes) { + if (d != null) { + String dataBinding = d.getDataBinding(); + if ("java:array".equals(dataBinding)) { + dataBinding = ((DataType)d.getLogical()).getDataBinding(); + } + if (dataBinding != null) { + dbs.add(dataBinding); + } + } + } + + dbs.remove(JavaBeansDataBinding.NAME); + dbs.remove(SimpleJavaDataBinding.NAME); + + if (dbs.size() == 1) { + String db = dbs.iterator().next(); + operation.getWrapper().setDataBinding(db); + return db; + } else { + return operation.getWrapper().getDataBinding(); + } + } +} |