You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by "Rich Scheuerle (JIRA)" <ji...@apache.org> on 2007/09/20 15:03:31 UTC
[jira] Resolved: (WSCOMMONS-236) Introduce a CopyUtils class that
makes copies of OM trees
[ https://issues.apache.org/jira/browse/WSCOMMONS-236?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Rich Scheuerle resolved WSCOMMONS-236.
--------------------------------------
Resolution: Fixed
This work has already been completed.
> Introduce a CopyUtils class that makes copies of OM trees
> ---------------------------------------------------------
>
> Key: WSCOMMONS-236
> URL: https://issues.apache.org/jira/browse/WSCOMMONS-236
> Project: WS-Commons
> Issue Type: Improvement
> Components: AXIOM
> Reporter: Rich Scheuerle
> Assignee: Rich Scheuerle
> Attachments: sandesha_patch.txt
>
>
> Problem Summary:
> Some consumers of Axiom need to make copies of the OM tree.
> Providing a CopyUtils utility in Axiom would allow them to delegate this work to Axiom.
> It would also allow the Axiom project to more tightly control this critical function.
> Goals of CopyUtils
> 1) The Source tree should be minimally affected by the copy. For example, copying an OM SOAPEnvelope
> should not cause unnecessary expansion of descendent OMDataSource elements.
> 2) Retain class identity for nodes in the tree. For example, a SOAPFault object in the source tree
> will cause a SOAPFault object to be created in the target tree.
> 3) Handle all of the nuances. For example, SOAPHeaderBlocks have processed flags. The state of these
> flags should be copied to the target tree.
> 4) If Axiom controls the CopyUtils code, then Axiom is in a better position to fix the utility as Axiom is
> improved/upgraded.
> Example Usage:
> An example is the Sandesha project. Here is the code in SandeshaUtils that makes a copy of a tree
> be writing and reparsing the data.
> public static MessageContext cloneMessageContext (MessageContext oldMsg) throws AxisFault {
> MessageContext newMsg = new MessageContext ();
> newMsg.setOptions(new Options (oldMsg.getOptions()));
>
>
> //TODO hd to use following hack since a 'clone' method was not available for SOAPEnvelopes.
> //Do it the correct way when that becomes available.
> OMElement newElement = oldMsg.getEnvelope().cloneOMElement();
> String elementString = newElement.toString();
>
> try {
> ByteArrayInputStream stream = new ByteArrayInputStream(
> elementString.getBytes("UTF8"));
> StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(
> XMLInputFactory.newInstance().createXMLStreamReader(stream),
> null);
> SOAPEnvelope envelope = builder.getSOAPEnvelope();
> newMsg.setEnvelope(envelope);
> } catch (XMLStreamException e) {
> throw AxisFault.makeFault(e);
> } catch (UnsupportedEncodingException e) {
> throw AxisFault.makeFault(e);
> }
>
> newMsg.setConfigurationContext(oldMsg.getConfigurationContext());
> newMsg.setAxisService(oldMsg.getAxisService());
> newMsg.setTransportOut(oldMsg.getTransportOut());
> newMsg.setTransportIn(oldMsg.getTransportIn());
>
> return newMsg;
>
> }
> This code will be changed to:
> /**
> * Clone the MessageContext
> * @param oldMsg
> * @return
> * @throws AxisFault
> */
> public static MessageContext cloneMessageContext (MessageContext oldMsg) throws AxisFault {
> MessageContext newMsg = new MessageContext ();
> newMsg.setOptions(new Options (oldMsg.getOptions()));
>
> // Create a copy of the envelope
> SOAPEnvelope oldEnvelope = oldMsg.getEnvelope();
> if (oldEnvelope != null) {
> SOAPEnvelope newEnvelope = CopyUtils.copy(oldMsg.getEnvelope());
> newMsg.setEnvelope(newEnvelope);
> }
>
> newMsg.setConfigurationContext(oldMsg.getConfigurationContext());
> newMsg.setAxisService(oldMsg.getAxisService());
> newMsg.setTransportOut(oldMsg.getTransportOut());
> newMsg.setTransportIn(oldMsg.getTransportIn());
>
> return newMsg;
>
> }
> Full Disclosure:
> I understand that Axiom provides a clone() method on its interfaces. Currently the implementation of clone() is
> inadequate and/or broken. For example, invoking clone() on a SOAP11BodyImpl will return a OMElement (not a SOAP11BodyImpl).
> Using a separate static utility to control the copying of a tree is an easy and effective way to fix the existing clone()
> inadequacies. If the clone() methods are fixed, then it will be easy to incorporate those changes into the CopyUtils code.
> In addition, an external copy utility allows us to provide more sophisticated copy support (e.g. copyAndFlatten).
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org