openamf/src/java/flashgateway/io ASObject.java,1.10,1.11

[email protected] Thu, 05 Feb 2004 18:49:02 -0800
Newsgroups gmane.comp.java.openamf.cvs
Message-ID <[email protected]>
Update of /cvsroot/openamf/openamf/src/java/flashgateway/io
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11448/src/java/flashgateway/io

Modified Files:
	ASObject.java 
Log Message:
added patch from Darin Wilson <[email protected]>

Now there is a config option called amf-serializer/force-lower-case-keys.

By default this is set to true, but can be set to false for ActionScript 2.0

Index: ASObject.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/flashgateway/io/ASObject.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** ASObject.java	19 Aug 2003 23:08:26 -0000	1.10
--- ASObject.java	6 Feb 2004 02:48:59 -0000	1.11
***************
*** 1,7 ****
  /*
   * www.openamf.org
!  *
!  * Distributable under LGPL license.
!  * See terms of license at gnu.org.
   */
  
--- 1,6 ----
  /*
   * www.openamf.org
!  * 
!  * Distributable under LGPL license. See terms of license at gnu.org.
   */
  
***************
*** 9,18 ****
  
  import java.util.HashMap;
! import org.apache.commons.logging.*;
  
  /**
!  * Implementation of MM's flashgateway.io.ASObject so that we can use ASTranslator
!  *
!  * @author Jason Calabrese <[email protected]>
   * @author Sean C. Sullivan
   * 
--- 8,22 ----
  
  import java.util.HashMap;
! 
! import org.apache.commons.logging.Log;
! import org.apache.commons.logging.LogFactory;
! import org.openamf.config.AMFSerializerConfig;
! import org.openamf.config.OpenAMFConfig;
  
  /**
!  * Implementation of MM's flashgateway.io.ASObject so that we can use
!  * ASTranslator
!  * 
!  * @author Jason Calabrese <[email protected]>
   * @author Sean C. Sullivan
   * 
***************
*** 21,164 ****
  public class ASObject extends HashMap {
  
! 	private static final Log log = LogFactory.getLog(ASObject.class);
! 	/**
! 	 * Object type
! 	 */
! 	private String type;
  
! 	public ASObject() {
! 		super();
! 	}
  
! 	/**
! 	 * Creates ASObject with type
! 	 *
! 	 * @param type
! 	 */
! 	public ASObject(String type) {
! 		super();
! 		this.type = type;
! 	}
  
! 	/**
! 	 * Gets object type
! 	 *
! 	 * @return
! 	 * 
! 	 * @see #setType(String)
! 	 * 
! 	 */
! 	public String getType() {
! 		return type;
! 	}
  
! 	/**
! 	 * Sets object type
! 	 *
! 	 * @param type
! 	 * 
! 	 * @see #getType()
! 	 * 
! 	 */
! 	public void setType(String type) {
! 		this.type = type;
! 	}
  
! 	/**
! 	 * Returns <tt>true</tt> if this map contains a mapping for the
! 	 * specified key.<br>
! 	 *
! 	 * @param   key   The key whose presence in this map is to be tested
! 	 * @return <tt>true</tt> if this map contains a mapping for the specified
! 	 * key.
! 	 */
! 	public boolean containsKey(Object key) {
! 		return super.containsKey(toLowerCase(key));
! 	}
  
! 	/**
! 	 * Returns the value to which the specified key is mapped in this identity
! 	 * hash map, or <tt>null</tt> if the map contains no mapping for this key.
! 	 * A return value of <tt>null</tt> does not <i>necessarily</i> indicate
! 	 * that the map contains no mapping for the key; it is also possible that
! 	 * the map explicitly maps the key to <tt>null</tt>. The
! 	 * <tt>containsKey</tt> method may be used to distinguish these two cases.
! 	 *
! 	 * @param   key the key whose associated value is to be returned.
! 	 * @return  the value to which this map maps the specified key, or
! 	 *          <tt>null</tt> if the map contains no mapping for this key.
! 	 * @see #put(Object, Object)
! 	 */
! 	public Object get(Object key) {
! 		return super.get(toLowerCase(key));
! 	}
  
! 	/**
! 	 * Associates the specified value with the specified key in this map.
! 	 * If the map previously contained a mapping for this key, the old
! 	 * value is replaced.
! 	 *
! 	 * @param key key with which the specified value is to be associated.
! 	 * @param value value to be associated with the specified key.
! 	 * @return previous value associated with specified key, or <tt>null</tt>
! 	 *	       if there was no mapping for key.  A <tt>null</tt> return can
! 	 *	       also indicate that the HashMap previously associated
! 	 *	       <tt>null</tt> with the specified key.
! 	 */
! 	public Object put(Object key, Object value) {
! 		return super.put(toLowerCase(key), value);
! 	}
  
! 	/**
! 	 * Removes the mapping for this key from this map if present.
! 	 *
! 	 * @param  key key whose mapping is to be removed from the map.
! 	 * @return previous value associated with specified key, or <tt>null</tt>
! 	 *	       if there was no mapping for key.  A <tt>null</tt> return can
! 	 *	       also indicate that the map previously associated <tt>null</tt>
! 	 *	       with the specified key.
! 	 */
! 	public Object remove(Object key) {
! 		return super.remove(toLowerCase(key));
! 	}
  
