/** * Instantiates a new message serializer. * * @return A new message serializer instance. */ public MessageSerializer newMessageSerializer() { Class serializerClass = getSerializerClass(); if (serializerClass == null) { serializerClass = ClassUtil.createClass("flex.messaging.io.amf.AmfMessageSerializer"); this.setSerializerClass(serializerClass); } return (MessageSerializer) ClassUtil.createDefaultInstance(serializerClass, MessageSerializer.class); }
public static String classLoaderToString(ClassLoader cl) { if (cl == null) return "null"; if (cl == ClassLoader.getSystemClassLoader()) return "system"; StringBuffer sb = new StringBuffer(); sb.append("hashCode: " + System.identityHashCode(cl) + " (parent " + ClassUtil.classLoaderToString(cl.getParent()) + ")"); return sb.toString(); } }
/** {@inheritDoc} */ @Override public void setValue(Object instance, String propertyName, Object value) { if (instance == null || propertyName == null) return; Map props = getBeanProperties(instance); if (props.containsKey(propertyName)) { super.setValue(instance, propertyName, value); } else if (instance instanceof Map) { ClassUtil.validateAssignment(instance, propertyName, value); ((Map)instance).put(propertyName, value); } }
/** * Create a class of the specified type. * Use {@link #createClass(String, ClassLoader)} and explicitly provide the MessageBroker class loader * * @param type fully qualified class name * @return the class instance */ public static Class createClass(String type) { return createClass(type, null); }
/** * Creates the default instance of the class and verifies that it matches * with the expected class type, if one passed in. * * @param cls The class to create. * @param expectedInstance The expected class type. * @return The default instance of the class. */ public static Object createDefaultInstance(Class cls, Class expectedInstance) { return ClassUtil.createDefaultInstance(cls, expectedInstance, false /*validate*/); }
map = (HashMap)ClassUtil.createDefaultInstance(HashMap.class, null, true /*validate*/); array = map; trace.namedElement(name); Object value = readObjectOneLevelDown(true); ClassUtil.validateAssignment(map, name, value); map.put(name, value); ClassUtil.validateCreation(ArrayList.class); int initialCapacity = len < INITIAL_COLLECTION_CAPACITY? len : INITIAL_COLLECTION_CAPACITY; array = new ArrayList(initialCapacity); ClassUtil.validateCreation(Object[].class); array = new Object[len]; trace.arrayElement(i); Object item = readObjectOneLevelDown(true); ClassUtil.validateAssignment(array, i, item); if (array instanceof ArrayList) ((ArrayList)array).add(item); Object item = readObjectOneLevelDown(true); String key = Integer.toString(i); ClassUtil.validateAssignment(map, key, item); map.put(key, item);
protected Object readDictionary() throws IOException, ClassNotFoundException { int ref = readUInt29(); if ((ref & 1) == 0) // This is a reference. return getObjectReference(ref >> 1); readBoolean(); // usingWeakTypes - irrelevant in Java. int len = (ref >> 1); Dictionary dictionary = (Hashtable)ClassUtil.createDefaultInstance(Hashtable.class, null, true /*validate*/); objectTable.add(dictionary); // Remember the object. if (isDebug) trace.startAMFDictionary(objectTable.size() - 1); for (int i = 0; i < len; i++) { if (isDebug) trace.startDictionaryElement(); Object key = readObjectOneLevelDown(true); if (isDebug) trace.addDictionaryEquals(); Object value = readObjectOneLevelDown(true); ClassUtil.validateAssignment(dictionary, key != null? key.toString() : null, value); dictionary.put(key, value); } if (isDebug) trace.endAMFDictionary(); return dictionary; }
validateCreation(cls); if (!hasValidDefaultConstructor(cls)) else if (isAbstract(cls)) variant = "2"; //Abstract types cannot be instantiated. else if (!hasValidDefaultConstructor(cls)) // Class might not have a suitable constructor? variant = "3"; // Types cannot be instantiated without a public, no arguments constructor.
if (useListTemporarily) ClassUtil.validateCreation(ArrayList.class); vector = new ArrayList<Long>(INITIAL_COLLECTION_CAPACITY); ClassUtil.validateCreation(Long[].class); vector = new Long[len]; ClassUtil.validateCreation(ArrayList.class); int initialCapacity = len < INITIAL_COLLECTION_CAPACITY? len : INITIAL_COLLECTION_CAPACITY; vector = new ArrayList<Long>(initialCapacity); trace.arrayElement(i); ClassUtil.validateCreation(Long.class); ClassUtil.validateAssignment(vector, i, item); if (vector instanceof Long[]) Array.set(vector, i, item);
if (!hasValidDefaultConstructor(cls)) else if (isAbstract(cls)) else if (!hasValidDefaultConstructor(cls))
/** * Create a class of the specified type. * Use {@link #createClass(String, ClassLoader)} and explicitly provide the MessageBroker class loader * * @param type fully qualified class name * @return the class instance */ public static Class createClass(String type) { return createClass(type, null); }
/** * Creates the default instance of the class and verifies that it matches * with the expected class type, if one passed in. * * @param cls The class to create. * @param expectedInstance The expected class type. * @return The default instance of the class. */ public static Object createDefaultInstance(Class cls, Class expectedInstance) { return ClassUtil.createDefaultInstance(cls, expectedInstance, false /*validate*/); }
map = (HashMap)ClassUtil.createDefaultInstance(HashMap.class, null, true /*validate*/); array = map; trace.namedElement(name); Object value = readObjectOneLevelDown(true); ClassUtil.validateAssignment(map, name, value); map.put(name, value); ClassUtil.validateCreation(ArrayList.class); int initialCapacity = len < INITIAL_COLLECTION_CAPACITY? len : INITIAL_COLLECTION_CAPACITY; array = new ArrayList(initialCapacity); ClassUtil.validateCreation(Object[].class); array = new Object[len]; trace.arrayElement(i); Object item = readObjectOneLevelDown(true); ClassUtil.validateAssignment(array, i, item); if (array instanceof ArrayList) ((ArrayList)array).add(item); Object item = readObjectOneLevelDown(true); String key = Integer.toString(i); ClassUtil.validateAssignment(map, key, item); map.put(key, item);
protected Object readDictionary() throws IOException, ClassNotFoundException { int ref = readUInt29(); if ((ref & 1) == 0) // This is a reference. return getObjectReference(ref >> 1); readBoolean(); // usingWeakTypes - irrelevant in Java. int len = (ref >> 1); Dictionary dictionary = (Hashtable)ClassUtil.createDefaultInstance(Hashtable.class, null, true /*validate*/); objectTable.add(dictionary); // Remember the object. if (isDebug) trace.startAMFDictionary(objectTable.size() - 1); for (int i = 0; i < len; i++) { if (isDebug) trace.startDictionaryElement(); Object key = readObjectOneLevelDown(true); if (isDebug) trace.addDictionaryEquals(); Object value = readObjectOneLevelDown(true); ClassUtil.validateAssignment(dictionary, key != null? key.toString() : null, value); dictionary.put(key, value); } if (isDebug) trace.endAMFDictionary(); return dictionary; }
validateCreation(cls); if (!hasValidDefaultConstructor(cls)) else if (isAbstract(cls)) variant = "2"; //Abstract types cannot be instantiated. else if (!hasValidDefaultConstructor(cls)) // Class might not have a suitable constructor? variant = "3"; // Types cannot be instantiated without a public, no arguments constructor.
if (useListTemporarily) ClassUtil.validateCreation(ArrayList.class); vector = new ArrayList<Long>(INITIAL_COLLECTION_CAPACITY); ClassUtil.validateCreation(Long[].class); vector = new Long[len]; ClassUtil.validateCreation(ArrayList.class); int initialCapacity = len < INITIAL_COLLECTION_CAPACITY? len : INITIAL_COLLECTION_CAPACITY; vector = new ArrayList<Long>(initialCapacity); trace.arrayElement(i); ClassUtil.validateCreation(Long.class); ClassUtil.validateAssignment(vector, i, item); if (vector instanceof Long[]) Array.set(vector, i, item);
/** * Instantiates a new message deserializer. * * @return A new message deserializer instance. */ public MessageDeserializer newMessageDeserializer() { Class deserializerClass = getDeserializerClass(); if (deserializerClass == null) { deserializerClass = ClassUtil.createClass("flex.messaging.io.amf.AmfMessageDeserializer"); this.setDeserializerClass(deserializerClass); } return (MessageDeserializer) ClassUtil.createDefaultInstance(deserializerClass, MessageDeserializer.class); }
/** * A utility method which returns the Class from the given Class name * using the current type context's class loader. * * @param className the class name. * @return a Class object for the named class. */ public static Class getClassFromClassName(String className) { TypeMarshallingContext typeContext = TypeMarshallingContext.getTypeMarshallingContext(); return ClassUtil.createClass(className, typeContext.getClassLoader()); }
public MessageSerializer newMessageSerializer() { MessageSerializer serializer = (MessageSerializer)ClassUtil.createDefaultInstance(getSerializerClass(), MessageSerializer.class); return serializer; }
if (useListTemporarily) ClassUtil.validateCreation(ArrayList.class); vector = new ArrayList<Double>(INITIAL_COLLECTION_CAPACITY); ClassUtil.validateCreation(Double[].class); vector = new Double[len]; ClassUtil.validateCreation(ArrayList.class); int initialCapacity = len < INITIAL_COLLECTION_CAPACITY? len : INITIAL_COLLECTION_CAPACITY; vector = new ArrayList<Double>(initialCapacity); ClassUtil.validateAssignment(vector, i, item); if (vector instanceof Double[]) Array.set(vector, i, item);