Example usage for java.lang Boolean TYPE

List of usage examples for java.lang Boolean TYPE

Introduction

In this page you can find the example usage for java.lang Boolean TYPE.

Prototype

Class TYPE

To view the source code for java.lang Boolean TYPE.

Click Source Link

Document

The Class object representing the primitive type boolean.

Usage

From source file:edu.wisc.commons.httpclient.HttpParamsBean.java

public boolean getBooleanParameter(final String name, boolean defaultValue) {
    return getTypedParameter(name, defaultValue, Boolean.TYPE, new Function<Object, Boolean>() {
        public Boolean apply(Object value) {
            final Boolean booleanValue = Boolean.valueOf(value.toString());

            //If this parameter is supposed to be a boolean store it as such to save future parsing work
            delegate.setBooleanParameter(name, booleanValue);

            return booleanValue;
        }//from   w ww.  j  a  v a 2  s .co  m
    });
}

From source file:nl.strohalm.cyclos.controls.accounts.accounttypes.SearchAccountTypesAjaxAction.java

public BeanCollectionBinder<Map<String, Object>> getAccountTypeBinderWithScheduling() {
    if (accountTypeBinderWithScheduling == null) {
        final BeanBinder<Map<String, Object>> binder = DataBinderHelper.accountTypeBinder();
        binder.registerBinder("allowsScheduledPayments",
                PropertyBinder.instance(Boolean.TYPE, "allowsScheduledPayments"));
        accountTypeBinderWithScheduling = BeanCollectionBinder.instance(binder);
    }/*from w w  w .ja v  a2s .co m*/
    return accountTypeBinderWithScheduling;
}

From source file:org.syncany.plugins.transfer.TransferSettings.java

/**
 * Set the value of a field in the settings class.
 *
 * @param key The field name as it is used in the {@link TransferSettings}
 * @param value The object which should be the setting's value. The object's type must match the field type.
 *              {@link Integer}, {@link String}, {@link Boolean}, {@link File} and implementation of
 *              {@link TransferSettings} are converted.
 * @throws StorageException Thrown if the field either does not exist or isn't accessible or
 *         conversion failed due to invalid field types.
 *///w w  w .ja  v  a  2s.  co  m
@SuppressWarnings({ "rawtypes", "unchecked" })
public final void setField(String key, Object value) throws StorageException {
    try {
        Field[] elementFields = ReflectionUtil.getAllFieldsWithAnnotation(this.getClass(), Element.class);

        for (Field field : elementFields) {
            field.setAccessible(true);

            String fieldName = field.getName();
            Type fieldType = field.getType();

            if (key.equalsIgnoreCase(fieldName)) {
                if (value == null) {
                    field.set(this, null);
                } else if (fieldType == Integer.TYPE && (value instanceof Integer || value instanceof String)) {
                    field.setInt(this, Integer.parseInt(String.valueOf(value)));
                } else if (fieldType == Boolean.TYPE && (value instanceof Boolean || value instanceof String)) {
                    field.setBoolean(this, Boolean.parseBoolean(String.valueOf(value)));
                } else if (fieldType == String.class && value instanceof String) {
                    field.set(this, value);
                } else if (fieldType == File.class && value instanceof String) {
                    field.set(this, new File(String.valueOf(value)));
                } else if (ReflectionUtil.getClassFromType(fieldType).isEnum() && value instanceof String) {
                    Class<? extends Enum> enumClass = (Class<? extends Enum>) ReflectionUtil
                            .getClassFromType(fieldType);
                    String enumValue = String.valueOf(value).toUpperCase();

                    Enum translatedEnum = Enum.valueOf(enumClass, enumValue);
                    field.set(this, translatedEnum);
                } else if (TransferSettings.class.isAssignableFrom(value.getClass())) {
                    field.set(this, ReflectionUtil.getClassFromType(fieldType).cast(value));
                } else {
                    throw new RuntimeException("Invalid value type: " + value.getClass());
                }
            }
        }
    } catch (Exception e) {
        throw new StorageException("Unable to parse value because its format is invalid: " + e.getMessage(), e);
    }
}

From source file:org.squale.welcom.taglib.table.InternalTableUtil.java

/**
 * Remiez a zero de l'attribut case a coch pass en parametre
 * //from  ww  w  . j a v  a2  s  .c  o  m
 * @param request : requets
 * @param form formulaire
 * @param attribute attribut
 */
