From bc1be36331eed12b96b995697fd849aed880a895 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 Dec 2024 17:24:49 +0000 Subject: [PATCH 1/3] Bump org.apache.xmlbeans:xmlbeans from 3.0.1 to 5.3.0 Bumps org.apache.xmlbeans:xmlbeans from 3.0.1 to 5.3.0. --- updated-dependencies: - dependency-name: org.apache.xmlbeans:xmlbeans dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2f6e0e178b..e54c45247d 100644 --- a/pom.xml +++ b/pom.xml @@ -490,7 +490,7 @@ 2.0.17 6.2.5 1.6.3 - 3.0.1 + 5.3.0 2.10.0 1.2 1.9.0 From c51d7d30c3dcc5002aade457bcaeb70445eff5a6 Mon Sep 17 00:00:00 2001 From: Christian Ortlepp Date: Sat, 22 Mar 2025 19:19:38 +0100 Subject: [PATCH 2/3] refactor: remove javaversion check - xmlbeans no longer supports the GENERATE_JAVA_VERSION attribute, i.e. the constant still exists but is not referenced and there is no way to set it with the new API --- .../org/apache/axis2/xmlbeans/CodeGenerationUtility.java | 5 ----- 1 file changed, 5 deletions(-) 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..e63cf041db 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 @@ -201,13 +201,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 From ee840ffa64b8ec00563a74377ed735b93f1a752a Mon Sep 17 00:00:00 2001 From: Christian Ortlepp Date: Sat, 22 Mar 2025 19:19:38 +0100 Subject: [PATCH 3/3] refactor: code cleanup, introduce generics --- .../axis2/xmlbeans/CodeGenerationUtility.java | 107 +++++++++--------- 1 file changed, 51 insertions(+), 56 deletions(-) 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 e63cf041db..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); @@ -241,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( @@ -350,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) { @@ -392,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; @@ -413,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; @@ -492,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); + } } /** @@ -499,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(); @@ -513,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? @@ -538,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); @@ -576,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); } @@ -598,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); @@ -674,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)) { @@ -710,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(); @@ -726,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 */ @@ -752,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)) { @@ -763,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); }