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:org.jcommon.com.util.config.ConfigLoader.java

/**
 * /* www. j  a  v a 2  s  . c o  m*/
 * @param conn
 * @param config
 * @param table{key,value,map,list}
 */
public static void loadConf4db(Connection conn, PreparedStatement ps, BaseConfigMBean config, String[] table) {
    ResultSet rs = null;
    String key_ = table[0];
    String value_ = table[1];
    try {
        rs = ps.executeQuery();

        Class<?> type = null;
        String name;
        String value;
        while (rs.next()) {
            name = rs.getString(key_);
            value = rs.getString(value_);
            java.lang.reflect.Field f = null;
            try {
                f = config.getClass().getDeclaredField(name);
            } catch (java.lang.NoSuchFieldException e) {
                continue;
            }

            if (f != null)
                type = f.getType();
            Object args = null;
            java.lang.reflect.Method m = getMethod(config.getClass(), "set" + name);
            if (m != null && notNull(value) && type != null) {
                if (String.class == type) {
                    args = value;
                } else if (java.lang.Integer.class == type || Integer.TYPE == type) {
                    args = Integer.valueOf(value);
                } else if (java.lang.Boolean.class == type || Boolean.TYPE == type) {
                    args = Boolean.parseBoolean(value);
                } else if (java.lang.Long.class == type || Long.TYPE == type) {
                    args = Long.valueOf(value);
                } else if (java.lang.Float.class == type || Float.TYPE == type) {
                    args = Float.valueOf(value);
                } else {
                    logger.info("not map Class:" + type);
                }
                m.invoke(config, args);
                logger.info(name + ":" + value);
            } else if (notNull(value))
                logger.warn("can't find element:" + value);
        }
    } catch (Exception e) {
        logger.error("load config error:", e);
    } finally {
        try {
            conn.close();
            ps.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            logger.error("load config error:", e);
        }
        conn = null;
    }
}

From source file:org.wings.template.DefaultPropertyValueConverter.java

/**
 * Describe <code>convertPropertyValue</code> method here.
 *
 * @param value       an <code>Object</code> value
 * @param targetClass a <code>Class</code> value
 * @return <description>/*ww  w  .j a  v  a2 s. co  m*/
 * @throws UnsupportedOperationException if an error occurs
 * @throws java.lang.UnsupportedOperationException
 *                                       <description>
 */
public Object convertPropertyValue(String value, Class targetClass) throws UnsupportedOperationException {
    if (value == null || "null".equals(value)) {
        return null;
    } // end of if ()

    if (targetClass == String.class) {
        return value;
    } // end of if ()

    if (targetClass == Boolean.TYPE || targetClass == Boolean.class) {
        return Boolean.valueOf(value);
    }

    if (targetClass == Integer.TYPE || targetClass == Integer.class) {
        return Integer.valueOf(value);
    }
    if (targetClass == Long.TYPE || targetClass == Long.class) {
        return Long.valueOf(value);
    }
    if (targetClass == Short.TYPE || targetClass == Short.class) {
        return Short.valueOf(value);
    }
    if (targetClass == Byte.TYPE || targetClass == Byte.class) {
        return Byte.valueOf(value);
    }
    if (targetClass == Float.TYPE || targetClass == Float.class) {
        return Float.valueOf(value);
    }
    if (targetClass == Double.TYPE || targetClass == Double.class) {
        return Double.valueOf(value);
    }
    if (targetClass == Character.TYPE || targetClass == Character.class) {
        return new Character(value.charAt(0));
    }

    if (targetClass == StringBuffer.class) {
        return new StringBuffer(value);
    } // end of if ()

    if (SIcon.class.isAssignableFrom(targetClass)) {
        return ResourceFactory.makeIcon(value);
    }

    if (targetClass == Color.class) {
        return ResourceFactory.makeColor(value);
    }

    if (targetClass == SDimension.class) {
        return ResourceFactory.makeDimension(value);
    }

    if (targetClass == SFont.class) {
        return TemplateUtil.parseFont(value);
    }

    if (Resource.class.isAssignableFrom(targetClass)) {
        return new ClassPathResource(value);
    }

    if (CSSAttributeSet.class.isAssignableFrom(targetClass)) {
        return ResourceFactory.makeAttributeSet(value);
    }

    if (StyleSheet.class.isAssignableFrom(targetClass)) {
        StyleSheet result;
        try {
            CSSStyleSheet styleSheet = new CSSStyleSheet();
            InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(value);
            styleSheet.read(in);
            in.close();
            result = styleSheet;
        } catch (Exception e) {
            log.warn("Exception", e);
            result = null;
        }
        return result;
    }

    if (ComponentCG.class.isAssignableFrom(targetClass)) {
        return ResourceFactory.makeComponentCG(value);
    }

    throw new UnsupportedOperationException("cannot create object of type " + targetClass.getName());
}