! 	/**
! 	 * Gets lower case object if object was instance of String
! 	 *
! 	 * @param key
! 	 * @return
! 	 */
! 	private Object toLowerCase(Object key) {
! 		if (key != null && key instanceof String) {
! 			key = ((String) key).toLowerCase();
! 		}
! 		return key;
! 	}
  
! 	/**
! 	 *
! 	 * @return this method may return null
! 	 * 
! 	 * @see #setType(String)
! 	 * @see #getType()
! 	 * 
! 	 */
! 	public Object instantiate() {
! 		Object ret;
! 		try {
! 			ClassLoader loader = Thread.currentThread().getContextClassLoader();
! 			Class clazz = loader.loadClass(type);
! 			ret = clazz.newInstance();
! 		} catch (Exception e) {
! 			ret = null;
! 		}
! 		return ret;
! 	}
! 	
! 	public String toString()
! 	{
!     if (log.isDebugEnabled()) return "ASObject[type=" + getType() + "," + super.toString() + "]";
!     else return "ASObject[type=" + getType() + "]";
! 	}
  
  }
--- 25,177 ----
  public class ASObject extends HashMap {
  
!     private static final Log log = LogFactory.getLog(ASObject.class);
!     private static final AMFSerializerConfig amfSerializerConfig =
!         OpenAMFConfig.getInstance().getAMFSerializerConfig();
  
!     /**
!      * Object type
!      */
!     private String type;
  
!     public ASObject() {
!         super();
!     }
  
!     /**
!      * Creates ASObject with type
!      * 
!      * @param type
!      */
!     public ASObject(String type) {
!         super();
!         this.type = type;
!     }
  
!     /**
!      * Gets object type
!      * 
!      * @return @see #setType(String)
!      *  
!      */
!     public String getType() {
!         return type;
!     }
  
!     /**
!      * Sets object type
!      * 
!      * @param type
!      * 
!      * @see #getType()
!      *  
!      */
!     public void setType(String type) {
!         this.type = type;
!     }
  
!     /**
!      * Returns <tt>true</tt> if this map contains a mapping for the specified
!      * key. <br>
!      * 
!      * @param key
!      *                The key whose presence in this map is to be tested
!      * @return <tt>true</tt> if this map contains a mapping for the specified
!      *            key.
!      */
!     public boolean containsKey(Object key) {
!         return super.containsKey(toLowerCase(key));
!     }
  
!     /**
!      * Returns the value to which the specified key is mapped in this identity
!      * hash map, or <tt>null</tt> if the map contains no mapping for this
!      * key. A return value of <tt>null</tt> does not <i>necessarily</i>
!      * indicate that the map contains no mapping for the key; it is also
!      * possible that the map explicitly maps the key to <tt>null</tt>. The
!      * <tt>containsKey</tt> method may be used to distinguish these two
!      * cases.
!      * 
!      * @param key
!      *                the key whose associated value is to be returned.
!      * @return the value to which this map maps the specified key, or <tt>null</tt>
!      *            if the map contains no mapping for this key.
!      * @see #put(Object, Object)
!      */
!     public Object get(Object key) {
!         return super.get(toLowerCase(key));
!     }
  
!     /**
!      * Associates the specified value with the specified key in this map. If
!      * the map previously contained a mapping for this key, the old value is
!      * replaced.
!      * 
!      * @param key
!      *                key with which the specified value is to be associated.
!      * @param value
!      *                value to be associated with the specified key.
!      * @return previous value associated with specified key, or <tt>null</tt>
!      *            if there was no mapping for key. A <tt>null</tt> return can
!      *            also indicate that the HashMap previously associated <tt>null</tt>
!      *            with the specified key.
!      */
!     public Object put(Object key, Object value) {
!         return super.put(toLowerCase(key), value);
!     }
  
!     /**
!      * Removes the mapping for this key from this map if present.
!      * 
!      * @param key
!      *                key whose mapping is to be removed from the map.
!      * @return previous value associated with specified key, or <tt>null</tt>
!      *            if there was no mapping for key. A <tt>null</tt> return can
!      *            also indicate that the map previously associated <tt>null</tt>
!      *            with the specified key.
!      */
!     public Object remove(Object key) {
!         return super.remove(toLowerCase(key));
!     }
  
!     /**
!      * Gets lower case object if object was instance of String
!      * 
!      * @param key
!      * @return
!      */
!     private Object toLowerCase(Object key) {
!         if (key != null
!             && key instanceof String
!             && amfSerializerConfig.forceLowerCaseKeys()) {
!             key = ((String) key).toLowerCase();
!         }
!         return key;
!     }
! 
!     /**
!      * @return this method may return null
!      * 
!      * @see #setType(String)
!      * @see #getType()
!      *  
!      */
!     public Object instantiate() {
!         Object ret;
!         try {
!             ClassLoader loader = Thread.currentThread().getContextClassLoader();
!             Class clazz = loader.loadClass(type);
!             ret = clazz.newInstance();
!         } catch (Exception e) {
!             ret = null;
!         }
!         return ret;
!     }
! 
!     public String toString() {
!         if (log.isDebugEnabled())
!             return "ASObject[type=" + getType() + "," + super.toString() + "]";
!         else
!             return "ASObject[type=" + getType() + "]";
!     }
  
  }



-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn