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.apache.jasper.compiler.JspUtil.java

/**
 * Produces a String representing a call to the EL interpreter.
 * @param expression a String containing zero or more "${}" expressions
 * @param expectedType the expected type of the interpreted result
 * @param fnmapvar Variable pointing to a function map.
 * @param XmlEscape True if the result should do XML escaping
 * @return a String representing a call to the EL interpreter.
 *///w ww  . ja v a 2s .c o  m
public static String interpreterCall(boolean isTagFile, String expression, Class expectedType, String fnmapvar,
        boolean XmlEscape) {
    /*
     * Determine which context object to use.
     */
    String jspCtxt = null;
    if (isTagFile)
        jspCtxt = "this.getJspContext()";
    else
        jspCtxt = "pageContext";

    /*
          * Determine whether to use the expected type's textual name
     * or, if it's a primitive, the name of its correspondent boxed
     * type.
          */
    String targetType = expectedType.getName();
    String primitiveConverterMethod = null;
    if (expectedType.isPrimitive()) {
        if (expectedType.equals(Boolean.TYPE)) {
            targetType = Boolean.class.getName();
            primitiveConverterMethod = "booleanValue";
        } else if (expectedType.equals(Byte.TYPE)) {
            targetType = Byte.class.getName();
            primitiveConverterMethod = "byteValue";
        } else if (expectedType.equals(Character.TYPE)) {
            targetType = Character.class.getName();
            primitiveConverterMethod = "charValue";
        } else if (expectedType.equals(Short.TYPE)) {
            targetType = Short.class.getName();
            primitiveConverterMethod = "shortValue";
        } else if (expectedType.equals(Integer.TYPE)) {
            targetType = Integer.class.getName();
            primitiveConverterMethod = "intValue";
        } else if (expectedType.equals(Long.TYPE)) {
            targetType = Long.class.getName();
            primitiveConverterMethod = "longValue";
        } else if (expectedType.equals(Float.TYPE)) {
            targetType = Float.class.getName();
            primitiveConverterMethod = "floatValue";
        } else if (expectedType.equals(Double.TYPE)) {
            targetType = Double.class.getName();
            primitiveConverterMethod = "doubleValue";
        }
    }

    if (primitiveConverterMethod != null) {
        XmlEscape = false;
    }

    /*
          * Build up the base call to the interpreter.
          */
    // XXX - We use a proprietary call to the interpreter for now
    // as the current standard machinery is inefficient and requires
    // lots of wrappers and adapters.  This should all clear up once
    // the EL interpreter moves out of JSTL and into its own project.
    // In the future, this should be replaced by code that calls
    // ExpressionEvaluator.parseExpression() and then cache the resulting
    // expression objects.  The interpreterCall would simply select
    // one of the pre-cached expressions and evaluate it.
    // Note that PageContextImpl implements VariableResolver and
    // the generated Servlet/SimpleTag implements FunctionMapper, so
    // that machinery is already in place (mroth).
    targetType = toJavaSourceType(targetType);
    StringBuffer call = new StringBuffer(
            "(" + targetType + ") " + "org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate" + "("
                    + Generator.quote(expression) + ", " + targetType + ".class, " + "(PageContext)" + jspCtxt
                    + ", " + fnmapvar + ", " + XmlEscape + ")");

    /*
          * Add the primitive converter method if we need to.
          */
    if (primitiveConverterMethod != null) {
        call.insert(0, "(");
        call.append(")." + primitiveConverterMethod + "()");
    }

    return call.toString();
}

From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java

/**
 * Convert a <code>ResultSet</code> column into an object.  Simple
 * implementations could just call <code>rs.getObject(index)</code> while
 * more complex implementations could perform type manipulation to match
 * the column's type to the bean property type.
 *
 * <p>/*  w w w .  j a v  a  2  s.  co  m*/
 * This implementation calls the appropriate <code>ResultSet</code> getter
 * method for the given property type to perform the type conversion.  If
 * the property type doesn't match one of the supported
 * <code>ResultSet</code> types, <code>getObject</code> is called.
 * </p>
 *
 * @param rs The <code>ResultSet</code> currently being processed.  It is
 * positioned on a valid row before being passed into this method.
 *
 * @param index The current column index being processed.
 *
 * @param propType The bean property type that this column needs to be
 * converted into.
 *
 * @throws SQLException if a database access error occurs
 *
 * @return The object from the <code>ResultSet</code> at the given column
 * index after optional type processing or <code>null</code> if the column
 * value was SQL NULL.
 */
protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException {

    if (!propType.isPrimitive() && rs.getObject(index) == null) {
        return null;
    }

    if (propType.equals(String.class)) {
        return rs.getString(index);

    } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) {
        return Integer.valueOf(rs.getInt(index));

    } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) {
        return Boolean.valueOf(rs.getBoolean(index));

    } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) {
        return Long.valueOf(rs.getLong(index));

    } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) {
        return Double.valueOf(rs.getDouble(index));

    } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) {
        return Float.valueOf(rs.getFloat(index));

    } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) {
        return Short.valueOf(rs.getShort(index));

    } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) {
        return Byte.valueOf(rs.getByte(index));

    } else if (propType.equals(Timestamp.class)) {
        return rs.getTimestamp(index);

    } else if (propType.equals(SQLXML.class)) {
        return rs.getSQLXML(index);

    } else {
        return rs.getObject(index);
    }

}

From source file:de.hasait.clap.CLAP.java

private void initDefaultConverters() {
    try {//w w w . ja  va2 s.  c o  m
        final CLAPConverter<String> stringConverter = new CLAPConverter<String>() {

            @Override
            public String convert(final String pInput) {
                return pInput;
            }

        };
        addConverter(String.class, stringConverter);

        final CLAPConverter<Boolean> booleanConverter = new CLAPConverter<Boolean>() {

            @Override
            public Boolean convert(final String pInput) {
                if (pInput.equalsIgnoreCase("true")) { //$NON-NLS-1$
                    return true;
                }
                if (pInput.equalsIgnoreCase("false")) { //$NON-NLS-1$
                    return false;
                }
                if (pInput.equalsIgnoreCase("yes")) { //$NON-NLS-1$
                    return true;
                }
                if (pInput.equalsIgnoreCase("no")) { //$NON-NLS-1$
                    return false;
                }
                if (pInput.equalsIgnoreCase("on")) { //$NON-NLS-1$
                    return true;
                }
                if (pInput.equalsIgnoreCase("off")) { //$NON-NLS-1$
                    return false;
                }
                if (pInput.equalsIgnoreCase("enable")) { //$NON-NLS-1$
                    return true;
                }
                if (pInput.equalsIgnoreCase("disable")) { //$NON-NLS-1$
                    return false;
                }
                throw new RuntimeException(pInput);
            }

        };
        addConverter(Boolean.class, booleanConverter);
        addConverter(Boolean.TYPE, booleanConverter);

        final Class<?>[] someWrapperClasses = new Class<?>[] { Byte.class, Short.class, Integer.class,
                Long.class, Float.class, Double.class };
        for (int i = 0; i < someWrapperClasses.length; i++) {
            final Class<?> wrapperClass = someWrapperClasses[i];
            addStringConstructorConverter(wrapperClass);
            final Class<?> primitiveClass = ClassUtils.wrapperToPrimitive(wrapperClass);
            if (primitiveClass != null) {
                addPrimitiveConverter(wrapperClass, primitiveClass);
            }
        }
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:bammerbom.ultimatecore.bukkit.resources.utils.BossbarUtil.java

public Object getSpawnPacket() {
    Class<?> Entity = Util.getCraftClass("Entity");
    Class<?> EntityLiving = Util.getCraftClass("EntityLiving");
    Class<?> EntityEnderDragon = Util.getCraftClass("EntityEnderDragon");
    Object packet = null;/*w  ww.j  a  va 2  s  .c o  m*/
    try {
        this.dragon = EntityEnderDragon.getConstructor(new Class[] { Util.getCraftClass("World") })
                .newInstance(new Object[] { getWorld() });

        Method setLocation = Util.getMethod(EntityEnderDragon, "setLocation",
                new Class[] { Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE });
        setLocation.invoke(this.dragon, new Object[] { Integer.valueOf(getX()), Integer.valueOf(getY()),
                Integer.valueOf(getZ()), Integer.valueOf(getPitch()), Integer.valueOf(getYaw()) });

        Method setInvisible = Util.getMethod(EntityEnderDragon, "setInvisible", new Class[] { Boolean.TYPE });
        setInvisible.invoke(this.dragon, new Object[] { Boolean.valueOf(isVisible()) });

        Method setCustomName = Util.getMethod(EntityEnderDragon, "setCustomName", new Class[] { String.class });
        setCustomName.invoke(this.dragon, new Object[] { this.name });

        Method setHealth = Util.getMethod(EntityEnderDragon, "setHealth", new Class[] { Float.TYPE });
        setHealth.invoke(this.dragon, new Object[] { Float.valueOf(this.health) });

        Field motX = Util.getField(Entity, "motX");
        motX.set(this.dragon, Byte.valueOf(getXvel()));

        Field motY = Util.getField(Entity, "motY");
        motY.set(this.dragon, Byte.valueOf(getYvel()));

        Field motZ = Util.getField(Entity, "motZ");
        motZ.set(this.dragon, Byte.valueOf(getZvel()));

        Method getId = Util.getMethod(EntityEnderDragon, "getId", new Class[0]);
        this.id = ((Number) getId.invoke(this.dragon, new Object[0])).intValue();

        Class<?> PacketPlayOutSpawnEntityLiving = Util.getCraftClass("PacketPlayOutSpawnEntityLiving");

        packet = PacketPlayOutSpawnEntityLiving.getConstructor(new Class[] { EntityLiving })
                .newInstance(new Object[] { this.dragon });
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }

    return packet;
}

From source file:com.thinkbiganalytics.policy.BasePolicyAnnotationTransformer.java

public Object convertStringToObject(String value, Class type) {
    if (type.isEnum()) {
        return Enum.valueOf(type, value);
    } else if (String.class.equals(type)) {
        return value;
    }// w w w . j  a  v  a 2 s .co m

    if (StringUtils.isBlank(value)) {
        return null;
    } else if (Number.class.equals(type)) {
        return NumberUtils.createNumber(value);
    } else if (Integer.class.equals(type) || Integer.TYPE.equals(type)) {
        return new Integer(value);
    } else if (Long.class.equals(type) || Long.TYPE.equals(type)) {
        return Long.valueOf(value);
    } else if (Double.class.equals(type) || Double.TYPE.equals(type)) {
        return Double.valueOf(value);
    } else if (Float.class.equals(type) || Float.TYPE.equals(type)) {
        return Float.valueOf(value);
    } else if (Pattern.class.equals(type)) {
        return Pattern.compile(value);
    } else if (Boolean.class.equals(type) || Boolean.TYPE.equals(type)) {
        return BooleanUtils.toBoolean(value);
    } else {
        throw new IllegalArgumentException(
                "Unable to convert the value " + value + " to an object of type " + type.getName());
    }

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new HttpsConnector/*from  ww  w .j a  va  2  s  .  c om*/
 *
 * @param parent MBean Name of the associated parent component
 * @param address The IP address on which to bind
 * @param port TCP port number to listen on
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createHttpsConnector(String parent, String address, int port) throws Exception {

    Object retobj = null;

    try {

        // Create a new CoyoteConnector instance
        // use reflection to avoid j-t-c compile-time circular dependencies
        Class cls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector");
        Constructor ct = cls.getConstructor(null);
        retobj = ct.newInstance(null);
        Class partypes1[] = new Class[1];
        // Set address
        String str = new String();
        partypes1[0] = str.getClass();
        Method meth1 = cls.getMethod("setAddress", partypes1);
        Object arglist1[] = new Object[1];
        arglist1[0] = address;
        meth1.invoke(retobj, arglist1);
        // Set port number
        Class partypes2[] = new Class[1];
        partypes2[0] = Integer.TYPE;
        Method meth2 = cls.getMethod("setPort", partypes2);
        Object arglist2[] = new Object[1];
        arglist2[0] = new Integer(port);
        meth2.invoke(retobj, arglist2);
        // Set scheme
        Class partypes3[] = new Class[1];
        partypes3[0] = str.getClass();
        Method meth3 = cls.getMethod("setScheme", partypes3);
        Object arglist3[] = new Object[1];
        arglist3[0] = new String("https");
        meth3.invoke(retobj, arglist3);
        // Set secure
        Class partypes4[] = new Class[1];
        partypes4[0] = Boolean.TYPE;
        Method meth4 = cls.getMethod("setSecure", partypes4);
        Object arglist4[] = new Object[1];
        arglist4[0] = new Boolean(true);
        meth4.invoke(retobj, arglist4);
        // Set factory 
        Class serverSocketFactoryCls = Class.forName("org.apache.catalina.net.ServerSocketFactory");
        Class coyoteServerSocketFactoryCls = Class
                .forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory");
        Constructor factoryConst = coyoteServerSocketFactoryCls.getConstructor(null);
        Object factoryObj = factoryConst.newInstance(null);
        Class partypes5[] = new Class[1];
        partypes5[0] = serverSocketFactoryCls;
        Method meth5 = cls.getMethod("setFactory", partypes5);
        Object arglist5[] = new Object[1];
        arglist5[0] = factoryObj;
        meth5.invoke(retobj, arglist5);
    } catch (Exception e) {
        throw new MBeanException(e);
    }

    try {
        // Add the new instance to its parent component
        ObjectName pname = new ObjectName(parent);
        Server server = ServerFactory.getServer();
        Service service = server.findService(pname.getKeyProperty("name"));
        service.addConnector((Connector) retobj);
    } catch (Exception e) {
        // FIXME
        // disply error message 
        // the user needs to use keytool to configure SSL first
        // addConnector will fail otherwise
        return null;
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("CoyoteConnector");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), (Connector) retobj);
    return (oname.toString());

}

From source file:org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.java

public static Class<?> getTypeForPrimitive(Class<?> primitiveType) {
    if (primitiveType == Boolean.TYPE) {
        return Boolean.class;
    } else if (primitiveType == Integer.TYPE) {
        return Integer.class;
    } else if (primitiveType == Long.TYPE) {
        return Long.class;
    } else if (primitiveType == Float.TYPE) {
        return Float.class;
    } else if (primitiveType == Double.TYPE) {
        return Double.class;
    } else if (primitiveType == Character.TYPE) {
        return Character.class;
    } else if (primitiveType == Byte.TYPE) {
        return Byte.class;
    } else if (primitiveType == Short.TYPE) {
        return Short.class;
    }//w w w. j a  v a 2s .co m
    return primitiveType;
}

From source file:com.example.android.wifidirect.WiFiDirectActivity.java

@Override
public boolean onMenuOpened(int featureId, Menu menu) {
    if (featureId == Window.FEATURE_ACTION_BAR && menu != null) {
        if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
            try {
                Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
                m.setAccessible(true);//from   www  . ja  v  a 2s . co m
                m.invoke(menu, true);
            } catch (Exception e) {
            }
        }
    }
    return super.onMenuOpened(featureId, menu);
}

From source file:org.lunarray.model.descriptor.scanner.AnnotationMetaModelProcessor.java

/**
 * Copy array values./*from ww  w .  j  ava 2s . c  o  m*/
 * 
 * @param values
 *            The array values.
 * @param name
 *            The property name.
 * @param obj
 *            The object value.
 * @param type
 *            The array type.
 * @param compType
 *            The component type.
 * @throws MappingException
 *             Thrown if the mapping was unsuccessful.
 */
private void extractNonFloats(final AnnotationMetaValues values, final String name, final Object obj,
        final Class<?> type, final Class<?> compType) throws MappingException {
    try {
        if (Boolean.TYPE.equals(compType)) {
            final boolean[] array = boolean[].class.cast(obj);
            for (final boolean a : array) {
                values.getMetaValueList(name).add(this.converterTool.convertToString(Boolean.TYPE, a));
            }
        } else if (Character.TYPE.equals(compType)) {
            final char[] array = char[].class.cast(obj);
            for (final char a : array) {
                values.getMetaValueList(name).add(this.converterTool.convertToString(Character.TYPE, a));
            }
        } else {
            this.copyObjectTypes(values, name, obj, type, compType);
        }
    } catch (final ConverterException e) {
        throw new MappingException(e);
    }
}

From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java

/**
 * Returns the virtual machine's Class object for the named primitive type.<br/>
 * If the type is not a primitive type, {@code null} is returned.
 *
 * @param name the name of the type/*from ww w  .j a  va2  s. c o m*/
 * @return the Class instance representing the primitive type
 */
private static Class<?> getPrimitiveType(String name) {
    name = StringUtils.defaultIfEmpty(name, "");
    if (name.equals("int"))
        return Integer.TYPE;
    if (name.equals("short"))
        return Short.TYPE;
    if (name.equals("long"))
        return Long.TYPE;
    if (name.equals("float"))
        return Float.TYPE;
    if (name.equals("double"))
        return Double.TYPE;
    if (name.equals("byte"))
        return Byte.TYPE;
    if (name.equals("char"))
        return Character.TYPE;
    if (name.equals("boolean"))
        return Boolean.TYPE;
    if (name.equals("void"))
        return Void.TYPE;

    return null;
}