com.alibaba.dubbo.common.utils.ReflectUtils Java Examples
The following examples show how to use
com.alibaba.dubbo.common.utils.ReflectUtils.
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 File: Proxy.java From dubbox with Apache License 2.0 | 6 votes |
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 #2
Source File: Proxy.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
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 #3
Source File: JavaBeanSerializeUtil.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
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 #4
Source File: RpcUtils.java From dubbo3 with Apache License 2.0 | 6 votes |
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 #5
Source File: ListTelnetHandlerTest.java From dubbox with Apache License 2.0 | 6 votes |
@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 #6
Source File: MakeWrapperInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
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 #7
Source File: AnnotationBean.java From dubbox with Apache License 2.0 | 6 votes |
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 #8
Source File: RpcUtils.java From dubbox with Apache License 2.0 | 6 votes |
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 #9
Source File: JavaBeanSerializeUtil.java From dubbox with Apache License 2.0 | 6 votes |
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 #10
Source File: JavaBeanSerializeUtil.java From dubbox with Apache License 2.0 | 6 votes |
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 #11
Source File: Mixin.java From dubbox with Apache License 2.0 | 6 votes |
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 File: GenericObjectOutput.java From dubbo3 with Apache License 2.0 | 6 votes |
@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 #13
Source File: ClassGenerator.java From dubbox with Apache License 2.0 | 6 votes |
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 #14
Source File: ClassGenerator.java From dubbox with Apache License 2.0 | 6 votes |
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 #15
Source File: JavaBeanSerializeUtil.java From dubbox with Apache License 2.0 | 6 votes |
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 #16
Source File: ListTelnetHandlerTest.java From dubbo3 with Apache License 2.0 | 6 votes |
@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 #17
Source File: JavaBeanSerializeUtil.java From dubbox with Apache License 2.0 | 6 votes |
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 #18
Source File: RpcUtils.java From dubbox with Apache License 2.0 | 6 votes |
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 #19
Source File: AnnotationBean.java From dubbox with Apache License 2.0 | 6 votes |
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 #20
Source File: DubboCodec.java From dubbo3 with Apache License 2.0 | 6 votes |
@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 #21
Source File: ClassGenerator.java From dubbox with Apache License 2.0 | 6 votes |
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 #22
Source File: RpcUtils.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
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 #23
Source File: RpcUtils.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
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 #24
Source File: RpcUtils.java From dubbox with Apache License 2.0 | 6 votes |
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 #25
Source File: JacksonObjectOutput.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public void writeObject(Object obj) throws IOException { // int i = ++index; if (obj == null) { writeObject0(obj); return; } //write data value writeObject0(obj); //write data type Class c = obj.getClass(); String desc = ReflectUtils.getDesc(c); data.put(KEY_PREFIX + (index) + "t", desc); // if (obj instanceof Collection) { // //集合类型 // } else if (obj instanceof Map) { // // // } else { // } }
Example #26
Source File: JacksonObjectInput.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException { // Object value = readObject(); //read data value String json = this.data.get(KEY_PREFIX + (++index)); //read data type String dataType = this.data.get(KEY_PREFIX + index + "t"); if (dataType != null) { Class clazz = ReflectUtils.desc2class(dataType); if (cls.isAssignableFrom(clazz)) { cls = clazz; } else { throw new IllegalArgumentException("Class \"" + clazz + "\" is not inherited from \"" + cls + "\""); } } logger.debug("index:{}, value:{}", index, json); return objectMapper.readValue(json, cls); }
Example #27
Source File: JavaBeanSerializeUtil.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
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 #28
Source File: ClassGenerator.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
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 #29
Source File: ClassGenerator.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
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 #30
Source File: AbstractProxyFactory.java From dubbo3 with Apache License 2.0 | 6 votes |
public <T> T getProxy(Invoker<T> invoker) throws RpcException { Class<?>[] interfaces = null; String config = invoker.getUrl().getParameter("interfaces"); if (config != null && config.length() > 0) { String[] types = Constants.COMMA_SPLIT_PATTERN.split(config); if (types != null && types.length > 0) { interfaces = new Class<?>[types.length + 2]; interfaces[0] = invoker.getInterface(); interfaces[1] = EchoService.class; for (int i = 0; i < types.length; i ++) { interfaces[i + 1] = ReflectUtils.forName(types[i]); } } } if (interfaces == null) { interfaces = new Class<?>[] {invoker.getInterface(), EchoService.class}; } return getProxy(invoker, interfaces); }