Example usage for java.lang Byte TYPE

List of usage examples for java.lang Byte TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class instance representing the primitive type byte .

Usage

From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowserUnmarshaller.java

/**
 * Gracefully convert given Object to given class given the precondition
 * that both are primitives or one of the classes associated with
 * primitives. eg. If val is of type Double and cls is of type int, return
 * Integer type with appropriate value truncation so that it can be assigned
 * to field with field.set()./*from ww w  .  ja va2 s  .c  o  m*/
 *
 * @param cls
 * @param val
 * @return
 * @throws com.initialxy.cordova.themeablebrowser.ThemeableBrowserUnmarshaller.TypeMismatchException
 */
private static Object convertToPrimitiveFieldObj(Object val, Class<?> cls) {
    Class<?> valClass = val.getClass();
    Object result = null;

    try {
        Method getter = null;
        if (cls.isAssignableFrom(Byte.class) || cls.isAssignableFrom(Byte.TYPE)) {
            getter = valClass.getMethod("byteValue");
        } else if (cls.isAssignableFrom(Short.class) || cls.isAssignableFrom(Short.TYPE)) {
            getter = valClass.getMethod("shortValue");
        } else if (cls.isAssignableFrom(Integer.class) || cls.isAssignableFrom(Integer.TYPE)) {
            getter = valClass.getMethod("intValue");
        } else if (cls.isAssignableFrom(Long.class) || cls.isAssignableFrom(Long.TYPE)) {
            getter = valClass.getMethod("longValue");
        } else if (cls.isAssignableFrom(Float.class) || cls.isAssignableFrom(Float.TYPE)) {
            getter = valClass.getMethod("floatValue");
        } else if (cls.isAssignableFrom(Double.class) || cls.isAssignableFrom(Double.TYPE)) {
            getter = valClass.getMethod("doubleValue");
        } else if (cls.isAssignableFrom(Boolean.class) || cls.isAssignableFrom(Boolean.TYPE)) {
            if (val instanceof Boolean) {
                result = val;
            } else {
                throw new TypeMismatchException(cls, val.getClass());
            }
        } else if (cls.isAssignableFrom(Character.class) || cls.isAssignableFrom(Character.TYPE)) {
            if (val instanceof String && ((String) val).length() == 1) {
                char c = ((String) val).charAt(0);
                result = Character.valueOf(c);
            } else if (val instanceof String) {
                throw new TypeMismatchException(
                        "Expected Character, " + "but received String with length other than 1.");
            } else {
                throw new TypeMismatchException(
                        String.format("Expected Character, accept String, but got %s.", val.getClass()));
            }
        }

        if (getter != null) {
            result = getter.invoke(val);
        }
    } catch (NoSuchMethodException e) {
        throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls));
    } catch (SecurityException e) {
        throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls));
    } catch (IllegalAccessException e) {
        throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls));
    } catch (InvocationTargetException e) {
        throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls));
    }

    return result;
}

From source file:org.xmlsh.util.JavaUtils.java

public static Class<?> fromPrimativeName(String name) {

    switch (name) {
    case "boolean":
        return java.lang.Boolean.TYPE;
    case "char":
        return java.lang.Character.TYPE;
    case "byte":
        return java.lang.Byte.TYPE;
    case "short":
        return java.lang.Short.TYPE;
    case "int":
        return java.lang.Integer.TYPE;
    case "long":
        return java.lang.Long.TYPE;
    case "float":
        return java.lang.Float.TYPE;
    case "double":
        return java.lang.Double.TYPE;
    case "void":
        return java.lang.Void.TYPE;
    default:/*from  w w  w. j a v a 2s  .  c  om*/
        return null;
    }

}

From source file:com.github.gekoh.yagen.util.FieldInfo.java