From source file:com.adobe.acs.commons.mcp.util.AnnotatedFieldDeserializer.java

@SuppressWarnings("squid:S3776")
private static void parseInput(Object target, ValueMap input, Field field)
        throws ReflectiveOperationException, ParseException {
    FormField inputAnnotation = field.getAnnotation(FormField.class);
    Object value;/*from  w  w w.  jav a  2  s  .com*/
    if (input.get(field.getName()) == null) {
        if (inputAnnotation != null && inputAnnotation.required()) {
            if (field.getType() == Boolean.class || field.getType() == Boolean.TYPE) {
                value = false;
            } else {
                throw new NullPointerException("Required field missing: " + field.getName());
            }
        } else {
            return;
        }
    } else {
        value = input.get(field.getName());
    }

    if (hasMultipleValues(field.getType())) {
        parseInputList(target, serializeToStringArray(value), field);
    } else {
        Object val = value;
        if (value.getClass().isArray()) {
            val = ((Object[]) value)[0];
        }

        if (val instanceof RequestParameter) {
            /** Special case handling uploaded files; Method call ~ copied from parseInputValue(..) **/
            if (field.getType() == RequestParameter.class) {
                FieldUtils.writeField(field, target, val, true);
            } else {
                try {
                    FieldUtils.writeField(field, target, ((RequestParameter) val).getInputStream(), true);
                } catch (IOException ex) {
                    LOG.error("Unable to get InputStream for uploaded file [ {} ]",
                            ((RequestParameter) val).getName(), ex);
                }
            }
        } else {
            parseInputValue(target, String.valueOf(val), field);
        }
    }
}

From source file:it.greenvulcano.gvesb.http.ProtocolFactory.java

/**
 *
 * @param objectClass/*  ww w.  j  a  v  a2s .com*/
 *        Object class to instantiate
 * @param node
 *        The configuration of constructor parameters.
 * @return
 */
private static Object createObjectUsingConstructor(Class<?> objectClass, Node node) throws Exception {
    NodeList paramList = XMLConfig.getNodeList(node, "constructor-param");
    Class<?>[] types = new Class[paramList.getLength()];
    Object[] params = new Object[types.length];

    for (int i = 0; i < types.length; ++i) {
        Node paramNode = paramList.item(i);
        String type = XMLConfig.get(paramNode, "@type");
        String value = XMLConfig.getDecrypted(paramNode, "@value");
        Class<?> cls = null;
        if (type.equals("byte")) {
            cls = Byte.TYPE;
        } else if (type.equals("boolean")) {
            cls = Boolean.TYPE;
        } else if (type.equals("char")) {
            cls = Character.TYPE;
        } else if (type.equals("double")) {
            cls = Double.TYPE;
        } else if (type.equals("float")) {
            cls = Float.TYPE;
        } else if (type.equals("int")) {
            cls = Integer.TYPE;
        } else if (type.equals("long")) {
            cls = Long.TYPE;
        } else if (type.equals("short")) {
            cls = Short.TYPE;
        } else if (type.equals("String")) {
            cls = String.class;
        }
        types[i] = cls;
        params[i] = cast(value, cls);
    }

    Constructor<?> constr = objectClass.getConstructor(types);
    return constr.newInstance(params);
}

From source file:com.nfwork.dbfound.json.JSONDynaBean.java

public Object get(String name) {
    Object value = dynaValues.get(name);
    if (value != null) {
        return value;
    }// ww w. ja  v a 2  s  .  c o m

    Class type = getDynaProperty(name).getType();
    if (type == null) {
        throw new NullPointerException("Unspecified property type for " + name);
    }
    if (!type.isPrimitive()) {
        return value;
    }

    if (type == Boolean.TYPE) {
        return Boolean.FALSE;
    } else if (type == Byte.TYPE) {
        return new Byte((byte) 0);
    } else if (type == Character.TYPE) {
        return new Character((char) 0);
    } else if (type == Short.TYPE) {
        return new Short((short) 0);
    } else if (type == Integer.TYPE) {
        return new Integer(0);
    } else if (type == Long.TYPE) {
        return new Long(0);
    } else if (type == Float.TYPE) {
        return new Float(0.0);
    } else if (type == Double.TYPE) {
        return new Double(0);
    }

    return null;
}

From source file:com.gemstone.gemfire.test.junit.rules.serializable.SerializableTimeoutTest.java

@Test
public void fieldLookForStuckThreadShouldExist() throws Exception {
    Field field = Timeout.class.getDeclaredField(FIELD_LOOK_FOR_STUCK_THREAD);
    assertThat(field.getType()).isEqualTo(Boolean.TYPE);
}

From source file:com.csipsimple.backup.Columns.java

