modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringInvoker.java [56:123]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                         RuntimeComponentService service,
                         Operation operation) {

        this.springContext = springContext;
        this.operation = operation;

        // From the component and the service, identify the Spring Bean which is the target
        SpringImplementation theImplementation = (SpringImplementation)component.getImplementation();
        beanElement = theImplementation.getBeanFromService(service.getService());

        if (beanElement == null) {
            badInvoker = true;
            return;
        }

    } // end constructor SpringInvoker

    // Lazy-load the method to avoid timing problems with the Spring Context
    private void setupMethod() throws SpringInvocationException {
        try {
            bean = springContext.getBean(beanElement.getId());
            Class<?> beanClass = bean.getClass();
            theMethod = JavaInterfaceUtil.findMethod(beanClass, operation);
            //System.out.println("SpringInvoker - found method " + theMethod.getName() );
        } catch (NoSuchMethodException e) {
            throw new SpringInvocationException(e);
        }
    }

    private Object doInvoke(Object payload) throws SpringInvocationException {
        if (theMethod == null)
            setupMethod();

        if (badInvoker)
            throw new SpringInvocationException("Spring invoker incorrectly configured");
        // Invoke the method on the Spring bean using the payload, returning the results
        try {
            Object ret;

            if (payload != null && !payload.getClass().isArray()) {
                ret = theMethod.invoke(bean, payload);
            } else {
                ret = theMethod.invoke(bean, (Object[])payload);
            }
            return ret;
        } catch (InvocationTargetException e) {
            throw new SpringInvocationException("Spring invoker invoke method '" + theMethod.getName() + "' error.",
                                                e.getCause());
        } catch (Exception e) {
            throw new SpringInvocationException("Spring invoker invoke method '" + theMethod.getName() + "' error.", e);
        }

    } // end method doInvoke

    /**
     * @param msg the message to invoke on the target bean
     */
    public Message invoke(Message msg) {
        try {
            Object resp = doInvoke(msg.getBody());
            msg.setBody(resp);
        } catch (SpringInvocationException e) {
            msg.setFaultBody(e.getCause());
        } catch (Throwable e) {
            msg.setFaultBody(e);
        }
        //System.out.println("Spring Invoker - invoke called");
        return msg;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



modules/implementation-spring-stub/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/stub/SpringInvoker.java [55:122]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                         RuntimeComponentService service,
                         Operation operation) {

        this.springContext = springContext;
        this.operation = operation;

        // From the component and the service, identify the Spring Bean which is the target
        SpringImplementation theImplementation = (SpringImplementation)component.getImplementation();
        beanElement = theImplementation.getBeanFromService(service.getService());

        if (beanElement == null) {
            badInvoker = true;
            return;
        }

    } // end constructor SpringInvoker

    // Lazy-load the method to avoid timing problems with the Spring Context
    private void setupMethod() throws SpringInvocationException {
        try {
            bean = springContext.getBean(beanElement.getId());
            Class<?> beanClass = bean.getClass();
            theMethod = JavaInterfaceUtil.findMethod(beanClass, operation);
            //System.out.println("SpringInvoker - found method " + theMethod.getName() );
        } catch (NoSuchMethodException e) {
            throw new SpringInvocationException(e);
        }
    }

    private Object doInvoke(Object payload) throws SpringInvocationException {
        if (theMethod == null)
            setupMethod();

        if (badInvoker)
            throw new SpringInvocationException("Spring invoker incorrectly configured");
        // Invoke the method on the Spring bean using the payload, returning the results
        try {
            Object ret;

            if (payload != null && !payload.getClass().isArray()) {
                ret = theMethod.invoke(bean, payload);
            } else {
                ret = theMethod.invoke(bean, (Object[])payload);
            }
            return ret;
        } catch (InvocationTargetException e) {
            throw new SpringInvocationException("Spring invoker invoke method '" + theMethod.getName() + "' error.",
                                                e.getCause());
        } catch (Exception e) {
            throw new SpringInvocationException("Spring invoker invoke method '" + theMethod.getName() + "' error.", e);
        }

    } // end method doInvoke

    /**
     * @param msg the message to invoke on the target bean
     */
    public Message invoke(Message msg) {
        try {
            Object resp = doInvoke(msg.getBody());
            msg.setBody(resp);
        } catch (SpringInvocationException e) {
            msg.setFaultBody(e.getCause());
        } catch (Throwable e) {
            msg.setFaultBody(e);
        }
        //System.out.println("Spring Invoker - invoke called");
        return msg;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



