Java Code Examples for com.alibaba.dubbo.common.utils.ReflectUtils

The following examples show how to use com.alibaba.dubbo.common.utils.ReflectUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: dubbo-2.6.5   Source File: MockInvoker.java    License: Apache License 2.0 6 votes vote down vote up
private Throwable getThrowable(String throwstr) {
    Throwable throwable = (Throwable) throwables.get(throwstr);
    if (throwable != null) {
        return throwable;
    } else {
        Throwable t = null;
        try {
            Class<?> bizException = ReflectUtils.forName(throwstr);
            Constructor<?> constructor;
            constructor = ReflectUtils.findConstructor(bizException, String.class);
            t = (Throwable) constructor.newInstance(new Object[]{" mocked exception for Service degradation. "});
            if (throwables.size() < 1000) {
                throwables.put(throwstr, t);
            }
        } catch (Exception e) {
            throw new RpcException("mock throw error :" + throwstr + " argument error.", e);
        }
        return t;
    }
}
 
Example 2
Source Project: dubbo-2.6.5   Source File: RpcUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Class<?> getReturnType(Invocation invocation) {
    try {
        if (invocation != null && invocation.getInvoker() != null
                && invocation.getInvoker().getUrl() != null
                && !invocation.getMethodName().startsWith("$")) {
            String service = invocation.getInvoker().getUrl().getServiceInterface();
            if (service != null && service.length() > 0) {
                Class<?> cls = ReflectUtils.forName(service);
                Method method = cls.getMethod(invocation.getMethodName(), invocation.getParameterTypes());
                if (method.getReturnType() == void.class) {
                    return null;
                }
                return method.getReturnType();
            }
        }
    } catch (Throwable t) {
        logger.warn(t.getMessage(), t);
    }
    return null;
}
 
Example 3
Source Project: dubbo-2.6.5   Source File: RpcUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Class<?>[] getParameterTypes(Invocation invocation) {
    if (Constants.$INVOKE.equals(invocation.getMethodName())
            && invocation.getArguments() != null
            && invocation.getArguments().length > 1
            && invocation.getArguments()[1] instanceof String[]) {
        String[] types = (String[]) invocation.getArguments()[1];
        if (types == null) {
            return new Class<?>[0];
        }
        Class<?>[] parameterTypes = new Class<?>[types.length];
        for (int i = 0; i < types.length; i++) {
            parameterTypes[i] = ReflectUtils.forName(types[0]);
        }
        return parameterTypes;
    }
    return invocation.getParameterTypes();
}
 
Example 4
Source Project: dubbo3   Source File: MockInvoker.java    License: Apache License 2.0 6 votes vote down vote up
private Throwable getThrowable(String throwstr) {
    Throwable throwable = throwables.get(throwstr);
    if (throwable != null) {
        return throwable;
    } else {
        Throwable t;
        try {
            Class<?> bizException = ReflectUtils.forName(throwstr);
            Constructor<?> constructor;
            constructor = ReflectUtils.findConstructor(bizException, String.class);
            t = (Throwable) constructor.newInstance(" mocked exception for Service degradation. ");
            if (throwables.size() < 1000) {
                throwables.put(throwstr, t);
            }
        } catch (Exception e) {
            throw new RpcException("mock throw error :" + throwstr + " argument error.", e);
        }
        return t;
    }
}
 
Example 5
Source Project: dubbo-2.6.5   Source File: ClassGenerator.java    License: Apache License 2.0 6 votes vote down vote up
public ClassGenerator addMethod(String name, int mod, Class<?> rt, Class<?>[] pts, Class<?>[] ets, String body) {
    StringBuilder sb = new StringBuilder();
    sb.append(modifier(mod)).append(' ').append(ReflectUtils.getName(rt)).append(' ').append(name);
    sb.append('(');
    for (int i = 0; i < pts.length; i++) {
        if (i > 0)
            sb.append(',');
        sb.append(ReflectUtils.getName(pts[i]));
        sb.append(" arg").append(i);
    }
    sb.append(')');
    if (ets != null && ets.length > 0) {
        sb.append(" throws ");
        for (int i = 0; i < ets.length; i++) {
            if (i > 0)
                sb.append(',');
            sb.append(ReflectUtils.getName(ets[i]));
        }
    }
    sb.append('{').append(body).append('}');
    return addMethod(sb.toString());
}
 