public Columns(String[] names, Class<?>[] classes) {
    this.names = new ArrayList<String>(Arrays.asList(names));
    types = new ArrayList<Type>(names.length);
    for (int i = 0; i < names.length; i++) {

        if (classes[i] == String.class) {
            types.add(i, Type.STRING);
        } else if (classes[i] == Integer.TYPE || classes[i] == Integer.class) {
            types.add(i, Type.INT);
        } else if (classes[i] == Long.TYPE || classes[i] == Long.class) {
            types.add(i, Type.LONG);
        } else if (classes[i] == Float.TYPE || classes[i] == Float.class) {
            types.add(i, Type.FLOAT);
        } else if (classes[i] == Double.TYPE || classes[i] == Double.class) {
            types.add(i, Type.DOUBLE);
        } else if (classes[i] == Boolean.TYPE || classes[i] == Boolean.class) {
            types.add(i, Type.BOOLEAN);
        }/*from   w  w w.  j a v a2s. c om*/
    }
}

From source file:nl.strohalm.cyclos.controls.elements.CreateElementAction.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static <E extends Element> DataBinder<E> getDataBinder(final LocalSettings localSettings,
        final AccessSettings accessSettings, final Class<E> elementClass, final Class userClass,
        final Class groupClass, final Class customField, final Class customFieldValue) {
    final BeanBinder<? extends CustomFieldValue> customValueBinder = BeanBinder.instance(customFieldValue);
    customValueBinder.registerBinder("field",
            PropertyBinder.instance(customField, "field", ReferenceConverter.instance(customField)));
    customValueBinder.registerBinder("value",
            PropertyBinder.instance(String.class, "value", HtmlConverter.instance()));
    if (MemberCustomFieldValue.class.isAssignableFrom(customFieldValue)) {
        customValueBinder.registerBinder("hidden", PropertyBinder.instance(Boolean.TYPE, "hidden"));
    }//from  w  ww .j  ava2s  .c  o  m

    final BeanBinder<E> elementBinder = BeanBinder.instance(elementClass);
    elementBinder.registerBinder("name", PropertyBinder.instance(String.class, "name"));
    elementBinder.registerBinder("email", PropertyBinder.instance(String.class, "email"));
    if (Member.class.isAssignableFrom(elementClass)) {
        elementBinder.registerBinder("hideEmail", PropertyBinder.instance(Boolean.TYPE, "hideEmail"));
    }
    elementBinder.registerBinder("group",
            PropertyBinder.instance(groupClass, "group", ReferenceConverter.instance(groupClass)));
    elementBinder.registerBinder("customValues",
            BeanCollectionBinder.instance(customValueBinder, "customValues"));

    final BeanBinder<? extends User> userBinder = BeanBinder.instance(userClass, "user");
    if (!(Member.class.isAssignableFrom(elementClass) && accessSettings.isUsernameGenerated())) {
        userBinder.registerBinder("username", PropertyBinder.instance(String.class, "username"));
    }
    userBinder.registerBinder("password", PropertyBinder.instance(String.class, "password"));
    elementBinder.registerBinder("user", userBinder);

    return elementBinder;
}

From source file:org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler.java

public void handleOption(CmdLineAction action, CmdLineOptionInstance optionInstance) {
    try {/*  w w  w .  ja v  a  2  s.  com*/
        Class<?> type = optionInstance.getOption().getType();
        List<?> vals = (optionInstance.getValues().isEmpty())
                ? convertToType(Arrays.asList(new String[] { "true" }), type = Boolean.TYPE)
                : convertToType(optionInstance.getValues(), type);
        String methodName = getMethodName(action.getName());
        if (methodName != null) {
            action.getClass().getMethod(methodName, type).invoke(action, vals.toArray(new Object[vals.size()]));
        } else {
            action.getClass()
                    .getMethod((optionInstance.getOption().isRepeating() ? "add" : "set")
                            + StringUtils.capitalize(optionInstance.getOption().getLongOption()), type)
                    .invoke(action, vals.toArray(new Object[vals.size()]));
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:springfox.documentation.schema.property.PojoPropertyBuilderFactory.java

/**
 * Applies to constructor/* ww w  . j  a v a2  s  .c  o m*/
    new POJOPropertyBuilder(
config,
annotationIntrospector,
forSerialization,
new PropertyName(beanProperty.getName()))
 */
private POJOPropertyBuilder jackson27Instance(MapperConfig<?> config, BeanPropertyDefinition beanProperty,
        AnnotationIntrospector annotationIntrospector, boolean forSerialization) {
    try {
        Constructor<POJOPropertyBuilder> constructor = constructorWithParams(MapperConfig.class,
                AnnotationIntrospector.class, Boolean.TYPE, PropertyName.class);

        return constructor.newInstance(config, annotationIntrospector, forSerialization,
                new PropertyName(beanProperty.getName()));
    } catch (Exception e) {
        throw new InstantiationError("Unable to create an instance of POJOPropertyBuilder");
    }
}