private static List<FieldInfo> convertFields(List<FieldInfo> fields, Class baseEntity) {

    for (Field field : baseEntity.getDeclaredFields()) {
        FieldInfo fi;//from  w  ww  . j  ava2s.  c  om
        Class type = field.getType();
        String name = field.getName();
        Column column = field.getAnnotation(Column.class);
        if (field.isAnnotationPresent(Embedded.class)) {
            if (field.isAnnotationPresent(AttributeOverride.class)) {
                fi = new FieldInfo(type, name, field.getAnnotation(AttributeOverride.class));
            } else {
                fi = new FieldInfo(type, name, field.getAnnotation(AttributeOverrides.class));
            }
        } else if (field.isAnnotationPresent(Enumerated.class)) {
            fi = new FieldInfo(type, name, true, column);
        } else if (column != null && !field.isAnnotationPresent(CollectionTable.class)) {
            if (type.isPrimitive()) {
                if (type.equals(Boolean.TYPE)) {
                    type = Boolean.class;
                } else if (type.equals(Long.TYPE)) {
                    type = Long.class;
                } else if (type.equals(Integer.TYPE)) {
                    type = Integer.class;
                } else if (type.equals(Short.TYPE)) {
                    type = Short.class;
                } else if (type.equals(Byte.TYPE)) {
                    type = Byte.class;
                } else if (type.equals(Double.TYPE)) {
                    type = Double.class;
                } else if (type.equals(Float.TYPE)) {
                    type = Float.class;
                } else if (type.equals(Character.TYPE)) {
                    type = Character.class;
                }
            }
            fi = new FieldInfo(type, name, false, column);
        } else if ((field.isAnnotationPresent(ManyToOne.class) && !field.isAnnotationPresent(JoinTable.class))
                || (field.isAnnotationPresent(OneToOne.class)
                        && StringUtils.isEmpty(field.getAnnotation(OneToOne.class).mappedBy()))) {
            String columnName = field.isAnnotationPresent(JoinColumn.class)
                    ? field.getAnnotation(JoinColumn.class).name()
                    : field.getName();
            fi = getIdFieldInfo(type, name, columnName);
        } else if (!field.isAnnotationPresent(Transient.class)
                && (Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type))
                && (field.isAnnotationPresent(JoinColumn.class) || field.isAnnotationPresent(JoinTable.class)
                        || field.isAnnotationPresent(CollectionTable.class))) {
            fi = new FieldInfo(type, name);
        } else {
            continue;
        }
        if (field.isAnnotationPresent(Type.class)) {
            fi.addAnnotation(field.getAnnotation(Type.class));
        }
        fi.setField(field);
        fields.add(fi);
    }

    return fields;
}

From source file:com.nonninz.robomodel.RoboModel.java

void saveField(Field field, TypedContentValues cv) {
    final Class<?> type = field.getType();
    final boolean wasAccessible = field.isAccessible();
    field.setAccessible(true);//from   www  . j  a  v a  2s . c o  m

    try {
        if (type == String.class) {
            cv.put(field.getName(), (String) field.get(this));
        } else if (type == Boolean.TYPE) {
            cv.put(field.getName(), field.getBoolean(this));
        } else if (type == Byte.TYPE) {
            cv.put(field.getName(), field.getByte(this));
        } else if (type == Double.TYPE) {
            cv.put(field.getName(), field.getDouble(this));
        } else if (type == Float.TYPE) {
            cv.put(field.getName(), field.getFloat(this));
        } else if (type == Integer.TYPE) {
            cv.put(field.getName(), field.getInt(this));
        } else if (type == Long.TYPE) {
            cv.put(field.getName(), field.getLong(this));
        } else if (type == Short.TYPE) {
            cv.put(field.getName(), field.getShort(this));
        } else if (type.isEnum()) {
            final Object value = field.get(this);
            if (value != null) {
                final Method method = type.getMethod("name");
                final String str = (String) method.invoke(value);
                cv.put(field.getName(), str);
            }
        } else {
            // Try to JSONify it (db column must be of type text)
            final String json = mMapper.writeValueAsString(field.get(this));
            cv.put(field.getName(), json);
        }
    } catch (final IllegalAccessException e) {
        final String msg = String.format("Field %s is not accessible", type, field.getName());
        throw new IllegalArgumentException(msg);
    } catch (final JsonProcessingException e) {
        Ln.w(e, "Error while dumping %s of type %s to Json", field.getName(), type);
        final String msg = String.format("Field %s is not accessible", type, field.getName());
        throw new IllegalArgumentException(msg);
    } catch (final NoSuchMethodException e) {
        // Should not happen
        throw new RuntimeException(e);
    } catch (final InvocationTargetException e) {
        // Should not happen
        throw new RuntimeException(e);
    } finally {
        field.setAccessible(wasAccessible);
    }
}

From source file:org.javelin.sws.ext.bind.internal.BuiltInMappings.java

/**
 * @param patterns//ww w  .java 2 s.c  o m
 */
public static <T> void initialize(Map<Class<?>, TypedPattern<?>> patterns,
        Map<QName, TypedPattern<?>> patternsForTypeQNames) {
    // see: com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl<T> and inner
    // com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.StringImpl<T> implementations

    // we have two places where XSD -> Java mapping is defined:
    // - JAX-RPC 1.1, section 4.2.1 Simple Types
    // - JAXB 2, section 6.2.2 Atomic Datatype

    // XML Schema (1.0) Part 2: Datatypes Second Edition, or/and
    // W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes

    // conversion of primitive types should be base on "Lexical Mapping" of simple types defined in XSD part 2

    // 3.2 Special Built-in Datatypes (#special-datatypes)
    // 3.2.1 anySimpleType (#anySimpleType)
    // 3.2.2 anyAtomicType (#anyAtomicType)

    // 3.3 Primitive Datatypes (#built-in-primitive-datatypes)

    // 3.3.1 string (#string)
    {
        SimpleContentPattern<String> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_STRING,
                String.class);
        patterns.put(pattern.getJavaType(), pattern);
        patternsForTypeQNames.put(pattern.getSchemaType(), pattern);
    }

    // 3.3.2 boolean (#boolean)
    {
        SimpleContentPattern<Boolean> pattern = SimpleContentPattern
                .newValuePattern(SweJaxbConstants.XSD_BOOLEAN, Boolean.class);
        patterns.put(Boolean.TYPE, pattern);
        patterns.put(pattern.getJavaType(), pattern);
        patternsForTypeQNames.put(pattern.getSchemaType(), pattern);
        pattern.setFormatter(new Formatter<Boolean>() {
            @Override
            public String print(Boolean object, Locale locale) {
                return Boolean.toString(object);
            }

            @Override
            public Boolean parse(String text, Locale locale) throws ParseException {
                // TODO: should allow "true", "false", "1", "0"
                return Boolean.parseBoolean(text);
            }
        });
    }

    // 3.3.3 decimal (#decimal)
    {
        SimpleContentPattern<BigDecimal> pattern = SimpleContentPattern
                .newValuePattern(SweJaxbConstants.XSD_DECIMAL, BigDecimal.class);
        patterns.put(pattern.getJavaType(), pattern);
        patternsForTypeQNames.put(pattern.getSchemaType(), pattern);
        pattern.setFormatter(new Formatter<BigDecimal>() {
            @Override
            public String print(BigDecimal object, Locale locale) {
                return object.toPlainString();
            }

            @Override
            public BigDecimal parse(String text, Locale locale) throws ParseException {
                // TODO: should allow (\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)
                return new BigDecimal(text);
            }
        });
    }

    // 3.3.4 float (#float)
    {
        SimpleContentPattern<Float> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_FLOAT,
                Float.class);
        patterns.put(Float.TYPE, pattern);
        patterns.put(pattern.getJavaType(), pattern);
        patternsForTypeQNames.put(pattern.getSchemaType(), pattern);
        pattern.setFormatter(new Formatter<Float>() {
            @Override
            public String print(Float object, Locale locale) {
                return Float.toString(object);
            }

            @Override
            public Float parse(String text, Locale locale) throws ParseException {
                // TODO: should allow (\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)([Ee](\+|-)?[0-9]+)?|(\+|-)?INF|NaN
                return Float.parseFloat(text);
            }
        });
    }

    // 3.3.5 double (#double)
    {
        SimpleContentPattern<Double> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_DOUBLE,
                Double.class);
        patterns.put(Double.TYPE, pattern);
        patterns.put(pattern.getJavaType(), pattern);
        patternsForTypeQNames.put(pattern.getSchemaType(), pattern);
        pattern.setFormatter(new Formatter<Double>() {
            @Override
            public String print(Double object, Locale locale) {
                return Double.toString(object);
            }

            @Override
            public Double parse(String text, Locale locale) throws ParseException {
                // TODO: should allow (\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)([Ee](\+|-)?[0-9]+)?|(\+|-)?INF|NaN
                return Double.parseDouble(text);
            }
        });
    }

    // 3.3.6 duration (#duration)
    // 3.3.7 dateTime (#dateTime)
    {
        SimpleContentPattern<DateTime> pattern = SimpleContentPattern
                .newValuePattern(SweJaxbConstants.XSD_DATETIME, DateTime.class);
        patterns.put(pattern.getJavaType(), pattern);
        patternsForTypeQNames.put(pattern.getSchemaType(), pattern);
        pattern.setFormatter(new Formatter<DateTime>() {
            private final DateTimeFormatter DTMS = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
            private final DateTimeFormatter DT = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZZ");
            private final DateTimeFormatter DTZMS = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
            private final DateTimeFormatter DTZ = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");

            @Override
            public DateTime parse(String text, Locale locale) throws ParseException {
                return null;
            }

            @Override
            public String print(DateTime object, Locale locale) {
                if (object.getMillisOfSecond() == 0) {
                    return object.getZone() == DateTimeZone.UTC ? DTZ.print(object) : DT.print(object);
                } else {
                    return object.getZone() == DateTimeZone.UTC ? DTZMS.print(object) : DTMS.print(object);
                }
            }
        });
    }
    // 3.3.8 time (#time)
    {
        SimpleContentPattern<DateTime> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_TIME,
                DateTime.class);
        patternsForTypeQNames.put(pattern.getSchemaType(), pattern);
        pattern.setFormatter(new Formatter<DateTime>() {
            private final DateTimeFormatter TMS = DateTimeFormat.forPattern("HH:mm:ss.SSS");
            private final DateTimeFormatter T = DateTimeFormat.forPattern("HH:mm:ss");

            @Override
            public DateTime parse(String text, Locale locale) throws ParseException {
                return null;
            }

            @Override
            public String print(DateTime object, Locale locale) {
                // TODO: should allow (([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\.[0-9]+)?|(24:00:00(\.0+)?))(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?
                if (object.getMillisOfSecond() == 0)
                    return T.print(object);
                else
                    return TMS.print(object);
            }
        });
    }
    // 3.3.9 date (#date)
    {
        SimpleContentPattern<DateTime> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_DATE,
                DateTime.class);
        patternsForTypeQNames.put(pattern.getSchemaType(), pattern);
        pattern.setFormatter(new Formatter<DateTime>() {
            private final DateTimeFormatter DT = DateTimeFormat.forPattern("yyyy-MM-ddZZ");
            private final DateTimeFormatter DTZ = DateTimeFormat.forPattern("yyyy-MM-dd'Z'");

            @Override
            public DateTime parse(String text, Locale locale) throws ParseException {
                return null;
            }

            @Override
            public String print(DateTime object, Locale locale) {
                return object.getZone() == DateTimeZone.UTC ? DTZ.print(object) : DT.print(object);
            }
        });
    }
    // 3.3.10 gYearMonth (#gYearMonth)
    // 3.3.11 gYear (#gYear)
    // 3.3.12 gMonthDay (#gMonthDay)
    // 3.3.13 gDay (#gDay)
    // 3.3.14 gMonth (#gMonth)
    // 3.3.15 hexBinary (#hexBinary)
    // 3.3.16 base64Binary (#base64Binary)
    // 3.3.17 anyURI (#anyURI)
    // 3.3.18 QName (#QName)
    // 3.3.19 NOTATION (#NOTATION)

    // 3.4 Other Built-in Datatypes (#ordinary-built-ins)

    // 3.4.1 normalizedString (#normalizedString)
    // 3.4.2 token (#token)
    // 3.4.3 language (#language)
    // 3.4.4 NMTOKEN (#NMTOKEN)
    // 3.4.5 NMTOKENS (#NMTOKENS)
    // 3.4.6 Name (#Name)
    // 3.4.7 NCName (#NCName)
    // 3.4.8 ID (#ID)
    // 3.4.9 IDREF (#IDREF)
    // 3.4.10 IDREFS (#IDREFS)
    // 3.4.11 ENTITY (#ENTITY)
    // 3.4.12 ENTITIES (#ENTITIES)
    // 3.4.13 integer (#integer)
    // 3.4.14 nonPositiveInteger (#nonPositiveInteger)
    // 3.4.15 negativeInteger (#negativeInteger)
    // 3.4.16 long (#long)
    {
        SimpleContentPattern<Long> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_LONG,
                Long.class);
        patterns.put(Long.TYPE, pattern);
        patterns.put(pattern.getJavaType(), pattern);
        patternsForTypeQNames.put(pattern.getSchemaType(), pattern);
        pattern.setFormatter(new Formatter<Long>() {
            @Override
            public String print(Long object, Locale locale) {
                return Long.toString(object);
            }

            @Override
            public Long parse(String text, Locale locale) throws ParseException {
                return Long.parseLong(text);
            }
        });
    }
    // 3.4.17 int (#int)
    {
        SimpleContentPattern<Integer> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_INT,
                Integer.class);
        patterns.put(Integer.TYPE, pattern);
        patterns.put(pattern.getJavaType(), pattern);
        patternsForTypeQNames.put(pattern.getSchemaType(), pattern);
        pattern.setFormatter(new Formatter<Integer>() {
            @Override
            public String print(Integer object, Locale locale) {
                return Integer.toString(object);
            }

            @Override
            public Integer parse(String text, Locale locale) throws ParseException {
                return Integer.parseInt(text);
            }
        });
    }
    // 3.4.18 short (#short)
    {
        SimpleContentPattern<Short> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_SHORT,
                Short.class);
        patterns.put(Short.TYPE, pattern);
        patterns.put(pattern.getJavaType(), pattern);
        patternsForTypeQNames.put(pattern.getSchemaType(), pattern);
        pattern.setFormatter(new Formatter<Short>() {
            @Override
            public String print(Short object, Locale locale) {
                return Short.toString(object);
            }

            @Override
            public Short parse(String text, Locale locale) throws ParseException {
                return Short.parseShort(text);
            }
        });
    }
    // 3.4.19 byte (#byte)
    {
        SimpleContentPattern<Byte> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_BYTE,
                Byte.class);
        patterns.put(Byte.TYPE, pattern);
        patterns.put(pattern.getJavaType(), pattern);
        patternsForTypeQNames.put(pattern.getSchemaType(), pattern);
        pattern.setFormatter(new Formatter<Byte>() {
            @Override
            public String print(Byte object, Locale locale) {
                return Byte.toString(object);
            }

            @Override
            public Byte parse(String text, Locale locale) throws ParseException {
                return Byte.parseByte(text);
            }
        });
    }
    // 3.4.20 nonNegativeInteger (#nonNegativeInteger)
    // 3.4.21 unsignedLong (#unsignedLong)
    // 3.4.22 unsignedInt (#unsignedInt)
    // 3.4.23 unsignedShort (#unsignedShort)
    // 3.4.24 unsignedByte (#unsignedByte)
    // 3.4.25 positiveInteger (#positiveInteger)
    // 3.4.26 yearMonthDuration (#yearMonthDuration)
    // 3.4.27 dayTimeDuration (#dayTimeDuration)
    // 3.4.28 dateTimeStamp (#dateTimeStamp)

    // other simple types
    // JAXB2 (static):
    /*
       class [B
       class char
       class java.awt.Image
       class java.io.File
       class java.lang.Character
       class java.lang.Class
       class java.lang.Void
       class java.math.BigDecimal
       class java.math.BigInteger
       class java.net.URI
       class java.net.URL
       class java.util.Calendar
       class java.util.Date
       class java.util.GregorianCalendar
       class java.util.UUID
       class javax.activation.DataHandler
       class javax.xml.datatype.Duration
       class javax.xml.datatype.XMLGregorianCalendar
       class javax.xml.namespace.QName
       interface javax.xml.transform.Source
       class void
     */
    // JAXB2 (additional mappings available at runtime):
    /*
     * class com.sun.xml.bind.api.CompositeStructure
     * class java.lang.Object
     * class javax.xml.bind.JAXBElement
     */
}

