List of usage examples for org.springframework.util ReflectionUtils findMethod
@Nullable public static Method findMethod(Class<?> clazz, String name)
From source file:by.creepid.docsreporter.converter.HtmlxConverterAdapterTest.java
public HtmlxConverterAdapterTest() { converter = new PoiXhtmlConverterAdapter() { @Override//from w ww . ja v a 2 s . c om public ImageExtractObservable createImageExtractObservable() { return new ImageExtractObservableImpl(); } }; Method propSetMethod = ReflectionUtils.findMethod(PoiXhtmlConverterAdapter.class, "afterPropertiesSet"); ReflectionUtils.invokeMethod(propSetMethod, converter); }
From source file:org.codehaus.groovy.grails.plugins.quartz.TaskArtefactHandler.java
public boolean isArtefactClass(Class clazz) { // class shouldn't be null and shoud ends with Job suffix if (clazz == null || !clazz.getName().endsWith(DefaultGrailsTaskClass.JOB)) return false; // and should have one of execute() or execute(JobExecutionContext) methods defined Method method = ReflectionUtils.findMethod(clazz, GrailsTaskClassProperty.EXECUTE); if (method == null) { // we're using Object as a param here to allow groovy-style 'def execute(param)' method method = ReflectionUtils.findMethod(clazz, GrailsTaskClassProperty.EXECUTE, new Class[] { Object.class }); }/*ww w . j av a 2s . c om*/ return method != null; }
From source file:grails.plugin.quartz2.JobArtefactHandler.java
public boolean isArtefactClass(Class clazz) { // class shouldn't be null and should ends with Job suffix if (clazz == null || !clazz.getName().endsWith(DefaultGrailsJobClass.JOB)) return false; // and should have one of execute() or execute(JobExecutionContext) methods defined Method method = ReflectionUtils.findMethod(clazz, GrailsJobClassConstants.EXECUTE); if (method == null) { // we're using Object as a param here to allow groovy-style 'def execute(param)' method method = ReflectionUtils.findMethod(clazz, GrailsJobClassConstants.EXECUTE, new Class[] { Object.class }); }//from ww w .j av a2 s. c o m if (method == null) { // also check for the execution context as a variable because that's what's being passed method = ReflectionUtils.findMethod(clazz, GrailsJobClassConstants.EXECUTE, new Class[] { JobExecutionContext.class }); } return method != null; }
From source file:org.codehaus.groovy.grails.plugins.quartz.JobArtefactHandler.java
public boolean isArtefactClass(Class clazz) { // class shouldn't be null and shoud ends with Job suffix if (clazz == null || !clazz.getName().endsWith(DefaultGrailsJobClass.JOB)) return false; // and should have one of execute() or execute(JobExecutionContext) methods defined Method method = ReflectionUtils.findMethod(clazz, GrailsJobClassProperty.EXECUTE); if (method == null) { // we're using Object as a param here to allow groovy-style 'def execute(param)' method method = ReflectionUtils.findMethod(clazz, GrailsJobClassProperty.EXECUTE, new Class[] { Object.class }); }// ww w .j a v a 2 s .c o m if (method == null) { // also check for the execution context as a variable because that's what's being passed method = ReflectionUtils.findMethod(clazz, GrailsJobClassProperty.EXECUTE, new Class[] { JobExecutionContext.class }); } return method != null; }
From source file:grails.plugins.quartz.JobArtefactHandler.java
@Override public boolean isArtefactClass(@SuppressWarnings("rawtypes") Class clazz) { // class can't be null and must end with "Job" suffix if (clazz == null || !clazz.getName().endsWith(DefaultGrailsJobClass.JOB)) return false; // and must have one of execute() or execute(JobExecutionContext) methods Method method = ReflectionUtils.findMethod(clazz, GrailsJobClassConstants.EXECUTE); if (method == null) { // we're using Object as a param here to allow groovy-style 'def execute(param)' method method = ReflectionUtils.findMethod(clazz, GrailsJobClassConstants.EXECUTE, new Class[] { Object.class }); }/* w ww .j a va 2 s .c o m*/ if (method == null) { // also check for the execution context as a variable because that's what's being passed method = ReflectionUtils.findMethod(clazz, GrailsJobClassConstants.EXECUTE, new Class[] { JobExecutionContext.class }); } return method != null; }
From source file:es.logongas.ix3.util.ReflectionUtilTest.java
@Test public void testGetAnnotationMethodGet() throws Exception { System.out.println("getAnnotation en un metodo get"); TestAnnotation expResult = ReflectionUtils.findMethod(BeanTestC.class, "getPropReadOnly") .getAnnotation(TestAnnotation.class); TestAnnotation result = ReflectionUtil.getAnnotation(BeanTestC.class, "propReadOnly", TestAnnotation.class); assertEquals(expResult, result);/*from w w w .j ava 2 s.com*/ }
From source file:cn.wanghaomiao.seimi.core.SeimiBeanResolver.java
private static Object defaultCastToTargetValue(Class target, Field field, List<Object> xpathRes) { Method getter = ReflectionUtils.findMethod(target, "get" + upperFirst(field.getName())); if (getter != null) { if (List.class.equals(getter.getReturnType())) { Class[] componentClazzs = GenericUtils.getActualClass(getter.getGenericReturnType()); if (componentClazzs != null && componentClazzs.length > 0) { Class componentClass = componentClazzs[0]; if (String.class.isAssignableFrom(componentClass)) { List<String> resTmp = new LinkedList<>(); for (Object obj : xpathRes) { if (obj instanceof Element) { resTmp.add(((Element) obj).html()); } else { resTmp.add(obj.toString()); }/*from w w w .j a v a 2s. c om*/ } return resTmp; } else if (Element.class.isAssignableFrom(componentClass)) { return xpathRes; } else if (GenericUtils.isNumber(componentClass)) { List resTmp = new LinkedList(); for (Object obj : xpathRes) { resTmp.add(GenericUtils.castToNumber(componentClass, obj.toString())); } return resTmp; } else { throw new SeimiBeanResolveException("not support field type"); } } } else if (!Collection.class.isAssignableFrom(getter.getReturnType()) && getter.getReturnType().isArray()) { Class componentClass = getter.getReturnType().getComponentType(); if (String.class.isAssignableFrom(componentClass)) { List<String> resTmp = new LinkedList<>(); for (Object obj : xpathRes) { if (obj instanceof Element) { resTmp.add(((Element) obj).html()); } else { resTmp.add(obj.toString()); } } return resTmp; } else if (Element.class.isAssignableFrom(componentClass)) { return xpathRes; } else if (GenericUtils.isNumber(componentClass)) { List resTmp = new LinkedList(); for (Object obj : xpathRes) { resTmp.add(GenericUtils.castToNumber(componentClass, obj.toString())); } return resTmp; } else { throw new SeimiBeanResolveException("not support field type"); } } else if (!Collection.class.isAssignableFrom(getter.getReturnType()) && GenericUtils.isNumber(field.getType())) { return GenericUtils.castToNumber(field.getType(), StringUtils.join(xpathRes, "")); } else if (!Collection.class.isAssignableFrom(getter.getReturnType()) && String.class.isAssignableFrom(field.getType())) { return StringUtils.join(xpathRes, ""); } } return null; }
From source file:org.eclipse.gemini.blueprint.test.internal.holder.ReflectionOsgiHolder.java
/** * Constructs a new <code>OsgiTestInfoHolder</code> instance wrapping the * given object and accessing it through reflection. This constructor is * used for accessing the instance loaded outside OSGi, from within OSGi. * /* w w w . ja va 2s .co m*/ * @param twinInstance */ ReflectionOsgiHolder(Object twinInstance) { Assert.notNull(twinInstance); this.instance = twinInstance; Class<?> clazz = instance.getClass(); GET_TEST_BUNDLE_ID = ReflectionUtils.findMethod(clazz, "getTestBundleId"); GET_TEST_CLASS_NAME = ReflectionUtils.findMethod(clazz, "getTestClassName"); GET_TEST_METHOD_NAME = ReflectionUtils.findMethod(clazz, "getTestMethodName"); ADD_TEST_ERROR = ReflectionUtils.findMethod(clazz, "addTestError", new Class<?>[] { Throwable.class }); ADD_TEST_FAILURE = ReflectionUtils.findMethod(clazz, "addTestFailure", new Class<?>[] { Throwable.class }); }
From source file:org.codehaus.griffon.runtime.quartz.JobArtifactHandler.java
public boolean isArtifactClass(Class clazz) { // class shouldn't be null and shoud ends with Job suffix if (clazz == null || !clazz.getName().endsWith(GriffonJobClass.TRAILING)) return false; // and should have one of execute() or execute(JobExecutionContext) methods defined Method method = ReflectionUtils.findMethod(clazz, QuartzConstants.EXECUTE); if (method == null) { // we're using Object as a param here to allow groovy-style 'def execute(param)' method method = ReflectionUtils.findMethod(clazz, QuartzConstants.EXECUTE, new Class[] { Object.class }); }/*ww w. j ava 2 s.c om*/ if (method == null) { // also check for the execution context as a variable because that's what's being passed method = ReflectionUtils.findMethod(clazz, QuartzConstants.EXECUTE, new Class[] { JobExecutionContext.class }); } return method != null; }
From source file:org.shept.persistence.provider.hibernate.HibernateUtils_old.java
/** * Checking if it is a new model/*from www. jav a2 s . com*/ * If the index is a compound index we must check all components if they are all non null * @param index * @return */ public static boolean isNewModel(HibernateDaoSupport dao, Object model) { final Object index = getIdValue(dao, model); final List<Field> nulls = new ArrayList<Field>(); if (index == null) return true; ReflectionUtils.doWithFields(index.getClass(), new ReflectionUtils.FieldCallback() { public void doWith(Field field) { try { Method idMth = ReflectionUtils.findMethod(index.getClass(), "get" + StringUtils.capitalize(field.getName())); Object value = ReflectionUtils.invokeMethod(idMth, index); if (value == null) { nulls.add(field); } } catch (Exception ex) { // ignore all Exception here as they are quit frequent // e.g. serialVersionUid e.t.c. or do better filtering // TODO better eliminate error cases } } }); return nulls.size() > 0; }