List of usage examples for java.lang.reflect Field get
@CallerSensitive @ForceInline public Object get(Object obj) throws IllegalArgumentException, IllegalAccessException
From source file:Main.java
public static Map<String, Object> optPublicFieldKeyValueMap(Object obj) { Map<String, Object> map = new HashMap<String, Object>(); if (obj != null) { Field[] fields = obj.getClass().getFields(); for (Field f : fields) { try { boolean isStatic = Modifier.isStatic(f.getModifiers()); if (!isStatic) { Object value = f.get(obj); if (value != null) map.put(f.getName(), value); }/*from w w w. j a v a 2 s. c o m*/ } catch (Exception e) { } } } return map; }
From source file:ReflectionUtils.java
public static Object getPropertyValue(Object bean, String propertyPath) throws NoSuchFieldException { if (bean == null) throw new IllegalArgumentException("bean cannot be null"); Field field = ReflectionUtils.getField(bean.getClass(), propertyPath); field.setAccessible(true);/*w w w. j ava2 s .co m*/ try { return (field.get(bean)); } catch (IllegalAccessException e) { return (null); } }
From source file:com.evolveum.midpoint.repo.sql.util.HibernateToSqlTranslator.java
/** * Do not use in production code! Only for testing purposes only. Used for example during query engine upgrade. * Method provides translation from hibernate {@link Criteria} to plain SQL string query. * * @param criteria//from w w w . j a va2s. co m * @return SQL string, null if criteria parameter was null. */ public static String toSql(Criteria criteria) { if (criteria == null) { return null; } try { CriteriaImpl c; if (criteria instanceof CriteriaImpl) { c = (CriteriaImpl) criteria; } else { CriteriaImpl.Subcriteria subcriteria = (CriteriaImpl.Subcriteria) criteria; c = (CriteriaImpl) subcriteria.getParent(); } SessionImpl s = (SessionImpl) c.getSession(); SessionFactoryImplementor factory = s.getSessionFactory(); String[] implementors = factory.getImplementors(c.getEntityOrClassName()); CriteriaLoader loader = new CriteriaLoader( (OuterJoinLoadable) factory.getEntityPersister(implementors[0]), factory, c, implementors[0], s.getLoadQueryInfluencers()); Field f = OuterJoinLoader.class.getDeclaredField("sql"); f.setAccessible(true); return (String) f.get(loader); } catch (Exception ex) { throw new SystemException(ex.getMessage(), ex); } }
From source file:Main.java
public static void setupChangeAnimationOneTime(ViewGroup viewGroup) { LayoutTransition layoutTransition = viewGroup.getLayoutTransition(); if (layoutTransition == null) { return;//from w w w. ja v a 2 s. co m } try { Method method = LayoutTransition.class.getMethod("enableTransitionType", new Class[] { int.class }); Field field = LayoutTransition.class.getField("CHANGING"); method.invoke(layoutTransition, field.get(null)); } catch (Exception e) { setupChangeAnimationOneTime((View) viewGroup); for (int i = 0; i < viewGroup.getChildCount(); i++) { View childAt = viewGroup.getChildAt(i); setupChangeAnimationOneTime(childAt); } } }
From source file:com.dangdang.ddframe.job.lite.spring.util.AopTargetUtils.java
private static Object getTargetObject(final Object object) { try {// ww w. j ava 2s .c o m Field advised = object.getClass().getDeclaredField("advised"); advised.setAccessible(true); return ((AdvisedSupport) advised.get(object)).getTargetSource().getTarget(); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON throw new JobSystemException(ex); } }
From source file:com.dwdesign.tweetings.util.WebViewProxySettings.java
private static Object getDeclaredField(Object obj, String name) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final Field f = obj.getClass().getDeclaredField(name); f.setAccessible(true);//from ww w . j a v a2 s.c o m return f.get(obj); }
From source file:Main.java
public static void hideSmartBar(Activity activity) { if (!hasSmartBar()) return;//from ww w . j av a2 s.c o m try { @SuppressWarnings("rawtypes") Class[] arrayOfClass = new Class[1]; arrayOfClass[0] = Integer.TYPE; Method localMethod = View.class.getMethod("setSystemUiVisibility", arrayOfClass); Field localField = View.class.getField("SYSTEM_UI_FLAG_HIDE_NAVIGATION"); Object[] arrayOfObject = new Object[1]; try { arrayOfObject[0] = localField.get(null); } catch (Exception e) { } localMethod.invoke(activity.getWindow().getDecorView(), arrayOfObject); return; } catch (Exception e) { e.printStackTrace(); } }
From source file:com.dangdang.ddframe.job.spring.util.AopTargetUtils.java
private static Object getTargetObject(final Object object) { try {//from ww w. j av a 2 s .c o m Field advised = object.getClass().getDeclaredField("advised"); advised.setAccessible(true); return ((AdvisedSupport) advised.get(object)).getTargetSource().getTarget(); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON throw new JobException(ex); } }
From source file:com.job.portal.utils.BeanUtils.java
public static Map<String, Object> convertToMap(Object bean) { Map<String, Object> m = new HashMap<String, Object>(); try {// w w w.j a va2 s . co m for (Field field : bean.getClass().getDeclaredFields()) { field.setAccessible(true); // You might want to set modifier to public first. Object value = field.get(bean); if (value != null) { m.put(field.getName(), value); } } } catch (Exception e) { LogOut.log.error("In " + new Object() { }.getClass().getEnclosingClass().getName() + "." + new Object() { }.getClass().getEnclosingMethod().getName() + " " + e); } return m; }
From source file:com.job.portal.utils.BeanUtils.java
public static JSONObject convertToJSON(Object bean) { JSONObject obj = new JSONObject(); try {// ww w . ja va2 s.c om for (Field field : bean.getClass().getDeclaredFields()) { field.setAccessible(true); // You might want to set modifier to public first. Object value = field.get(bean); if (value != null) { obj.put(field.getName(), value); } } } catch (Exception e) { LogOut.log.error("In " + new Object() { }.getClass().getEnclosingClass().getName() + "." + new Object() { }.getClass().getEnclosingMethod().getName() + " " + e); } return obj; }