[
https://issues.apache.org/jira/browse/WSCOMMONS-236?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12520991
]
Ajith Harshana Ranabahu commented on WSCOMMONS-236:
---------------------------------------------------
Hi Rich/All
This seems to be a timely addition. I have been looking into some corner cases
and discovered that the discard method is not functional at all (see issue
235). In the course of that I also found that we may have issues with the
import node procedure as well since when nodes are imported (say from DOOM to
llom) they are always cast to the base class.
As for this case I feel that if we can override the clone method of each
specialized OM class (say the SOAP classes) it might be a bit cleaner (you can
just call the clone method and be sure you are getting the right node back).
Also there are a few cases that I am not sure of
1. What happens to the builder ? It seems to me the builder is shared (actually
the stream underneath is shared). If this is indeed the case if one tree gets
expanded it will consume the stream and the other tree will be left with the
consumed stream !
> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]