cortlepp commented on code in PR #980:
URL: 
https://github.com/apache/axis-axis2-java-core/pull/980#discussion_r2278766430


##########
modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java:
##########
@@ -46,39 +48,82 @@ public JSOMElementConvertor() {
     }
 
     public Object toScript(OMElement o) {
-        XmlObject xml;
         try {
-            xml = XmlObject.Factory.parse(o.getXMLStreamReader());
+            XmlObject xml = XmlObject.Factory.parse(o.getXMLStreamReader());
+            
+            Context cx = Context.enter();
+            try {
+                // Enable E4X support
+                cx.setLanguageVersion(Context.VERSION_1_6);
+                Scriptable tempScope = cx.initStandardObjects();
+                
+                // Wrap the XmlObject directly
+                return cx.getWrapFactory().wrap(cx, tempScope, xml, 
XmlObject.class);
+                
+            } finally {
+                Context.exit();
+            }
         } catch (Exception e) {
             throw new RuntimeException("exception getting message XML: " + e);
         }
-
-        Context cx = Context.enter();
-        try {
-
-            Object wrappedXML = cx.getWrapFactory().wrap(cx, scope, xml, 
XmlObject.class);
-            Scriptable jsXML = cx.newObject(scope, "XML", new Object[] { 
wrappedXML });
-
-            return jsXML;
-
-        } finally {
-            Context.exit();
-        }
     }
 
     public OMElement fromScript(Object o) {
-        if (!(o instanceof XMLObject)) {
+        if (!(o instanceof XMLObject) && !(o instanceof Wrapper)) {
             return super.fromScript(o);
         }
 
-        // TODO: E4X Bug? Shouldn't need this copy, but without it the outer 
element gets lost. See Mozilla bugzilla 361722
-        Scriptable jsXML = (Scriptable) 
ScriptableObject.callMethod((Scriptable) o, "copy", new Object[0]);
-        Wrapper wrapper = (Wrapper) 
ScriptableObject.callMethod((XMLObject)jsXML, "getXmlObject", new Object[0]);
-        XmlObject xmlObject = (XmlObject)wrapper.unwrap();
-        OMXMLParserWrapper builder = 
OMXMLBuilderFactory.createOMBuilder(xmlObject.newInputStream());
-        OMElement omElement = builder.getDocumentElement();
-
-        return omElement;
+        try {
+            XmlObject xmlObject = null;
+            
+            // Handle wrapped XmlObject
+            if (o instanceof Wrapper) {
+                Object unwrapped = ((Wrapper) o).unwrap();
+                if (unwrapped instanceof XmlObject) {
+                    xmlObject = (XmlObject) unwrapped;
+                }
+            }
+            
+            // If we have an XMLObject but not a wrapped XmlObject, try the 
old approach
+            if (xmlObject == null && o instanceof XMLObject) {
+                // TODO: E4X Bug? Shouldn't need this copy, but without it the 
outer element gets lost. See Mozilla bugzilla 361722
+                Scriptable jsXML = (Scriptable) 
ScriptableObject.callMethod((Scriptable) o, "copy", new Object[0]);
+                
+                try {
+                    // Try the old API first (getXmlObject)

Review Comment:
   Is the idea behind this that axis would then support both xmlbeans 3 and 5? 
If that is the case, I think we should really think about whether this is 
actually realistically possible & maintainable for us. Maybe @robertlazarski 
can weigh in on this too, but IMO it would be fine to just require the new 
xmlbeans with the next release. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to