From source file:org.yestech.jmlnitrate.transformation.inbound.BaseInboundTransformation.java

/**
 *  Returns the Class Type for a Primitive type.
 *
 * @param  classType Description of the Parameter
 * @return  the Class Type//from   w ww. ja v  a 2 s .com
 * @exception  Exception Description of the Exception
 */
private Class getClass(String classType) throws Exception {
    TransformationParameter classParameter = TransformationParameter.getByName(classType);
    Class type = null;
    if (classParameter != null) {
        if (classParameter.equals(TransformationParameter.INT)) {
            //int
            type = Integer.TYPE;
        } else if (classParameter.equals(TransformationParameter.LONG)) {
            //long
            type = Long.TYPE;
        } else if (classParameter.equals(TransformationParameter.FLOAT)) {
            //float
            type = Float.TYPE;
        } else if (classParameter.equals(TransformationParameter.DOUBLE)) {
            //double
            type = Double.TYPE;
        } else if (classParameter.equals(TransformationParameter.BOOLEAN)) {
            //boolean
            type = Boolean.TYPE;
        } else if (classParameter.equals(TransformationParameter.CHAR)) {
            //char
            type = Character.TYPE;
        } else if (classParameter.equals(TransformationParameter.BYTE)) {
            //byte
            type = Byte.TYPE;
        } else {
            logger.error("Not a valid Class Type...");
            throw new IllegalArgumentException("Not a valid Class Type...");
        }
    } else {
        type = Clazz.getClass(classType);
    }
    return type;
}