Example 6
Source Project: dubbox   Source File: RpcUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Class<?>[] getParameterTypes(Invocation invocation){
	if(Constants.$INVOKE.equals(invocation.getMethodName()) 
            && invocation.getArguments() != null 
            && invocation.getArguments().length > 1
            && invocation.getArguments()[1] instanceof String[]){
        String[] types = (String[]) invocation.getArguments()[1];
        if (types == null) {
        	return new Class<?>[0];
        }
        Class<?>[] parameterTypes = new Class<?>[types.length];
        for (int i = 0; i < types.length; i ++) {
        	parameterTypes[i] = ReflectUtils.forName(types[0]);
        }
        return parameterTypes;
    }
	return invocation.getParameterTypes();
}
 
Example 7
Source Project: dubbo-2.6.5   Source File: Proxy.java    License: Apache License 2.0 6 votes vote down vote up
private static String asArgument(Class<?> cl, String name) {
    if (cl.isPrimitive()) {
        if (Boolean.TYPE == cl)
            return name + "==null?false:((Boolean)" + name + ").booleanValue()";
        if (Byte.TYPE == cl)
            return name + "==null?(byte)0:((Byte)" + name + ").byteValue()";
        if (Character.TYPE == cl)
            return name + "==null?(char)0:((Character)" + name + ").charValue()";
        if (Double.TYPE == cl)
            return name + "==null?(double)0:((Double)" + name + ").doubleValue()";
        if (Float.TYPE == cl)
            return name + "==null?(float)0:((Float)" + name + ").floatValue()";
        if (Integer.TYPE == cl)
            return name + "==null?(int)0:((Integer)" + name + ").intValue()";
        if (Long.TYPE == cl)
            return name + "==null?(long)0:((Long)" + name + ").longValue()";
        if (Short.TYPE == cl)
            return name + "==null?(short)0:((Short)" + name + ").shortValue()";
        throw new RuntimeException(name + " is unknown primitive type.");
    }
    return "(" + ReflectUtils.getName(cl) + ")" + name;
}
 
Example 8
Source Project: dubbo-2.6.5   Source File: Wrapper.java    License: Apache License 2.0 6 votes vote down vote up
private static String arg(Class<?> cl, String name) {
    if (cl.isPrimitive()) {
        if (cl == Boolean.TYPE)
            return "((Boolean)" + name + ").booleanValue()";
        if (cl == Byte.TYPE)
            return "((Byte)" + name + ").byteValue()";
        if (cl == Character.TYPE)
            return "((Character)" + name + ").charValue()";
        if (cl == Double.TYPE)
            return "((Number)" + name + ").doubleValue()";
        if (cl == Float.TYPE)
            return "((Number)" + name + ").floatValue()";
        if (cl == Integer.TYPE)
            return "((Number)" + name + ").intValue()";
        if (cl == Long.TYPE)
            return "((Number)" + name + ").longValue()";
        if (cl == Short.TYPE)
            return "((Number)" + name + ").shortValue()";
        throw new RuntimeException("Unknown primitive type: " + cl.getName());
    }
    return "(" + ReflectUtils.getName(cl) + ")" + name;
}
 
Example 9
Source Project: dubbo-2.6.5   Source File: JavaBeanSerializeUtil.java    License: Apache License 2.0 6 votes vote down vote up
private static JavaBeanDescriptor createDescriptorForSerialize(Class<?> cl) {
    if (cl.isEnum()) {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_ENUM);
    } else if (cl.isArray()) {
        return new JavaBeanDescriptor(cl.getComponentType().getName(), JavaBeanDescriptor.TYPE_ARRAY);
    } else if (ReflectUtils.isPrimitive(cl)) {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
    } else if (Class.class.equals(cl)) {
        return new JavaBeanDescriptor(Class.class.getName(), JavaBeanDescriptor.TYPE_CLASS);
    } else if (Collection.class.isAssignableFrom(cl)) {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_COLLECTION);
    } else if (Map.class.isAssignableFrom(cl)) {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_MAP);
    } else {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_BEAN);
    }
}
 
