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.enerj.apache.commons.beanutils.ConvertUtilsBean.java

/**
 * Remove all registered {@link Converter}s, and re-establish the
 * standard Converters./*from   ww  w .ja  v  a2 s  .c om*/
 */
public void deregister() {

    boolean booleanArray[] = new boolean[0];
    byte byteArray[] = new byte[0];
    char charArray[] = new char[0];
    double doubleArray[] = new double[0];
    float floatArray[] = new float[0];
    int intArray[] = new int[0];
    long longArray[] = new long[0];
    short shortArray[] = new short[0];
    String stringArray[] = new String[0];

    converters.clear();
    register(BigDecimal.class, new BigDecimalConverter());
    register(BigInteger.class, new BigIntegerConverter());
    register(Boolean.TYPE, new BooleanConverter(defaultBoolean));
    register(Boolean.class, new BooleanConverter(defaultBoolean));
    register(booleanArray.getClass(), new BooleanArrayConverter(booleanArray));
    register(Byte.TYPE, new ByteConverter(defaultByte));
    register(Byte.class, new ByteConverter(defaultByte));
    register(byteArray.getClass(), new ByteArrayConverter(byteArray));
    register(Character.TYPE, new CharacterConverter(defaultCharacter));
    register(Character.class, new CharacterConverter(defaultCharacter));
    register(charArray.getClass(), new CharacterArrayConverter(charArray));
    register(Class.class, new ClassConverter());
    register(Double.TYPE, new DoubleConverter(defaultDouble));
    register(Double.class, new DoubleConverter(defaultDouble));
    register(doubleArray.getClass(), new DoubleArrayConverter(doubleArray));
    register(Float.TYPE, new FloatConverter(defaultFloat));
    register(Float.class, new FloatConverter(defaultFloat));
    register(floatArray.getClass(), new FloatArrayConverter(floatArray));
    register(Integer.TYPE, new IntegerConverter(defaultInteger));
    register(Integer.class, new IntegerConverter(defaultInteger));
    register(intArray.getClass(), new IntegerArrayConverter(intArray));
    register(Long.TYPE, new LongConverter(defaultLong));
    register(Long.class, new LongConverter(defaultLong));
    register(longArray.getClass(), new LongArrayConverter(longArray));
    register(Short.TYPE, new ShortConverter(defaultShort));
    register(Short.class, new ShortConverter(defaultShort));
    register(shortArray.getClass(), new ShortArrayConverter(shortArray));
    register(String.class, new StringConverter());
    register(stringArray.getClass(), new StringArrayConverter(stringArray));
    register(Date.class, new SqlDateConverter());
    register(Time.class, new SqlTimeConverter());
    register(Timestamp.class, new SqlTimestampConverter());
    register(File.class, new FileConverter());
    register(URL.class, new URLConverter());

}

From source file:org.apache.struts2.jasper.compiler.JspUtil.java

/**
 * Produces a String representing a call to the EL interpreter.
 *
 * @param isTagFile    is a tag file/*ww w.  ja  va  2  s.  c  o  m*/
 * @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.
 */
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 = "_jspx_page_context";

    /*
         * 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);
    StringBuilder call = new StringBuilder(
            "(" + targetType + ") " + "org.apache.struts2.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:org.talend.components.netsuite.NetSuiteDatasetRuntimeImpl.java

/**
 * Infers an Avro schema for the given FieldDesc. This can be an expensive operation so the schema should be
 * cached where possible. The return type will be the Avro Schema that can contain the fieldDesc data without loss of
 * precision./*from   ww w .j ava  2 s . c o  m*/
 *
 * @param fieldDesc the <code>FieldDesc</code> to analyse.
 * @return the schema for data that the fieldDesc describes.
 */
