diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2008-07-30 22:11:46 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2008-07-30 22:11:46 +0000 |
commit | ac1b197298975b185c90ab02f28a2666861f977c (patch) | |
tree | 2af110a42dc407657210ec401cfc4fdfc6040811 /java/sca/modules/binding-corba-runtime | |
parent | e29862c8a179a0f815fe16506d1d71b17a0eca9a (diff) |
Apply the patch for TUSCANY-2469 from Wojtek. (sca-binding-sdo-problem-jira-2469-30-july.patch)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@681221 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/binding-corba-runtime')
4 files changed, 105 insertions, 132 deletions
diff --git a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java index a7cc210470..fe4fabc293 100644 --- a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java +++ b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java @@ -20,9 +20,13 @@ package org.apache.tuscany.sca.binding.corba.impl; import org.apache.tuscany.sca.binding.corba.CorbaBinding; +import org.apache.tuscany.sca.binding.corba.impl.service.ComponentInvocationProxy; import org.apache.tuscany.sca.binding.corba.impl.service.DynaCorbaServant; +import org.apache.tuscany.sca.binding.corba.impl.service.InvocationProxy; +import org.apache.tuscany.sca.binding.corba.impl.types.util.Utils; import org.apache.tuscany.sca.host.corba.CorbaHost; import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.provider.ServiceBindingProvider; import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.osoa.sca.ServiceRuntimeException; @@ -55,7 +59,9 @@ public class CorbaServiceBindingProvider implements ServiceBindingProvider { */ public void start() { try { - servant = new DynaCorbaServant(service, binding); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(binding), javaClass); + servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); servant.setIds(new String[] {binding.getId()}); host.registerServant(binding.getCorbaname(), servant); } catch (Exception e) { diff --git a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java index 0d9d33b198..26f006242e 100644 --- a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java +++ b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java @@ -19,24 +19,14 @@ package org.apache.tuscany.sca.binding.corba.impl.service; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; import org.apache.tuscany.sca.binding.corba.impl.types.TypeTree; import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeCreator; import org.apache.tuscany.sca.binding.corba.impl.types.util.TypeHelpersProxy; import org.apache.tuscany.sca.binding.corba.impl.types.util.Utils; -import org.apache.tuscany.sca.binding.corba.impl.util.OperationMapper; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.interfacedef.java.JavaInterface; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.omg.CORBA.MARSHAL; import org.omg.CORBA.portable.InputStream; import org.omg.CORBA.portable.InvokeHandler; @@ -49,114 +39,23 @@ import org.omg.CORBA.portable.ResponseHandler; */ public class DynaCorbaServant extends ObjectImpl implements InvokeHandler { - private RuntimeComponentService service; - private Binding binding; private String[] ids; - private Map<Operation, OperationTypes> operationsCache = new HashMap<Operation, OperationTypes>(); - private Class<?> javaClass; - private Map<String, Method> operationsMap; - private Map<Method, Operation> methodOperationMapping; - private boolean scaBindingRules; - - /** - * Creates servant with CORBA binding mapping rules in default - * - * @param service backed service - * @param binding binding object - * @throws RequestConfigurationException - */ - public DynaCorbaServant(RuntimeComponentService service, Binding binding) throws RequestConfigurationException { - // use CORBA binding rules by default - this(service, binding, false); - } + private InvocationProxy invocationProxy; + private String typeId; /** * Creates servant object - * - * @param service backed service - * @param binding binding object - * @param scaBindingRules apply SCA default binding mapping rules + * @param invocationProxy + * @param typeId * @throws RequestConfigurationException */ - public DynaCorbaServant(RuntimeComponentService service, Binding binding, boolean scaBindingRules) throws RequestConfigurationException { - this.scaBindingRules = scaBindingRules; - this.service = service; - this.binding = binding; - this.javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); - this.operationsMap = OperationMapper.mapOperationToMethod(javaClass); - cacheOperationTypes(service.getInterfaceContract().getInterface().getOperations()); - createMethod2OperationMapping(); + public DynaCorbaServant(InvocationProxy invocationProxy, String typeId) throws RequestConfigurationException { + this.invocationProxy = invocationProxy; + this.typeId = typeId; setDefaultIds(); } /** - * Maps Java methods to Tuscany operations - */ - private void createMethod2OperationMapping() { - // for every operation find all methods with the same name, then - // compare operations and methods parameters - this.methodOperationMapping = new HashMap<Method, Operation>(); - for (Operation operation : service.getInterfaceContract().getInterface().getOperations()) { - List<DataType> inputTypes = operation.getInputType().getLogical(); - Method[] methods = javaClass.getMethods(); - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals(operation.getName()) && inputTypes.size() == methods[i] - .getParameterTypes().length) { - Class<?>[] parameterTypes = methods[i].getParameterTypes(); - int j = 0; - boolean parameterMatch = true; - for (DataType dataType : inputTypes) { - if (!dataType.getPhysical().equals(parameterTypes[j])) { - parameterMatch = false; - break; - } - j++; - } - if (parameterMatch) { - // match found - methodOperationMapping.put(methods[i], operation); - break; - } - } - } - - } - } - - /** - * Caches TypeTree for every operation in backed component - * @param operations - * @throws RequestConfigurationException - */ - private void cacheOperationTypes(List<Operation> operations) throws RequestConfigurationException { - for (Operation operation : operations) { - try { - OperationTypes operationTypes = new OperationTypes(); - List<TypeTree> inputInstances = new ArrayList<TypeTree>(); - // cache output type tree - if (operation.getOutputType() != null && operation.getOutputType().getPhysical() != null - && !operation.getOutputType().getPhysical().equals(void.class)) { - TypeTree outputType = TypeTreeCreator.createTypeTree(operation.getOutputType().getPhysical(), scaBindingRules); - operationTypes.setOutputType(outputType); - } - // cache input types trees - if (operation.getInputType() != null) { - for (DataType<List<DataType>> type : operation.getInputType().getLogical()) { - Class<?> forClass = type.getPhysical(); - TypeTree inputType = TypeTreeCreator.createTypeTree(forClass, scaBindingRules); - inputInstances.add(inputType); - } - - } - operationTypes.setInputType(inputInstances); - operationsCache.put(operation, operationTypes); - } catch (RequestConfigurationException e) { - throw e; - } - } - } - - /** * Sets CORBA object ID * @param ids */ @@ -172,16 +71,12 @@ public class DynaCorbaServant extends ObjectImpl implements InvokeHandler { } public OutputStream _invoke(String operationName, InputStream in, ResponseHandler rh) { - Operation operation = null; - Method method = operationsMap.get(operationName); - // searching for proper operation - operation = methodOperationMapping.get(method); - if (operation == null) { + OperationTypes types = invocationProxy.getOperationTypes(operationName); + if (types == null) { // operation wasn't found throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); } else { List<Object> inputInstances = new ArrayList<Object>(); - OperationTypes types = operationsCache.get(operation); try { // retrieving in arguments for (TypeTree tree : types.getInputType()) { @@ -195,19 +90,19 @@ public class DynaCorbaServant extends ObjectImpl implements InvokeHandler { } try { // invocation and sending result - Object result = service.getRuntimeWire(binding).invoke(operation, inputInstances.toArray()); + Object result = invocationProxy.invoke(operationName, inputInstances); OutputStream out = rh.createReply(); if (types.getOutputType() != null) { TypeTree tree = types.getOutputType(); TypeHelpersProxy.write(tree.getRootNode(), out, result); } return out; - } catch (InvocationTargetException ie) { + } catch (InvocationException ie) { // handling user exception try { OutputStream out = rh.createExceptionReply(); Class<?> exceptionClass = ie.getTargetException().getClass(); - TypeTree tree = TypeTreeCreator.createTypeTree(exceptionClass, scaBindingRules); + TypeTree tree = TypeTreeCreator.createTypeTree(exceptionClass, false); String exceptionId = Utils.getTypeId(exceptionClass); out.write_string(exceptionId); TypeHelpersProxy.write(tree.getRootNode(), out, ie.getTargetException()); @@ -234,8 +129,7 @@ public class DynaCorbaServant extends ObjectImpl implements InvokeHandler { * Sets servant ID to default, based on Java class name */ private void setDefaultIds() { - String id = Utils.getTypeId(javaClass); - this.ids = new String[] {id}; + this.ids = new String[] {typeId}; } } diff --git a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/InvocationProxy.java b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/InvocationProxy.java new file mode 100644 index 0000000000..f732e142b2 --- /dev/null +++ b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/InvocationProxy.java @@ -0,0 +1,45 @@ +/* + * 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.binding.corba.impl.service; + +import java.util.List; + +/** + * Target proxy interface for service bindings + */ +public interface InvocationProxy { + + /** + * Gets operations types for target + * @param operationName + * @return + */ + public OperationTypes getOperationTypes(String operationName); + + /** + * Invokes target operation + * @param operationName + * @param arguments + * @return + * @throws InvocationException + */ + public Object invoke(String operationName, List<Object> arguments) throws InvocationException; + +} diff --git a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java index 74642f1984..1ccf22140b 100644 --- a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java +++ b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java @@ -30,7 +30,10 @@ import org.apache.tuscany.sca.binding.corba.impl.exceptions.CorbaException; import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; import org.apache.tuscany.sca.binding.corba.impl.reference.DynaCorbaRequest; import org.apache.tuscany.sca.binding.corba.impl.reference.DynaCorbaResponse; +import org.apache.tuscany.sca.binding.corba.impl.service.ComponentInvocationProxy; import org.apache.tuscany.sca.binding.corba.impl.service.DynaCorbaServant; +import org.apache.tuscany.sca.binding.corba.impl.service.InvocationProxy; +import org.apache.tuscany.sca.binding.corba.impl.types.util.Utils; import org.apache.tuscany.sca.binding.corba.testing.enums.Color; import org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager; import org.apache.tuscany.sca.binding.corba.testing.enums.EnumManagerHelper; @@ -58,6 +61,7 @@ import org.apache.tuscany.sca.binding.corba.testing.servants.TestObjectServant; import org.apache.tuscany.sca.binding.corba.testing.service.mocks.TestRuntimeComponentService; import org.apache.tuscany.sca.host.corba.naming.TransientNameServer; import org.apache.tuscany.sca.host.corba.naming.TransientNameService; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -138,7 +142,9 @@ public class CorbaServantTestCase { try { PrimitivesSetter primitivesSetter = new PrimitivesSetterServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(primitivesSetter); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter:1.0"}; servant.setIds(ids); @@ -187,7 +193,9 @@ public class CorbaServantTestCase { try { ArraysSetter arraysSetter = new ArraysSetterServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(arraysSetter); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter:1.0"}; servant.setIds(ids); java.lang.Object result = null; @@ -244,7 +252,9 @@ public class CorbaServantTestCase { try { TestObject to = new TestObjectServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(to); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"}; servant.setIds(ids); bindServant(servant, "TestObject"); @@ -279,7 +289,9 @@ public class CorbaServantTestCase { try { TestObjectServant tos = new TestObjectServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(tos); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"}; servant.setIds(ids); bindServant(servant, "TestObject"); @@ -298,7 +310,9 @@ public class CorbaServantTestCase { try { InvalidTestObjectServant tos = new InvalidTestObjectServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(tos); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"}; servant.setIds(ids); bindServant(servant, "InvalidTestObject"); @@ -328,7 +342,9 @@ public class CorbaServantTestCase { try { CalcServant calc = new CalcServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(calc); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc:1.0"}; servant.setIds(ids); bindServant(servant, "Calc"); @@ -347,7 +363,9 @@ public class CorbaServantTestCase { try { CalcServant calc = new CalcServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(calc); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc:1.0"}; servant.setIds(ids); bindServant(servant, "Calc"); @@ -372,7 +390,9 @@ public class CorbaServantTestCase { try { EnumManagerServant ems = new EnumManagerServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(ems); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/enums/EnumManager:1.0"}; servant.setIds(ids); bindServant(servant, "Enum"); @@ -390,7 +410,9 @@ public class CorbaServantTestCase { try { NonCorbaServant ncs = new NonCorbaServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(ncs); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); bindServant(servant, "NonCorbaServant"); // it's non corba servant so we don't have stubs to test them DynaCorbaRequest request = new DynaCorbaRequest(bindReference("NonCorbaServant"), "setString"); @@ -406,7 +428,9 @@ public class CorbaServantTestCase { try { NonCorbaServant ncs = new NonCorbaServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(ncs); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); bindServant(servant, "NonCorbaServant"); // it's non corba servant so we don't have stubs to test them DynaCorbaRequest request = new DynaCorbaRequest(bindReference("NonCorbaServant"), "throwException"); @@ -431,7 +455,9 @@ public class CorbaServantTestCase { try { CalcServant calc = new CalcServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(calc); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"}; servant.setIds(ids); bindServant(servant, "Calc"); @@ -459,7 +485,9 @@ public class CorbaServantTestCase { InvalidTypesServant its = new InvalidTypesServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(its); //expecting exception... - new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); fail(); } catch (Exception e) { if (e instanceof RequestConfigurationException) { |