ws架构

package service;


public interface IService
{
    Object call(String serviceid, Object... params) throws Exception;
}
package service;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.MethodUtils;
import org.apache.commons.lang.StringUtils;

public class Service implements IService
{
    public Object call(String serviceid, Object... params)
    {
        String className = StringUtils.substringBeforeLast(serviceid, ".");
        String methodName = StringUtils.substringAfterLast(serviceid, ".");
        Object ret = null;
        try
        {
            ClassLoader clsLoader = Thread.currentThread()
                    .getContextClassLoader();
            ret = MethodUtils.invokeMethod(clsLoader.loadClass(className)
                    .newInstance(), methodName, params);
        }
        catch(ClassNotFoundException e1)
        {
            throw new RuntimeException("=====业务接口未定义=====");
        }
        catch(InstantiationException e1)
        {
            throw new RuntimeException(e1.getMessage());
        }
        catch(IllegalAccessException e1)
        {
            throw new RuntimeException("=====非法访问业务接口=====");
        }
        catch(InvocationTargetException e1)
        {
            throw new RuntimeException(e1.getMessage());
        }
        catch(NoSuchMethodException e1)
        {
            throw new RuntimeException("=====业务接口方法未定义=====");
        }
        return ret;
    }
}

猜你喜欢

转载自rzy.iteye.com/blog/1591417
wsd
今日推荐