public static Schema inferSchemaForField(FieldDesc fieldDesc) {
    Schema base;

    if (fieldDesc instanceof CustomFieldDesc) {
        CustomFieldDesc customFieldInfo = (CustomFieldDesc) fieldDesc;
        CustomFieldRefType customFieldRefType = customFieldInfo.getCustomFieldType();

        if (customFieldRefType == CustomFieldRefType.BOOLEAN) {
            base = AvroUtils._boolean();
        } else if (customFieldRefType == CustomFieldRefType.LONG) {
            base = AvroUtils._long();
        } else if (customFieldRefType == CustomFieldRefType.DOUBLE) {
            base = AvroUtils._double();
        } else if (customFieldRefType == CustomFieldRefType.DATE) {
            base = AvroUtils._logicalTimestamp();
        } else if (customFieldRefType == CustomFieldRefType.STRING) {
            base = AvroUtils._string();
        } else {
            base = AvroUtils._string();
        }

    } else {
        Class<?> fieldType = fieldDesc.getValueType();

        if (fieldType == Boolean.TYPE || fieldType == Boolean.class) {
            base = AvroUtils._boolean();
        } else if (fieldType == Integer.TYPE || fieldType == Integer.class) {
            base = AvroUtils._int();
        } else if (fieldType == Long.TYPE || fieldType == Long.class) {
            base = AvroUtils._long();
        } else if (fieldType == Float.TYPE || fieldType == Float.class) {
            base = AvroUtils._float();
        } else if (fieldType == Double.TYPE || fieldType == Double.class) {
            base = AvroUtils._double();
        } else if (fieldType == XMLGregorianCalendar.class) {
            base = AvroUtils._logicalTimestamp();
        } else if (fieldType == String.class) {
            base = AvroUtils._string();
        } else if (fieldType.isEnum()) {
            base = AvroUtils._string();
        } else {
            base = AvroUtils._string();
        }
    }

    base = fieldDesc.isNullable() ? AvroUtils.wrapAsNullable(base) : base;

    return base;
}

From source file:au.com.addstar.cellblock.configuration.AutoConfig.java