From source file:com.sun.faces.el.impl.Coercions.java

/**
 * Returns true if the given class is Byte, Short, Integer, Long,
 * Float, Double, BigInteger, or BigDecimal
 */// w w w  .ja v  a  2 s.c  o m
static boolean isNumberClass(Class pClass) {
    return pClass == Byte.class || pClass == Byte.TYPE || pClass == Short.class || pClass == Short.TYPE
            || pClass == Integer.class || pClass == Integer.TYPE || pClass == Long.class || pClass == Long.TYPE
            || pClass == Float.class || pClass == Float.TYPE || pClass == Double.class || pClass == Double.TYPE
            || pClass == BigInteger.class || pClass == BigDecimal.class;
}

From source file:org.castor.jaxb.reflection.ClassDescriptorBuilder.java

/**
 * Creates the TypeInfo for the field to create the correct FieldHandler.
 * For collection fields a collection handler is instantiated and for arrays
 * the type is set to the object type of the array elements.
 * //from  w ww .ja v  a 2s . c om
 * @param jaxbFieldNature
 *            the field for which the TypeInfo should be created
 * @return the TypeInfo instance
 */
private TypeInfo buildTypeInfo(final JaxbFieldNature jaxbFieldNature) {
    if (jaxbFieldNature == null) {
        IllegalArgumentException e = new IllegalArgumentException("Argument fieldInfo must not be null.");
        throw e;
    }
    CollectionHandler collectionHandler = null;
    if (jaxbFieldNature.isMultivalue()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(jaxbFieldNature + " is multivalued and required special collection handler.");
        }
        try {
            collectionHandler = CollectionHandlers.getHandler(getType(jaxbFieldNature));
        } catch (MappingException e) {
            // No collection found - continue without collection handler
        }
        if (getType(jaxbFieldNature).isArray()) {
            if (getType(jaxbFieldNature).getComponentType() == Byte.TYPE) {
                collectionHandler = null;
            } else {
                // fieldInfo.setFieldType(fieldInfo.getElementType());
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(jaxbFieldNature + " creating TypeInfo.");
    }
    return new TypeInfo(getType(jaxbFieldNature), null, null, false, null, collectionHandler);
}

From source file:com.xwtec.xwserver.util.json.JSONArray.java

/**
 * Creates a java array from a JSONArray.<br>
 *///from  w  ww  .j a va  2  s  .c o  m
public static Object toArray(JSONArray jsonArray, JsonConfig jsonConfig) {
    Class objectClass = jsonConfig.getRootClass();
    Map classMap = jsonConfig.getClassMap();

    if (jsonArray.size() == 0) {
        return Array.newInstance(objectClass == null ? Object.class : objectClass, 0);
    }

    int[] dimensions = JSONArray.getDimensions(jsonArray);
    Object array = Array.newInstance(objectClass == null ? Object.class : objectClass, dimensions);
    int size = jsonArray.size();
    for (int i = 0; i < size; i++) {
        Object value = jsonArray.get(i);
        if (JSONUtils.isNull(value)) {
            Array.set(array, i, null);
        } else {
            Class type = value.getClass();
            if (JSONArray.class.isAssignableFrom(type)) {
                Array.set(array, i, toArray((JSONArray) value, objectClass, classMap));
            } else if (String.class.isAssignableFrom(type) || Boolean.class.isAssignableFrom(type)
                    || Character.class.isAssignableFrom(type) || JSONFunction.class.isAssignableFrom(type)) {
                if (objectClass != null && !objectClass.isAssignableFrom(type)) {
                    value = JSONUtils.getMorpherRegistry().morph(objectClass, value);
                }
                Array.set(array, i, value);
            } else if (JSONUtils.isNumber(type)) {
                if (objectClass != null && (Byte.class.isAssignableFrom(objectClass)
                        || Byte.TYPE.isAssignableFrom(objectClass))) {
                    Array.set(array, i, Byte.valueOf(String.valueOf(value)));
                } else if (objectClass != null && (Short.class.isAssignableFrom(objectClass)
                        || Short.TYPE.isAssignableFrom(objectClass))) {
                    Array.set(array, i, Short.valueOf(String.valueOf(value)));
                } else {
                    Array.set(array, i, value);
                }
            } else {
                if (objectClass != null) {
                    JsonConfig jsc = jsonConfig.copy();
                    jsc.setRootClass(objectClass);
                    jsc.setClassMap(classMap);
                    Array.set(array, i, JSONObject.toBean((JSONObject) value, jsc));
                } else {
                    Array.set(array, i, JSONObject.toBean((JSONObject) value));
                }
            }
        }
    }
    return array;
}

From source file:org.enerj.apache.commons.beanutils.locale.LocaleConvertUtilsBean.java

/**
 *  Create all {@link LocaleConverter} types for specified locale.
 *
 * @param locale The Locale/* w ww.  j a va2 s .com*/
 * @return The FastHashMap instance contains the all {@link LocaleConverter} types
 *  for the specified locale.
 */
protected FastHashMap create(Locale locale) {

    FastHashMap converter = new FastHashMap();
    converter.setFast(false);

    converter.put(BigDecimal.class, new BigDecimalLocaleConverter(locale, applyLocalized));
    converter.put(BigInteger.class, new BigIntegerLocaleConverter(locale, applyLocalized));

    converter.put(Byte.class, new ByteLocaleConverter(locale, applyLocalized));
    converter.put(Byte.TYPE, new ByteLocaleConverter(locale, applyLocalized));

    converter.put(Double.class, new DoubleLocaleConverter(locale, applyLocalized));
    converter.put(Double.TYPE, new DoubleLocaleConverter(locale, applyLocalized));

    converter.put(Float.class, new FloatLocaleConverter(locale, applyLocalized));
    converter.put(Float.TYPE, new FloatLocaleConverter(locale, applyLocalized));

    converter.put(Integer.class, new IntegerLocaleConverter(locale, applyLocalized));
    converter.put(Integer.TYPE, new IntegerLocaleConverter(locale, applyLocalized));

    converter.put(Long.class, new LongLocaleConverter(locale, applyLocalized));
    converter.put(Long.TYPE, new LongLocaleConverter(locale, applyLocalized));

    converter.put(Short.class, new ShortLocaleConverter(locale, applyLocalized));
    converter.put(Short.TYPE, new ShortLocaleConverter(locale, applyLocalized));

    converter.put(String.class, new StringLocaleConverter(locale, applyLocalized));

    // conversion format patterns of java.sql.* types should correspond to default
    // behaviour of toString and valueOf methods of these classes
    converter.put(java.sql.Date.class, new SqlDateLocaleConverter(locale, "yyyy-MM-dd"));
    converter.put(java.sql.Time.class, new SqlTimeLocaleConverter(locale, "HH:mm:ss"));
    converter.put(java.sql.Timestamp.class, new SqlTimestampLocaleConverter(locale, "yyyy-MM-dd HH:mm:ss.S"));

    converter.setFast(true);

    return converter;
}