hughesj     2003/07/15 02:39:11

  Modified:    java/src/org/apache/wsif/base WSIFDefaultMessage.java
  Log:
  No need to copy objectified primitive type instances as they are immutable
  PR:
  Obtained from:
  Submitted by: 
  Reviewed by:  
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.14      +19 -17    
xml-axis-wsif/java/src/org/apache/wsif/base/WSIFDefaultMessage.java
  
  Index: WSIFDefaultMessage.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/base/WSIFDefaultMessage.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- WSIFDefaultMessage.java   1 Jul 2003 10:16:42 -0000       1.13
  +++ WSIFDefaultMessage.java   15 Jul 2003 09:39:11 -0000      1.14
  @@ -516,12 +516,14 @@
               while (it.hasNext()) {
                // For each part:
                // 1. if it's null, null out the clone
  -             // 2. if it's an objectified primitive type, copy the object
  +             // 2. if it's an objectified primitive type, use the same object
                // 3. if it's cloneable, create a clone for it
                // 4. if it's serializable, write it to an objectstream, read
                //    it back into a new object for the clone 
                   String pn = (String) it.next();
                   Object po = parts.get(pn);
  +                
  +                // 1. if the part is null use null in the clone
                   if (po == null) {
                       try {
                           dm.setObjectPart(pn, null);
  @@ -536,23 +538,18 @@
                       continue;
                   }
   
  +                // 2. if the part is an objectified primitive type, use the
  +                //    same object ... as these are all immutable.
                   Object simpleTypeObj = null;
  -                if (po instanceof String) {
  -                    simpleTypeObj = new String((String) po);
  -                } else if (po instanceof Integer) {
  -                    simpleTypeObj = new Integer(((Integer) po).intValue());
  -                } else if (po instanceof Float) {
  -                    simpleTypeObj = new Float(((Float) po).floatValue());
  -                } else if (po instanceof Byte) {
  -                    simpleTypeObj = new Byte(((Byte) po).byteValue());
  -                } else if (po instanceof Long) {
  -                    simpleTypeObj = new Long(((Long) po).longValue());
  -                } else if (po instanceof Short) {
  -                    simpleTypeObj = new Short(((Short) po).shortValue());
  -                } else if (po instanceof Double) {
  -                    simpleTypeObj = new Double(((Double) po).doubleValue());
  -                } else if (po instanceof Boolean) {
  -                    simpleTypeObj = new Boolean(((Boolean) po).booleanValue());
  +                if ((po instanceof String)
  +                    || (po instanceof Integer)
  +                    || (po instanceof Float)
  +                    || (po instanceof Byte)
  +                    || (po instanceof Long)
  +                    || (po instanceof Short)
  +                    || (po instanceof Double)
  +                    || (po instanceof Boolean)) {
  +                    simpleTypeObj = po;
                   }
   
                   try {
  @@ -569,6 +566,7 @@
                               + e.getMessage());
                   }
   
  +                // 3. if the part is Cloneable call its clone method
                   if (po instanceof Cloneable) {
                       Class cls = po.getClass();
                       try {
  @@ -592,6 +590,10 @@
                       }
                       continue;
                   }
  +                
  +                // 4. all else has failed so the only way to deep copy the object
  +                //    is to serialize it to an object stream and read it back into
  +                //    another instance
                   if (po instanceof Serializable) {
                       try {
                           ByteArrayOutputStream b = new ByteArrayOutputStream();
  
  
  

Reply via email to