public boolean save() {
    try {/* w  w w. j  a v a 2 s.c om*/
        onPreSave();

        YamlConfiguration config = new YamlConfiguration();
        Map<String, String> comments = new HashMap<>();

        // Add all the category comments
        comments.putAll(mCategoryComments);

        // Add all the values
        for (Field field : getClass().getDeclaredFields()) {
            ConfigField configField = field.getAnnotation(ConfigField.class);
            if (configField == null)
                continue;

            String optionName = configField.name();
            if (optionName.isEmpty())
                optionName = field.getName();

            field.setAccessible(true);

            String path = (configField.category().isEmpty() ? "" : configField.category() + ".") + optionName; //$NON-NLS-2$

            // Ensure the secion exists
            if (!configField.category().isEmpty() && !config.contains(configField.category()))
                config.createSection(configField.category());

            if (field.getType().isArray()) {
                // Integer
                if (field.getType().getComponentType().equals(Integer.TYPE))
                    config.set(path, Arrays.asList((Integer[]) field.get(this)));

                // Float
                else if (field.getType().getComponentType().equals(Float.TYPE))
                    config.set(path, Arrays.asList((Float[]) field.get(this)));

                // Double
                else if (field.getType().getComponentType().equals(Double.TYPE))
                    config.set(path, Arrays.asList((Double[]) field.get(this)));

                // Long
                else if (field.getType().getComponentType().equals(Long.TYPE))
                    config.set(path, Arrays.asList((Long[]) field.get(this)));

                // Short
                else if (field.getType().getComponentType().equals(Short.TYPE))
                    config.set(path, Arrays.asList((Short[]) field.get(this)));

                // Boolean
                else if (field.getType().getComponentType().equals(Boolean.TYPE))
                    config.set(path, Arrays.asList((Boolean[]) field.get(this)));

                // String
                else if (field.getType().getComponentType().equals(String.class))
                    config.set(path, Arrays.asList((String[]) field.get(this)));
                else
                    throw new IllegalArgumentException(
                            "Cannot use type " + field.getType().getSimpleName() + " for AutoConfiguration"); //$NON-NLS-2$
            } else if (List.class.isAssignableFrom(field.getType())) {
                if (field.getGenericType() == null)
                    throw new IllegalArgumentException(
                            "Cannot use type List without specifying generic type for AutoConfiguration");

                Type type = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];

                if (type.equals(Integer.class) || type.equals(Float.class) || type.equals(Double.class)
                        || type.equals(Long.class) || type.equals(Short.class) || type.equals(Boolean.class)
                        || type.equals(String.class)) {
                    config.set(path, field.get(this));
                } else
                    throw new IllegalArgumentException("Cannot use type " + field.getType().getSimpleName()
                            + "<" + type.toString() + "> for AutoConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
            } else if (Set.class.isAssignableFrom(field.getType())) {
                if (field.getGenericType() == null)
                    throw new IllegalArgumentException(
                            "Cannot use type Set without specifying generic type for AutoConfiguration");

                Type type = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];

                if (type.equals(Integer.class) || type.equals(Float.class) || type.equals(Double.class)
                        || type.equals(Long.class) || type.equals(Short.class) || type.equals(Boolean.class)
                        || type.equals(String.class)) {
                    config.set(path, new ArrayList<Object>((Set<?>) field.get(this)));
                } else
                    throw new IllegalArgumentException("Cannot use type " + field.getType().getSimpleName()
                            + "<" + type.toString() + "> for AutoConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
            } else {
                // Integer
                if (field.getType().equals(Integer.TYPE))
                    config.set(path, field.get(this));

                // Float
                else if (field.getType().equals(Float.TYPE))
                    config.set(path, field.get(this));

                // Double
                else if (field.getType().equals(Double.TYPE))
                    config.set(path, field.get(this));

                // Long
                else if (field.getType().equals(Long.TYPE))
                    config.set(path, field.get(this));

                // Short
                else if (field.getType().equals(Short.TYPE))
                    config.set(path, field.get(this));

                // Boolean
                else if (field.getType().equals(Boolean.TYPE))
                    config.set(path, field.get(this));

                // ItemStack
                else if (field.getType().equals(ItemStack.class))
                    config.set(path, field.get(this));

                // String
                else if (field.getType().equals(String.class))
                    config.set(path, field.get(this));
                else
                    throw new IllegalArgumentException(
                            "Cannot use type " + field.getType().getSimpleName() + " for AutoConfiguration"); //$NON-NLS-2$
            }

            // Record the comment
            if (!configField.comment().isEmpty())
                comments.put(path, configField.comment());
        }

        String output = config.saveToString();

        // Apply comments
        String category = "";
        List<String> lines = new ArrayList<>(Arrays.asList(output.split("\n")));
        for (int l = 0; l < lines.size(); l++) {
            String line = lines.get(l);

            if (line.startsWith("#"))
                continue;

            if (line.trim().startsWith("-"))
                continue;

            if (!line.contains(":"))
                continue;

            String path;
            line = line.substring(0, line.indexOf(":"));

            if (line.startsWith("  "))
                path = category + "." + line.substring(2).trim();
            else {
                category = line.trim();
                path = line.trim();
            }

            if (comments.containsKey(path)) {
                String indent = "";
                for (int i = 0; i < line.length(); i++) {
                    if (line.charAt(i) == ' ')
                        indent += " ";
                    else
                        break;
                }

                // Add in the comment lines
                String[] commentLines = comments.get(path).split("\n");
                lines.add(l++, "");
                for (int i = 0; i < commentLines.length; i++) {
                    commentLines[i] = indent + "# " + commentLines[i];
                    lines.add(l++, commentLines[i]);
                }
            }
        }
        output = "";
        for (String line : lines)
            output += line + "\n";

        FileWriter writer = new FileWriter(mFile);
        writer.write(output);
        writer.close();
        return true;
    } catch (IllegalArgumentException | IOException | IllegalAccessException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:org.apache.hadoop.hbase.security.access.HbaseObjectWritableFor96Migration.java

/**
 * Write a {@link Writable}, {@link String}, primitive type, or an array of
 * the preceding./*from   w  w w.jav a2 s  . c o  m*/
 * @param out
 * @param instance
 * @param declaredClass
 * @param conf
 * @throws IOException
 */
@SuppressWarnings("unchecked")
static void writeObject(DataOutput out, Object instance, Class declaredClass, Configuration conf)
        throws IOException {

    Object instanceObj = instance;
    Class declClass = declaredClass;

    if (instanceObj == null) { // null
        instanceObj = new NullInstance(declClass, conf);
        declClass = Writable.class;
    }
    writeClassCode(out, declClass);
    if (declClass.isArray()) { // array
        // If bytearray, just dump it out -- avoid the recursion and
        // byte-at-a-time we were previously doing.
        if (declClass.equals(byte[].class)) {
            Bytes.writeByteArray(out, (byte[]) instanceObj);
        } else {
            //if it is a Generic array, write the element's type
            if (getClassCode(declaredClass) == GENERIC_ARRAY_CODE) {
                Class<?> componentType = declaredClass.getComponentType();
                writeClass(out, componentType);
            }

            int length = Array.getLength(instanceObj);
            out.writeInt(length);
            for (int i = 0; i < length; i++) {
                Object item = Array.get(instanceObj, i);
                writeObject(out, item, item.getClass(), conf);
            }
        }
    } else if (List.class.isAssignableFrom(declClass)) {
        List list = (List) instanceObj;
        int length = list.size();
        out.writeInt(length);
        for (int i = 0; i < length; i++) {
            Object elem = list.get(i);
            writeObject(out, elem, elem == null ? Writable.class : elem.getClass(), conf);
        }
    } else if (declClass == String.class) { // String
        Text.writeString(out, (String) instanceObj);
    } else if (declClass.isPrimitive()) { // primitive type
        if (declClass == Boolean.TYPE) { // boolean
            out.writeBoolean(((Boolean) instanceObj).booleanValue());
        } else if (declClass == Character.TYPE) { // char
            out.writeChar(((Character) instanceObj).charValue());
        } else if (declClass == Byte.TYPE) { // byte
            out.writeByte(((Byte) instanceObj).byteValue());
        } else if (declClass == Short.TYPE) { // short
            out.writeShort(((Short) instanceObj).shortValue());
        } else if (declClass == Integer.TYPE) { // int
            out.writeInt(((Integer) instanceObj).intValue());
        } else if (declClass == Long.TYPE) { // long
            out.writeLong(((Long) instanceObj).longValue());
        } else if (declClass == Float.TYPE) { // float
            out.writeFloat(((Float) instanceObj).floatValue());
        } else if (declClass == Double.TYPE) { // double
            out.writeDouble(((Double) instanceObj).doubleValue());
        } else if (declClass == Void.TYPE) { // void
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declClass);
        }
    } else if (declClass.isEnum()) { // enum
        Text.writeString(out, ((Enum) instanceObj).name());
    } else if (Message.class.isAssignableFrom(declaredClass)) {
        Text.writeString(out, instanceObj.getClass().getName());
        ((Message) instance).writeDelimitedTo(DataOutputOutputStream.constructOutputStream(out));
    } else if (Writable.class.isAssignableFrom(declClass)) { // Writable
        Class<?> c = instanceObj.getClass();
        Integer code = CLASS_TO_CODE.get(c);
        if (code == null) {
            out.writeByte(NOT_ENCODED);
            Text.writeString(out, c.getName());
        } else {
            writeClassCode(out, c);
        }
        ((Writable) instanceObj).write(out);
    } else if (Serializable.class.isAssignableFrom(declClass)) {
        Class<?> c = instanceObj.getClass();
        Integer code = CLASS_TO_CODE.get(c);
        if (code == null) {
            out.writeByte(NOT_ENCODED);
            Text.writeString(out, c.getName());
        } else {
            writeClassCode(out, c);
        }
        ByteArrayOutputStream bos = null;
        ObjectOutputStream oos = null;
        try {
            bos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(bos);
            oos.writeObject(instanceObj);
            byte[] value = bos.toByteArray();
            out.writeInt(value.length);
            out.write(value);
        } finally {
            if (bos != null)
                bos.close();
            if (oos != null)
                oos.close();
        }
    } else if (Scan.class.isAssignableFrom(declClass)) {
        Scan scan = (Scan) instanceObj;
        byte[] scanBytes = ProtobufUtil.toScan(scan).toByteArray();
        out.writeInt(scanBytes.length);
        out.write(scanBytes);
    } else {
        throw new IOException("Can't write: " + instanceObj + " as " + declClass);
    }
}

From source file:com.aimfire.main.MainActivity.java

/**
 * Override Activity lifecycle method.//from   www.ja  v  a 2 s.  c  o  m
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_main, menu);

    /*
      * To show icon (instead of only text) in action bar overflow
      */
    if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
        try {
            Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
            m.setAccessible(true);
            m.invoke(menu, true);
        } catch (NoSuchMethodException e) {
            if (BuildConfig.DEBUG)
                Log.e(TAG, "onMenuOpened", e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:org.apache.hadoop.hbase.io.HbaseObjectWritable.java

/**
 * Write a {@link Writable}, {@link String}, primitive type, or an array of
 * the preceding./*  ww  w .  j  a v a 2s.  c  o m*/
 * @param out
 * @param instance
 * @param declaredClass
 * @param conf
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static void writeObject(DataOutput out, Object instance, Class declaredClass, Configuration conf)
        throws IOException {

    Object instanceObj = instance;
    Class declClass = declaredClass;

    if (instanceObj == null) { // null
        instanceObj = new NullInstance(declClass, conf);
        declClass = Writable.class;
    }
    writeClassCode(out, declClass);
    if (declClass.isArray()) { // array
        // If bytearray, just dump it out -- avoid the recursion and
        // byte-at-a-time we were previously doing.
        if (declClass.equals(byte[].class)) {
            Bytes.writeByteArray(out, (byte[]) instanceObj);
        } else if (declClass.equals(Result[].class)) {
            Result.writeArray(out, (Result[]) instanceObj);
        } else {
            //if it is a Generic array, write the element's type
            if (getClassCode(declaredClass) == GENERIC_ARRAY_CODE) {
                Class<?> componentType = declaredClass.getComponentType();
                writeClass(out, componentType);
            }

            int length = Array.getLength(instanceObj);
            out.writeInt(length);
            for (int i = 0; i < length; i++) {
                Object item = Array.get(instanceObj, i);
                writeObject(out, item, item.getClass(), conf);
            }
        }
    } else if (List.class.isAssignableFrom(declClass)) {
        List list = (List) instanceObj;
        int length = list.size();
        out.writeInt(length);
        for (int i = 0; i < length; i++) {
            Object elem = list.get(i);
            writeObject(out, elem, elem == null ? Writable.class : elem.getClass(), conf);
        }
    } else if (declClass == String.class) { // String
        Text.writeString(out, (String) instanceObj);
    } else if (declClass.isPrimitive()) { // primitive type
        if (declClass == Boolean.TYPE) { // boolean
            out.writeBoolean(((Boolean) instanceObj).booleanValue());
        } else if (declClass == Character.TYPE) { // char
            out.writeChar(((Character) instanceObj).charValue());
        } else if (declClass == Byte.TYPE) { // byte
            out.writeByte(((Byte) instanceObj).byteValue());
        } else if (declClass == Short.TYPE) { // short
            out.writeShort(((Short) instanceObj).shortValue());
        } else if (declClass == Integer.TYPE) { // int
            out.writeInt(((Integer) instanceObj).intValue());
        } else if (declClass == Long.TYPE) { // long
            out.writeLong(((Long) instanceObj).longValue());
        } else if (declClass == Float.TYPE) { // float
            out.writeFloat(((Float) instanceObj).floatValue());
        } else if (declClass == Double.TYPE) { // double
            out.writeDouble(((Double) instanceObj).doubleValue());
        } else if (declClass == Void.TYPE) { // void
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declClass);
        }
    } else if (declClass.isEnum()) { // enum
        Text.writeString(out, ((Enum) instanceObj).name());
    } else if (Message.class.isAssignableFrom(declaredClass)) {
        Text.writeString(out, instanceObj.getClass().getName());
        ((Message) instance).writeDelimitedTo(DataOutputOutputStream.constructOutputStream(out));
    } else if (Writable.class.isAssignableFrom(declClass)) { // Writable
        Class<?> c = instanceObj.getClass();
        Integer code = CLASS_TO_CODE.get(c);
        if (code == null) {
            out.writeByte(NOT_ENCODED);
            Text.writeString(out, c.getName());
        } else {
            writeClassCode(out, c);
        }
        ((Writable) instanceObj).write(out);
    } else if (Serializable.class.isAssignableFrom(declClass)) {
        Class<?> c = instanceObj.getClass();
        Integer code = CLASS_TO_CODE.get(c);
        if (code == null) {
            out.writeByte(NOT_ENCODED);
            Text.writeString(out, c.getName());
        } else {
            writeClassCode(out, c);
        }
        ByteArrayOutputStream bos = null;
        ObjectOutputStream oos = null;
        try {
            bos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(bos);
            oos.writeObject(instanceObj);
            byte[] value = bos.toByteArray();
            out.writeInt(value.length);
            out.write(value);
        } finally {
            if (bos != null)
                bos.close();
            if (oos != null)
                oos.close();
        }
    } else {
        throw new IOException("Can't write: " + instanceObj + " as " + declClass);
    }
}

From source file:microsoft.exchange.webservices.data.property.complex.UserConfigurationDictionary.java

/**
 * Loads an entry, consisting of a key value pair, into this dictionary from
 * the specified reader.//from   w  w w. j  ava2  s.  com
 *
 * @param reader The reader.
 * @throws Exception the exception
 */
private void loadEntry(EwsServiceXmlReader reader) throws Exception {
    EwsUtilities.ewsAssert(reader != null, "UserConfigurationDictionary.LoadEntry", "reader is null");

    Object key;
    Object value = null;

    // Position at DictionaryKey
    reader.readStartElement(this.getNamespace(), XmlElementNames.DictionaryKey);

    key = this.getDictionaryObject(reader);

    // Position at DictionaryValue
    reader.readStartElement(this.getNamespace(), XmlElementNames.DictionaryValue);

    String nil = reader.readAttributeValue(XmlNamespace.XmlSchemaInstance, XmlAttributeNames.Nil);
    boolean hasValue = (nil == null) || (!nil.getClass().equals(Boolean.TYPE));
    if (hasValue) {
        value = this.getDictionaryObject(reader);
    }
    this.dictionary.put(key, value);
}

From source file:org.liveSense.api.beanprocessors.DbStandardBeanProcessor.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.
 * /*  w  w  w  . j  av a  2  s. com*/
 * <p>
 * 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.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 (rs.getInt(index));

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

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

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

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

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

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

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

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

}

From source file:org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator.java

private final Class<?> getClassForName(String type) {
    try {/*  w  w  w .ja  v a 2 s.co  m*/
        if (type.equals("boolean") || type.equals("java.lang.Boolean")) {
            return Boolean.TYPE;
        } else if (type.equals("byte") || type.equals("java.lang.Byte")) {
            return Byte.TYPE;
        } else if (type.equals("char") || type.equals("java.lang.Character")) {
            return Character.TYPE;
        } else if (type.equals("double") || type.equals("java.lang.Double")) {
            return Double.TYPE;
        } else if (type.equals("float") || type.equals("java.lang.Float")) {
            return Float.TYPE;
        } else if (type.equals("int") || type.equals("java.lang.Integer")) {
            return Integer.TYPE;
        } else if (type.equals("long") || type.equals("java.lang.Long")) {
            return Long.TYPE;
        } else if (type.equals("short") || type.equals("java.lang.Short")) {
            return Short.TYPE;
        } else if (type.equals("String")) {
            return Class.forName("java.lang." + type, true,
                    TestGenerationContext.getInstance().getClassLoaderForSUT());
        }

        if (type.endsWith("[]")) {
            // see http://stackoverflow.com/questions/3442090/java-what-is-this-ljava-lang-object

            final StringBuilder arrayTypeNameBuilder = new StringBuilder(30);

            int index = 0;
            while ((index = type.indexOf('[', index)) != -1) {
                arrayTypeNameBuilder.append('[');
                index++;
            }

            arrayTypeNameBuilder.append('L'); // always needed for Object arrays

            // remove bracket from type name get array component type
            type = type.replace("[]", "");
            arrayTypeNameBuilder.append(type);

            arrayTypeNameBuilder.append(';'); // finalize object array name

            return Class.forName(arrayTypeNameBuilder.toString(), true,
                    TestGenerationContext.getInstance().getClassLoaderForSUT());
        } else {
            return Class.forName(ResourceList.getClassNameFromResourcePath(type), true,
                    TestGenerationContext.getInstance().getClassLoaderForSUT());
        }
    } catch (final ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}