http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/PropertyProxy.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/PropertyProxy.java b/core/src/flex/messaging/io/PropertyProxy.java deleted file mode 100644 index 02513f6..0000000 --- a/core/src/flex/messaging/io/PropertyProxy.java +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io; - -import java.util.List; - -/** - * A PropertyProxy allows customized serialization and deserialization of complex objects by - * providing access to each of the steps in the serialization and deserialization process. - * A serializer asks a PropertyProxy for the class name, traits - * and properties during serialization. A deserializer asks a PropertyProxy - * to create a new instance and set property values. - * - * Different PropertyProxy implementations may be written for different - * types of objects such as Map, Dictionary, Enumerable, Throwable, - * and Beans. - */ -public interface PropertyProxy extends Cloneable -{ - /** - * The default instance managed by this PropertyProxy. The - * default instance is used for one-type proxied instances. - * - * @return The proxied instance. - */ - Object getDefaultInstance(); - - /** - * Sets the default instance managed by this PropertyProxy. - * - * @param defaultInstance The default instance. - */ - void setDefaultInstance(Object defaultInstance); - - /** - * Creates a new instance for the given className. ClassName is the - * value of the "alias" for the ActionScript class serialized. - * If the className is invalid an anonymous ASObject is created. If the className is - * prefixed with ">" an ASObject is created with the type set however - * a concrete instance is not instantiated. - * @param className the class to create - * @return an instance of className - */ - Object createInstance(String className); - - /** - * The List of property names as Strings that make up the traits - * of the default instance. These traits determine which properties - * are to be serialized. - * - * @return The set of property names as Strings to be serialized. - */ - List getPropertyNames(); - - /** - * The List of property names as Strings that make up the traits - * of the given instance. These traits determine which properties - * are to be serialized. - * - * @param instance the object to examine - * @return List of property names as Strings to be serialized. - */ - List getPropertyNames(Object instance); - - /** - * Looks up the Class type of the property by name on the default instance. - * @param propertyName The name of the property. - * @return The property type. - */ - Class getType(String propertyName); - - /** - * Looks up the Class type of the property by name on the given instance. - * @param instance The instance that possesses the property. - * @param propertyName The name of the property. - * @return The property type. - */ - Class getType(Object instance, String propertyName); - - /** - * Looks up the value of the property by name from the default - * instance. - * - * @param propertyName The name of the property. - * @return The value of the given property. - */ - Object getValue(String propertyName); - - /** - * Looks up the value of a property by name for the given instance. - * - * @param instance The instance that possesses the requested property. - * @param propertyName The name of the property. - * @return The value of the given property. - */ - Object getValue(Object instance, String propertyName); - - /** - * Updates the value of a propery by name for the default instance. - * - * @param propertyName the property name - * @param value the new value - */ - void setValue(String propertyName, Object value); - - /** - * Updates the value of a property by name for the given instance. - * - * @param instance The instance that possesses the requested property. - * @param propertyName The name of the property to update. - * @param value The updated value for the property. - */ - void setValue(Object instance, String propertyName, Object value); - - /** - * This is called after the deserialization of the instance is complete (i.e. - * after the lastSetValue call. It has the opportunity to return an instance - * to use to replace the instance returned previously in createInstance. - * NOTE however that this approach does not support recursive references back to - * this same object (i.e. if a property of this object refers back to itself). - * @param instance the instance being deserialized (previously returned from a - * createInstance call) - * @return possibly the same instance to use for this object. - */ - Object instanceComplete(Object instance); - - /** - * Allows an alias to be set for the instance type. By default - * the classname of the instance is used. - * - * @param value The class name alias. - */ - void setAlias(String value); - - /** - * The class name alias for the default instance. - * - * @return The class name alias to be used in serializing the type traits. - */ - String getAlias(); - - /** - * The class name alias for the given instance. - * - * @param instance the object to get the alias of. - * @return The class name alias to be used in serializing the type traits. - */ - String getAlias(Object instance); - - /** - * Dynamic is a client-only concept for types that allow for arbitrary - * public properties to be defined at runtime. This setting isn't yet - * relevant for serialization but can still be set in the Object traits. - * - * @param value Whether the client type is expected to be dynamic. This setting - * is currently not used. - */ - void setDynamic(boolean value); - - /** - * The trait setting "dynamic" is a client-only concept for types that - * allow for arbitrary public properties to be defined at runtime. - * The default is false and it is unlikely that it would need to be set. - * - * @return The dynamic client trait setting to be used during serialization of the type. - */ - boolean isDynamic(); - - /** - * Specifies whether the default instance manages its own serialization through the - * Externalizable interface. - * - * @return Whether the default instance implements java.io.Externalizable. - */ - boolean isExternalizable(); - - /** - * Specifies whether the given instance manages its own serialization through the - * Externalizable interface. - * - * @param instance the object to check - * @return Whether the given instance implements java.io.Externalizable. - */ - boolean isExternalizable(Object instance); - - /** - * Specifies whether the given instance manages its own serialization through the - * Externalizable interface. If this property is set to true then the type - * must implement java.io.Externalizable. Setting this property to false allows an - * otherwise Externalizable instance to be considered as a normal type for - * custom serialization. - * - * @param value if set to true the instance must implement java.io.Externalizable, otherwise - * if set to false the proxied type can avoid external serialization - * for an otherwise Externalizable type. - */ - void setExternalizable(boolean value); - - /** - * The context holds settings that govern serialization behavior. - * @return The current serialization context, or a new default instance if undefined. - */ - SerializationContext getSerializationContext(); - - /** - * Sets the context for serialization behavior. - * @param value the new context - */ - void setSerializationContext(SerializationContext value); - - /** - * If set to true, read only properties will be included - * during default serialization. The default is false. - * - * @param value whether read only properties should be included. - */ - void setIncludeReadOnly(boolean value); - - /** - * Determines whether read only properties from the instance should be included - * during default serialization. The default is false. - * - * @return Whether read only properties should be included during default - * serialization. - */ - boolean getIncludeReadOnly(); - - /** - * A serialization descriptor that provides overrides to the - * default behavior for selecting properties for serialization. At - * any given level a list of includes and excludes can be specified. - * Complex child properties can have their own descriptors specified - * in a nested manner. - * - * @return The serialization descriptor for custom serialization. - */ - SerializationDescriptor getDescriptor(); - - /** - * Allows non-default inclusion/exclusion of properties for - * serialization. - * - * @param descriptor The descriptor to customize property selection for serialization. - */ - void setDescriptor(SerializationDescriptor descriptor); - - /** - * Returns a copy of the PropertyProxy so that it can be used as a template without - * modifying/creating global references to instances, descriptors etc. - * - * @return A copy of the PropertyProxy. - */ - Object clone(); - - /** - * This is called right before we are about to serialize the supplied instance. - * You can override this method to serialize an instance which you want to serialize - * instead of the instance encountered in the object graph. If you return an - * instance of a different class, we use the PropertyProxyRegistry to get a new - * proxy for that instance. That proxy is then used during the rest of the serialization. - * Note that the objects returned from this method should be serialized through their - * properties. You cannot return a String, Integer or other primitive type. - * - * @param instance the instance encountered during AMF serialization - * @return the instance you want to serialize in its place - */ - Object getInstanceToSerialize(Object instance); -}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/PropertyProxyRegistry.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/PropertyProxyRegistry.java b/core/src/flex/messaging/io/PropertyProxyRegistry.java deleted file mode 100644 index a925eb3..0000000 --- a/core/src/flex/messaging/io/PropertyProxyRegistry.java +++ /dev/null @@ -1,336 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io; - -import flex.messaging.LocalizedException; -import flex.messaging.MessageException; -import flex.messaging.io.amf.ASObject; - -import javax.sql.RowSet; -import java.util.AbstractMap; -import java.util.Dictionary; -import java.util.HashMap; -import java.util.IdentityHashMap; -import java.util.Map; - -/** - * Allows custom PropertyProxy's to be registered on a Class basis. - * - * Class hierarchies can be optionally searched with the first match winning. - * The search starts by trying an exact Class match, then the immediate - * interfaces are tried in the order that they are declared on the Class and - * finally the process is repeated for the superclass, if one exists. If a - * PropertyProxy is found in the immediate parent hierarchy (either the - * immediate superclass or directly implemented interfaces) then the - * implementing class is registered with the selected PropertyProxy to optimize - * subsequent searches. - */ -public class PropertyProxyRegistry -{ - private final Map<Class, PropertyProxy> classRegistry = new IdentityHashMap<Class, PropertyProxy>(); - - /** - * A global registry that maps a Class type to a PropertyProxy. - */ - private static final PropertyProxyRegistry registry = new PropertyProxyRegistry(); - static - { - preRegister(); - } - - /** - * Constructs an empty PropertyProxy registry. - */ - public PropertyProxyRegistry() - { - // No-op. - } - - /** - * 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 static PropertyProxyRegistry getRegistry() - { - return registry; - } - - /** - * 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 - } - - - /** - * 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); - } - - /** - * 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; - } - - /** - * 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; - } - - /** - * Attempts to select a suitable proxy for the given instance - * based on common type mappings. - * @param instance the object to examine. - * @return a proxy for getting properties. - */ - private static PropertyProxy guessProxy(Object instance) - { - PropertyProxy proxy; - - if (instance instanceof Map) - { - proxy = new MapProxy(); - } - else if (instance instanceof Throwable) - { - proxy = new ThrowableProxy(); - } - else if (instance instanceof PageableRowSet || instance instanceof RowSet) - { - proxy = new PageableRowSetProxy(); - } - else if (instance instanceof Dictionary) - { - proxy = new DictionaryProxy(); - } - else - { - proxy = new BeanProxy(); - } - - 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); - } - - /** - * 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); - } - - /** - * Locates a custom PropertyProxy for the given Class. If the - * searchHierarchy argument is true the search starts by trying an exact - * Class match, then the immediate interfaces are tried in the order that - * they are declared on the Class and finally the process is repeated for - * the superclass, if one exists. - * - * @param c the Class used to search the registry. - * @param searchHierarchy if true the entire class hierarchy is searched. - * @param autoRegister if true a successful match is registerd for top - * level class - * @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, boolean searchHierarchy, boolean autoRegister) - { - if (c == null) - return null; - - // Check for native Array so we can unwrap for Class component type - if (c.isArray()) - c = c.getComponentType(); - - // Locate PropertyProxy by Class reference - PropertyProxy proxy = null; - synchronized(classRegistry) - { - proxy = classRegistry.get(c); - } - - if (proxy == null && searchHierarchy) - { - // Next, try matching PropertyProxy by interface - Class[] interfaces = c.getInterfaces(); - for (int i = 0; i < interfaces.length; i++) - { - Class interfaceClass = interfaces[i]; - synchronized(classRegistry) - { - proxy = classRegistry.get(interfaceClass); - } - if (proxy != null && autoRegister) - { - register(c, proxy); - break; - } - else - { - // Recursively check super interfaces too - proxy = getProxy(interfaceClass, searchHierarchy, autoRegister); - if (proxy != null) - { - break; - } - } - } - } - - if (proxy == null && searchHierarchy) - { - // Finally, recursively search superclass hierarchy - Class superclass = c.getSuperclass(); - if (superclass != null) - { - proxy = getProxy(superclass, searchHierarchy, autoRegister); - if (proxy != null && autoRegister) - { - register(c, proxy); - } - } - } - - return proxy; - } - - /** - * Removes all items from the class registry. - */ - public void clear() - { - synchronized(classRegistry) - { - classRegistry.clear(); - } - } - - /** - * Register a custom PropertyProxy for a Class. - * - * @param c The key for the class registry. - * @param proxy The custom PropertyProxy implementation. - */ - public void register(Class c, PropertyProxy proxy) - { - synchronized(classRegistry) - { - classRegistry.put(c, proxy); - } - } - - /** - * Removes a custom PropertyProxy from the registry. - * - * @param c The Class to be removed from the registry. - */ - public void unregister(Class c) - { - synchronized(classRegistry) - { - classRegistry.remove(c); - } - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/RecoverableSerializationException.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/RecoverableSerializationException.java b/core/src/flex/messaging/io/RecoverableSerializationException.java deleted file mode 100644 index 41fb1f2..0000000 --- a/core/src/flex/messaging/io/RecoverableSerializationException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io; - -/** - * This exception class should be used by the deserializers to indicate - * that a non fatal exception occurred during serialization. - * The exception is such that the message body can still be created - * and the message can be processed in the usual stream. - * The BatchProcessFilter will add an error message to the response - * of any messages which have a recoverable serialization exception. - */ -public class RecoverableSerializationException extends SerializationException -{ - static final long serialVersionUID = 2671402324412964558L; - - public RecoverableSerializationException() - { - super(); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/SerializationContext.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/SerializationContext.java b/core/src/flex/messaging/io/SerializationContext.java deleted file mode 100644 index 9ffe17c..0000000 --- a/core/src/flex/messaging/io/SerializationContext.java +++ /dev/null @@ -1,299 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io; - -import flex.messaging.util.ClassUtil; -import flex.messaging.validators.DeserializationValidator; - -import java.io.Serializable; - -/** - * A simple context to get settings from an endpoint to a deserializer - * or serializer. - */ -public class SerializationContext implements Serializable, Cloneable -{ - static final long serialVersionUID = -3020985035377116475L; - - // Endpoint serialization configuration flags - public boolean legacyXMLDocument; - public boolean legacyXMLNamespaces; - public boolean legacyCollection; - public boolean legacyDictionary; - public boolean legacyMap; - public boolean legacyThrowable; - public boolean legacyBigNumbers; - public boolean legacyExternalizable; - public boolean restoreReferences; - public boolean supportRemoteClass; - public boolean supportDatesByReference; // Typically used by AMF Version 3 requests - - /** - * Determines whether an ASObject is created by default for a type that is - * missing on the server, instead of throwing a server resource not found - * exception. - */ - public boolean createASObjectForMissingType = false; - - /** - * Provides a way to control whether small messages should be sent even - * if the client can support them. If set to false, small messages - * will not be sent. - * - * The default is true. - */ - public boolean enableSmallMessages = true; - - /** - * Determines whether type information will be used to instantiate a new instance. - * If set to false, types will be deserialized as flex.messaging.io.ASObject instances - * with type information retained but not used to create an instance. - * - * Note that types in the flex.* package (and any subpackage) will always be - * instantiated. - * - * The default is true. - */ - public boolean instantiateTypes = true; - public boolean ignorePropertyErrors = true; - public boolean logPropertyErrors = false; - public boolean includeReadOnly = false; - - // How deep level of nest object in the object graph that we support - public int maxObjectNestLevel = 512; - - // How deep level of nest collection objects in the object graph that we support - // Similarly like how many dimensional matrix that we support for serialization. - public int maxCollectionNestLevel = 15; - - public boolean allowXmlDoctypeDeclaration = false; - public boolean allowXmlExternalEntityExpansion = false; - - /** - * In server-to-client serialization, determines whether Java Arrays and Lists - * should be serialized as Flash Vectors, rather than Flash Array, and Flex - * ArrayCollection respectively. - */ - public boolean preferVectors = false; - - private Class deserializer; - private Class serializer; - private DeserializationValidator deserializationValidator; - - /** - * The default constructor. - */ - public SerializationContext() - { - } - - /** - * Returns the deserializer class. - * - * @return The deserializer class. - */ - public Class getDeserializerClass() - { - return deserializer; - } - - /** - * Sets the deserializer class. - * - * @param c The deserializer class. - */ - public void setDeserializerClass(Class c) - { - deserializer = c; - } - - /** - * Returns the serializer class. - * - * @return The serializer class. - */ - public Class getSerializerClass() - { - return serializer; - } - - /** - * Sets the serializer class. - * - * @param c The serializer class. - */ - public void setSerializerClass(Class c) - { - serializer = c; - } - - /** - * 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); - } - MessageDeserializer deserializer = (MessageDeserializer)ClassUtil.createDefaultInstance(deserializerClass, MessageDeserializer.class); - return deserializer; - } - - /** - * 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); - } - MessageSerializer serializer = (MessageSerializer)ClassUtil.createDefaultInstance(serializerClass, MessageSerializer.class); - return serializer; - } - - /** - * Returns the deserialization validator. - * - * @return The deserialization validator. - */ - public DeserializationValidator getDeserializationValidator() - { - return deserializationValidator; - } - - /** - * Sets the deserialization validator. - * - * @param deserializationValidator The deserialization validator. - */ - public void setDeserializationValidator(DeserializationValidator deserializationValidator) - { - this.deserializationValidator = deserializationValidator; - } - - @Override - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - // this should never happen since this class extends object - // but just in case revert to manual clone - SerializationContext context = new SerializationContext(); - context.createASObjectForMissingType = createASObjectForMissingType; - context.legacyXMLDocument = legacyXMLDocument; - context.legacyXMLNamespaces = legacyXMLNamespaces; - context.legacyCollection = legacyCollection; - context.legacyDictionary = legacyDictionary; - context.legacyMap = legacyMap; - context.legacyThrowable = legacyThrowable; - context.legacyBigNumbers = legacyBigNumbers; - context.legacyExternalizable = legacyExternalizable; - context.restoreReferences = restoreReferences; - context.supportRemoteClass = supportRemoteClass; - context.supportDatesByReference = supportDatesByReference; // Typically used by AMF Version 3 requests - context.instantiateTypes = instantiateTypes; - context.ignorePropertyErrors = ignorePropertyErrors; - context.includeReadOnly = includeReadOnly; - context.logPropertyErrors = logPropertyErrors; - context.deserializer = deserializer; - context.serializer = serializer; - context.deserializationValidator = deserializationValidator; - context.maxObjectNestLevel = maxObjectNestLevel; - context.maxCollectionNestLevel = maxCollectionNestLevel; - context.allowXmlDoctypeDeclaration = allowXmlDoctypeDeclaration; - context.allowXmlExternalEntityExpansion = allowXmlExternalEntityExpansion; - context.preferVectors = preferVectors; - return context; - } - - } - - private static ThreadLocal<SerializationContext> contexts = new ThreadLocal<SerializationContext>(); - - /** - * Establishes a SerializationContext for the current thread. - * Users are not expected to call this function. - * @param context The current SerializationContext. - */ - public static void setSerializationContext(SerializationContext context) - { - if (context == null) - contexts.remove(); - else - contexts.set(context); - } - - /** - * @return The current thread's SerializationContext. - */ - public static SerializationContext getSerializationContext() - { - SerializationContext sc = contexts.get(); - if (sc == null) - { - sc = new SerializationContext(); - SerializationContext.setSerializationContext(sc); - } - return sc; - } - /** - * Clears out the thread local state after the request completes. - */ - public static void clearThreadLocalObjects() - { - if (contexts != null) - { - contexts.remove(); - } - } - - /** - * - * Create thread local storage. - */ - public static void createThreadLocalObjects() - { - if (contexts == null) - contexts = new ThreadLocal(); - } - - /** - * - * Destroy thread local storage. - * Call ONLY on shutdown. - */ - public static void releaseThreadLocalObjects() - { - clearThreadLocalObjects(); - - contexts = null; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/SerializationDescriptor.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/SerializationDescriptor.java b/core/src/flex/messaging/io/SerializationDescriptor.java deleted file mode 100644 index c5b4af2..0000000 --- a/core/src/flex/messaging/io/SerializationDescriptor.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io; - -import java.util.HashMap; -import java.util.List; - -/** - * The SerializationProxy uses this descriptor to determine which - * fields and properties should be excluded from an object graph - * on an instance-by-instance basis. By default, all public instance - * variables and properties will be serialized. - * - * If excludes need to be specified for a complex child property, - * the property name is added to this dynamic descriptor and its value - * set to another descriptor with its own set of excludes. - * - * The absence of excludes implies default serialization. The absence of - * a child property implies default serialization. - * - * @see flex.messaging.io.PropertyProxy - */ -public class SerializationDescriptor extends HashMap -{ - static final long serialVersionUID = 1828426777611186569L; - - private List excludes; - - public SerializationDescriptor() - { - super(); - } - - public List getExcludesForInstance(Object instance) - { - return excludes; - } - - /* - * Deprecated in favor of getExcludesForInstance(instance). - */ - public List getExcludes() - { - return excludes; - } - - public void setExcludes(List excludes) - { - this.excludes = excludes; - } - - public String toString() - { - return "[ excludes: " + excludes + "]"; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/SerializationException.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/SerializationException.java b/core/src/flex/messaging/io/SerializationException.java deleted file mode 100644 index bb5ee87..0000000 --- a/core/src/flex/messaging/io/SerializationException.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io; - -import flex.messaging.MessageException; - -/** - * Typically signifies that a fatal exception happened during deserialization or - * serialization. The messaging framework should try to get a meaningful - * message back to the client in a response, however this is not always possible, - * especially for batched AMF messages, so at the very least the error should be - * logged. - * - * A special sub-class RecoverableSerializationException can be thrown for non-fatal - * serialization exceptions. - * - * @see flex.messaging.io.RecoverableSerializationException - */ -public class SerializationException extends MessageException -{ - static final long serialVersionUID = -5723542920189973518L; - - public static final String CLIENT_PACKET_ENCODING = "Client.Packet.Encoding"; - - public SerializationException() - { - setCode(CLIENT_PACKET_ENCODING); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/SerializationProxy.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/SerializationProxy.java b/core/src/flex/messaging/io/SerializationProxy.java deleted file mode 100644 index e525e4b..0000000 --- a/core/src/flex/messaging/io/SerializationProxy.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io; - -import flex.messaging.io.amf.Amf3Input; -import flex.messaging.io.amf.Amf3Output; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; - -/** - * This class is the server side portion of a custom serialization - * mechanism to support partial serialization of Objects. - * - * The client uses the Externalizable interface to guarantee the - * serialization order of the properties. The name of the remote class - * is the first property send as it is needed to construct an object shell - * before deserializing any of the wrapped instance properties so that - * object references are correctly restored. - */ -public class SerializationProxy extends MapProxy implements Externalizable -{ - static final long serialVersionUID = -2544463435731984479L; - - /** - * Default constructor required for deserialization of - * client SerializationProxy instances. A SerializationProxy - * is merely a utility wrapper on the server side which is - * discarded once the externalizable information has been - * read and the wrapped instance constructed. - */ - public SerializationProxy() - { - super(null); - externalizable = false; - } - - public SerializationProxy(Object defaultInstance) - { - super(defaultInstance); - externalizable = false; - } - - public boolean isExternalizable() - { - return false; - } - - public boolean isExternalizable(Object instance) - { - return false; - } - - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException - { - Object saveObjectTable = null; - Object saveTraitsTable = null; - Object saveStringTable = null; - Amf3Input in3 = null; - - if (in instanceof Amf3Input) - in3 = (Amf3Input) in; - - try - { - if (in3 != null) - { - saveObjectTable = in3.saveObjectTable(); - saveTraitsTable = in3.saveTraitsTable(); - saveStringTable = in3.saveStringTable(); - } - - this.defaultInstance = in.readObject(); - } - finally - { - if (in3 != null) - { - in3.restoreObjectTable(saveObjectTable); - in3.restoreTraitsTable(saveTraitsTable); - in3.restoreStringTable(saveStringTable); - } - } - } - - public void writeExternal(ObjectOutput out) throws IOException - { - if (out instanceof Amf3Output) - throw new UnsupportedOperationException("This method should not be used for AMF3 serialization."); - - // this method is used to serialize the proxy during cluster serialization - out.writeObject(this.defaultInstance); - } - - public String toString() - { - return "[Proxy(" + defaultInstance + ") descriptor=" + descriptor + "]"; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/StatusInfoProxy.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/StatusInfoProxy.java b/core/src/flex/messaging/io/StatusInfoProxy.java deleted file mode 100644 index 3d460c6..0000000 --- a/core/src/flex/messaging/io/StatusInfoProxy.java +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io; - -import java.io.ByteArrayOutputStream; -import java.io.PrintWriter; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.ServletException; - -import flex.messaging.MessageException; - -/** - * Serializes a Throwable as a Status Info object. The object is sent - * back to the client as an ActionScript object with the following - * keys: - * <ul> - * <li>code: In 1.0, we always report this as "Server.Processing". To be expanded in a future version.</li> - * <li>description: The error message.</li> - * <li>details: The error stack trace.</li> - * <li>type: The error class name.</li> - * <li>rootcause: If the exception was a ServletException, the rootcause will be included as a nested Status Info object.</li> - * </ul> - */ -public class StatusInfoProxy extends AbstractProxy -{ - static final long serialVersionUID = 8860353096401173320L; - - /** - * Brief description of the error. This is intended to describe the - * problem in a short manner that may be displayed to a human during - * run-time of the client's application. - */ - public static final String DESCRIPTION = "description"; - - /** - * Long description of the error. This may contain a verbose description - * that may be provided to a more intelligent human for diagnosis. - */ - public static final String DETAILS = "details"; - - /** - * The class name of the Throwable instance, if allowed to be - * revealed to the client... - */ - public static final String CLASS = "type"; - - /** - * Hierarchical dot "." string description of the problem. - * <p> - * The top error string shall be on of the following.... - * </p> - * Client - Indicates the error was caused by something the client - * did. Possibly the message was not well formed and/or did not - * contain the proper information. - * <p> - * Server - Indicates the error was caused by something not directly - * related to the contents of the message. Possibly the server could - * not gain a needed resource or communicate with the desire WebService. - * </p> - * <p>VersionMismatch - The received AMF packet was of a version that - * the Server does not recognize. - * </p> - * <p>The server can generate any number of sub errors to be attached to one - * of the 3 above roots. The idea is that these strings provide an - * intuitive description of where the problem happened and what it was. - * Ultimately, finding and fixing the errors fast is the goal. - * </p> - */ - public static final String CODE = "code"; - - public static final String ROOTCAUSE = "rootcause"; - - public static final List propertyNameCache = new ArrayList(); - static - { - propertyNameCache.add(CODE); - propertyNameCache.add(CLASS); - propertyNameCache.add(DESCRIPTION); - propertyNameCache.add(DETAILS); - propertyNameCache.add(ROOTCAUSE); - } - - protected boolean showStacktraces; - - public StatusInfoProxy() - { - super(null); - } - - public StatusInfoProxy(Throwable defaultInstance) - { - super(defaultInstance); - } - - public void setShowStacktraces(boolean value) - { - showStacktraces = value; - } - - public String getAlias(Object instance) - { - // Status Info objects are anonymous - return null; - } - - public List getPropertyNames(Object instance) - { - return propertyNameCache; - } - - public Class getType(Object instance, String propertyName) - { - Class type = null; - - if (CODE.equals(propertyName)) - { - type = String.class; - } - else if (CLASS.equals(propertyName)) - { - type = String.class; - } - else if (DESCRIPTION.equals(propertyName)) - { - type = String.class; - } - else if (DETAILS.equals(propertyName)) - { - type = String.class; - } - else if (ROOTCAUSE.equals(propertyName)) - { - type = Map.class; - } - - return type; - } - - public Object getValue(Object instance, String propertyName) - { - Object value = null; - - if (CODE.equals(propertyName)) - { - value = getCode(instance); - } - else if (CLASS.equals(propertyName)) - { - value = getType(instance); - } - else if (DESCRIPTION.equals(propertyName)) - { - value = getDescription(instance); - } - else if (DETAILS.equals(propertyName)) - { - value = getDetails(instance); - } - else if (ROOTCAUSE.equals(propertyName)) - { - value = getRootCause(instance); - } - - return value; - } - - public void setValue(Object instance, String propertyName, Object value) - { - return; // Throwable is essentially read-only - } - - private String getCode(Object ex) - { - String code = null; - if (ex instanceof MessageException) - { - code = ((MessageException)ex).getCode(); - } - - if (code == null) - { - code = "Server.Processing"; - } - - return code; - } - - private String getType(Object ex) - { - String type = ""; - if (ex != null && showStacktraces) - { - type = ex.getClass().getName(); - } - return type; - } - - private String getDescription(Object ex) - { - String desc = null; - if (ex instanceof Throwable) - { - desc = ((Throwable)ex).getMessage(); - } - - return desc; - } - - private String getDetails(Object ex) - { - StringBuffer details = new StringBuffer(); - if (ex instanceof MessageException) - { - MessageException e = (MessageException)ex; - if (e.getDetails() != null) - details.append(e.getDetails()); - } - - if (showStacktraces && ex instanceof Throwable) - details.append(getTraceback((Throwable)ex)); - - return details.toString(); - } - - private Throwable getRootCauseException(Object ex) - { - if (ex == null) - return null; - - if (ex instanceof ServletException) - { - ex = ((ServletException)ex).getRootCause(); - } - - if (ex instanceof Throwable) - return ((Throwable)ex).getCause(); - else - return null; - } - - private Map getRootCause(Object ex) - { - Throwable t = getRootCauseException(ex); - - if (t != null) - return getExceptionInfo(t); - else - return null; - } - - private Map getExceptionInfo(Throwable t) - { - Map info = new HashMap(); - info.put(CODE, getCode(t)); - info.put(CLASS, getType(t)); - info.put(DESCRIPTION, getDescription(t)); - info.put(DETAILS, getDetails(t)); - info.put(ROOTCAUSE, t); - return info; - } - - private static String getTraceback(Throwable e) - { - String trace = ""; - - if (e != null) - { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - PrintWriter pr = new PrintWriter(outputStream); - pr.println(); - e.printStackTrace(pr); - pr.flush(); - trace = outputStream.toString(); - } - - return trace; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/ThrowableProxy.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/ThrowableProxy.java b/core/src/flex/messaging/io/ThrowableProxy.java deleted file mode 100644 index f5285dc..0000000 --- a/core/src/flex/messaging/io/ThrowableProxy.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io; - -/** - * Throwable instances are treated as a special type of Bean as - * usually properties are read only but need to be serialized. - */ -public class ThrowableProxy extends BeanProxy -{ - static final long serialVersionUID = 6363249716988887262L; - - public ThrowableProxy() - { - super(); - setIncludeReadOnly(true); - } - - public ThrowableProxy(Throwable defaultInstance) - { - super(defaultInstance); - setIncludeReadOnly(true); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/TypeMarshaller.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/TypeMarshaller.java b/core/src/flex/messaging/io/TypeMarshaller.java deleted file mode 100644 index ceb5dfa..0000000 --- a/core/src/flex/messaging/io/TypeMarshaller.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io; - -/** - * A utility to convert between data types, useful for mapping - * loosely typed client classes to more strongly typed server classes. - */ -public interface TypeMarshaller -{ - /** - * Creates an instance of the desired class without populating the type. - * - * @param source The raw <tt>Object</tt> to be converted into an instance of the desired class. - * @param desiredClass The type to which the source needs to be converted. - * @return An instance of the desired class. - */ - Object createInstance(Object source, Class desiredClass); - - /** - * Converts the supplied source instance to an instance of the desired <tt>Class</tt>. - * - * @param source The source instance. - * @param desiredClass The type to which the source needs to be converted. - * @return The converted instance of the desired class. - */ - Object convert(Object source, Class desiredClass); - -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/TypeMarshallingContext.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/TypeMarshallingContext.java b/core/src/flex/messaging/io/TypeMarshallingContext.java deleted file mode 100644 index 7a505a0..0000000 --- a/core/src/flex/messaging/io/TypeMarshallingContext.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io; - -import flex.messaging.FlexContext; -import flex.messaging.MessageBroker; -import flex.messaging.io.amf.ASObject; -import flex.messaging.io.amf.translator.ASTranslator; - -import java.util.IdentityHashMap; -import java.util.Map; - -/** - * A simple context to hold type marshalling specific settings. - */ -public class TypeMarshallingContext -{ - private static ThreadLocal<TypeMarshallingContext> contexts = new ThreadLocal<TypeMarshallingContext>(); - private static ThreadLocal<TypeMarshaller> marshallers = new ThreadLocal<TypeMarshaller>(); - private IdentityHashMap knownObjects; - private ClassLoader classLoader; - - /** - * Constructs a default type marshalling context. - */ - public TypeMarshallingContext() - { - } - - /** - * Establishes a TypeMarshallingContext for the current thread. - * Users are not expected to call this function. - * @param context The current TypeMarshallingContext. - */ - public static void setTypeMarshallingContext(TypeMarshallingContext context) - { - if (context == null) - contexts.remove(); - else - contexts.set(context); - } - - /** - * Get current TypeMarshallingContext object - * @return The current thread's TypeMarshallingContext. - */ - public static TypeMarshallingContext getTypeMarshallingContext() - { - TypeMarshallingContext context = contexts.get(); - if (context == null) - { - context = new TypeMarshallingContext(); - TypeMarshallingContext.setTypeMarshallingContext(context); - } - return context; - } - - /** - * Establishes a TypeMarshallingContext for the current thread. - * Users are not expected to call this function. - * - * @param marshaller The current TypeMarshaller. - */ - public static void setTypeMarshaller(TypeMarshaller marshaller) - { - if (marshaller == null) - marshallers.remove(); - else - marshallers.set(marshaller); - } - - /** - * Get current TypeMarshaller. - * @return The current thread's TypeMarshaller. - */ - public static TypeMarshaller getTypeMarshaller() - { - TypeMarshaller marshaller = marshallers.get(); - if (marshaller == null) - { - marshaller = new ASTranslator(); - setTypeMarshaller(marshaller); - } - - return marshaller; - } - - /** - * Returns the custom ClassLoader for this type marshalling session, or - * defaults to the current MessageBroker's ClassLoader if none has been set. - * @return ClassLoader the ClassLoader in use - */ - public ClassLoader getClassLoader() - { - if (classLoader != null) - return classLoader; - - try - { - MessageBroker messageBroker = FlexContext.getMessageBroker(); - return messageBroker != null? messageBroker.getClassLoader() : null; - } - catch (NoClassDefFoundError exception) // Could happen in client mode. - { - return null; - } - } - - /** - * Sets a custom classloader for this type marshalling session that will - * be used to create new instances of strongly typed objects. - * @param loader the ClassLoader to use - */ - public void setClassLoader(ClassLoader loader) - { - classLoader = loader; - } - - /** - * A map of known objects already encountered in this type marshalling - * session. - * @return IdentityHashMap the known objects - */ - public IdentityHashMap getKnownObjects() - { - if (knownObjects == null) - knownObjects = new IdentityHashMap(64); - - return knownObjects; - } - - /** - * Sets the list of the objects already encountered for this type - * marshalling session. - * @param knownObjects the IdentityHashMap object - */ - public void setKnownObjects(IdentityHashMap knownObjects) - { - this.knownObjects = knownObjects; - } - - /** - * Resets the list of known objects. - */ - public void reset() - { - if (knownObjects != null) - knownObjects.clear(); - } - - /** - * A utility method to determine whether an anonymous type specifies - * a strong type name, such as ASObject.getType() or the legacy Flash - * Remoting convention of using a _remoteClass property. - * @param obj the object to check - * @return The name of the strong type, or null if none was specified. - */ - public static String getType(Object obj) - { - String type = null; - - if (obj != null && obj instanceof Map) - { - Map map = (Map)obj; - - //Check for an Object.registerClass Typed ASObject - if (map instanceof ASObject) - { - ASObject aso = (ASObject)map; - type = aso.getType(); - } - - SerializationContext sc = SerializationContext.getSerializationContext(); - - if (type == null && sc.supportRemoteClass) - { - Object registerClass = map.get(MessageIOConstants.REMOTE_CLASS_FIELD); - if (registerClass != null && registerClass instanceof String) - { - type = (String)registerClass; - } - } - } - - return type; - } - - /** - * Clears out the thread local state after the request completes. - */ - public static void clearThreadLocalObjects() - { - if (contexts != null) - { - contexts.remove(); - } - if (marshallers != null) - { - marshallers.remove(); - } - } - - /** - * - * Destroy static thread local storage. - * Call ONLY on shutdown. - */ - public static void releaseThreadLocalObjects() - { - clearThreadLocalObjects(); - - contexts = null; - marshallers = null; - } - - /** - * - * Create static thread local storage. - */ - public static void createThreadLocalObjects() - { - if (contexts == null) - contexts = new ThreadLocal(); - if (marshallers == null) - marshallers = new ThreadLocal(); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/UnknownTypeException.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/UnknownTypeException.java b/core/src/flex/messaging/io/UnknownTypeException.java deleted file mode 100644 index 9788b41..0000000 --- a/core/src/flex/messaging/io/UnknownTypeException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io; - -/** - * - */ -public class UnknownTypeException extends SerializationException -{ - static final long serialVersionUID = 8407391043989798441L; - - public UnknownTypeException() - { - super(); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/ASObject.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/ASObject.java b/core/src/flex/messaging/io/amf/ASObject.java deleted file mode 100644 index 06279e5..0000000 --- a/core/src/flex/messaging/io/amf/ASObject.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -public class ASObject extends HashMap -{ - static final long serialVersionUID = 1613529666682805692L; - private boolean inHashCode = false; - private boolean inToString = false; - - String namedType = null; - - public ASObject() - { - super(); - } - - public ASObject(String name) - { - super(); - namedType = name; - } - - public String getType() - { - return namedType; - } - - public void setType(String type) - { - namedType = type; - } - - public int hashCode() - { - int h = 0; - if (!inHashCode) - { - inHashCode = true; - try - { - Iterator i = entrySet().iterator(); - while (i.hasNext()) - { - h += i.next().hashCode(); - } - } - finally - { - inHashCode = false; - } - } - return h; - } - - public String toString() - { - String className = getClass().getName(); - int dotIndex = className.lastIndexOf('.'); - - StringBuffer buffer = new StringBuffer(); - buffer.append(className.substring(dotIndex + 1)); - buffer.append('(').append(System.identityHashCode(this)).append(')'); - buffer.append('{'); - if (!inToString) - { - inToString = true; - try - { - boolean pairEmitted = false; - - Iterator i = entrySet().iterator(); - while (i.hasNext()) - { - if (pairEmitted) - { - buffer.append(", "); - } - Map.Entry e = (Map.Entry) (i.next()); - buffer.append(e.getKey()).append('=').append(e.getValue()); - pairEmitted = true; - } - } - finally - { - inToString = false; - } - } - else - { - buffer.append("..."); - } - buffer.append('}'); - return buffer.toString(); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/AbstractAmfInput.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/AbstractAmfInput.java b/core/src/flex/messaging/io/amf/AbstractAmfInput.java deleted file mode 100644 index a62a546..0000000 --- a/core/src/flex/messaging/io/amf/AbstractAmfInput.java +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf; - -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; - -import flex.messaging.MessageException; -import flex.messaging.io.AbstractProxy; -import flex.messaging.io.BeanProxy; -import flex.messaging.io.ClassAliasRegistry; -import flex.messaging.io.PropertyProxy; -import flex.messaging.io.PropertyProxyRegistry; -import flex.messaging.io.SerializationContext; -import flex.messaging.io.SerializationException; -import flex.messaging.util.ClassUtil; -import flex.messaging.util.XMLUtil; - -/** - * A deserializer of AMF protocol data. - * - * @see ActionMessageOutput - * - */ -public abstract class AbstractAmfInput extends AmfIO implements ActionMessageInput -{ - /** - * This is the initial capacity that will be used for AMF arrays, vectors, etc. - * that have length greater than 1024. - */ - public static final int INITIAL_COLLECTION_CAPACITY = 1024; - - /** - * This is the default max String length (25MB). - */ - public static final int DEFAULT_MAX_STRING_BYTES = 26214400; - public static final String STRING_MAX_STRING_BYTES = "max-string-bytes"; - - protected BeanProxy beanProxy = new BeanProxy(); - protected DataInputStream in = null; - protected int maxStringBytes = DEFAULT_MAX_STRING_BYTES; - - /** - * Construct a deserializer without connecting it to an input stream. - * @param context serialization parameters. - */ - public AbstractAmfInput(SerializationContext context) - { - super(context); - - readMaxStringBytes(); - } - - /** - * Internal use - * - */ - public void setInputStream(InputStream in) - { - this.in = new DataInputStream(in); - } - - protected Object stringToDocument(String xml) - { - // FIXME: Temporary workaround for bug 194815 - if (xml != null && xml.indexOf('<') == -1) - return xml; - - // Validation performed in XMLUtil#stringToDocument. - return XMLUtil.stringToDocument(xml, !(context.legacyXMLNamespaces), - context.allowXmlDoctypeDeclaration, context.allowXmlExternalEntityExpansion); - } - - /** - * A utility method that is used by subclasses to perform max-string-bytes - * checks. By default, max-string-bytes is limited to 25MB for security - * but this can be changed via JVM option called max-string-bytes. - * - * @param utflen The UTF string length to check. - * @throws <tt>SerializationException</tt> if max-string-bytes has been exceeded. - */ - protected void checkUTFLength(int utflen) - { - if (utflen > maxStringBytes) - { - // Error deserializing the string with length ''{0}'', it exceeds the max-string-bytes limit of ''{1}''. - SerializationException ex = new SerializationException(); - ex.setMessage(10314, new Object[] {utflen, maxStringBytes}); - throw ex; - } - } - - /** - * Internal use. Common logic for creating an object for AMF0 and AMF3. Used from - * Amf0Input.readObjectValue() and Amf3Input.readScriptObject(). - * This method is responsible for resolving class aliases, creating and - * registering a property proxy and instantiating an instance of the desired class. - * The params array is used as a holder for parameter values that are updated or - * created in this method, but are needed by its callers. - * @param params array of values that may be updated by this method. - * [0] - String className - the name or alias of the class to create - * [1] - PropertyProxy proxy - * @return an instance of the appropriate object for deserialization - * - */ - protected Object createObjectInstance(Object[] params) - { - String className = (String)params[0]; - - // Check for any registered class aliases - String aliasedClass = ClassAliasRegistry.getRegistry().getClassName(className); - if (aliasedClass != null) - { - className = aliasedClass; - params[0] = className; //update the params array so that callers get this change - } - - Object object = null; - PropertyProxy proxy = null; - - if (className != null && className.startsWith(">")) // Handle [RemoteClass] (no server alias) - { - object = createDefaultASObject(className); - } - else if (className != null && className.length() > 0 && (context.instantiateTypes || className.startsWith("flex."))) - { - // otherwise attempt to create an instance if we have a className - Class<?> desiredClass = null; - try - { - desiredClass = AbstractProxy.getClassFromClassName(className); - } - catch (MessageException me) - { - // Type not found and don't want to use ASObject for the missing type. - if (!(me.getCode().startsWith(MessageException.CODE_SERVER_RESOURCE_UNAVAILABLE) - && context.createASObjectForMissingType)) - { - throw me; // Rethrow. - } - // if we didn't rethrow the exception, the default ASObject will be created further down. - } - - // Type exists. Create either default instance of desiredClass or an instance from a registered proxy. - if (desiredClass != null) - { - proxy = PropertyProxyRegistry.getRegistry().getProxyAndRegister(desiredClass); - if (proxy == null) - { - object = ClassUtil.createDefaultInstance(desiredClass, null, true /*validate*/); - } - else - { - object = proxy.createInstance(className); // Validation is performed in the proxy. - } - } - } - - // if we still don't have an object, create an ASObject with what we have for className (can be null) - if (object == null) - object = createDefaultASObject(className); - - // if proxy wasn't created, create one based on the new instance. - if (proxy == null) - proxy = PropertyProxyRegistry.getProxyAndRegister(object); - - params[1] = proxy; //update the params array so that callers get the proxy - - return object; - } - - /** - * Internal use. Convenience method for creating an ASObject and assigning it a type - * @param type named type for the ASObject or null - * @return a new instance of ASObject - * - */ - protected ASObject createDefaultASObject(String type) - { - ASObject object = (ASObject) ClassUtil.createDefaultInstance(ASObject.class, null, true /*validate*/); - if (type != null && type.length() > 0) - object.setType(type); - return object; - } - - /** - * - */ - protected void readMaxStringBytes() - { - // See if a JVM option is specified for max-string-bytes. - String maxStringBytes = null; - try - { - maxStringBytes = System.getProperty(STRING_MAX_STRING_BYTES); - } - catch (SecurityException se) - { - // Ignore and use the default. - } - - if (maxStringBytes == null) - return; - - try - { - this.maxStringBytes = Integer.parseInt(maxStringBytes); - } - catch (NumberFormatException ignore) - { - // Ignore and use the default. - } - } - - // - // java.io.ObjectInput IMPLEMENTATIONS - // - - /** {@inheritDoc} */ - public int available() throws IOException - { - return in.available(); - } - - /** {@inheritDoc} */ - public void close() throws IOException - { - in.close(); - } - - /** {@inheritDoc} */ - public int read() throws IOException - { - return in.read(); - } - - /** {@inheritDoc} */ - public int read(byte[] bytes) throws IOException - { - return in.read(bytes); - } - - /** {@inheritDoc} */ - public int read(byte[] bytes, int offset, int length) throws IOException - { - return in.read(bytes, offset, length); - } - - /** {@inheritDoc} */ - public long skip(long n) throws IOException - { - return in.skip(n); - } - - /** {@inheritDoc} */ - public int skipBytes(int n) throws IOException - { - return in.skipBytes(n); - } - - // - // java.io.DataInput IMPLEMENTATIONS - // - - /** {@inheritDoc} */ - public boolean readBoolean() throws IOException - { - return in.readBoolean(); - } - - /** {@inheritDoc} */ - public byte readByte() throws IOException - { - return in.readByte(); - } - - /** {@inheritDoc} */ - public char readChar() throws IOException - { - return in.readChar(); - } - - /** {@inheritDoc} */ - public double readDouble() throws IOException - { - return in.readDouble(); - } - - /** {@inheritDoc} */ - public float readFloat() throws IOException - { - return in.readFloat(); - } - - /** {@inheritDoc} */ - public void readFully(byte[] bytes) throws IOException - { - in.readFully(bytes); - } - - /** {@inheritDoc} */ - public void readFully(byte[] bytes, int offset, int length) throws IOException - { - in.readFully(bytes, offset, length); - } - - /** {@inheritDoc} */ - public int readInt() throws IOException - { - return in.readInt(); - } - - /** - * Reads the next line of text from the input stream. - * @deprecated - */ - public String readLine() throws IOException - { - return in.readLine(); - } - - /** {@inheritDoc} */ - public long readLong() throws IOException - { - return in.readLong(); - } - - /** {@inheritDoc} */ - public short readShort() throws IOException - { - return in.readShort(); - } - - /** {@inheritDoc} */ - public int readUnsignedByte() throws IOException - { - return in.readUnsignedByte(); - } - - /** {@inheritDoc} */ - public int readUnsignedShort() throws IOException - { - return in.readUnsignedShort(); - } - - /** {@inheritDoc} */ - public String readUTF() throws IOException - { - return in.readUTF(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/AbstractAmfOutput.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/AbstractAmfOutput.java b/core/src/flex/messaging/io/amf/AbstractAmfOutput.java deleted file mode 100644 index 0a3fb4f..0000000 --- a/core/src/flex/messaging/io/amf/AbstractAmfOutput.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf; - -import flex.messaging.io.SerializationContext; -import flex.messaging.util.XMLUtil; - -import java.io.DataOutputStream; -import java.io.OutputStream; -import java.io.IOException; - -import org.w3c.dom.Document; - -/** - * An abstract serializer of AMF protocol data. - * - * @see ActionMessageOutput - * - */ -public abstract class AbstractAmfOutput extends AmfIO implements ActionMessageOutput -{ - /** - * - */ - protected DataOutputStream out; - - /** - * Construct a serializer without connecting it to an output stream. - * @param context serialization parameters - */ - public AbstractAmfOutput(SerializationContext context) - { - super(context); - } - - /** - * Sets the output stream that the serializer should use. - * - * @param out DataOutputStream to use - */ - public void setOutputStream(OutputStream out) - { - if (out instanceof DataOutputStream) - { - this.out = (DataOutputStream) out; - } - else - { - this.out = new DataOutputStream(out); - } - reset(); - } - - protected String documentToString(Object value) throws IOException - { - return XMLUtil.documentToString((Document)value); - } - - // - // java.io.ObjectOutput implementations - // - - /** {@inheritDoc} */ - public void close() throws IOException - { - out.close(); - } - - /** {@inheritDoc} */ - public void flush() throws IOException - { - out.flush(); - } - - /** {@inheritDoc} */ - public void write(int b) throws IOException - { - out.write(b); - } - - /** {@inheritDoc} */ - public void write(byte bytes[]) throws IOException - { - out.write(bytes); - } - - /** {@inheritDoc} */ - public void write(byte bytes[], int offset, int length) throws IOException - { - out.write(bytes, offset, length); - } - - - // - // java.io.DataOutput implementations - // - - /** {@inheritDoc} */ - public void writeBoolean(boolean v) throws IOException - { - out.writeBoolean(v); - } - - /** {@inheritDoc} */ - public void writeByte(int v) throws IOException - { - out.writeByte(v); - } - - /** {@inheritDoc} */ - public void writeBytes(String s) throws IOException - { - out.writeBytes(s); - } - - /** {@inheritDoc} */ - public void writeChar(int v) throws IOException - { - out.writeChar(v); - } - - /** {@inheritDoc} */ - public void writeChars(String s) throws IOException - { - out.writeChars(s); - } - - /** {@inheritDoc} */ - public void writeDouble(double v) throws IOException - { - out.writeDouble(v); - } - - /** {@inheritDoc} */ - public void writeFloat(float v) throws IOException - { - out.writeFloat(v); - } - - /** {@inheritDoc} */ - public void writeInt(int v) throws IOException - { - out.writeInt(v); - } - - /** {@inheritDoc} */ - public void writeLong(long v) throws IOException - { - out.writeLong(v); - } - - /** {@inheritDoc} */ - public void writeShort(int v) throws IOException - { - out.writeShort(v); - } - - /** {@inheritDoc} */ - public void writeUTF(String s) throws IOException - { - out.writeUTF(s); - } -}
