List of usage examples for java.lang.reflect Field getInt
@CallerSensitive @ForceInline public int getInt(Object obj) throws IllegalArgumentException, IllegalAccessException
From source file:org.apache.sqoop.SqoopOptions.java
/** * Return a Properties instance that encapsulates all the "sticky" * state of this SqoopOptions that should be written to a metastore * to restore the job later.// w w w.j a v a2 s .co m */ public Properties writeProperties() { Properties props = new Properties(); try { Field[] fields = SqoopOptions.class.getDeclaredFields(); for (Field f : fields) { if (f.isAnnotationPresent(StoredAsProperty.class)) { Class typ = f.getType(); StoredAsProperty storedAs = f.getAnnotation(StoredAsProperty.class); String propName = storedAs.value(); if (typ.equals(int.class)) { putProperty(props, propName, Integer.toString(f.getInt(this))); } else if (typ.equals(boolean.class)) { putProperty(props, propName, Boolean.toString(f.getBoolean(this))); } else if (typ.equals(long.class)) { putProperty(props, propName, Long.toString(f.getLong(this))); } else if (typ.equals(String.class)) { putProperty(props, propName, (String) f.get(this)); } else if (typ.equals(Integer.class)) { putProperty(props, propName, f.get(this) == null ? "null" : f.get(this).toString()); } else if (typ.isEnum()) { putProperty(props, propName, f.get(this).toString()); } else { throw new RuntimeException("Could not set property " + propName + " for type: " + typ); } } } } catch (IllegalAccessException iae) { throw new RuntimeException("Illegal access to field in property setter", iae); } if (this.getConf().getBoolean(METASTORE_PASSWORD_KEY, METASTORE_PASSWORD_DEFAULT)) { // If the user specifies, we may store the password in the metastore. putProperty(props, "db.password", this.password); putProperty(props, "db.require.password", "false"); } else if (this.password != null) { // Otherwise, if the user has set a password, we just record // a flag stating that the password will need to be reentered. putProperty(props, "db.require.password", "true"); } else { // No password saved or required. putProperty(props, "db.require.password", "false"); } putProperty(props, "db.column.list", arrayToList(this.columns)); setDelimiterProperties(props, "codegen.input.delimiters", this.inputDelimiters); setDelimiterProperties(props, "codegen.output.delimiters", this.outputDelimiters); setArgArrayProperties(props, "tool.arguments", this.extraArgs); setPropertiesAsNestedProperties(props, "db.connect.params", this.connectionParams); setPropertiesAsNestedProperties(props, "map.column.hive", this.mapColumnHive); setPropertiesAsNestedProperties(props, "map.column.java", this.mapColumnJava); return props; }
From source file:org.apache.sqoop.SqoopOptions.java
@SuppressWarnings("unchecked") /**/*w ww . j a v a 2 s .c om*/ * Given a set of properties, load this into the current SqoopOptions * instance. */ public void loadProperties(Properties props) { try { Field[] fields = SqoopOptions.class.getDeclaredFields(); for (Field f : fields) { if (f.isAnnotationPresent(StoredAsProperty.class)) { Class typ = f.getType(); StoredAsProperty storedAs = f.getAnnotation(StoredAsProperty.class); String propName = storedAs.value(); if (typ.equals(int.class)) { f.setInt(this, getIntProperty(props, propName, f.getInt(this))); } else if (typ.equals(boolean.class)) { f.setBoolean(this, getBooleanProperty(props, propName, f.getBoolean(this))); } else if (typ.equals(long.class)) { f.setLong(this, getLongProperty(props, propName, f.getLong(this))); } else if (typ.equals(String.class)) { f.set(this, props.getProperty(propName, (String) f.get(this))); } else if (typ.equals(Integer.class)) { String value = props.getProperty(propName, f.get(this) == null ? "null" : f.get(this).toString()); f.set(this, value.equals("null") ? null : new Integer(value)); } else if (typ.isEnum()) { f.set(this, Enum.valueOf(typ, props.getProperty(propName, f.get(this).toString()))); } else { throw new RuntimeException("Could not retrieve property " + propName + " for type: " + typ); } } } } catch (IllegalAccessException iae) { throw new RuntimeException("Illegal access to field in property setter", iae); } // Now load properties that were stored with special types, or require // additional logic to set. if (getBooleanProperty(props, "db.require.password", false)) { // The user's password was stripped out from the metastore. // Require that the user enter it now. setPasswordFromConsole(); } else { this.password = props.getProperty("db.password", this.password); } if (this.jarDirIsAuto) { // We memoized a user-specific nonce dir for compilation to the data // store. Disregard that setting and create a new nonce dir. String localUsername = System.getProperty("user.name", "unknown"); this.jarOutputDir = getNonceJarDir(tmpDir + "sqoop-" + localUsername + "/compile"); } String colListStr = props.getProperty("db.column.list", null); if (null != colListStr) { this.columns = listToArray(colListStr); } this.inputDelimiters = getDelimiterProperties(props, "codegen.input.delimiters", this.inputDelimiters); this.outputDelimiters = getDelimiterProperties(props, "codegen.output.delimiters", this.outputDelimiters); this.extraArgs = getArgArrayProperty(props, "tool.arguments", this.extraArgs); this.connectionParams = getPropertiesAsNetstedProperties(props, "db.connect.params"); // Loading user mapping this.mapColumnHive = getPropertiesAsNetstedProperties(props, "map.column.hive"); this.mapColumnJava = getPropertiesAsNetstedProperties(props, "map.column.java"); // Delimiters were previously memoized; don't let the tool override // them with defaults. this.areDelimsManuallySet = true; // If we loaded true verbose flag, we need to apply it if (this.verbose) { LoggingUtils.setDebugLevel(); } // Custom configuration options this.invalidIdentifierPrefix = props.getProperty("invalid.identifier.prefix", "_"); }
From source file:com.android.leanlauncher.LauncherTransitionable.java
/** * Sets up transparent navigation and status bars in LMP. * This method is a no-op for other platform versions. *//*from w w w. j a v a 2 s. c o m*/ @TargetApi(19) private void setupTransparentSystemBarsForLmp() { // TODO(sansid): use the APIs directly when compiling against L sdk. // Currently we use reflection to access the flags and the API to set the transparency // on the System bars. if (Utilities.isLmpOrAbove()) { try { getWindow().getAttributes().systemUiVisibility |= (View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); Field drawsSysBackgroundsField = WindowManager.LayoutParams.class .getField("FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS"); getWindow().addFlags(drawsSysBackgroundsField.getInt(null)); Method setStatusBarColorMethod = Window.class.getDeclaredMethod("setStatusBarColor", int.class); Method setNavigationBarColorMethod = Window.class.getDeclaredMethod("setNavigationBarColor", int.class); setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); } catch (NoSuchFieldException e) { Log.w(TAG, "NoSuchFieldException while setting up transparent bars"); } catch (NoSuchMethodException ex) { Log.w(TAG, "NoSuchMethodException while setting up transparent bars"); } catch (IllegalAccessException e) { Log.w(TAG, "IllegalAccessException while setting up transparent bars"); } catch (IllegalArgumentException e) { Log.w(TAG, "IllegalArgumentException while setting up transparent bars"); } catch (InvocationTargetException e) { Log.w(TAG, "InvocationTargetException while setting up transparent bars"); } } }
From source file:at.treedb.db.Base.java
/** * Updates an entity./*from w ww. ja v a 2 s . c o m*/ * * @param dao * {@code DAOiface} (data access object) * @param user * user who updates the entity * @param map * map containing the changes * @throws Exception */ protected void update(DAOiface dao, User user, UpdateMap map) throws Exception { Class<?> c = this.getClass(); for (Enum<?> field : map.getMap().keySet()) { Update u = map.get(field); Field f; try { f = c.getDeclaredField(field.name()); } catch (java.lang.NoSuchFieldException e) { f = c.getSuperclass().getDeclaredField(field.name()); } f.setAccessible(true); switch (u.getType()) { case STRING: f.set(this, u.getString()); break; case DOUBLE: f.set(this, u.getDouble()); break; case FLOAT: f.set(this, u.getFloat()); break; case LONG: f.set(this, u.getLong()); break; case INT: f.set(this, u.getInt()); break; case LAZY_BINARY: case BINARY: f.set(this, u.getBinary()); break; case BOOLEAN: f.set(this, u.getBoolean()); break; case DATE: f.set(this, u.getDate()); break; case ENUM: f.set(this, u.getEnum()); break; case BIGDECIMAL: f.set(this, u.getBigDecimal()); break; case ISTRING: { DBkey a = f.getAnnotation(DBkey.class); if (a == null || !a.value().equals(Istring.class)) { throw new Exception("Base.update(): Field type mismatch for an IString"); } ArrayList<IstringDummy> list = u.getIstringDummy(); // dao.flush(); for (IstringDummy i : list) { Istring istr = null; int userId = user != null ? user.getHistId() : 0; if (f.getInt(this) == 0) { istr = Istring.create(dao, domain, user, this.getCID(), i.getText(), i.getLanguage()); } else { istr = Istring.saveOrUpdate(dao, domain, userId, f.getInt(this), i.getText(), i.getLanguage(), i.getCountry(), this.getCID()); } // only for CI make a reference form IString to the owner if (this instanceof CI) { istr.setCI(this.getHistId()); } if (f.getInt(this) == 0) { f.setInt(this, istr.getHistId()); dao.update(this); } } break; } case ISTRING_DELETE: { DBkey a = f.getAnnotation(DBkey.class); if (a == null || !a.value().equals(Istring.class)) { throw new Exception("Base.update(): Field type mismatch for an IString"); } ArrayList<IstringDummy> list = u.getIstringDummy(); for (IstringDummy i : list) { if (i.getCountry() == null && i.getLanguage() == null) { Istring.delete(dao, user, f.getInt(this)); } else if (i.getCountry() == null && i.getLanguage() != null) { Istring.delete(dao, user, f.getInt(this), i.getLanguage()); } else if (i.getCountry() != null && i.getLanguage() != null) { Istring.delete(dao, user, f.getInt(this), i.getLanguage(), i.getCountry()); } } break; } case IMAGE: { DBkey a = f.getAnnotation(DBkey.class); if (a == null || !a.value().equals(Image.class)) { throw new Exception("Base.update(): Field type mismatch for an Image"); } Image.update(dao, user, f.getInt(this), u.getUpdateMap()); break; } case IMAGE_DUMMY: { DBkey a = f.getAnnotation(DBkey.class); if (a == null || !a.value().equals(Image.class)) { throw new Exception("Base.update(): Field type mismatch for an Image"); } int id = f.getInt(this); if (id == 0) { ImageDummy idummy = u.getImageDummy(); if (this instanceof User) { User uuser = (User) this; Image i = Image.create(dao, null, user, "userImage_" + Base.getRandomLong(), idummy.getData(), idummy.getMimeType(), idummy.getLicense()); uuser.setImage(i.getHistId()); } else if (this instanceof DBcategory) { DBcategory cat = (DBcategory) this; Image i = Image.create(dao, null, user, "catImage_" + Base.getRandomLong(), idummy.getData(), idummy.getMimeType(), idummy.getLicense()); cat.setIcon(i.getHistId()); } else { throw new Exception("Base.update(): ImageDummy for this relationship is't defined"); } } else { Image.update(dao, user, id, u.getImageDummy().getImageUpdateMap()); } break; } case IMAGE_DELETE: { DBkey a = f.getAnnotation(DBkey.class); if (a == null || !a.value().equals(Image.class)) { throw new Exception("Base.update(): Field type mismatch for an Image"); } Image.delete(dao, user, f.getInt(this)); f.setInt(this, 0); break; } default: throw new Exception("Base.update(): Type not implemented!"); } } }
From source file:g7.bluesky.launcher3.Launcher.java
/** * Sets up transparent navigation and status bars in LMP. * This method is a no-op for other platform versions. *///w w w . j a v a 2 s.c o m @TargetApi(19) private void setupTransparentSystemBarsForLmp() { // TODO(sansid): use the APIs directly when compiling against L sdk. // Currently we use reflection to access the flags and the API to set the transparency // on the System bars. if (Utilities.isLmpOrAbove()) { try { getWindow().getAttributes().systemUiVisibility |= (View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); Field drawsSysBackgroundsField = WindowManager.LayoutParams.class .getField("FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS"); getWindow().addFlags(drawsSysBackgroundsField.getInt(null)); Method setStatusBarColorMethod = Window.class.getDeclaredMethod("setStatusBarColor", int.class); Method setNavigationBarColorMethod = Window.class.getDeclaredMethod("setNavigationBarColor", int.class); setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); } catch (NoSuchFieldException e) { Log.w(TAG, "NoSuchFieldException while setting up transparent bars"); } catch (NoSuchMethodException ex) { Log.w(TAG, "NoSuchMethodException while setting up transparent bars"); } catch (IllegalAccessException e) { Log.w(TAG, "IllegalAccessException while setting up transparent bars"); } catch (IllegalArgumentException e) { Log.w(TAG, "IllegalArgumentException while setting up transparent bars"); } catch (InvocationTargetException e) { Log.w(TAG, "InvocationTargetException while setting up transparent bars"); } finally { } } }