List of usage examples for java.lang Class getField
@CallerSensitive public Field getField(String name) throws NoSuchFieldException, SecurityException
From source file:org.apache.jackrabbit.core.TestRepository.java
/** * Attempts to retrieve the test repository instance used by the * Jackrabbit main test suite without having a direct dependency to any * of the classes in src/test/java. This method assumes that we are * running within the Jackrabbit main test suite if the AbstractJCRTest * class is available. The initialized RepositoryHelper instance is * retrieved from the static "helper" field of the AbstractJCRTest class, * and the underlying repository and configured superuser credentials are * extracted from the helper instance. This information is in turn used * to create a custom Repository adapter that delegates calls to the * underlying repository and uses the superuser credentials for the login * methods where no credentials are passed by the client. * * @return test repository instance// ww w .j a v a2 s .c o m * @throws Exception if the test repository could not be retrieved */ private static Repository getIntegratedInstance() throws Exception { Class test = Class.forName("org.apache.jackrabbit.test.AbstractJCRTest"); Map helper = new BeanMap(test.getField("helper").get(null)); final Repository repository = (Repository) helper.get("repository"); final Credentials superuser = (Credentials) helper.get("superuserCredentials"); return new ProxyRepository(new RepositoryFactory() { public Repository getRepository() throws RepositoryException { return repository; } }) { public Session login(String workspace) throws RepositoryException { return repository.login(superuser, workspace); } public Session login() throws RepositoryException { return repository.login(superuser); } }; }
From source file:Main.java
public static int getStatusHeight(Activity activity) { int statusHeight = 0; Rect localRect = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect); statusHeight = localRect.top;//from w w w. jav a 2s.c o m if (0 == statusHeight) { Class<?> localClass; try { localClass = Class.forName("com.android.internal.R$dimen"); Object localObject = localClass.newInstance(); int i5 = Integer.parseInt(localClass.getField("status_bar_height").get(localObject).toString()); statusHeight = activity.getResources().getDimensionPixelSize(i5); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (NumberFormatException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } } return statusHeight; }
From source file:Main.java
public static int getStatusBarHeight(Context context) { Class<?> c = null; Object obj = null;/*from w ww.j a v a 2 s.c o m*/ Field field = null; int x = 0, statusBarHeight = 0; try { c = Class.forName("com.android.internal.R$dimen"); obj = c.newInstance(); field = c.getField("status_bar_height"); x = Integer.parseInt(field.get(obj).toString()); statusBarHeight = context.getResources().getDimensionPixelSize(x); } catch (Exception e1) { e1.printStackTrace(); } return statusBarHeight; }
From source file:Main.java
public static int getStatusBarHeight1(Context activity) { Class<?> c = null; Object obj = null;/*from w ww . j a va 2s. co m*/ Field field = null; int x = 0, statusBarHeight = 0; try { c = Class.forName("com.android.internal.R$dimen"); obj = c.newInstance(); field = c.getField("status_bar_height"); x = Integer.parseInt(field.get(obj).toString()); statusBarHeight = activity.getResources().getDimensionPixelSize(x); } catch (Exception e1) { e1.printStackTrace(); } return statusBarHeight; }
From source file:com.feilong.core.lang.reflect.FieldUtilTemp.java
/** * ./*from w w w. j a v a 2 s.com*/ * * <p> * <code>owner</code> null, {@link NullPointerException}<br> * <code>fieldName</code> null, {@link NullPointerException}<br> * <code>fieldName</code> blank, {@link IllegalArgumentException}<br> * </p> * * @param owner * the owner * @param fieldName * * @param value * * @see java.lang.Object#getClass() * @see java.lang.Class#getField(String) * @see java.lang.reflect.Field#set(Object, Object) * * @see org.apache.commons.lang3.reflect.FieldUtils#writeField(Field, Object, Object, boolean) * @since 1.4.0 */ public static void setFieldValue(Object owner, String fieldName, Object value) { Validate.notNull(owner, "owner can't be null!"); Validate.notBlank(fieldName, "fieldName can't be blank!"); try { Class<?> ownerClass = owner.getClass(); Field field = ownerClass.getField(fieldName); field.set(ownerClass, value); } catch (Exception e) { throw new ReflectException(e); } }
From source file:org.tros.utils.logging.Logging.java
public static void initLogging(BuildInfo binfo, Class init) { try {/* w ww.j a va 2 s.co m*/ //hack to get this logger to shut up Class<?> forName = Class.forName("org.reflections.Reflections"); Field f = forName.getField("log"); f.set(null, null); } catch (ClassNotFoundException | NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) { Logger.getLogger(Logging.class.getName()).log(Level.FINEST, "org.reflections.Reflections not in CLASSPATH..."); } //make logs directory getLogDirectory(binfo); //init logger String dir = getApplicationEtcDirectory(binfo) + "/logging.properties"; File logProp = new File(dir); if (!logProp.exists()) { copyFile(binfo, init, logProp); } if (logProp.exists()) { loadFile(logProp); } LogManager lm = LogManager.getLogManager(); String property = lm.getProperty("version"); if (property == null || !property.equals(binfo.getVersion().replace("-SNAPSHOT", ""))) { //backup old file File backup = new File(logProp.getAbsolutePath() + "." + (property == null ? "old" : property)); logProp.renameTo(backup); //copy new file copyFile(binfo, init, logProp); //re-load new file loadFile(logProp); } //Small hack to close SwingComponentHandler which should only be used by a GUI //however, if the logging.properties file is already set with this handler, remove //it and then the GUI will manually re-add it in the LogConsole constructor. Logger logger = Logger.getLogger(""); try { Class<?> swingLogger = Class.forName("org.tros.utils.logging.SwingComponentHandler"); for (Handler h : logger.getHandlers()) { if (swingLogger.isAssignableFrom(h.getClass())) { logger.removeHandler(h); h.close(); } } } catch (ClassNotFoundException ex) { Logger.getLogger(Logging.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Main.java
public static int getStatusBarHeight(Context context) { Class<?> c = null; Object obj = null;/* ww w . j a v a2s. c o m*/ Field field = null; int x = 0, statusBarHeight = 0; try { c = Class.forName("com.android.internal.R$dimen"); obj = c.newInstance(); field = c.getField("status_bar_height"); x = Integer.parseInt(field.get(obj).toString()); statusBarHeight = context.getResources().getDimensionPixelSize(x); } catch (Exception e1) { e1.printStackTrace(); } return statusBarHeight; }
From source file:Main.java
public static int getStatusBarHeight(Context context) { Class<?> c; Object obj;/*from www . j av a 2s . c o m*/ Field field; int x, statusBarHeight = 0; try { c = Class.forName("com.android.internal.R$dimen"); obj = c.newInstance(); field = c.getField("status_bar_height"); x = Integer.parseInt(field.get(obj).toString()); statusBarHeight = context.getResources().getDimensionPixelSize(x); } catch (Exception e1) { e1.printStackTrace(); } return statusBarHeight; /** * Rect frame = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; */ }
From source file:Main.java
public static int getStatusBarHeight(Context context) { Class c = null; Object bj = null;/*from ww w . j a va2s. co m*/ Field field = null; int x = 0, statusBarHeight = 0; try { c = Class.forName("com.android.internal.R$dimen"); bj = c.newInstance(); field = c.getField("status_bar_height"); x = Integer.parseInt(field.get(bj).toString()); statusBarHeight = context.getResources().getDimensionPixelSize(x); } catch (Exception e1) { e1.printStackTrace(); } return statusBarHeight; }
From source file:Main.java
public static int getStatusBarHeight(Context context) { Class<?> c = null; Object obj = null;/* w w w .ja v a 2 s . c om*/ Field field = null; int x = 0; int sbar = 0; try { c = Class.forName("com.android.internal.R$dimen"); obj = c.newInstance(); field = c.getField("status_bar_height"); x = Integer.parseInt(field.get(obj).toString()); sbar = context.getResources().getDimensionPixelSize(x); } catch (Exception e) { e.printStackTrace(); } return sbar; }