Package org.apache.tuscany.spi.model

Examples of org.apache.tuscany.spi.model.ServiceContract


public class ContractCompatibilityTestCase extends TestCase {

    private WireService wireService = new MockWireService();

    public void testNoOperation() throws Exception {
        ServiceContract source = new MockContract<Type>("FooContract");
        ServiceContract target = new MockContract<Type>("FooContract");
        wireService.checkCompatibility(source, target, false);
    }
View Full Code Here


        springContext.refresh();
        this.springContext = springContext;
    }

    public TargetInvoker createTargetInvoker(String targetName, Operation operation) {
        ServiceContract contract = operation.getServiceContract();
        Method[] methods = contract.getInterfaceClass().getMethods();
        Method method = findMethod(operation, methods);
        // FIXME test m == null
        // Treat the serviceName as the Spring bean name to look up
        return new SpringInvoker(targetName, method, springContext);
    }
View Full Code Here

            InboundWire inboundWire = reference.getInboundWire();
            Map<Operation<?>, InboundInvocationChain> inboundChains = inboundWire.getInvocationChains();
            for (InboundInvocationChain chain : inboundChains.values()) {
                //TODO handle async
                // add target invoker on inbound side
                ServiceContract contract = inboundWire.getServiceContract();
                Operation operation = chain.getOperation();
                TargetInvoker invoker = reference.createTargetInvoker(contract, operation);
                chain.setTargetInvoker(invoker);
                chain.prepare();
            }