private static void razTheCheckBoxAttribute(final HttpServletRequest request, final ActionForm form,
        final String attribute) {
    try {
        // Recupere le type de l'attribut
        Class propertyType = PropertyUtils.getPropertyType(form, attribute);
        if (String.class.equals(propertyType)) {
            BeanUtils.setProperty(form, attribute, "false");
        } else if (Boolean.class.equals(propertyType)) {
            BeanUtils.setProperty(form, attribute, Boolean.FALSE);
        } else if (Boolean.TYPE.equals(propertyType)) {
            BeanUtils.setProperty(form, attribute, "false");
        } else {
            log.warn("Impossible de reinitialiser la checkbox de la liste, type de l'attribut : " + attribute
                    + "=" + propertyType);
        }
    } catch (IllegalAccessException e) {
        log.error(e, e);
    } catch (InvocationTargetException e) {
        log.error(e, e);
    } catch (NoSuchMethodException e) {
        log.error(e, e);
    }
}

From source file:org.skfiy.typhon.spi.GMConsoleProvider.java

/**
 *
 * @param uid/* w w  w  . j  av a2s  .  com*/
 * @param propertyName
 * @param val
 * @throws javax.management.MBeanException
 */
public void changeProperty(final String uid, final String propertyName, final String val)
        throws MBeanException {
    try {
        invoke(transcoding(uid), new Handler() {

            @Override
            void execute() {
                Player player = SessionUtils.getPlayer();
                try {
                    Class<?> propertyType = PropertyUtils.getPropertyType(player, propertyName);
                    if (propertyType == null) { // Not found property
                        throw new IllegalArgumentException("Not found property[" + propertyName + "]");
                    }

                    if (propertyType == Byte.class || propertyType == Byte.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Byte.valueOf(val));
                    } else if (propertyType == Character.class || propertyType == Character.TYPE) {
                        BeanUtils.setProperty(player, propertyName, val.charAt(0));
                    } else if (propertyType == Boolean.class || propertyType == Boolean.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Boolean.valueOf(val));
                    } else if (propertyType == Integer.class || propertyType == Integer.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Integer.valueOf(val));
                    } else if (propertyType == Long.class || propertyType == Long.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Long.valueOf(val));
                    } else if (propertyType == Float.class || propertyType == Float.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Float.valueOf(val));
                    } else if (propertyType == Double.class || propertyType == Double.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Double.valueOf(val));
                    } else {
                        BeanUtils.setProperty(player, propertyName, val);
                    }

                } catch (Exception ex) {
                    throw new IllegalArgumentException(ex.getMessage());
                }
            }

        });
    } catch (Exception e) {
        throw new MBeanException(e, e.getMessage());
    }
}

From source file:org.openflexo.foundation.ie.widget.IERadioButtonWidget.java

public WidgetBindingDefinition getBindingCheckedDefinition() {
    return WidgetBindingDefinition.get(this, "bindingChecked", Boolean.TYPE, BindingDefinitionType.GET_SET,
            true);//w  w w  .jav  a  2s. c  om
}

From source file:com.netflix.governator.lifecycle.ConfigurationProcessor.java

private Supplier<?> getConfigurationSupplier(final Field field, final ConfigurationKey key, final Class<?> type,
        Supplier<?> current) {
    if (String.class.isAssignableFrom(type)) {
        return configurationProvider.getStringSupplier(key, (String) current.get());
    } else if (Boolean.class.isAssignableFrom(type) || Boolean.TYPE.isAssignableFrom(type)) {
        return configurationProvider.getBooleanSupplier(key, (Boolean) current.get());
    } else if (Integer.class.isAssignableFrom(type) || Integer.TYPE.isAssignableFrom(type)) {
        return configurationProvider.getIntegerSupplier(key, (Integer) current.get());
    } else if (Long.class.isAssignableFrom(type) || Long.TYPE.isAssignableFrom(type)) {
        return configurationProvider.getLongSupplier(key, (Long) current.get());
    } else if (Double.class.isAssignableFrom(type) || Double.TYPE.isAssignableFrom(type)) {
        return configurationProvider.getDoubleSupplier(key, (Double) current.get());
    } else if (Date.class.isAssignableFrom(type)) {
        return configurationProvider.getDateSupplier(key, (Date) current.get());
    } else {// ww w  .  j  av  a2  s  .com
        log.error("Field type not supported: " + type + " (" + field.getName() + ")");
        return null;
    }
}

