diff --git a/modules/scripting/pom.xml b/modules/scripting/pom.xml
index cdc70e8e76..8d16982c94 100644
--- a/modules/scripting/pom.xml
+++ b/modules/scripting/pom.xml
@@ -50,8 +50,12 @@
${project.version}
- rhino
- js
+ org.mozilla
+ rhino
+
+
+ org.mozilla
+ rhino-xml
org.apache.xmlbeans
diff --git a/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java b/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java
index 15ceabaa53..00277fa641 100644
--- a/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java
+++ b/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java
@@ -21,7 +21,6 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMXMLBuilderFactory;
-import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.xmlbeans.XmlObject;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
@@ -33,18 +32,6 @@
* JSObjectConvertor converts between OMElements and JavaScript E4X XML objects
*/
public class JSOMElementConvertor extends DefaultOMElementConvertor {
-
- protected Scriptable scope;
-
- public JSOMElementConvertor() {
- Context cx = Context.enter();
- try {
- this.scope = cx.initStandardObjects();
- } finally {
- Context.exit();
- }
- }
-
public Object toScript(OMElement o) {
XmlObject xml;
try {
@@ -55,30 +42,65 @@ public Object toScript(OMElement o) {
Context cx = Context.enter();
try {
+ // Enable E4X support
+ cx.setLanguageVersion(Context.VERSION_1_6);
+ Scriptable tempScope = cx.initStandardObjects();
- Object wrappedXML = cx.getWrapFactory().wrap(cx, scope, xml, XmlObject.class);
- Scriptable jsXML = cx.newObject(scope, "XML", new Object[] { wrappedXML });
-
- return jsXML;
-
+ // Wrap the XmlObject directly
+ return cx.getWrapFactory().wrap(cx, tempScope, xml, XmlObject.class);
} 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();
+ try {
+ XmlObject xmlObject = null;
+
+ // Handle wrapped XmlObject
+ if (o instanceof Wrapper) {
+ Object unwrapped = ((Wrapper) o).unwrap();
+ if (unwrapped instanceof XmlObject) {
+ xmlObject = (XmlObject) unwrapped;
+ }
+ }
- return omElement;
- }
+ // 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
+ XMLObject jsXML = (XMLObject) ScriptableObject.callMethod((XMLObject) o, "copy", new Object[0]);
+
+ // get proper XML representation from toXMLString()
+ String xmlString;
+ try {
+ // Try toXMLString() method first
+ xmlString = (String) ScriptableObject.callMethod(jsXML, "toXMLString", new Object[0]);
+ } catch (Exception toXMLException) {
+ // If toXMLString() doesn't work, try toString()
+ xmlString = jsXML.toString();
+ }
+ // Remove extra whitespace to match expected format
+ String normalizedXML = xmlString.replaceAll(">\\s+<", "><").trim();
+ return OMXMLBuilderFactory
+ .createOMBuilder(new java.io.StringReader(normalizedXML))
+ .getDocumentElement();
+ }
+
+ if (xmlObject != null) {
+ return OMXMLBuilderFactory
+ .createOMBuilder(xmlObject.newInputStream())
+ .getDocumentElement();
+ } else {
+ throw new RuntimeException("Unable to extract XmlObject from JavaScript object");
+ }
+
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to convert JavaScript XML to OMElement: " + e.getMessage(), e);
+ }
+ }
}
diff --git a/modules/xmlbeans-codegen/src/main/java/org/apache/axis2/xmlbeans/CodeGenerationUtility.java b/modules/xmlbeans-codegen/src/main/java/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
index a4f53b1d7a..0341dba552 100644
--- a/modules/xmlbeans-codegen/src/main/java/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
+++ b/modules/xmlbeans-codegen/src/main/java/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
@@ -84,7 +84,6 @@
import java.util.Map;
import java.util.Stack;
import java.util.StringTokenizer;
-import java.util.Vector;
import java.util.stream.Stream;
/**
@@ -110,7 +109,7 @@ public class CodeGenerationUtility {
* @param additionalSchemas
* @throws RuntimeException
*/
- public static TypeMapper processSchemas(List schemas,
+ public static TypeMapper processSchemas(List> schemas,
Element[] additionalSchemas,
CodeGenConfiguration cgconfig,
String typeSystemName) throws RuntimeException {
@@ -125,8 +124,8 @@ public static TypeMapper processSchemas(List schemas,
}
SchemaTypeSystem sts;
- List completeSchemaList = new ArrayList();
- List topLevelSchemaList = new ArrayList();
+ List completeSchemaList = new ArrayList<>();
+ List topLevelSchemaList = new ArrayList<>();
//create the type mapper
//First try to take the one that is already there
@@ -139,11 +138,11 @@ public static TypeMapper processSchemas(List schemas,
//xmlbeans specific XMLObject
mapper.setDefaultMappingName(XmlObject.class.getName());
- Map nameSpacesMap = new HashMap();
- List axisServices = cgconfig.getAxisServices();
+ Map nameSpacesMap = new HashMap<>();
+ List axisServices = cgconfig.getAxisServices();
AxisService axisService;
- for (Iterator iter = axisServices.iterator(); iter.hasNext();) {
- axisService = (AxisService)iter.next();
+ for (Iterator iter = axisServices.iterator(); iter.hasNext();) {
+ axisService = iter.next();
nameSpacesMap.putAll(axisService.getNamespaceMap());
}
@@ -167,7 +166,7 @@ public static TypeMapper processSchemas(List schemas,
options.setLoadAdditionalNamespaces(
nameSpacesMap); //add the namespaces
topLevelSchemaList.add(
- XmlObject.Factory.parse(
+ (SchemaDocument) XmlObject.Factory.parse(
getSchemaAsString(schema)
, options));
@@ -179,15 +178,15 @@ public static TypeMapper processSchemas(List schemas,
//make the generated code work efficiently
for (int i = 0; i < additionalSchemas.length; i++) {
completeSchemaList.add(extras.read(additionalSchemas[i]));
- topLevelSchemaList.add(XmlObject.Factory.parse(
+ topLevelSchemaList.add((SchemaDocument) XmlObject.Factory.parse(
additionalSchemas[i]
, null));
}
//compile the type system
Axis2EntityResolver er = new Axis2EntityResolver();
- er.setSchemas((XmlSchema[])completeSchemaList
- .toArray(new XmlSchema[completeSchemaList.size()]));
+ er.setSchemas(completeSchemaList
+ .toArray(new XmlSchema[0]));
er.setBaseUri(cgconfig.getBaseURI());
String xsdConfigFile = (String) cgconfig.getProperties().get(XMLBeansExtension.XSDCONFIG_OPTION_LONG);
@@ -201,13 +200,8 @@ public static TypeMapper processSchemas(List schemas,
BindingConfig bindConf = new Axis2BindingConfig(cgconfig.getUri2PackageNameMap(),
xsdConfigFile, javaFiles, classpath);
- //-Ejavaversion switch to XmlOptions to generate 1.5 compliant code
XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setEntityResolver(er);
- //test if javaversion property in CodeGenConfig
- if(null!=cgconfig.getProperty("javaversion")){
- xmlOptions.put(XmlOptions.GENERATE_JAVA_VERSION,cgconfig.getProperty("javaversion"));
- }
sts = XmlBeans.compileXmlBeans(
// set the STS name; defaults to null, which makes the generated class
@@ -246,11 +240,11 @@ public static TypeMapper processSchemas(List schemas,
if (!cgconfig.isParametersWrapped()) {
//figure out the unwrapped operations
axisServices = cgconfig.getAxisServices();
- for (Iterator servicesIter = axisServices.iterator(); servicesIter.hasNext();) {
- axisService = (AxisService)servicesIter.next();
- for (Iterator operations = axisService.getOperations();
+ for (Iterator servicesIter = axisServices.iterator(); servicesIter.hasNext();) {
+ axisService = servicesIter.next();
+ for (Iterator operations = axisService.getOperations();
operations.hasNext();) {
- AxisOperation op = (AxisOperation)operations.next();
+ AxisOperation op = operations.next();
if (WSDLUtil.isInputPresentForMEP(op.getMessageExchangePattern())) {
AxisMessage message = op.getMessage(
@@ -355,16 +349,16 @@ public static TypeMapper processSchemas(List schemas,
*
* @param sts
*/
- private static List findBase64Types(SchemaTypeSystem sts) {
- List allSeenTypes = new ArrayList();
- List base64ElementQNamesList = new ArrayList();
+ private static List findBase64Types(SchemaTypeSystem sts) {
+ List allSeenTypes = new ArrayList<>();
+ List base64ElementQNamesList = new ArrayList<>();
SchemaType outerType;
//add the document types and global types
allSeenTypes.addAll(Arrays.asList(sts.documentTypes()));
allSeenTypes.addAll(Arrays.asList(sts.globalTypes()));
for (int i = 0; i < allSeenTypes.size(); i++) {
- SchemaType sType = (SchemaType)allSeenTypes.get(i);
+ SchemaType sType = allSeenTypes.get(i);
if (sType.getContentType() == SchemaType.SIMPLE_CONTENT &&
sType.getPrimitiveType() != null) {
@@ -397,17 +391,17 @@ private static List findBase64Types(SchemaTypeSystem sts) {
* @param sts
* @return array list
*/
- private static List findPlainBase64Types(SchemaTypeSystem sts) {
- ArrayList allSeenTypes = new ArrayList();
+ private static List findPlainBase64Types(SchemaTypeSystem sts) {
+ ArrayList allSeenTypes = new ArrayList<>();
allSeenTypes.addAll(Arrays.asList(sts.documentTypes()));
allSeenTypes.addAll(Arrays.asList(sts.globalTypes()));
- ArrayList base64Types = new ArrayList();
+ ArrayList base64Types = new ArrayList<>();
- for (Iterator iterator = allSeenTypes.iterator(); iterator.hasNext();) {
- SchemaType stype = (SchemaType)iterator.next();
- findPlainBase64Types(stype, base64Types, new ArrayList());
+ for (Iterator iterator = allSeenTypes.iterator(); iterator.hasNext();) {
+ SchemaType stype = iterator.next();
+ findPlainBase64Types(stype, base64Types, new ArrayList<>());
}
return base64Types;
@@ -418,8 +412,8 @@ private static List findPlainBase64Types(SchemaTypeSystem sts) {
* @param base64Types
*/
private static void findPlainBase64Types(SchemaType stype,
- ArrayList base64Types,
- ArrayList processedTypes) {
+ ArrayList base64Types,
+ ArrayList processedTypes) {
SchemaProperty[] elementProperties = stype.getElementProperties();
QName name;
@@ -497,6 +491,11 @@ public Writer createSourceFile(String typename)
file.createNewFile();
return new FileWriter(file);
}
+
+ @Override
+ public Writer createSourceFile(String s, String s1) throws IOException {
+ return createSourceFile(s);
+ }
}
/**
@@ -504,7 +503,7 @@ public Writer createSourceFile(String typename)
*
* @param schema
*/
- private static String getSchemaAsString(XmlSchema schema) throws IOException {
+ private static String getSchemaAsString(XmlSchema schema) {
StringWriter writer = new StringWriter();
schema.write(writer);
return writer.toString();
@@ -518,15 +517,15 @@ private static String getSchemaAsString(XmlSchema schema) throws IOException {
*/
private static class Axis2BindingConfig extends BindingConfig {
- private Map uri2packageMappings = null;
+ private Map uri2packageMappings;
private BindingConfig bindConf = null;
- public Axis2BindingConfig(Map uri2packageMappings, String xsdConfigfile, File[] javaFiles,
+ public Axis2BindingConfig(Map uri2packageMappings, String xsdConfigfile, File[] javaFiles,
File[] classpath) {
this.uri2packageMappings = uri2packageMappings;
if (this.uri2packageMappings == null) {
//make an empty one to avoid nasty surprises
- this.uri2packageMappings = new HashMap();
+ this.uri2packageMappings = new HashMap<>();
}
// Do we have an xsdconfig file?
@@ -543,9 +542,9 @@ private BindingConfig buildBindingConfig(String configPath, File[] javaFiles,
SchemaTypeLoader loader = XmlBeans
.typeLoaderForClassLoader(SchemaDocument.class.getClassLoader());
XmlOptions options = new XmlOptions();
- options.put(XmlOptions.LOAD_LINE_NUMBERS);
+ options.setLoadLineNumbers();
// options.setEntityResolver(entResolver); // useless?
- Map MAP_COMPATIBILITY_CONFIG_URIS = new HashMap();
+ Map MAP_COMPATIBILITY_CONFIG_URIS = new HashMap<>();
MAP_COMPATIBILITY_CONFIG_URIS.put("http://www.bea.com/2002/09/xbean/config",
"http://xml.apache.org/xmlbeans/2004/02/xbean/config");
options.setLoadSubstituteNamespaces(MAP_COMPATIBILITY_CONFIG_URIS);
@@ -581,7 +580,7 @@ public String lookupPackageForNamespace(String uri) {
}
if (uri2packageMappings.containsKey(uri)) {
- return (String)uri2packageMappings.get(uri);
+ return uri2packageMappings.get(uri);
} else {
return URLProcessor.makePackageName(uri);
}
@@ -603,14 +602,6 @@ public String lookupSuffixForNamespace(String uri) {
}
}
- public String lookupJavanameForQName(QName qname) {
- if (bindConf != null) {
- return bindConf.lookupJavanameForQName(qname);
- } else {
- return super.lookupJavanameForQName(qname);
- }
- }
-
public String lookupJavanameForQName(QName qname, int kind) {
if (bindConf != null) {
return bindConf.lookupJavanameForQName(qname, kind);
@@ -679,7 +670,7 @@ private static File[] getBindingConfigJavaFiles(String javaFileNames) {
if (javaFileNames == null) {
return new File[0];
}
- List files = new Vector();
+ List files = new ArrayList<>();
for (String javaFileName : javaFileNames.split("\\s")) {
try (Stream pathStream = Files.walk(new File(javaFileName).toPath(),
FileVisitOption.FOLLOW_LINKS)) {
@@ -715,12 +706,12 @@ private static File[] getBindingConfigClasspath(String classpathNames) {
* @param vec
* @return schema array
*/
- private static SchemaDocument.Schema[] convertToSchemaArray(List vec) {
+ private static SchemaDocument.Schema[] convertToSchemaArray(List vec) {
SchemaDocument[] schemaDocuments =
- (SchemaDocument[])vec.toArray(new SchemaDocument[vec.size()]);
+ vec.toArray(new SchemaDocument[0]);
//remove duplicates
- Vector uniqueSchemas = new Vector(schemaDocuments.length);
- Vector uniqueSchemaTns = new Vector(schemaDocuments.length);
+ List uniqueSchemas = new ArrayList<>(schemaDocuments.length);
+ List uniqueSchemaTns = new ArrayList<>(schemaDocuments.length);
SchemaDocument.Schema s;
for (int i = 0; i < schemaDocuments.length; i++) {
s = schemaDocuments[i].getSchema();
@@ -731,9 +722,8 @@ private static SchemaDocument.Schema[] convertToSchemaArray(List vec) {
uniqueSchemas.add(s);
}
}
- return (SchemaDocument.Schema[])
- uniqueSchemas.toArray(
- new SchemaDocument.Schema[uniqueSchemas.size()]);
+ return uniqueSchemas.toArray(
+ new SchemaDocument.Schema[0]);
}
/** Axis2 specific entity resolver */
@@ -757,7 +747,7 @@ public InputSource resolveEntity(String publicId, String systemId)
// to avoid this we check whether it is started with http:// or not
if (!systemId.startsWith("http://")) {
StringTokenizer pathElements = new StringTokenizer(systemId, "/");
- Stack pathElementStack = new Stack();
+ Stack pathElementStack = new Stack<>();
while (pathElements.hasMoreTokens()) {
String pathElement = pathElements.nextToken();
if (".".equals(pathElement)) {
@@ -768,11 +758,11 @@ public InputSource resolveEntity(String publicId, String systemId)
pathElementStack.push(pathElement);
}
}
- StringBuffer pathBuilder = new StringBuffer();
- for (Iterator iter = pathElementStack.iterator(); iter.hasNext();) {
- pathBuilder.append(File.separator + iter.next());
+ StringBuilder pathBuilder = new StringBuilder();
+ for (Iterator iter = pathElementStack.iterator(); iter.hasNext();) {
+ pathBuilder.append(File.separator).append(iter.next());
}
- systemId = pathBuilder.toString().substring(1);
+ systemId = pathBuilder.substring(1);
}
diff --git a/pom.xml b/pom.xml
index b3c6debe7f..a722eb322b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -486,11 +486,11 @@
1.4.2
3.6.4
3.9.11
- 1.6R7
+ 1.8.0
2.0.17
6.2.9
1.6.3
- 3.0.1
+ 5.3.0
2.10.3
1.2
1.10.0
@@ -954,8 +954,13 @@
${intellij.version}
- rhino
- js
+ org.mozilla
+ rhino
+ ${rhino.version}
+
+
+ org.mozilla
+ rhino-xml
${rhino.version}