Example 10
Source Project: dubbo-2.6.5   Source File: AnnotationBean.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
    throws BeansException {
    if (annotationPackage == null || annotationPackage.length() == 0) {
        return;
    }
    if (beanFactory instanceof BeanDefinitionRegistry) {
        try {
            // init scanner
            Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
            Object scanner = scannerClass.getConstructor(new Class<?>[]{BeanDefinitionRegistry.class, boolean.class}).newInstance(new Object[]{(BeanDefinitionRegistry) beanFactory, true});
            // add filter
            Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
            Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
            Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
            addIncludeFilter.invoke(scanner, filter);
            // scan packages
            String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
            Method scan = scannerClass.getMethod("scan", new Class<?>[]{String[].class});
            scan.invoke(scanner, new Object[]{packages});
        } catch (Throwable e) {
            // spring 2.0
        }
    }
}
 
Example 11
Source Project: dubbox   Source File: Mixin.java    License: Apache License 2.0 6 votes vote down vote up
private static int findMethod(Class<?>[] dcs, String desc)
{
	Class<?> cl;
	Method[] methods;
	for(int i=0;i<dcs.length;i++)
	{
		cl = dcs[i];
		methods = cl.getMethods();
		for( Method method : methods )
		{
			if( desc.equals(ReflectUtils.getDesc(method)) )
				return i;
		}
	}
	return -1;
}
 
Example 12
Source Project: dubbo3   Source File: RpcUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Class<?> getReturnType(Invocation invocation) {
    try {
        if (invocation != null && invocation.getInvoker() != null
                && invocation.getInvoker().getUrl() != null
                && !invocation.getMethodName().startsWith("$")) {
            String service = invocation.getInvoker().getUrl().getServiceInterface();
            if (service != null && service.length() > 0) {
                Class<?> cls = ReflectUtils.forName(service);
                Method method = cls.getMethod(invocation.getMethodName(), invocation.getParameterTypes());
                if (method.getReturnType() == void.class) {
                    return null;
                }
                return method.getReturnType();
            }
        }
    } catch (Throwable t) {
        logger.warn(t.getMessage(), t);
    }
    return null;
}
 
Example 13
Source Project: dubbox   Source File: ListTelnetHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() {
    StringBuilder buf = new StringBuilder();
    StringBuilder buf2 = new StringBuilder();
    Method[] methods = DemoService.class.getMethods();
    for (Method method : methods) {
        if (buf.length() > 0) {
            buf.append("\r\n");
        }
        if (buf2.length() > 0) {
            buf2.append("\r\n");
        }
        buf2.append(method.getName());
        buf.append(ReflectUtils.getName(method));
    }
    detailMethods = buf.toString();
    methodsName = buf2.toString();
    
    ProtocolUtils.closeAll();
}
 
Example 14
Source Project: skywalking   Source File: MakeWrapperInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
private static String arg(Class<?> cl, String name) {
    if (cl.isPrimitive()) {
        if (cl == Boolean.TYPE)
            return "((Boolean)" + name + ").booleanValue()";
        if (cl == Byte.TYPE)
            return "((Byte)" + name + ").byteValue()";
        if (cl == Character.TYPE)
            return "((Character)" + name + ").charValue()";
        if (cl == Double.TYPE)
            return "((Number)" + name + ").doubleValue()";
        if (cl == Float.TYPE)
            return "((Number)" + name + ").floatValue()";
        if (cl == Integer.TYPE)
            return "((Number)" + name + ").intValue()";
        if (cl == Long.TYPE)
            return "((Number)" + name + ").longValue()";
        if (cl == Short.TYPE)
            return "((Number)" + name + ").shortValue()";
        throw new RuntimeException("Unknown primitive type: " + cl.getName());
    }
    return "(" + ReflectUtils.getName(cl) + ")" + name;
}
 
Example 15
Source Project: dubbox   Source File: AnnotationBean.java    License: Apache License 2.0 6 votes vote down vote up
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
        throws BeansException {
    if (annotationPackage == null || annotationPackage.length() == 0) {
        return;
    }
    if (beanFactory instanceof BeanDefinitionRegistry) {
        try {
            // init scanner
            Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
            Object scanner = scannerClass.getConstructor(new Class<?>[] {BeanDefinitionRegistry.class, boolean.class}).newInstance(new Object[] {(BeanDefinitionRegistry) beanFactory, true});
            // add filter
            Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
            Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
            Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
            addIncludeFilter.invoke(scanner, filter);
            // scan packages
            String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
            Method scan = scannerClass.getMethod("scan", new Class<?>[]{String[].class});
            scan.invoke(scanner, new Object[] {packages});
        } catch (Throwable e) {
            // spring 2.0
        }
    }
}
 
