List of usage examples for java.lang Byte TYPE
Class TYPE
To view the source code for java.lang Byte TYPE.
Click Source Link
From source file:org.apache.myfaces.ov2021.application.ApplicationImpl.java
@SuppressWarnings("unchecked") private Converter internalCreateConverter(final Class<?> targetClass) { // Locate a Converter registered for the target class itself. Object converterClassOrClassName = _converterTargetClassToConverterClassMap.get(targetClass); // Locate a Converter registered for interfaces that are // implemented by the target class (directly or indirectly). // Skip if class is String, for performance reasons // (save 3 additional lookups over a concurrent map per request). if (converterClassOrClassName == null && !String.class.equals(targetClass)) { final Class<?> interfaces[] = targetClass.getInterfaces(); if (interfaces != null) { for (int i = 0, len = interfaces.length; i < len; i++) { // search all superinterfaces for a matching converter, // create it final Converter converter = internalCreateConverter(interfaces[i]); if (converter != null) { return converter; }/*w ww . j a va2 s . c o m*/ } } } // Get EnumConverter for enum classes with no special converter, check // here as recursive call with java.lang.Enum will not work if (converterClassOrClassName == null && targetClass.isEnum()) { converterClassOrClassName = _converterTargetClassToConverterClassMap.get(Enum.class); } if (converterClassOrClassName != null) { try { Class<? extends Converter> converterClass = null; if (converterClassOrClassName instanceof Class<?>) { converterClass = (Class<? extends Converter>) converterClassOrClassName; } else if (converterClassOrClassName instanceof String) { converterClass = ClassUtils.simpleClassForName((String) converterClassOrClassName); _converterTargetClassToConverterClassMap.put(targetClass, converterClass); } else { //object stored in the map for this id is an invalid type. remove it and return null _converterTargetClassToConverterClassMap.remove(targetClass); } Converter converter = null; // check cached constructor information if (!_noArgConstructorConverterClasses.contains(converterClass)) { // the converter class either supports the one-arg constructor // or has never been processed before try { // look for a constructor that takes a single Class object // See JSF 1.2 javadoc for Converter Constructor<? extends Converter> constructor = converterClass .getConstructor(new Class[] { Class.class }); converter = constructor.newInstance(new Object[] { targetClass }); } catch (Exception e) { // the constructor does not exist // add the class to the no-arg constructor classes cache _noArgConstructorConverterClasses.add(converterClass); // use no-arg constructor converter = converterClass.newInstance(); } } else { // use no-arg constructor converter = converterClass.newInstance(); } setConverterProperties(converterClass, converter); return converter; } catch (Exception e) { log.log(Level.SEVERE, "Could not instantiate converter " + converterClassOrClassName.toString(), e); throw new FacesException("Could not instantiate converter: " + converterClassOrClassName.toString(), e); } } // locate converter for primitive types if (targetClass == Long.TYPE) { return internalCreateConverter(Long.class); } else if (targetClass == Boolean.TYPE) { return internalCreateConverter(Boolean.class); } else if (targetClass == Double.TYPE) { return internalCreateConverter(Double.class); } else if (targetClass == Byte.TYPE) { return internalCreateConverter(Byte.class); } else if (targetClass == Short.TYPE) { return internalCreateConverter(Short.class); } else if (targetClass == Integer.TYPE) { return internalCreateConverter(Integer.class); } else if (targetClass == Float.TYPE) { return internalCreateConverter(Float.class); } else if (targetClass == Character.TYPE) { return internalCreateConverter(Character.class); } // Locate a Converter registered for the superclass (if any) of the // target class, // recursively working up the inheritance hierarchy. Class<?> superClazz = targetClass.getSuperclass(); return superClazz != null ? internalCreateConverter(superClazz) : null; }
From source file:org.apache.myfaces.application.ApplicationImpl.java
@SuppressWarnings("unchecked") private Converter internalCreateConverter(final Class<?> targetClass) { // Locate a Converter registered for the target class itself. Object converterClassOrClassName = _converterTargetClassToConverterClassMap.get(targetClass); // Locate a Converter registered for interfaces that are // implemented by the target class (directly or indirectly). // Skip if class is String, for performance reasons // (save 3 additional lookups over a concurrent map per request). if (converterClassOrClassName == null && !String.class.equals(targetClass)) { final Class<?> interfaces[] = targetClass.getInterfaces(); if (interfaces != null) { for (int i = 0, len = interfaces.length; i < len; i++) { // search all superinterfaces for a matching converter, // create it final Converter converter = internalCreateConverter(interfaces[i]); if (converter != null) { return converter; }/* w ww. j ava 2s. c om*/ } } } // Get EnumConverter for enum classes with no special converter, check // here as recursive call with java.lang.Enum will not work if (converterClassOrClassName == null && targetClass.isEnum()) { converterClassOrClassName = _converterTargetClassToConverterClassMap.get(Enum.class); } if (converterClassOrClassName != null) { try { Class<? extends Converter> converterClass = null; if (converterClassOrClassName instanceof Class<?>) { converterClass = (Class<? extends Converter>) converterClassOrClassName; } else if (converterClassOrClassName instanceof String) { converterClass = ClassUtils.simpleClassForName((String) converterClassOrClassName); _converterTargetClassToConverterClassMap.put(targetClass, converterClass); } else { //object stored in the map for this id is an invalid type. remove it and return null _converterTargetClassToConverterClassMap.remove(targetClass); } Converter converter = null; // check cached constructor information if (!_noArgConstructorConverterClasses.contains(converterClass)) { // the converter class either supports the one-arg constructor // or has never been processed before try { // look for a constructor that takes a single Class object // See JSF 1.2 javadoc for Converter Constructor<? extends Converter> constructor = converterClass .getConstructor(new Class[] { Class.class }); converter = constructor.newInstance(new Object[] { targetClass }); } catch (Exception e) { // the constructor does not exist // add the class to the no-arg constructor classes cache _noArgConstructorConverterClasses.add(converterClass); // use no-arg constructor converter = createConverterInstance(converterClass); } } else { // use no-arg constructor converter = createConverterInstance(converterClass); } setConverterProperties(converterClass, converter); return converter; } catch (Exception e) { log.log(Level.SEVERE, "Could not instantiate converter " + converterClassOrClassName.toString(), e); throw new FacesException("Could not instantiate converter: " + converterClassOrClassName.toString(), e); } } // locate converter for primitive types if (targetClass == Long.TYPE) { return internalCreateConverter(Long.class); } else if (targetClass == Boolean.TYPE) { return internalCreateConverter(Boolean.class); } else if (targetClass == Double.TYPE) { return internalCreateConverter(Double.class); } else if (targetClass == Byte.TYPE) { return internalCreateConverter(Byte.class); } else if (targetClass == Short.TYPE) { return internalCreateConverter(Short.class); } else if (targetClass == Integer.TYPE) { return internalCreateConverter(Integer.class); } else if (targetClass == Float.TYPE) { return internalCreateConverter(Float.class); } else if (targetClass == Character.TYPE) { return internalCreateConverter(Character.class); } // Locate a Converter registered for the superclass (if any) of the // target class, // recursively working up the inheritance hierarchy. Class<?> superClazz = targetClass.getSuperclass(); return superClazz != null ? internalCreateConverter(superClazz) : null; }
From source file:com.netspective.commons.xdm.XmlDataModelSchema.java
/** * Create a proper implementation of AttributeSetter for the given * attribute type./*from ww w .j ava2 s .c o m*/ */ private AttributeSetter createAttributeSetter(final Method m, final String attrName, final Class arg) { if (java.lang.String[].class.equals(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException { m.invoke(parent, new Object[] { TextUtils.getInstance().split(value, ",", true) }); } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (java.lang.String.class.equals(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException { m.invoke(parent, new String[] { value }); } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (java.lang.Character.class.equals(arg) || java.lang.Character.TYPE.equals(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException { m.invoke(parent, new Character[] { new Character(value.charAt(0)) }); } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (java.lang.Byte.TYPE.equals(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException { m.invoke(parent, new Byte[] { new Byte(value) }); } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (java.lang.Short.TYPE.equals(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException { m.invoke(parent, new Short[] { new Short(value) }); } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (java.lang.Integer.TYPE.equals(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException { m.invoke(parent, new Integer[] { new Integer(value) }); } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (java.lang.Long.TYPE.equals(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException { m.invoke(parent, new Long[] { new Long(value) }); } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (java.lang.Float.TYPE.equals(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException { m.invoke(parent, new Float[] { new Float(value) }); } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (java.lang.Double.TYPE.equals(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException { m.invoke(parent, new Double[] { new Double(value) }); } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } // boolean gets an extra treatment, because we have a nice method else if (java.lang.Boolean.class.equals(arg) || java.lang.Boolean.TYPE.equals(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException { m.invoke(parent, new Boolean[] { new Boolean(TextUtils.getInstance().toBoolean(value)) }); } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } // Class doesn't have a String constructor but a decent factory method else if (java.lang.Class.class.equals(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException, DataModelException { try { m.invoke(parent, new Class[] { Class.forName(value) }); } catch (ClassNotFoundException ce) { if (pc != null) { DataModelException dme = new DataModelException(pc, ce); pc.addError(dme); if (pc.isThrowErrorException()) throw dme; } else log.error(ce); } } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (java.io.File.class.equals(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException { // resolve relative paths through DataModel m.invoke(parent, new File[] { pc != null ? pc.resolveFile(value) : new File(value) }); } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (RedirectValueSource.class.isAssignableFrom(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException { TextUtils textUtils = TextUtils.getInstance(); ValueSource vs = ValueSources.getInstance().getValueSourceOrStatic(value); if (vs == null) { // better to throw an error here since if there are objects which are based on null/non-null // value of the value source, it is easier to debug pc.addError("Unable to find ValueSource '" + value + "' to wrap in RedirectValueSource at " + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber() + ". Valid value sources are: " + textUtils.join(ValueSources.getInstance().getAllValueSourceIdentifiers(), ", ")); } try { RedirectValueSource redirectValueSource = (RedirectValueSource) arg.newInstance(); redirectValueSource.setValueSource(vs); m.invoke(parent, new RedirectValueSource[] { redirectValueSource }); } catch (InstantiationException e) { pc.addError("Unable to create RedirectValueSource for '" + value + "' at " + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber() + ". Valid value sources are: " + textUtils.join(ValueSources.getInstance().getAllValueSourceIdentifiers(), ", ")); } } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (ValueSource.class.equals(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException { TextUtils textUtils = TextUtils.getInstance(); ValueSource vs = ValueSources.getInstance().getValueSourceOrStatic(value); if (vs == null) { // better to throw an error here since if there are objects which are based on null/non-null // value of the value source, it is easier to debug if (pc != null) pc.addError("Unable to create ValueSource for '" + value + "' at " + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber() + ". Valid value sources are: " + textUtils .join(ValueSources.getInstance().getAllValueSourceIdentifiers(), ", ")); else log.error("Unable to create ValueSource for '" + value + ". Valid value sources are: " + textUtils.join(ValueSources.getInstance().getAllValueSourceIdentifiers(), ", ")); } m.invoke(parent, new ValueSource[] { vs }); } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (Command.class.isAssignableFrom(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException, DataModelException { try { m.invoke(parent, new Command[] { Commands.getInstance().getCommand(value) }); } catch (CommandNotFoundException e) { if (pc != null) { pc.addError("Unable to create Command for '" + value + "' at " + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber() + "."); if (pc.isThrowErrorException()) throw new DataModelException(pc, e); } else log.error("Unable to create Command for '" + value + "'", e); } } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (XdmEnumeratedAttribute.class.isAssignableFrom(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException, DataModelException { try { XdmEnumeratedAttribute ea = (XdmEnumeratedAttribute) arg.newInstance(); ea.setValue(pc, parent, attrName, value); m.invoke(parent, new XdmEnumeratedAttribute[] { ea }); } catch (InstantiationException ie) { pc.addError(ie); if (pc.isThrowErrorException()) throw new DataModelException(pc, ie); } } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (XdmBitmaskedFlagsAttribute.class.isAssignableFrom(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException, DataModelException { try { XdmBitmaskedFlagsAttribute bfa; NestedCreator creator = (NestedCreator) nestedCreators.get(attrName); if (creator != null) bfa = (XdmBitmaskedFlagsAttribute) creator.create(parent); else bfa = (XdmBitmaskedFlagsAttribute) arg.newInstance(); bfa.setValue(pc, parent, attrName, value); m.invoke(parent, new XdmBitmaskedFlagsAttribute[] { bfa }); } catch (InstantiationException ie) { pc.addError(ie); if (pc.isThrowErrorException()) throw new DataModelException(pc, ie); } } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (Locale.class.isAssignableFrom(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException, DataModelException { String[] items = TextUtils.getInstance().split(value, ",", true); switch (items.length) { case 1: m.invoke(parent, new Locale[] { new Locale(items[0], "") }); break; case 2: m.invoke(parent, new Locale[] { new Locale(items[1], items[2]) }); break; case 3: m.invoke(parent, new Locale[] { new Locale(items[1], items[2], items[3]) }); break; case 4: if (pc != null) throw new DataModelException(pc, "Too many items in Locale constructor."); else log.error("Too many items in Locale constructor: " + value); } } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (ResourceBundle.class.isAssignableFrom(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException, DataModelException { String[] items = TextUtils.getInstance().split(value, ",", true); switch (items.length) { case 1: m.invoke(parent, new ResourceBundle[] { ResourceBundle.getBundle(items[0]) }); break; case 2: m.invoke(parent, new ResourceBundle[] { ResourceBundle.getBundle(items[0], new Locale(items[1], Locale.US.getCountry())) }); break; case 3: m.invoke(parent, new ResourceBundle[] { ResourceBundle.getBundle(items[0], new Locale(items[1], items[2])) }); break; case 4: m.invoke(parent, new ResourceBundle[] { ResourceBundle.getBundle(items[0], new Locale(items[1], items[2], items[3])) }); default: if (pc != null) throw new DataModelException(pc, "Too many items in ResourceBundle constructor."); else log.error("Too many items in Locale constructor: " + value); } } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else if (Properties.class.isAssignableFrom(arg)) { return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException, DataModelException { // when specifying properties the following are valid // <xxx properties="abc.properties"> <!-- load this property file, throw exception if not found --> // <xxx properties="abc.properties:optional"> <!-- load this property file, no exception if not found --> // <xxx properties="/a/b/abc.properties,/x/y/def.properties"> <!-- load the first property file found, throw exception if none found --> // <xxx properties="/a/b/abc.properties,/x/y/def.properties:optional"> <!-- load the first property file found, no exception if none found --> final TextUtils textUtils = TextUtils.getInstance(); final String[] options = textUtils.split(value, ":", true); final String[] fileNames = textUtils.split(value, ",", true); final Properties properties; switch (options.length) { case 1: properties = PropertiesLoader.loadProperties(fileNames, true, false); m.invoke(parent, new Properties[] { properties }); break; case 2: properties = PropertiesLoader.loadProperties(fileNames, options[1].equals("optional") ? false : true, false); if (properties != null) m.invoke(parent, new Properties[] { properties }); break; default: if (pc != null) throw new DataModelException(pc, "Don't know how to get properties from PropertiesLoader: " + value); else log.error("Don't know how to get properties from PropertiesLoader:" + value); } } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } else { // worst case. look for a public String constructor and use it try { final Constructor c = arg.getConstructor(new Class[] { java.lang.String.class }); return new AttributeSetter() { public void set(XdmParseContext pc, Object parent, String value) throws InvocationTargetException, IllegalAccessException, DataModelException { try { Object attribute = c.newInstance(new String[] { value }); m.invoke(parent, new Object[] { attribute }); } catch (InstantiationException ie) { if (pc != null) { pc.addError(ie); if (pc.isThrowErrorException()) throw new DataModelException(pc, ie); } else log.error(ie); } } public boolean isInherited() { return !m.getDeclaringClass().equals(bean); } public Class getDeclaringClass() { return m.getDeclaringClass(); } }; } catch (NoSuchMethodException nme) { } } return null; }
From source file:org.apache.geode.internal.InternalDataSerializer.java
/** * Writes the type code for a primitive type Class to {@code DataOutput}. *//*w w w . ja va 2 s. c o m*/ public static void writePrimitiveClass(Class c, DataOutput out) throws IOException { if (c == Boolean.TYPE) { out.writeByte(BOOLEAN_TYPE); } else if (c == Character.TYPE) { out.writeByte(CHARACTER_TYPE); } else if (c == Byte.TYPE) { out.writeByte(BYTE_TYPE); } else if (c == Short.TYPE) { out.writeByte(SHORT_TYPE); } else if (c == Integer.TYPE) { out.writeByte(INTEGER_TYPE); } else if (c == Long.TYPE) { out.writeByte(LONG_TYPE); } else if (c == Float.TYPE) { out.writeByte(FLOAT_TYPE); } else if (c == Double.TYPE) { out.writeByte(DOUBLE_TYPE); } else if (c == Void.TYPE) { out.writeByte(VOID_TYPE); } else if (c == null) { out.writeByte(NULL); } else { throw new InternalGemFireError(LocalizedStrings.InternalDataSerializer_UNKNOWN_PRIMITIVE_TYPE_0 .toLocalizedString(c.getName())); } }
From source file:org.apache.geode.internal.InternalDataSerializer.java
public static Class decodePrimitiveClass(byte typeCode) { switch (typeCode) { case BOOLEAN_TYPE: return Boolean.TYPE; case CHARACTER_TYPE: return Character.TYPE; case BYTE_TYPE: return Byte.TYPE; case SHORT_TYPE: return Short.TYPE; case INTEGER_TYPE: return Integer.TYPE; case LONG_TYPE: return Long.TYPE; case FLOAT_TYPE: return Float.TYPE; case DOUBLE_TYPE: return Double.TYPE; case VOID_TYPE: return Void.TYPE; case NULL://from w ww . j a v a 2 s. co m return null; default: throw new InternalGemFireError( LocalizedStrings.InternalDataSerializer_UNEXPECTED_TYPECODE_0.toLocalizedString(typeCode)); } }
From source file:org.apache.geode.internal.InternalDataSerializer.java
public static Object basicReadObject(final DataInput in) throws IOException, ClassNotFoundException { checkIn(in);// w w w . ja v a 2 s .c o m // Read the header byte byte header = in.readByte(); if (logger.isTraceEnabled(LogMarker.SERIALIZER)) { logger.trace(LogMarker.SERIALIZER, "basicReadObject: header={}", header); } switch (header) { case DS_FIXED_ID_BYTE: return DSFIDFactory.create(in.readByte(), in); case DS_FIXED_ID_SHORT: return DSFIDFactory.create(in.readShort(), in); case DS_FIXED_ID_INT: return DSFIDFactory.create(in.readInt(), in); case DS_NO_FIXED_ID: return readDataSerializableFixedID(in); case NULL: return null; case NULL_STRING: case STRING: case HUGE_STRING: case STRING_BYTES: case HUGE_STRING_BYTES: return readString(in, header); case CLASS: return readClass(in); case DATE: return readDate(in); case FILE: return readFile(in); case INET_ADDRESS: return readInetAddress(in); case BOOLEAN: return readBoolean(in); case CHARACTER: return readCharacter(in); case BYTE: return readByte(in); case SHORT: return readShort(in); case INTEGER: return readInteger(in); case LONG: return readLong(in); case FLOAT: return readFloat(in); case DOUBLE: return readDouble(in); case BYTE_ARRAY: return readByteArray(in); case ARRAY_OF_BYTE_ARRAYS: return readArrayOfByteArrays(in); case SHORT_ARRAY: return readShortArray(in); case STRING_ARRAY: return readStringArray(in); case INT_ARRAY: return readIntArray(in); case LONG_ARRAY: return readLongArray(in); case FLOAT_ARRAY: return readFloatArray(in); case DOUBLE_ARRAY: return readDoubleArray(in); case BOOLEAN_ARRAY: return readBooleanArray(in); case CHAR_ARRAY: return readCharArray(in); case OBJECT_ARRAY: return readObjectArray(in); case ARRAY_LIST: return readArrayList(in); case LINKED_LIST: return readLinkedList(in); case HASH_SET: return readHashSet(in); case LINKED_HASH_SET: return readLinkedHashSet(in); case HASH_MAP: return readHashMap(in); case IDENTITY_HASH_MAP: return readIdentityHashMap(in); case HASH_TABLE: return readHashtable(in); case CONCURRENT_HASH_MAP: return readConcurrentHashMap(in); case PROPERTIES: return readProperties(in); case TIME_UNIT: return readTimeUnit(in); case USER_CLASS: return readUserObject(in, in.readByte()); case USER_CLASS_2: return readUserObject(in, in.readShort()); case USER_CLASS_4: return readUserObject(in, in.readInt()); case VECTOR: return readVector(in); case STACK: return readStack(in); case TREE_MAP: return readTreeMap(in); case TREE_SET: return readTreeSet(in); case BOOLEAN_TYPE: return Boolean.TYPE; case CHARACTER_TYPE: return Character.TYPE; case BYTE_TYPE: return Byte.TYPE; case SHORT_TYPE: return Short.TYPE; case INTEGER_TYPE: return Integer.TYPE; case LONG_TYPE: return Long.TYPE; case FLOAT_TYPE: return Float.TYPE; case DOUBLE_TYPE: return Double.TYPE; case VOID_TYPE: return Void.TYPE; case USER_DATA_SERIALIZABLE: return readUserDataSerializable(in, in.readByte()); case USER_DATA_SERIALIZABLE_2: return readUserDataSerializable(in, in.readShort()); case USER_DATA_SERIALIZABLE_4: return readUserDataSerializable(in, in.readInt()); case DATA_SERIALIZABLE: return readDataSerializable(in); case SERIALIZABLE: { final boolean isDebugEnabled_SERIALIZER = logger.isTraceEnabled(LogMarker.SERIALIZER); Object serializableResult; if (in instanceof DSObjectInputStream) { serializableResult = ((DSObjectInputStream) in).readObject(); } else { InputStream stream; if (in instanceof InputStream) { stream = (InputStream) in; } else { stream = new InputStream() { @Override public int read() throws IOException { try { return in.readUnsignedByte(); // fix for bug 47249 } catch (EOFException ignored) { return -1; } } }; } ObjectInput ois = new DSObjectInputStream(stream); if (stream instanceof VersionedDataStream) { Version v = ((VersionedDataStream) stream).getVersion(); if (v != null && v != Version.CURRENT) { ois = new VersionedObjectInput(ois, v); } } serializableResult = ois.readObject(); if (isDebugEnabled_SERIALIZER) { logger.trace(LogMarker.SERIALIZER, "Read Serializable object: {}", serializableResult); } } if (isDebugEnabled_SERIALIZER) { logger.trace(LogMarker.SERIALIZER, "deserialized instanceof {}", serializableResult.getClass()); } return serializableResult; } case PDX: return readPdxSerializable(in); case PDX_ENUM: return readPdxEnum(in); case GEMFIRE_ENUM: return readGemFireEnum(in); case PDX_INLINE_ENUM: return readPdxInlineEnum(in); case BIG_INTEGER: return readBigInteger(in); case BIG_DECIMAL: return readBigDecimal(in); case UUID: return readUUID(in); case TIMESTAMP: return readTimestamp(in); default: String s = "Unknown header byte: " + header; throw new IOException(s); } }
From source file:com.clark.func.Functions.java
/** * <p>//w w w . ja v a 2 s. c om * Checks if one <code>Class</code> can be assigned to a variable of another * <code>Class</code>. * </p> * * <p> * Unlike the {@link Class#isAssignableFrom(java.lang.Class)} method, this * method takes into account widenings of primitive classes and * <code>null</code>s. * </p> * * <p> * Primitive widenings allow an int to be assigned to a long, float or * double. This method returns the correct result for these cases. * </p> * * <p> * <code>Null</code> may be assigned to any reference type. This method will * return <code>true</code> if <code>null</code> is passed in and the * toClass is non-primitive. * </p> * * <p> * Specifically, this method tests whether the type represented by the * specified <code>Class</code> parameter can be converted to the type * represented by this <code>Class</code> object via an identity conversion * widening primitive or widening reference conversion. See * <em><a href="http://java.sun.com/docs/books/jls/">The Java Language Specification</a></em> * , sections 5.1.1, 5.1.2 and 5.1.4 for details. * </p> * * @param cls * the Class to check, may be null * @param toClass * the Class to try to assign into, returns false if null * @param autoboxing * whether to use implicit autoboxing/unboxing between primitives * and wrappers * @return <code>true</code> if assignment possible */ public static boolean isAssignable(Class<?> cls, Class<?> toClass, boolean autoboxing) { if (toClass == null) { return false; } // have to check for null, as isAssignableFrom doesn't if (cls == null) { return !(toClass.isPrimitive()); } // autoboxing: if (autoboxing) { if (cls.isPrimitive() && !toClass.isPrimitive()) { cls = primitiveToWrapper(cls); if (cls == null) { return false; } } if (toClass.isPrimitive() && !cls.isPrimitive()) { cls = wrapperToPrimitive(cls); if (cls == null) { return false; } } } if (cls.equals(toClass)) { return true; } if (cls.isPrimitive()) { if (toClass.isPrimitive() == false) { return false; } if (Integer.TYPE.equals(cls)) { return Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Long.TYPE.equals(cls)) { return Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Boolean.TYPE.equals(cls)) { return false; } if (Double.TYPE.equals(cls)) { return false; } if (Float.TYPE.equals(cls)) { return Double.TYPE.equals(toClass); } if (Character.TYPE.equals(cls)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Short.TYPE.equals(cls)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Byte.TYPE.equals(cls)) { return Short.TYPE.equals(toClass) || Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } // should never get here return false; } return toClass.isAssignableFrom(cls); }