View Full Code Here

     * @param optimizable true if the wire connection can be optimized
     */
    void connect(OutboundWire sourceWire, InboundWire targetWire, boolean optimizable) {
        SCAObject source = sourceWire.getContainer();
        SCAObject target = targetWire.getContainer();
        ServiceContract contract = sourceWire.getServiceContract();
        Map<Operation<?>, InboundInvocationChain> targetChains = targetWire.getInvocationChains();
        // perform optimization, if possible
        // REVIEW: (kentaminator@gmail.com) shouldn't this check whether the interceptors in the
        // source & target chains are marked as optimizable?  (and if so, optimize them away?)
        if (optimizable && sourceWire.getInvocationChains().isEmpty() && targetChains.isEmpty()) {
            sourceWire.setTargetWire(targetWire);
            if (postProcessorRegistry != null) {
                // run wire post-processors
                postProcessorRegistry.process(sourceWire, targetWire);
            }
            return;
        }
        // match outbound to inbound chains
        for (OutboundInvocationChain outboundChain : sourceWire.getInvocationChains().values()) {
            Operation<?> operation = outboundChain.getOperation();
            InboundInvocationChain inboundChain = targetChains.get(operation);
            if (inboundChain == null) {
                BuilderConfigException e =
                    new BuilderConfigException("Incompatible source and target interfaces for reference");
                e.setIdentifier(sourceWire.getReferenceName());
                throw e;
            }
            Operation<?> inboundOperation = inboundChain.getOperation();
            boolean isOneWayOperation = operation.isNonBlocking();
            boolean operationHasCallback = contract.getCallbackName() != null;
            if (isOneWayOperation && operationHasCallback) {
                throw new ComponentRuntimeException("Operation cannot be marked one-way and have a callback");
            }
            TargetInvoker invoker = null;
            if (target instanceof Component) {
                Component component = (Component) target;
                if (isOneWayOperation || operationHasCallback) {
                    invoker = component.createAsyncTargetInvoker(targetWire, inboundOperation);
                } else {
                    String portName = sourceWire.getTargetName().getPortName();
                    invoker = component.createTargetInvoker(portName, inboundOperation);
                }
            } else if (target instanceof Reference) {
                Reference reference = (Reference) target;
                if (!(reference instanceof CompositeReference) && operationHasCallback) {
                    // Notice that for bound references we only use async target invokers for callback operations
                    invoker = reference.createAsyncTargetInvoker(sourceWire, inboundOperation);
                } else {
                    ServiceContract targetContract = targetWire.getServiceContract();
                    invoker = reference.createTargetInvoker(targetContract, inboundOperation);
                }
            } else if (target instanceof CompositeService) {
                CompositeService compServ = (CompositeService) target;
                invoker = compServ.createTargetInvoker(targetWire.getServiceContract(), inboundChain.getOperation());
            }

            if (source instanceof Service && !(source instanceof CompositeService)) {
                // services are a special case: invoker must go on the inbound chain
                if (target instanceof Component && (isOneWayOperation || operationHasCallback)) {
                    // if the target is a component and the operation is non-blocking
                    connect(outboundChain, inboundChain, null, true);
                } else {
                    connect(outboundChain, inboundChain, null, false);
                }
                Service service = (Service) source;
                InboundInvocationChain chain = service.getInboundWire().getInvocationChains().get(operation);
                chain.setTargetInvoker(invoker);
            } else {
                if (target instanceof Component && (isOneWayOperation || operationHasCallback)) {
                    // if the target is a component and the operation is non-blocking
                    connect(outboundChain, inboundChain, invoker, true);
                } else {
                    connect(outboundChain, inboundChain, invoker, false);
                }
            }
        }

        // create source callback chains and connect them if target callback chains exist
        Map<Operation<?>, OutboundInvocationChain> sourceCallbackChains =
            targetWire.getSourceCallbackInvocationChains(source.getName());
        for (InboundInvocationChain inboundChain : sourceWire.getTargetCallbackInvocationChains().values()) {
            Operation<?> operation = inboundChain.getOperation();
            if (sourceCallbackChains != null && sourceCallbackChains.get(operation) != null) {
                String name = operation.getName();
                BuilderConfigException e =
                    new BuilderConfigException("Source callback chain should not exist for operation [" + name + "]");
                e.setIdentifier(sourceWire.getReferenceName());
                throw e;
            }
           
            Operation targetOp =
                (Operation)targetWire.getServiceContract().getCallbackOperations().get(operation.getName());
            OutboundInvocationChain outboundChain = wireService.createOutboundChain(targetOp);
            targetWire.addSourceCallbackInvocationChain(source.getName(), targetOp, outboundChain);
            if (source instanceof Component) {
                Component component = (Component) source;
                TargetInvoker invoker = component.createTargetInvoker(null, operation);
                connect(outboundChain, inboundChain, invoker, false);
            } else if (source instanceof CompositeReference) {
                CompositeReference compRef = (CompositeReference) source;
                ServiceContract sourceContract = sourceWire.getServiceContract();
                TargetInvoker invoker = compRef.createCallbackTargetInvoker(sourceContract, operation);
                connect(outboundChain, inboundChain, invoker, false);
            } else if (source instanceof Service) {
                Service service = (Service) source;
                ServiceContract sourceContract = sourceWire.getServiceContract();
                TargetInvoker invoker = service.createCallbackTargetInvoker(sourceContract, operation);
                connect(outboundChain, inboundChain, invoker, false);
            }
        }
        if (postProcessorRegistry != null) {
View Full Code Here

    public void testMethodAnnotation() throws Exception {
        processor.visitMethod(null, ReferenceProcessorTestCase.Foo.class.getMethod("setFoo", Ref.class), type, null);
        JavaMappedReference reference = type.getReferences().get("foo");
        assertNotNull(reference);
        ServiceContract contract = reference.getServiceContract();
        assertEquals(Ref.class, contract.getInterfaceClass());
        assertEquals("ReferenceProcessorTestCase$Ref", contract.getInterfaceName());
    }
View Full Code Here

    public void testFieldAnnotation() throws Exception {
        processor.visitField(null, ReferenceProcessorTestCase.Foo.class.getDeclaredField("baz"), type, null);
        JavaMappedReference reference = type.getReferences().get("baz");
        assertNotNull(reference);
        ServiceContract contract = reference.getServiceContract();
        assertEquals(Ref.class, contract.getInterfaceClass());
        assertEquals("ReferenceProcessorTestCase$Ref", contract.getInterfaceName());
    }
View Full Code Here

        }
        return invoker;
    }

    private Operation findCallbackOperation() {
        ServiceContract contract = inboundWire.getServiceContract();
        Operation callbackOperation = null;
        Collection callbackOperations = contract.getCallbackOperations().values();
        if (callbackOperations.size() != 1) {
            throw new Axis2BindingRunTimeException("Can only handle one callback operation");
        } else {
            callbackOperation = (Operation)callbackOperations.iterator().next();
        }
View Full Code Here

    public void testMultipleInterfaces() throws Exception {
        processor.visitClass(null, FooMultiple.class, type, null);
        assertEquals(2, type.getServices().size());
        JavaMappedService service = type.getServices().get("ServiceProcessorTestCase$Baz");
        ServiceContract contract = service.getServiceContract();
        assertEquals(Baz.class, contract.getInterfaceClass());
        assertEquals(Bar.class, contract.getCallbackClass());
        assertEquals("ServiceProcessorTestCase$Bar", contract.getCallbackName());
        assertNotNull(type.getServices().get("ServiceProcessorTestCase$Bar"));
    }
View Full Code Here

    public void testRemotableNoService() throws Exception {
        processor.visitClass(null, FooRemotableNoService.class, type, null);
        assertEquals(1, type.getServices().size());
        JavaMappedService service = type.getServices().get("ServiceProcessorTestCase$BazRemotable");
        ServiceContract contract = service.getServiceContract();
        assertEquals(BazRemotable.class, contract.getInterfaceClass());
    }
View Full Code Here

        String name = reader.getAttributeValue(null, "name");
        Multiplicity multiplicity =
            StAXUtil.multiplicity(reader.getAttributeValue(null, "multiplicity"), Multiplicity.ONE_ONE);
        Binding binding = null;
        ServiceContract serviceContract = null;
        while (true) {
            switch (reader.next()) {
                case START_ELEMENT:
                    ModelObject o = registry.load(parent, reader, deploymentContext);
                    if (o instanceof ServiceContract) {
View Full Code Here

TOP

Related Classes of org.apache.tuscany.spi.model.ServiceContract

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.