hughesj 2003/07/01 03:16:42
Modified: java/src/org/apache/wsif/base WSIFDefaultMessage.java
Log:
Performance improvement for clone(). If the part is an objectified simple type
then make a copy rather than serialize to an objectstream.
Also, don't construct an iterator for part names if there are no parts.
Removed unused WSIFConstants import
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.13 +99 -48 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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- WSIFDefaultMessage.java 9 Apr 2003 17:02:42 -0000 1.12
+++ WSIFDefaultMessage.java 1 Jul 2003 10:16:42 -0000 1.13
@@ -68,7 +68,6 @@
import java.util.Map;
import javax.wsdl.Message;
-import org.apache.wsif.WSIFConstants;
import org.apache.wsif.WSIFException;
import org.apache.wsif.WSIFMessage;
import org.apache.wsif.logging.Trc;
@@ -510,64 +509,116 @@
dm.setName(this.name);
dm.setRepresentationStyle(this.style);
dm.setMessageDefinition(this.msgDefinition);
- Iterator it = getPartNames();
- while (it.hasNext()) {
- String pn = (String) it.next();
- Object po = parts.get(pn);
- if (po == null) {
- try {
- dm.setObjectPart(pn, null);
- } catch (Exception e) {
- Trc.exception(e);
- throw new CloneNotSupportedException(
- "Exception thrown whilst cloning part "
- + pn
- + ". Message is "
- + e.getMessage());
+
+ if (parts != null) {
+ // Clone the parts:
+ Iterator it = getPartNames();
+ 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
+ // 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);
+ if (po == null) {
+ try {
+ dm.setObjectPart(pn, null);
+ } catch (Exception e) {
+ Trc.exception(e);
+ throw new CloneNotSupportedException(
+ "Exception thrown whilst cloning part "
+ + pn
+ + ". Message is "
+ + e.getMessage());
+ }
+ continue;
+ }
+
+ 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());
}
- } else if (po instanceof Cloneable) {
- Class cls = po.getClass();
+
try {
- Method clone = cls.getMethod("clone", null);
- Object poc = clone.invoke(po, null);
- dm.setObjectPart(pn, poc);
- } catch (InvocationTargetException e) {
- Trc.exception(e);
- throw new CloneNotSupportedException(
- "Exception thrown whilst cloning part "
- + pn
- + ". Message is "
- + e.getTargetException().getMessage());
+ if (simpleTypeObj != null) {
+ dm.setObjectPart(pn, simpleTypeObj);
+ continue;
+ }
} catch (Exception e) {
- Trc.exception(e);
+ Trc.exception(e);
throw new CloneNotSupportedException(
"Exception thrown whilst cloning part "
+ pn
+ ". Message is "
+ e.getMessage());
}
- } else if (po instanceof Serializable) {
- try {
- ByteArrayOutputStream b = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream(b);
- out.writeObject(po);
- out.flush();
- out.close();
- byte[] data = b.toByteArray();
- WSIFObjectInputStream in = new WSIFObjectInputStream(new ByteArrayInputStream(data));
- Object poc = in.readObject();
- in.close();
- dm.setObjectPart(pn, poc);
- } catch (Exception e) {
- Trc.exception(e);
+
+ if (po instanceof Cloneable) {
+ Class cls = po.getClass();
+ try {
+ Method clone = cls.getMethod("clone", null);
+ Object poc = clone.invoke(po, null);
+ dm.setObjectPart(pn, poc);
+ } catch (InvocationTargetException e) {
+ Trc.exception(e);
+ throw new CloneNotSupportedException(
+ "Exception thrown whilst cloning part "
+ + pn
+ + ". Message is "
+ + e.getTargetException().getMessage());
+ } catch (Exception e) {
+ Trc.exception(e);
+ throw new CloneNotSupportedException(
+ "Exception thrown whilst cloning part "
+ + pn
+ + ". Message is "
+ + e.getMessage());
+ }
+ continue;
+ }
+ if (po instanceof Serializable) {
+ try {
+ ByteArrayOutputStream b = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(b);
+ out.writeObject(po);
+ out.flush();
+ out.close();
+ byte[] data = b.toByteArray();
+ WSIFObjectInputStream in =
+ new WSIFObjectInputStream(
+ new ByteArrayInputStream(data));
+ Object poc = in.readObject();
+ in.close();
+ dm.setObjectPart(pn, poc);
+ } catch (Exception e) {
+ Trc.exception(e);
+ throw new CloneNotSupportedException(
+ "Exception thrown whilst cloning part "
+ + pn
+ + " by serialization. Message is "
+ + e.getMessage());
+ }
+ } else {
throw new CloneNotSupportedException(
- "Exception thrown whilst cloning part "
- + pn
- + " by serialization. Message is "
- + e.getMessage());
+ "Part " + pn + " cannot be cloned");
}
- } else {
- throw new CloneNotSupportedException("Part " + pn + " cannot be cloned");
+ // Not reached. Don't put code here
}
}
if (Trc.ON)
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.