/** * create a new instance by the given constructor. */ public static <T> T newInstance(Constructor<T> constructor){ return newInstance(constructor, Arrays2.EMPTY_BOOLEAN_ARRAY); }
@Override public List<DbCommand> getSchemaChangeCommands(SchemaChange change, SchemaChangeContext context) { List<DbCommand> commands = new ArrayList<>(); Method method = schemaChangeMethods.get(change.getClass()); if (null == method) { method = Reflection.findMethod(this.getClass(), "createSchemaChangeCommands", SchemaChangeContext.class, change.getClass(), List.class); if (null == method) { throw new UnsupportedChangeException("Unsupported change '" + change.getClass().getSimpleName() + "'", change); } schemaChangeMethods.put(change.getClass(), method); } Reflection.invokeMethod(method, this, context, change, commands); return commands; }
/** * Attempt to find a {@link Field field} on the supplied {@link Class} with the supplied <code>name</code>. * * Searches all superclasses up to {@link Object}. * * @param clazz the class to introspect * @param name the name of the field * @return the corresponding Field object, or <code>null</code> if not found */ public static Field findField(Class<?> clazz, String name) { return findField(clazz, name, null); }
/** * Invoke the specified {@link Method} against the supplied target object with no Args. The target object can * be <code>null</code> when invoking a static {@link Method}. * * @param method the method to invoke * @param target the target object to invoke the method on * @return the invocation result, if any * @see #invokeMethod(java.lang.reflect.Method, Object, Object[]) */ public static Object invokeMethod(Method method, Object target) { return invokeMethod(method, target, Arrays2.EMPTY_OBJECT_ARRAY); }
/** * Attempt to find a {@link Method} on the supplied class with the supplied name and no parameters. * * Searches all superclasses up to <code>Object</code>. * * <p> * Returns <code>null</code> if no {@link Method} can be found. * * @param clazz the class to introspect * @param name the name of the method * @return the Method object, or <code>null</code> if none found */ public static Method findMethod(Class<?> clazz, String name) { return findMethod(clazz, name, Arrays2.EMPTY_CLASS_ARRAY); }
@Override public String convertToString(Method m) throws Throwable { return Reflection.fullQualifyName(m); } }
public static ElFunction createFunction(Class<?> cls, String methodNameOrDesc) { return new ElStaticMethod(Reflection.getMethodByNameOrDesc(cls, methodNameOrDesc)); }
protected static String doGetPath(Object resource) { return (String) Reflection.invokeMethod(VIRTUAL_FILE_METHOD_GET_PATH_NAME, resource); } }
bean.setInitMethod(Reflection.findMethod(bean.getBeanClass(), initMethodName)); if (null == bean.getInitMethod()) { throw new BeanDefinitionException("init method '" + initMethodName + "' not found in class '" + beanClassName + "', source : " + reader.getSource()); bean.setDestroyMethod(Reflection.findMethod(bean.getBeanClass(), destroyMethodName)); if (null == bean.getDestroyMethod()) { throw new BeanDefinitionException("destroy method '" + initMethodName + "' not found in class '" + beanClassName + "', source : " + reader.getSource());
public ReflectDeleteEntityListener(Object inst, ReflectMethod m) { this.inst = inst; this.method = m; if(m.getParameters().length == 1) { this.transactional = false; ReflectParameter p = m.getParameters()[0]; if(p.getType().equals(Object.class)) { func = (e) -> m.invoke(inst, e.getId()); return; }else if(p.getType().equals(DeleteEntityEvent.class)) { func = (e) -> m.invoke(inst, e); return; } } else if(m.getParameters().length == 2) { this.transactional = true; ReflectParameter p0 = m.getParameters()[0]; ReflectParameter p1 = m.getParameters()[1]; if(p0.getType().equals(Object.class) && p1.getType().equals(TransactionStatus.class)) { func = (e) -> m.invoke(inst, e.getId(), e.getTransactionStatus()); return; } if(p0.getType().equals(DeleteEntityEvent.class) && p1.getType().equals(TransactionStatus.class)) { func = (e) -> m.invoke(inst, e, e.getTransactionStatus()); return; } } throw new IllegalArgumentException("Incorrect parameters in method '" + Reflection.fullQualifyName(m.getReflectedMethod()) + "' for 'DeleteEntity' event"); }
void resolve() { Class<?> cls = Classes.tryForName(className); if(null == cls) { throw new AppConfigException("Class '" + className + "' not found, check xml '" + source + "'"); } Method m = null; try { m = Reflection.getMethodByNameOrDesc(cls, methodDesc); } catch (Exception e) { throw new AppConfigException("Method name '" + methodDesc + "', check xml '" + source + "'", e); } if(Strings.isEmpty(funcName)){ funcName = m.getName(); } if(!Modifier.isPublic(m.getModifiers()) || !Modifier.isStatic(m.getModifiers())){ throw new AppConfigException("Function method '" + methodDesc + "' must be 'public static', check xml '" + source + "'"); } function = new ElStaticMethod(m); }
protected static Map createMap(Class<?> mapType){ if(mapType.equals(Map.class)){ return new LinkedHashMap(); } return (Map)Reflection.newInstance(mapType); }
initMethod = Reflection.findMethod(clazz, initMethodName); Reflection.invokeMethod(initMethod,null); } catch (Exception e) { throw new BeanException("Error invoking the init method '" + initMethodName + "' in class '" + initClassName + "', source : " + init.getSource());
protected Resource resolveRootDirResource(Resource original) throws IOException { if (equinoxResolveMethod != null) { URL url = original.getURL(); if (url.getProtocol().startsWith("bundle")) { return new UrlResource((URL)Reflection.invokeMethod(equinoxResolveMethod, null, url)); } } return original; }
if(null == Reflection.findField(RequestMappingHandlerMapping.class, "mappingRegistry")) { log.error("Can't find 'mappingRegistry' field at '" + RequestMappingHandlerMapping.class + "'"); return; Field field = Reflection.findField(mapping.getClass(), "mappingRegistry"); if(null == field) { log.info("Can't find 'mappingRegistry' field at '" + mapping.getClass() + "'"); field = Reflection.findField(registry.getClass(), "registry"); if (null == field) { log.error("Can't find 'registry' field at '" + registry.getClass() + "'"); Field field1 = Reflection.findField(v.getClass(), "handlerMethod"); if (null != field1) { try {
Reflection.fullQualifyName(m.getReflectedMethod()) + "' for '" + eventType.getSimpleName() + "' event");
protected Collection newCollection(Class c) { if(List.class.equals(c)) { return new ArrayList(); } if(Set.class.equals(c)) { return new LinkedHashSet(); } return (Collection)Reflection.newInstance(c); }
if(null != destroyMethod) { try { Reflection.invokeMethod(destroyMethod, bean); } catch (Throwable e) { log.warn("Error destroy bean '{}' : {}", null == bd ? bean : bd, e.getMessage(), e);
public static MSimpleType tryForClass(Class<?> cls) { if(cls.isEnum()){ Field field = Reflection.findField(cls, "value"); if(null != field) { return tryForClass(field.getType()); }else{ return tryForClass(String.class); } } for(MSimpleType t : all()){ if(t.getJavaType().equals(cls)){ return t; } } for(MSimpleType t : all()){ for(Class<?> javaType : t.getJavaTypes()){ if(javaType.equals(cls)){ return t; } } } return null; }
public static <T> T copyNew(T from) { if(null == from) { return null; } T to = (T)Reflection.newInstance(from.getClass()); copyProperties(from, to); return to; }