List of usage examples for java.lang Integer TYPE
Class TYPE
To view the source code for java.lang Integer TYPE.
Click Source Link
From source file:android.reflect.ClazzLoader.java
/** * ????//from w ww .j a v a 2s . c om */ public static <O, V> void setFieldValue(O o, Field field, V v) { if (field != null) { try { field.setAccessible(true); if (v == null) { field.set(o, null); } else { Class<?> vType = v.getClass(); if (vType == Integer.TYPE) { field.setInt(o, (Integer) v); } else if (vType == Long.TYPE) { field.setLong(o, (Long) v); } else if (vType == Boolean.TYPE) { field.setBoolean(o, (Boolean) v); } else if (vType == Float.TYPE) { field.setFloat(o, (Float) v); } else if (vType == Short.TYPE) { field.setShort(o, (Short) v); } else if (vType == Byte.TYPE) { field.setByte(o, (Byte) v); } else if (vType == Double.TYPE) { field.setDouble(o, (Double) v); } else if (vType == Character.TYPE) { field.setChar(o, (Character) v); } else { field.set(o, v); } } } catch (Throwable t) { Log.e(TAG, t); } } }
From source file:org.javelin.sws.ext.bind.internal.BuiltInMappings.java
/** * @param patterns//www .j av a 2s. 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:com.phoenixnap.oss.ramlapisync.naming.SchemaHelper.java
/** * Maps primitives and other simple Java types into simple types supported by RAML * /* ww w. j ava 2 s . c o m*/ * @param clazz The Class to map * @return The Simple RAML ParamType which maps to this class or null if one is not found */ public static ParamType mapSimpleType(Class<?> clazz) { Class<?> targetClazz = clazz; if (targetClazz.isArray() && clazz.getComponentType() != null) { targetClazz = clazz.getComponentType(); } if (targetClazz.equals(Long.TYPE) || targetClazz.equals(Long.class) || targetClazz.equals(Integer.TYPE) || targetClazz.equals(Integer.class) || targetClazz.equals(Short.TYPE) || targetClazz.equals(Short.class) || targetClazz.equals(Byte.TYPE) || targetClazz.equals(Byte.class)) { return ParamType.INTEGER; } else if (targetClazz.equals(Float.TYPE) || targetClazz.equals(Float.class) || targetClazz.equals(Double.TYPE) || targetClazz.equals(Double.class) || targetClazz.equals(BigDecimal.class)) { return ParamType.NUMBER; } else if (targetClazz.equals(Boolean.class) || targetClazz.equals(Boolean.TYPE)) { return ParamType.BOOLEAN; } else if (targetClazz.equals(String.class)) { return ParamType.STRING; } return null; // default to string }
From source file:com.examples.with.different.packagename.testcarver.AbstractConverter.java
/** * Change primitve Class types to the associated wrapper class. * @param type The class type to check./* w w w . j a v a 2s .co m*/ * @return The converted type. */ Class primitive(Class type) { if (type == null || !type.isPrimitive()) { return type; } if (type == Integer.TYPE) { return Integer.class; } else if (type == Double.TYPE) { return Double.class; } else if (type == Long.TYPE) { return Long.class; } else if (type == Boolean.TYPE) { return Boolean.class; } else if (type == Float.TYPE) { return Float.class; } else if (type == Short.TYPE) { return Short.class; } else if (type == Byte.TYPE) { return Byte.class; } else if (type == Character.TYPE) { return Character.class; } else { return type; } }
From source file:Classes.java
/** * This method acts equivalently to invoking classLoader.loadClass(className) * but it also supports primitive types and array classes of object types or * primitive types./*from w w w. j a va2s . c o m*/ * * @param className * the qualified name of the class or the name of primitive type or * array in the same format as returned by the * java.lang.Class.getName() method. * @param classLoader * the ClassLoader used to load classes * @return the Class object for the requested className * * @throws ClassNotFoundException * when the <code>classLoader</code> can not find the requested * class */ public static Class loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException { // ClassLoader.loadClass() does not handle primitive types: // // B byte // C char // D double // F float // I int // J long // S short // Z boolean // V void // if (className.length() == 1) { char type = className.charAt(0); if (type == 'B') return Byte.TYPE; if (type == 'C') return Character.TYPE; if (type == 'D') return Double.TYPE; if (type == 'F') return Float.TYPE; if (type == 'I') return Integer.TYPE; if (type == 'J') return Long.TYPE; if (type == 'S') return Short.TYPE; if (type == 'Z') return Boolean.TYPE; if (type == 'V') return Void.TYPE; // else throw... throw new ClassNotFoundException(className); } // Check for a primative type if (isPrimitive(className) == true) return (Class) Classes.PRIMITIVE_NAME_TYPE_MAP.get(className); // Check for the internal vm format: Lclassname; if (className.charAt(0) == 'L' && className.charAt(className.length() - 1) == ';') return classLoader.loadClass(className.substring(1, className.length() - 1)); // first try - be optimistic // this will succeed for all non-array classes and array classes that have // already been resolved // try { return classLoader.loadClass(className); } catch (ClassNotFoundException e) { // if it was non-array class then throw it if (className.charAt(0) != '[') throw e; } // we are now resolving array class for the first time // count opening braces int arrayDimension = 0; while (className.charAt(arrayDimension) == '[') arrayDimension++; // resolve component type - use recursion so that we can resolve primitive // types also Class componentType = loadClass(className.substring(arrayDimension), classLoader); // construct array class return Array.newInstance(componentType, new int[arrayDimension]).getClass(); }
From source file:at.alladin.rmbt.shared.hstoreparser.HstoreParser.java
/** * //w w w. j a v a 2s .c o m * @param f * @param o * @return */ public static Object parseFieldValue(Field f, Object o) { if (o != JSONObject.NULL) { if (f.getType().equals(Integer.class) || f.getType().equals(Integer.TYPE)) { return Integer.parseInt(String.valueOf(o)); } else if (f.getType().equals(String.class)) { return String.valueOf(o); } else if (f.getType().equals(Long.class) || f.getType().equals(Long.TYPE)) { return Long.parseLong(String.valueOf(o)); } else if (f.getType().equals(Boolean.class) || f.getType().equals(Boolean.TYPE)) { return Boolean.parseBoolean(String.valueOf(o)); } else if (f.getType().equals(Float.class) || f.getType().equals(Float.TYPE)) { return Float.parseFloat(String.valueOf(o)); } else if (f.getType().equals(Double.class) || f.getType().equals(Double.TYPE)) { return Double.parseDouble(String.valueOf(o)); } else if (f.getType().equals(Short.class) || f.getType().equals(Short.TYPE)) { return Short.parseShort(String.valueOf(o)); } else { return o; } } return null; }
From source file:com.mawujun.util.AnnotationUtils.java
/** * Helper method for generating a hash code for an array. * * @param componentType the component type of the array * @param o the array// w w w.j a va 2s . c o m * @return a hash code for the specified array */ private static int arrayMemberHash(Class<?> componentType, Object o) { if (componentType.equals(Byte.TYPE)) { return Arrays.hashCode((byte[]) o); } if (componentType.equals(Short.TYPE)) { return Arrays.hashCode((short[]) o); } if (componentType.equals(Integer.TYPE)) { return Arrays.hashCode((int[]) o); } if (componentType.equals(Character.TYPE)) { return Arrays.hashCode((char[]) o); } if (componentType.equals(Long.TYPE)) { return Arrays.hashCode((long[]) o); } if (componentType.equals(Float.TYPE)) { return Arrays.hashCode((float[]) o); } if (componentType.equals(Double.TYPE)) { return Arrays.hashCode((double[]) o); } if (componentType.equals(Boolean.TYPE)) { return Arrays.hashCode((boolean[]) o); } return Arrays.hashCode((Object[]) o); }
From source file:com.sun.faces.renderkit.html_basic.MenuRenderer.java
protected Object handleArrayCase(FacesContext context, UISelectMany uiSelectMany, Class arrayClass, String[] newValues) throws ConverterException { Object result = null;/*from ww w.j a v a2 s . c o m*/ Class elementType = null; Converter converter = null; int i = 0, len = (null != newValues ? newValues.length : 0); elementType = arrayClass.getComponentType(); // Optimization: If the elementType is String, we don't need // conversion. Just return newValues. if (elementType.equals(String.class)) { return newValues; } try { result = Array.newInstance(elementType, len); } catch (Exception e) { throw new ConverterException(e); } // bail out now if we have no new values, returning our // oh-so-useful zero-length array. if (null == newValues) { return result; } // obtain a converter. // attached converter takes priority if (null == (converter = uiSelectMany.getConverter())) { // Otherwise, look for a by-type converter if (null == (converter = Util.getConverterForClass(elementType, context))) { // if that fails, and the attached values are of Object type, // we don't need conversion. if (elementType.equals(Object.class)) { return newValues; } String valueStr = ""; for (i = 0; i < newValues.length; i++) { valueStr = valueStr + " " + newValues[i]; } Object[] params = { valueStr, "null Converter" }; throw new ConverterException(Util.getExceptionMessage(Util.CONVERSION_ERROR_MESSAGE_ID, params)); } } Util.doAssert(null != result); if (elementType.isPrimitive()) { for (i = 0; i < len; i++) { if (elementType.equals(Boolean.TYPE)) { Array.setBoolean(result, i, ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i])).booleanValue()); } else if (elementType.equals(Byte.TYPE)) { Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i])).byteValue()); } else if (elementType.equals(Double.TYPE)) { Array.setDouble(result, i, ((Double) converter.getAsObject(context, uiSelectMany, newValues[i])).doubleValue()); } else if (elementType.equals(Float.TYPE)) { Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i])).floatValue()); } else if (elementType.equals(Integer.TYPE)) { Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i])).intValue()); } else if (elementType.equals(Character.TYPE)) { Array.setChar(result, i, ((Character) converter.getAsObject(context, uiSelectMany, newValues[i])).charValue()); } else if (elementType.equals(Short.TYPE)) { Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i])).shortValue()); } else if (elementType.equals(Long.TYPE)) { Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i])).longValue()); } } } else { for (i = 0; i < len; i++) { if (log.isDebugEnabled()) { Object converted = converter.getAsObject(context, uiSelectMany, newValues[i]); log.debug("String value: " + newValues[i] + " converts to : " + converted.toString()); } Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i])); } } return result; }
From source file:com.nway.spring.jdbc.bean.JavassistBeanProcessor.java
private Object processColumn(ResultSet rs, int index, Class<?> propType, String writer, StringBuilder handler) throws SQLException { if (propType.equals(String.class)) { handler.append("bean.").append(writer).append("(").append("$1.getString(").append(index).append("));"); return rs.getString(index); } else if (propType.equals(Integer.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getInt(").append(index).append("));"); return rs.getInt(index); } else if (propType.equals(Integer.class)) { handler.append("bean.").append(writer).append("(").append("integerValue($1.getInt(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Integer.class); } else if (propType.equals(Long.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getLong(").append(index).append("));"); return rs.getLong(index); } else if (propType.equals(Long.class)) { handler.append("bean.").append(writer).append("(").append("longValue($1.getLong(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Long.class); } else if (propType.equals(java.sql.Date.class)) { handler.append("bean.").append(writer).append("(").append("$1.getDate(").append(index).append("));"); return rs.getDate(index); } else if (propType.equals(java.util.Date.class) || propType.equals(Timestamp.class)) { handler.append("bean.").append(writer).append("(").append("$1.getTimestamp(").append(index) .append("));"); return rs.getTimestamp(index); } else if (propType.equals(Double.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getDouble(").append(index).append("));"); return rs.getDouble(index); } else if (propType.equals(Double.class)) { handler.append("bean.").append(writer).append("(").append("doubleValue($1.getDouble(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Double.class); } else if (propType.equals(Float.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getFloat(").append(index).append("));"); return rs.getFloat(index); } else if (propType.equals(Float.class)) { handler.append("bean.").append(writer).append("(").append("floatValue($1.getFloat(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Float.class); } else if (propType.equals(Time.class)) { handler.append("bean.").append(writer).append("(").append("$1.getTime(").append(index).append("));"); return rs.getTime(index); } else if (propType.equals(Boolean.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getBoolean(").append(index).append("));"); return rs.getBoolean(index); } else if (propType.equals(Boolean.class)) { handler.append("bean.").append(writer).append("(").append("booleanValue($1.getBoolean(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Boolean.class); } else if (propType.equals(byte[].class)) { handler.append("bean.").append(writer).append("(").append("$1.getBytes(").append(index).append("));"); return rs.getBytes(index); } else if (BigDecimal.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getBigDecimal(").append(index) .append("));"); return rs.getBigDecimal(index); } else if (Blob.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getBlob(").append(index).append("));"); return rs.getBlob(index); } else if (Clob.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getClob(").append(index).append("));"); return rs.getClob(index); } else if (propType.equals(Short.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getShort(").append(index).append("));"); return rs.getShort(index); } else if (propType.equals(Short.class)) { handler.append("bean.").append(writer).append("(").append("shortValue($1.getShort(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Short.class); } else if (propType.equals(Byte.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getByte(").append(index).append("));"); return rs.getByte(index); } else if (propType.equals(Byte.class)) { handler.append("bean.").append(writer).append("(").append("byteValue($1.getByte(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Byte.class); } else {/*w ww .ja va2s .c o m*/ handler.append("bean.").append(writer).append("(").append("(").append(propType.getName()).append(")") .append("$1.getObject(").append(index).append("));"); return rs.getObject(index); } }
From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java
/** * ResultSet.getObject() returns an Integer object for an INT column. The * setter method for the property might take an Integer or a primitive int. * This method returns true if the value can be successfully passed into * the setter method. Remember, Method.invoke() handles the unwrapping * of Integer into an int./*from ww w . ja va2s .co m*/ * * @param value The value to be passed into the setter method. * @param type The setter's parameter type (non-null) * @return boolean True if the value is compatible (null => true) */ private boolean isCompatibleType(Object value, Class<?> type) { // Do object check first, then primitives if (value == null || type.isInstance(value)) { return true; } else if (type.equals(Integer.TYPE) && Integer.class.isInstance(value)) { return true; } else if (type.equals(Long.TYPE) && Long.class.isInstance(value)) { return true; } else if (type.equals(Double.TYPE) && Double.class.isInstance(value)) { return true; } else if (type.equals(Float.TYPE) && Float.class.isInstance(value)) { return true; } else if (type.equals(Short.TYPE) && Short.class.isInstance(value)) { return true; } else if (type.equals(Byte.TYPE) && Byte.class.isInstance(value)) { return true; } else if (type.equals(Character.TYPE) && Character.class.isInstance(value)) { return true; } else if (type.equals(Boolean.TYPE) && Boolean.class.isInstance(value)) { return true; } return false; }