Example usage for java.lang.reflect Field getBoolean

List of usage examples for java.lang.reflect Field getBoolean

Introduction

In this page you can find the example usage for java.lang.reflect Field getBoolean.

Prototype

@CallerSensitive
@ForceInline 
public boolean getBoolean(Object obj) throws IllegalArgumentException, IllegalAccessException 

Source Link

Document

Gets the value of a static or instance boolean field.

Usage

From source file:com.cloudera.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 ww  .  j  a  v a 2 s.c om*/
 */
public Properties writeProperties() {
    Properties props = new Properties();

    try {
        Field[] fields = getClass().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);

    return props;
}

From source file:com.cloudera.sqoop.SqoopOptions.java

@SuppressWarnings("unchecked")
/**/*from  ww  w .j av a 2  s  . co  m*/
 * Given a set of properties, load this into the current SqoopOptions
 * instance.
 */
public void loadProperties(Properties props) {

    try {
        Field[] fields = getClass().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);

    // Delimiters were previously memoized; don't let the tool override
    // them with defaults.
    this.areDelimsManuallySet = true;
}

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 va  2s. c  o 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")
/**/*  ww w  . j  a  v  a 2s.c o  m*/
 * 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:cz.tsystems.portablecheckin.MainActivity.java

private void populateTextsAndRbtn(ViewGroup theView) {
    String fieldName = "";
    DMCheckin checkinData = app.getCheckin();
    for (int i = 0; i < theView.getChildCount(); i++) {
        View v = theView.getChildAt(i);
        Class<? extends View> c = v.getClass();
        fieldName = (String) v.getTag();
        if (fieldName == null)
            continue;

        Field field = null;
        try {// ww  w  . ja va  2  s  .  co m
            field = DMCheckin.class.getField(fieldName.toLowerCase(Locale.ENGLISH));
        } catch (NoSuchFieldException e) {
            Log.v(TAG, "NOT FOUND :" + fieldName.toLowerCase(Locale.ENGLISH));
            continue;
        }
        Log.v(TAG, fieldName.toLowerCase(Locale.ENGLISH));

        try {

            if (c == EditText.class || c == vinEditText.class || c == BaseEditText.class) {

                EditText editText = (EditText) v;
                editText.setText("");

                if (field.get(checkinData) == null)
                    continue;
                DecimalFormat nf = new DecimalFormat("#");
                if (field.getType() == String.class)// jnCheckin.hasNonNull(fieldName))
                    editText.setText((String) field.get(checkinData));
                else if (field.getType() == int.class)
                    editText.setText(String.valueOf(field.getInt(checkinData)));
                else if (field.getType() == short.class)
                    editText.setText(String.valueOf(field.getShort(checkinData)));
                else if (field.getType() == double.class)
                    editText.setText(nf.format(field.getDouble(checkinData)));
                else if (field.getType() == Double.class)
                    editText.setText(NumberFormat.getInstance().format((Double) field.get(checkinData)));
                else if (field.getType() == Date.class)
                    editText.setText(sdto.format((Date) field.get(checkinData)));

            } else if (c == Switch.class) {
                ((Switch) v).setChecked(field.getBoolean(checkinData));
            }

        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}