List of usage examples for org.springframework.util ReflectionUtils invokeMethod
@Nullable public static Object invokeMethod(Method method, @Nullable Object target)
From source file:com.mylife.hbase.mapper.HBaseEntityMapper.java
private Object fieldValue(final Field field, final Object hbasePersistableObject, final ImmutableMap<Class<?>, ImmutableMap<Field, Method>> map) { final Method getter = map.get(hbasePersistableObject.getClass()).get(field); ReflectionUtils.makeAccessible(getter); return ReflectionUtils.invokeMethod(getter, hbasePersistableObject); }
From source file:org.hibernate.internal.SessionFactoryImpl.java
public Dialect getDialect() { if (serviceRegistry == null) { throw new IllegalStateException("Cannot determine dialect because serviceRegistry is null."); }/* w w w .j a v a2s. c om*/ try { if (currentSessionContext != null) { Method m = getCurrentSession().getClass().getMethod("connection"); Connection con = (Connection) ReflectionUtils.invokeMethod(m, getCurrentSession()); return resolveDialectInternal(con.getMetaData()); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return dialect; }
From source file:net.stickycode.mockwire.spring30.MockwireFieldInjectionAnnotationBeanPostProcessor.java
/** * Determine if the annotated field or method requires its dependency. * <p>A 'required' dependency means that autowiring should fail when no beans * are found. Otherwise, the autowiring process will simply bypass the field * or method when no beans are found.// w ww . j a v a 2s .c om * @param annotation the Autowired annotation * @return whether the annotation indicates that a dependency is required */ protected boolean determineRequiredStatus(Annotation annotation) { try { Method method = ReflectionUtils.findMethod(annotation.annotationType(), this.requiredParameterName); return (this.requiredParameterValue == (Boolean) ReflectionUtils.invokeMethod(method, annotation)); } catch (Exception ex) { // required by default return true; } }
From source file:org.artifactory.storage.db.spring.ArtifactoryPoolableConnectionFactory.java
@Override public void passivateObject(Object obj) throws Exception { if (obj instanceof Connection) { Connection conn = (Connection) obj; if (!conn.getAutoCommit() && !conn.isReadOnly()) { conn.rollback();/* www .j a v a 2 s . c o m*/ } conn.clearWarnings(); //if(!conn.getAutoCommit()) { // conn.setAutoCommit(true); //} } if (obj instanceof DelegatingConnection) { Method passivateMethod = ReflectionUtils.findMethod(DelegatingConnection.class, "passivate"); passivateMethod.setAccessible(true); ReflectionUtils.invokeMethod(passivateMethod, obj); } }
From source file:org.cloudfoundry.identity.statsd.UaaMetricsEmitter.java
public Number getValueFromBean(Object mbean, String getter) { Method method = findMethod(mbean.getClass(), getter); if (method != null) { boolean original = method.isAccessible(); method.setAccessible(true);//from ww w . ja v a 2s . c o m try { return (Number) ReflectionUtils.invokeMethod(method, mbean); } catch (Exception e) { logger.debug("Unable to invoke metric", e); } finally { method.setAccessible(original); } } return null; }
From source file:org.lexevs.dao.database.utility.DaoUtility.java
@SuppressWarnings("unchecked") public static <T extends URIMap> T getURIMap(Mappings mappings, Class<T> uriMapClass, String localId) { if (mappings == null) { return null; }//from www . j a va 2s .c om final String getPrefix = "get"; final String getSuffix = "AsReference"; List<T> uriMapList = (List<T>) ReflectionUtils.invokeMethod( ReflectionUtils.findMethod(Mappings.class, getPrefix + uriMapClass.getSimpleName() + getSuffix), mappings); List<T> returnList = new ArrayList<T>(); for (T map : uriMapList) { if (map.getLocalId().equalsIgnoreCase(localId)) { returnList.add(map); } } if (CollectionUtils.isEmpty(returnList)) { return null; } if (returnList.size() > 1) { throw new IllegalStateException("Two URIMaps found with the same LocalID: " + localId); } return returnList.get(0); }
From source file:org.openmrs.module.chartsearch.api.db.hibernate.HibernateChartSearchDAO.java
public Connection getConnection() { try {/* w w w. j ava 2 s.co m*/ // reflective lookup to bridge between Hibernate 3.x and 4.x Method connectionMethod = sessionFactory.getCurrentSession().getClass().getMethod("connection"); return (Connection) ReflectionUtils.invokeMethod(connectionMethod, sessionFactory.getCurrentSession()); } catch (NoSuchMethodException ex) { throw new IllegalStateException("Cannot find connection() method on Hibernate session", ex); } }
From source file:org.shept.org.springframework.web.servlet.mvc.delegation.command.AssociationCommandFactory.java
/** * @param mth/*from ww w.j a v a 2s. c o m*/ * @param model * @param * @return */ protected Object createWrappedEntity(TargetConfiguration config, Method mth, Object model) { Object target = ReflectionUtils.invokeMethod(mth, model); // this code resolves Hibernate proxies into the real objects // but its an additional dependency on hibernate and shouldn't be necessary // if (target instanceof HibernateProxy) { // target = ((HibernateProxy)target).getHibernateLazyInitializer().getImplementation(); // } Object command = ModelUtils.wrapIfNecessary(target); return command; }
From source file:org.shept.org.springframework.web.servlet.mvc.delegation.ComponentUtils.java
/** * /*from w w w . j av a2s. c o m*/ * @param * @return * * @param wrapper * @param ctx * @param model * @param selector * @return */ public static String getComponentInfo(HttpServletRequest request, InfoItem item, Object model) { if (item == null) return null; if (item.getCode() == null) return null; WebApplicationContext ctx = RequestContextUtils.getWebApplicationContext(request); Locale locale = RequestContextUtils.getLocale(request); String arg = null; Method mth; if (model != null) { if (StringUtils.hasText(item.getSelector())) { mth = ReflectionUtils.findMethod(model.getClass(), StringUtilsExtended.getReadAccessor(item.getSelector())); if (mth != null) { arg = (String) ReflectionUtils.invokeMethod(mth, model); } } } if (StringUtils.hasText(arg)) { return ctx.getMessage(item.getCode(), new String[] { arg }, "???", locale); } else { return ctx.getMessage(item.getCode(), null, "???", locale); } }
From source file:org.shept.org.springframework.web.servlet.mvc.support.ModelUtils.java
/** * When the object to be copied provides a clone implementation * return a clone of the object./* w w w .j a v a 2s . c o m*/ * * @param model * @return */ private static Object cloneCopy(Object model) { Object newModel = null; Method mth = ReflectionUtils.findMethod(model.getClass(), "clone"); if (mth != null) { try { newModel = ReflectionUtils.invokeMethod(mth, model); } catch (Exception ex) { // ignore any exception during cloning if (logger.isDebugEnabled()) { logger.debug("Cloning " + model + " failure", ex); } } } return newModel; }