Example 16
Source Project: dubbox   Source File: RpcUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Type[] getReturnTypes(Invocation invocation) {
    try {
        if (invocation != null && invocation.getInvoker() != null
                && invocation.getInvoker().getUrl() != null
                && ! invocation.getMethodName().startsWith("$")) {
            String service = invocation.getInvoker().getUrl().getServiceInterface();
            if (service != null && service.length() > 0) {
                Class<?> cls = ReflectUtils.forName(service);
                Method method = cls.getMethod(invocation.getMethodName(), invocation.getParameterTypes());
                if (method.getReturnType() == void.class) {
                    return null;
                }
                return new Type[]{method.getReturnType(), method.getGenericReturnType()};
            }
        }
    } catch (Throwable t) {
        logger.warn(t.getMessage(), t);
    }
    return null;
}
 
Example 17
Source Project: dubbox   Source File: JavaBeanSerializeUtil.java    License: Apache License 2.0 6 votes vote down vote up
private static Method getSetterMethod(Class<?> cls, String property, Class<?> valueCls) {
    String name = "set" + property.substring(0, 1).toUpperCase() + property.substring(1);
    Method method = null;
    try {
        method = cls.getMethod(name, valueCls);
    } catch (NoSuchMethodException e) {
        for (Method m : cls.getMethods()) {
            if (ReflectUtils.isBeanPropertyWriteMethod(m)
                && m.getName().equals(name)) {
                method = m;
            }
        }
    }
    if (method != null) {
        method.setAccessible(true);
    }
    return method;
}
 
Example 18
Source Project: dubbo3   Source File: ListTelnetHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() {
    StringBuilder buf = new StringBuilder();
    StringBuilder buf2 = new StringBuilder();
    Method[] methods = DemoService.class.getMethods();
    for (Method method : methods) {
        if (buf.length() > 0) {
            buf.append("\r\n");
        }
        if (buf2.length() > 0) {
            buf2.append("\r\n");
        }
        buf2.append(method.getName());
        buf.append(ReflectUtils.getName(method));
    }
    detailMethods = buf.toString();
    methodsName = buf2.toString();
    
    ProtocolUtils.closeAll();
}
 
Example 19
Source Project: dubbox   Source File: JavaBeanSerializeUtil.java    License: Apache License 2.0 6 votes vote down vote up
private static Method getSetterMethod(Class<?> cls, String property, Class<?> valueCls) {
    String name = "set" + property.substring(0, 1).toUpperCase() + property.substring(1);
    Method method = null;
    try {
        method = cls.getMethod(name, valueCls);
    } catch (NoSuchMethodException e) {
        for (Method m : cls.getMethods()) {
            if (ReflectUtils.isBeanPropertyWriteMethod(m)
                && m.getName().equals(name)) {
                method = m;
            }
        }
    }
    if (method != null) {
        method.setAccessible(true);
    }
    return method;
}
 
Example 20
Source Project: dubbox   Source File: Mixin.java    License: Apache License 2.0 6 votes vote down vote up
private static int findMethod(Class<?>[] dcs, String desc)
{
	Class<?> cl;
	Method[] methods;
	for(int i=0;i<dcs.length;i++)
	{
		cl = dcs[i];
		methods = cl.getMethods();
		for( Method method : methods )
		{
			if( desc.equals(ReflectUtils.getDesc(method)) )
				return i;
		}
	}
	return -1;
}
 
Example 21
Source Project: dubbo3   Source File: GenericObjectOutput.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public void writeObject(Object obj) throws IOException {
    if (obj == null) {
        write0(OBJECT_NULL);
        return;
    }

    Class<?> c = obj.getClass();
    if (c == Object.class) {
        write0(OBJECT_DUMMY);
    } else {
        String desc = ReflectUtils.getDesc(c);
        int index = mMapper.getDescriptorIndex(desc);
        if (index < 0) {
            write0(OBJECT_DESC);
            writeUTF(desc);
        } else {
            write0(OBJECT_DESC_ID);
            writeUInt(index);
        }
        Builder b = Builder.register(c, isAllowNonSerializable);
        b.writeTo(obj, this);
    }
}
 
