Package net.helipilot50.stocktrade.framework.remoting

Source Code of net.helipilot50.stocktrade.framework.remoting.PluggableRmiProxyFactoryBean

/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package net.helipilot50.stocktrade.framework.remoting;

import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import java.util.Collections;
import java.util.List;

import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.support.AopUtils;
import org.springframework.remoting.rmi.RmiInvocationHandler;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
import org.springframework.remoting.support.RemoteInvocation;
/**
* Provides RMI remote invocation for service object.
* @author Ivan
*
*/
public class PluggableRmiProxyFactoryBean extends RmiProxyFactoryBean {

    private List<RemoteInvocationAttributeProvider> attributeProviders;                  //JVM 1.5
    private List<RemoteInvocationAttributeConsumer> attributeConsumers;                  //JVM 1.5

    public void setRemoteInvocationAttributeProviders(List<RemoteInvocationAttributeProvider> attributeProviders) {                  //JVM 1.5
        this.attributeProviders = attributeProviders;
    }

    public List<RemoteInvocationAttributeProvider> getRemoteInvocationAttributeProviders() {                  //JVM 1.5
        if (attributeProviders == null) return Collections.emptyList();                  //JVM 1.5
        return Collections.unmodifiableList(attributeProviders);
    }

    public void setRemoteInvocationAttributeConsumers(List<RemoteInvocationAttributeConsumer> attributeConsumers) {                  //JVM 1.5
        this.attributeConsumers = attributeConsumers;
    }

    public List<RemoteInvocationAttributeConsumer> getRemoteInvocationAttributeConsumers() {                  //JVM 1.5
        if (attributeConsumers == null) return Collections.emptyList();                  //JVM 1.5
        return Collections.unmodifiableList(attributeConsumers);
    }

    protected Object doInvoke(MethodInvocation methodInvocation, RmiInvocationHandler invocationHandler) throws RemoteException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {

        // copied from superclass
        if (AopUtils.isToStringMethod(methodInvocation.getMethod())) {
            return "RMI invoker proxy for service URL [" + getServiceUrl() + "]";
        }
        RemoteInvocation remoteInvocation = createRemoteInvocation(methodInvocation);

        // Attribute Provides
        for (RemoteInvocationAttributeProvider attributeProvider : getRemoteInvocationAttributeProviders()) {                  //JVM 1.5
            remoteInvocation.addAttribute(attributeProvider.getAttributeName(), attributeProvider.getAttributeValue(remoteInvocation, null));
        }

        Object result = invocationHandler.invoke(remoteInvocation);

        if (result instanceof RemoteInvocationResultWrapper) {
            RemoteInvocationResultWrapper resultWrapper = (RemoteInvocationResultWrapper)result;

            // Attribute Consumers
            for (RemoteInvocationAttributeConsumer attributeConsumer : getRemoteInvocationAttributeConsumers()) {                  //JVM 1.5
                attributeConsumer.consume(remoteInvocation.getArguments(), resultWrapper.getAttribute(attributeConsumer.getAttributeName()));
            }
            return resultWrapper.getReturnValue();
        }
        return result;
    }

}
TOP

Related Classes of net.helipilot50.stocktrade.framework.remoting.PluggableRmiProxyFactoryBean

TOP
Copyright © 2018 www.massapi.com. 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.