ffang commented on code in PR #3093:
URL: https://github.com/apache/cxf/pull/3093#discussion_r3210400998


##########
tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java:
##########
@@ -851,6 +855,90 @@ public void generate(ToolContext c) throws ToolException {
         }
     }
 
+
+    private void fixXmlTypeNamespacesForSharedPackages(S2JJAXBModel model, 
JCodeModel codeModel) {
+        Map<String, Set<String>> packageToNamespaces = new HashMap<>();
+        for (Map.Entry<String, String> entry : 
context.getNamespacePackageMap().entrySet()) {
+            packageToNamespaces.computeIfAbsent(entry.getValue(), k -> new 
HashSet<>()).add(entry.getKey());
+        }
+
+        Set<String> sharedPackageNamespaces = new HashSet<>();
+        for (Set<String> namespaces : packageToNamespaces.values()) {
+            if (namespaces.size() > 1) {
+                sharedPackageNamespaces.addAll(namespaces);
+            }
+        }
+        if (sharedPackageNamespaces.isEmpty()) {
+            return;
+        }
+
+        SchemaCollection schemas = (SchemaCollection) 
context.get(ToolConstants.XML_SCHEMA_COLLECTION);
+        if (schemas == null) {
+            return;
+        }
+
+        Map<String, String> classToNamespace = new HashMap<>();
+        for (XmlSchema schema : schemas.getXmlSchemas()) {
+            String namespace = schema.getTargetNamespace();
+            if (StringUtils.isEmpty(namespace) || 
!sharedPackageNamespaces.contains(namespace)) {
+                continue;
+            }
+            for (QName typeName : schema.getSchemaTypes().keySet()) {
+                XmlSchemaType schemaType = schema.getTypeByName(typeName);
+                if (schemaType == null) {
+                    continue;
+                }
+                TypeAndAnnotation type = model.getJavaType(typeName);
+                if (type != null && type.getTypeClass() instanceof 
JDefinedClass) {
+                    JDefinedClass cls = (JDefinedClass)type.getTypeClass();
+                    classToNamespace.put(cls.fullName(), namespace);
+                }
+            }
+        }
+
+        for (Map.Entry<String, String> entry : classToNamespace.entrySet()) {
+            JDefinedClass cls = codeModel._getClass(entry.getKey());
+            if (cls == null) {
+                continue;
+            }
+            JAnnotationUse xmlType = getAnnotation(cls, 
"jakarta.xml.bind.annotation.XmlType");
+            if (xmlType == null) {
+                xmlType = getAnnotation(cls, 
"javax.xml.bind.annotation.XmlType");

Review Comment:
   Hi @reta ,
   
   You are right, just a fallback which never will be reached for CXF 4.x, I 
will remove it.
   
   Thanks!
   Freeman



-- 
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]

Reply via email to