From source file:org.apache.jackrabbit.core.util.db.Oracle10R1ConnectionHelper.java

/**
 * Creates a temporary oracle.sql.BLOB instance via reflection and spools the contents of the specified
 * stream.//from w  ww . j ava2s.  c o m
 */
private Blob createTemporaryBlob(Connection con, InputStream in) throws Exception {
    /*
     * BLOB blob = BLOB.createTemporary(con, false, BLOB.DURATION_SESSION);
     * blob.open(BLOB.MODE_READWRITE); OutputStream out = blob.getBinaryOutputStream(); ... out.flush();
     * out.close(); blob.close(); return blob;
     */
    Method createTemporary = blobClass.getMethod("createTemporary",
            new Class[] { Connection.class, Boolean.TYPE, Integer.TYPE });
    Object blob = createTemporary.invoke(null,
            new Object[] { ConnectionFactory.unwrap(con), Boolean.FALSE, durationSessionConstant });
    Method open = blobClass.getMethod("open", new Class[] { Integer.TYPE });
    open.invoke(blob, new Object[] { modeReadWriteConstant });
    Method getBinaryOutputStream = blobClass.getMethod("getBinaryOutputStream", new Class[0]);
    OutputStream out = (OutputStream) getBinaryOutputStream.invoke(blob);
    try {
        IOUtils.copy(in, out);
    } finally {
        try {
            out.flush();
        } catch (IOException ioe) {
        }
        out.close();
    }
    Method close = blobClass.getMethod("close", new Class[0]);
    close.invoke(blob);
    return (Blob) blob;
}

From source file:de.micromata.genome.util.bean.PrivateBeanUtils.java

/**
 * Find getter from field./* w  ww  .j  a va 2s .  co  m*/
 *
 * @param clazz the clazz
 * @param fieldName the field name
 * @param fieldType the field type
 * @return the method
 */
public static Method findGetterFromField(Class<?> clazz, String fieldName, Class<?> fieldType) {

    String prefix = "get";
    if (fieldType == Boolean.TYPE) {
        prefix = "is";
    }
    String methodName = getGetterOrSetterMethodNameFromFieldName(fieldName, prefix);
    try {
        Method m = clazz.getMethod(methodName);
        return m;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}

From source file:candr.yoclip.option.OptionSetter.java

@Override
public void setOption(final T bean, final String value) {

    final Class<?> setterParameterType = getType();
    try {//from www  .j a v  a2  s  .co m

        if (Boolean.TYPE.equals(setterParameterType) || Boolean.class.isAssignableFrom(setterParameterType)) {
            setBooleanOption(bean, value);

        } else if (Byte.TYPE.equals(setterParameterType) || Byte.class.isAssignableFrom(setterParameterType)) {
            setByteOption(bean, value);

        } else if (Short.TYPE.equals(setterParameterType)
                || Short.class.isAssignableFrom(setterParameterType)) {
            setShortOption(bean, value);

        } else if (Integer.TYPE.equals(setterParameterType)
                || Integer.class.isAssignableFrom(setterParameterType)) {
            setIntegerOption(bean, value);

        } else if (Long.TYPE.equals(setterParameterType) || Long.class.isAssignableFrom(setterParameterType)) {
            setLongOption(bean, value);

        } else if (Character.TYPE.equals(setterParameterType)
                || Character.class.isAssignableFrom(setterParameterType)) {
            setCharacterOption(bean, value);

        } else if (Float.TYPE.equals(setterParameterType)
                || Float.class.isAssignableFrom(setterParameterType)) {
            setFloatOption(bean, value);

        } else if (Double.TYPE.equals(setterParameterType)
                || Double.class.isAssignableFrom(setterParameterType)) {
            setDoubleOption(bean, value);

        } else if (String.class.isAssignableFrom(setterParameterType)) {
            setStringOption(bean, value);

        } else {
            final String supportedTypes = "boolean, byte, short, int, long, char, float, double, and String";
            throw new OptionsParseException(
                    String.format("OptionParameter only supports %s types", supportedTypes));
        }

    } catch (NumberFormatException e) {
        final String error = String.format("Error converting '%s' to %s", value, setterParameterType);
        throw new OptionsParseException(error, e);
    }
}