/** * Returns a PropertyProxy suitable for the given instance and registers * the selected PropertyProxy for the Class of the instance. Note that * the PropertyProxy is not cloned so either the PropertyProxy should be * used as a template else you must first call clone() on the returned * PropertyProxy and then set the instance as the default on the resulting * clone. * * @param instance the type to search for a suitable PropertyProxy. * @return PropertyProxy suitable for the instance type. */ public static PropertyProxy getProxyAndRegister(Object instance) { if (instance instanceof PropertyProxy) return (PropertyProxy)instance; Class c = instance.getClass(); PropertyProxy proxy = getRegistry().getProxyAndRegister(c); if (proxy == null) { proxy = guessProxy(instance); getRegistry().register(c, proxy); } return proxy; }
/** * Call this on Message broker shutdown ONLY. * Clears the registry and removes the static global registry. */ public static void release() { registry.clear(); preRegister(); // init for restart }
/** * Serialize the provided object to the output stream. * Convert enums to their string representation for Actionscript. */ public void writeObject(Object o) throws IOException { if (o != null && o instanceof Enum && PropertyProxyRegistry.getRegistry().getProxy(o.getClass()) == null) { Enum enumValue = (Enum)o; writeString(enumValue.name()); } else { super.writeObject(o); } }
/** * Returns the static or "application scope" PropertyProxy registry. If * custom sets of PropertyProxies are required in different scopes then * new instances of PropertyProxyRegistry should be manually created, * however these will not be used for serialization. * * @return The global PropertyProxy registry. */ public synchronized static PropertyProxyRegistry getRegistry() { if (registry == null) { registry = new PropertyProxyRegistry(); preRegister(); } return registry; }
private Object getInstantiatedObject(String className, PropertyProxy proxy) { Class<?> desiredClass = null; try { desiredClass = AbstractProxy.getClassFromClassName(className); } catch (MessageException me) { // Type not found but don't mind using ASObject for the missing type. if (me.getCode().startsWith(MessageException.CODE_SERVER_RESOURCE_UNAVAILABLE) && context.createASObjectForMissingType) { ASObject object = (ASObject)ClassUtil.createDefaultInstance(ASObject.class, null, true /*validate*/); object.setType(className); return object; } throw me; // Rethrow. } // Type exists. proxy = PropertyProxyRegistry.getRegistry().getProxyAndRegister(desiredClass); return proxy == null? ClassUtil.createDefaultInstance(desiredClass, null, true /*validate*/) : proxy.createInstance(className); // Validation is performed in the proxy. }
/** * Returns a PropertyProxy suitable for the given instance but does not * register the selected PropertyProxy for the Class of the instance. Note * that the PropertyProxy is not cloned so either the PropertyProxy should * be used as a template else you must first call clone() on the returned * PropertyProxy and then set the instance as the default on the resulting * clone. * * @param instance the type to search for a suitable PropertyProxy. * @return PropertyProxy suitable for the instance type. */ public static PropertyProxy getProxy(Object instance) { if (instance instanceof PropertyProxy) return (PropertyProxy)instance; Class c = instance.getClass(); PropertyProxy proxy = getRegistry().getProxy(c); if (proxy == null) { proxy = guessProxy(instance); } proxy = (PropertyProxy)proxy.clone(); proxy.setDefaultInstance(instance); return proxy; }
/** * Locates a custom PropertyProxy for the given Class. The entire class * hierarchy is searched. Even if a match is found in the class heirarchy * the PropertyProxy is not registered for the given Class. * * @param c the Class used to search the registry. * @return the custom PropertyProxy registered for the Class or * null if a PropertyProxy was not found or if the given Class is null. */ public PropertyProxy getProxy(Class c) { return getProxy(c, true, false); }
pp = PropertyProxyRegistry.getProxyAndRegister(newInst); instance = newInst;
/** * Registers the given {@link SpringPropertyProxy} with the BlazeDS {@link PropertyProxyRegistry}. * @param proxy the property proxy to register */ protected void registerPropertyProxy(SpringPropertyProxy proxy) { PropertyProxyRegistry.getRegistry().register(proxy.getBeanType(), proxy); }
/** * Pre-registers a few common types that are often proxied to * speed up lookups. */ private static void preRegister() { ThrowableProxy proxy = new ThrowableProxy(); registry.register(MessageException.class, proxy); registry.register(LocalizedException.class, proxy); registry.register(Throwable.class, proxy); MapProxy mapProxy = new MapProxy(); registry.register(ASObject.class, mapProxy); registry.register(HashMap.class, mapProxy); registry.register(AbstractMap.class, mapProxy); registry.register(Map.class, mapProxy); }
private void initThreadLocals() { // allocate static thread local objects // If available, invoke the MessageBroker.createThreadLocalObjects() method: Method createThreadLocalObjMethod = ReflectionUtils.findMethod(MessageBroker.class, "createThreadLocalObjects"); if (createThreadLocalObjMethod != null) { ReflectionUtils.invokeMethod(createThreadLocalObjMethod, null); } FlexContext.createThreadLocalObjects(); SerializationContext.createThreadLocalObjects(); TypeMarshallingContext.createThreadLocalObjects(); PropertyProxyRegistry.getRegistry(); }
/** * Call this on Message broker shutdown ONLY. * Clears the registry and removes the static global registry. */ public static void release() { if (registry != null) { registry.clear(); registry = null; } }
PropertyProxyRegistry.release();
private Object getInstantiatedObject(String className, PropertyProxy proxy) { Class<?> desiredClass = null; try { desiredClass = AbstractProxy.getClassFromClassName(className); } catch (MessageException me) { // Type not found but don't mind using ASObject for the missing type. if (me.getCode().startsWith(MessageException.CODE_SERVER_RESOURCE_UNAVAILABLE) && context.createASObjectForMissingType) { ASObject object = (ASObject)ClassUtil.createDefaultInstance(ASObject.class, null, true /*validate*/); object.setType(className); return object; } throw me; // Rethrow. } // Type exists. proxy = PropertyProxyRegistry.getRegistry().getProxyAndRegister(desiredClass); return proxy == null? ClassUtil.createDefaultInstance(desiredClass, null, true /*validate*/) : proxy.createInstance(className); // Validation is performed in the proxy. }
/** * Returns a PropertyProxy suitable for the given instance but does not * register the selected PropertyProxy for the Class of the instance. Note * that the PropertyProxy is not cloned so either the PropertyProxy should * be used as a template else you must first call clone() on the returned * PropertyProxy and then set the instance as the default on the resulting * clone. * * @param instance the type to search for a suitable PropertyProxy. * @return PropertyProxy suitable for the instance type. */ public static PropertyProxy getProxy(Object instance) { if (instance instanceof PropertyProxy) return (PropertyProxy)instance; Class c = instance.getClass(); PropertyProxy proxy = getRegistry().getProxy(c); if (proxy == null) { proxy = guessProxy(instance); } proxy = (PropertyProxy)proxy.clone(); proxy.setDefaultInstance(instance); return proxy; }
/** * Locates a custom PropertyProxy for the given Class. The entire class * hierarchy is searched. If a match is found in the class heirarchy the * PropertyProxy is registered for the given class. * * @param c the Class used to search the registry. * @return the custom PropertyProxy registered for the Class or * null if a PropertyProxy was not found or if the given Class is null. */ public PropertyProxy getProxyAndRegister(Class c) { return getProxy(c, true, true); }
protected Object decodeTypedObject(Object bean, Object encodedObject) PropertyProxy beanProxy = PropertyProxyRegistry.getProxyAndRegister(bean); PropertyProxy encodedProxy = PropertyProxyRegistry.getProxyAndRegister(encodedObject);
/** * Pre-registers a few common types that are often proxied to * speed up lookups. */ private static void preRegister() { ThrowableProxy proxy = new ThrowableProxy(); registry.register(MessageException.class, proxy); registry.register(LocalizedException.class, proxy); registry.register(Throwable.class, proxy); MapProxy mapProxy = new MapProxy(); registry.register(ASObject.class, mapProxy); registry.register(HashMap.class, mapProxy); registry.register(AbstractMap.class, mapProxy); registry.register(Map.class, mapProxy); }