List of usage examples for java.lang.reflect Field set
@CallerSensitive @ForceInline public void set(Object obj, Object value) throws IllegalArgumentException, IllegalAccessException
From source file:Main.java
public static void keep_setShort(Field field, Object obj, Cursor cursor, int i) { try {// w w w .j a v a 2 s . com if (field.getType().equals(Short.TYPE)) field.setShort(obj, cursor.getShort(i)); else field.set(obj, Short.valueOf(cursor.getShort(i))); } catch (Exception exception) { exception.printStackTrace(); } }
From source file:Main.java
public static boolean replaceField(String className, String fieldName, Object desObj, Object fieldObj) { Field tempField; try {//w w w .j a va2s. com tempField = Class.forName(className).getDeclaredField(fieldName); tempField.setAccessible(true); tempField.set(desObj, fieldObj); return true; } catch (NoSuchFieldException e) { // TODO Auto-generated catch block Log.i("DEX", "" + e.getMessage()); // e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; }
From source file:com.userhook.model.UHMessageMeta.java
public static UHMessageMeta fromJSON(JSONObject json) { UHMessageMeta meta = new UHMessageMeta(); try {//from w w w. ja v a 2 s.c om String[] fields = { "displayType", "body" }; for (String field : fields) { if (json.has(field)) { Field f = UHMessageMeta.class.getDeclaredField(field); f.set(meta, json.getString(field)); } } if (json.has("button1")) { meta.button1 = UHMessageMetaButton.fromJSON(json.getJSONObject("button1")); } if (json.has("button2")) { meta.button2 = UHMessageMetaButton.fromJSON(json.getJSONObject("button2")); } } catch (JSONException e) { Log.e(UserHook.TAG, "error parsing message meta json", e); } catch (NoSuchFieldException nsf) { Log.e(UserHook.TAG, "error setting properties of message meta", nsf); } catch (IllegalAccessException ia) { Log.e(UserHook.TAG, "error accessing properties of message meta", ia); } return meta; }
From source file:Main.java
public static void setField(Object value, Field field, Object target) { boolean accessible = field.isAccessible(); field.setAccessible(true);//from w w w.ja v a 2s . c om Object result = null; try { field.set(target, value); } catch (IllegalAccessException e) { // ignore } field.setAccessible(accessible); }
From source file:com.dwdesign.tweetings.util.WebViewProxySettings.java
private static void setDeclaredField(Object obj, String name, Object value) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final Field f = obj.getClass().getDeclaredField(name); f.setAccessible(true);// w w w. j av a 2 s . c o m f.set(obj, value); }
From source file:name.martingeisse.esdk.simulation.lwjgl.NativeLibraryHelper.java
/** * Extracts LWJGL libraries to a folder and * @throws Exception on errors//from www . ja v a 2 s.c o m */ public static void prepareNativeLibraries() throws Exception { // Unfortunately, Java is also too stupid to create a temp directory... tempFolder = File.createTempFile("miner-launcher-", ""); deleteRecursively(tempFolder); tempFolder.mkdir(); logger.debug("temp: " + tempFolder.getAbsolutePath()); // detect which set of native libraries to load, then extract the files resourcePath = OperatingSystemSelector.getHostOs().getNativeLibraryPath(); logger.debug("native library path: " + resourcePath); for (String fileName : OperatingSystemSelector.getHostOs().getNativeLibraryFileNames()) { extractFile(fileName); } // make Java use our libraries System.setProperty("java.library.path", tempFolder.getAbsolutePath()); final Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths"); fieldSysPath.setAccessible(true); fieldSysPath.set(null, null); }
From source file:com.picklecode.popflix.App.java
public static void setLibraryPath(String path) throws Exception { System.setProperty("java.library.path", path); //set sys_paths to null so that java.library.path will be reevalueted next time it is needed final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths"); sysPathsField.setAccessible(true);/*from w w w . ja v a 2 s . c o m*/ sysPathsField.set(null, null); }
From source file:com.funtl.framework.smoke.core.modules.act.service.creator.RuntimeActivityCreatorSupport.java
private static void copyFields(Object source, Object target, String... fieldNames) { Assert.assertNotNull(source);/*from w w w . j a v a 2 s. co m*/ Assert.assertNotNull(target); Assert.assertSame(source.getClass(), target.getClass()); for (String fieldName : fieldNames) { try { Field field = FieldUtils.getField(source.getClass(), fieldName, true); field.setAccessible(true); field.set(target, field.get(source)); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.npower.dm.util.BeanHelper.java
/** * private/protected/*from w w w . j a va 2 s . c o m*/ */ static public void setPrivateProperty(Object object, String propertyName, Object newValue) throws IllegalAccessException, NoSuchFieldException { assert object != null; assert StringUtils.isNotEmpty(propertyName); Field field = object.getClass().getDeclaredField(propertyName); field.setAccessible(true); field.set(object, newValue); }
From source file:pl.softech.eav.example.SimpleInMemmoryRepository.java
private static void setId(AbstractEntity entity, Long id) { try {/* w w w .j a v a2 s . com*/ Field f = AbstractEntity.class.getDeclaredField("id"); f.setAccessible(true); f.set(entity, id); } catch (Exception e) { throw new RuntimeException(e); } }