Example 22
Source Project: dubbox   Source File: ClassGenerator.java    License: Apache License 2.0 6 votes vote down vote up
public ClassGenerator addMethod(String name, int mod, Class<?> rt, Class<?>[] pts, Class<?>[] ets, String body)
{
	StringBuilder sb = new StringBuilder();
	sb.append(modifier(mod)).append(' ').append(ReflectUtils.getName(rt)).append(' ').append(name);
	sb.append('(');
	for(int i=0;i<pts.length;i++)
	{
		if( i > 0 )
			sb.append(',');
		sb.append(ReflectUtils.getName(pts[i]));
		sb.append(" arg").append(i);
	}
	sb.append(')');
	if( ets != null && ets.length > 0 )
	{
		sb.append(" throws ");
		for(int i=0;i<ets.length;i++)
		{
			if( i > 0 )
				sb.append(',');
			sb.append(ReflectUtils.getName(ets[i]));
		}
	}
	sb.append('{').append(body).append('}');
	return addMethod(sb.toString());
}
 
Example 23
Source Project: dubbox   Source File: ClassGenerator.java    License: Apache License 2.0 6 votes vote down vote up
public ClassGenerator addConstructor(int mod, Class<?>[] pts, Class<?>[] ets, String body)
{
	StringBuilder sb = new StringBuilder();
	sb.append(modifier(mod)).append(' ').append(SIMPLE_NAME_TAG);
	sb.append('(');
	for(int i=0;i<pts.length;i++)
	{
		if( i > 0 )
			sb.append(',');
		sb.append(ReflectUtils.getName(pts[i]));
		sb.append(" arg").append(i);
	}
	sb.append(')');
	if( ets != null && ets.length > 0 )
	{
		sb.append(" throws ");
		for(int i=0;i<ets.length;i++)
		{
			if( i > 0 )
				sb.append(',');
			sb.append(ReflectUtils.getName(ets[i]));
		}
	}
	sb.append('{').append(body).append('}');
	return addConstructor(sb.toString());
}
 
Example 24
Source Project: dubbox   Source File: JavaBeanSerializeUtil.java    License: Apache License 2.0 6 votes vote down vote up
private static JavaBeanDescriptor createDescriptorForSerialize(Class<?> cl) {
    if (cl.isEnum()) {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_ENUM);
    } else if (cl.isArray()) {
        return new JavaBeanDescriptor(cl.getComponentType().getName(), JavaBeanDescriptor.TYPE_ARRAY);
    } else if (ReflectUtils.isPrimitive(cl)) {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
    } else if (Class.class.equals(cl)) {
        return new JavaBeanDescriptor(Class.class.getName(), JavaBeanDescriptor.TYPE_CLASS);
    } else if (Collection.class.isAssignableFrom(cl)) {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_COLLECTION);
    } else if (Map.class.isAssignableFrom(cl)) {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_MAP);
    } else {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_BEAN);
    }
}
 
Example 25
Source Project: dubbox   Source File: Proxy.java    License: Apache License 2.0 6 votes vote down vote up
private static String asArgument(Class<?> cl, String name)
{
	if( cl.isPrimitive() )
	{
		if( Boolean.TYPE == cl )
			return name + "==null?false:((Boolean)" + name + ").booleanValue()";
		if( Byte.TYPE == cl )
			return name + "==null?(byte)0:((Byte)" + name + ").byteValue()";
		if( Character.TYPE == cl )
			return name + "==null?(char)0:((Character)" + name + ").charValue()";
		if( Double.TYPE == cl )
			return name + "==null?(double)0:((Double)" + name + ").doubleValue()";
		if( Float.TYPE == cl )
			return name + "==null?(float)0:((Float)" + name + ").floatValue()";
		if( Integer.TYPE == cl )
			return name + "==null?(int)0:((Integer)" + name + ").intValue()";
		if( Long.TYPE == cl )
			return name + "==null?(long)0:((Long)" + name + ").longValue()";
		if( Short.TYPE == cl )
			return name + "==null?(short)0:((Short)" + name + ").shortValue()";
		throw new RuntimeException(name+" is unknown primitive type."); 
	}
	return "(" + ReflectUtils.getName(cl) + ")"+name;
}
 
Example 26
Source Project: dubbox   Source File: JavaBeanSerializeUtil.java    License: Apache License 2.0 6 votes vote down vote up
private static JavaBeanDescriptor createDescriptorForSerialize(Class<?> cl) {
    if (cl.isEnum()) {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_ENUM);
    } else if (cl.isArray()) {
        return new JavaBeanDescriptor(cl.getComponentType().getName(), JavaBeanDescriptor.TYPE_ARRAY);
    } else if (ReflectUtils.isPrimitive(cl)) {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
    } else if (Class.class.equals(cl)) {
        return new JavaBeanDescriptor(Class.class.getName(), JavaBeanDescriptor.TYPE_CLASS);
    } else if (Collection.class.isAssignableFrom(cl)) {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_COLLECTION);
    } else if (Map.class.isAssignableFrom(cl)) {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_MAP);
    } else {
        return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_BEAN);
    }
}
 
Example 27
Source Project: dubbox   Source File: RpcUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Class<?>[] getParameterTypes(Invocation invocation){
	if(Constants.$INVOKE.equals(invocation.getMethodName()) 
            && invocation.getArguments() != null 
            && invocation.getArguments().length > 1
            && invocation.getArguments()[1] instanceof String[]){
        String[] types = (String[]) invocation.getArguments()[1];
        if (types == null) {
        	return new Class<?>[0];
        }
        Class<?>[] parameterTypes = new Class<?>[types.length];
        for (int i = 0; i < types.length; i ++) {
        	parameterTypes[i] = ReflectUtils.forName(types[0]);
        }
        return parameterTypes;
    }
	return invocation.getParameterTypes();
}
 
Example 28
Source Project: dubbox   Source File: AnnotationBean.java    License: Apache License 2.0 6 votes vote down vote up
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
        throws BeansException {
    if (annotationPackage == null || annotationPackage.length() == 0) {
        return;
    }
    if (beanFactory instanceof BeanDefinitionRegistry) {
        try {
            // init scanner
            Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
            Object scanner = scannerClass.getConstructor(new Class<?>[] {BeanDefinitionRegistry.class, boolean.class}).newInstance(new Object[] {(BeanDefinitionRegistry) beanFactory, true});
            // add filter
            Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
            Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
            Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
            addIncludeFilter.invoke(scanner, filter);
            // scan packages
            String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
            Method scan = scannerClass.getMethod("scan", new Class<?>[]{String[].class});
            scan.invoke(scanner, new Object[] {packages});
        } catch (Throwable e) {
            // spring 2.0
        }
    }
}
 
Example 29
Source Project: dubbo3   Source File: DubboCodec.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void encodeRequestData(Channel channel, ObjectOutput out, Object data) throws IOException {
    RpcInvocation inv = (RpcInvocation) data;

    out.writeUTF(inv.getAttachment(Constants.DUBBO_VERSION_KEY, DUBBO_VERSION));
    out.writeUTF(inv.getAttachment(Constants.PATH_KEY));
    out.writeUTF(inv.getAttachment(Constants.VERSION_KEY));

    out.writeUTF(inv.getMethodName());
    out.writeUTF(ReflectUtils.getDesc(inv.getParameterTypes()));
    Object[] args = inv.getArguments();
    if (args != null)
    for (int i = 0; i < args.length; i++){
        out.writeObject(encodeInvocationArgument(channel, inv, i));
    }
    out.writeObject(inv.getAttachments());
}
 
Example 30
Source Project: dubbox   Source File: ClassGenerator.java    License: Apache License 2.0 6 votes vote down vote up
public ClassGenerator addMethod(String name, int mod, Class<?> rt, Class<?>[] pts, Class<?>[] ets, String body)
{
	StringBuilder sb = new StringBuilder();
	sb.append(modifier(mod)).append(' ').append(ReflectUtils.getName(rt)).append(' ').append(name);
	sb.append('(');
	for(int i=0;i<pts.length;i++)
	{
		if( i > 0 )
			sb.append(',');
		sb.append(ReflectUtils.getName(pts[i]));
		sb.append(" arg").append(i);
	}
	sb.append(')');
	if( ets != null && ets.length > 0 )
	{
		sb.append(" throws ");
		for(int i=0;i<ets.length;i++)
		{
			if( i > 0 )
				sb.append(',');
			sb.append(ReflectUtils.getName(ets[i]));
		}
	}
	sb.append('{').append(body).append('}');
	return addMethod(sb.toString());
}