[jbossws-commits] JBossWS SVN: r2479 - branches/dlofthouse/JBWS-1538/jbossws-core/src/main/java/org/jboss/ws/tools/schema.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Tue Feb 27 19:40:41 EST 2007


Author: darran.lofthouse at jboss.com
Date: 2007-02-27 19:40:40 -0500 (Tue, 27 Feb 2007)
New Revision: 2479

Modified:
   branches/dlofthouse/JBWS-1538/jbossws-core/src/main/java/org/jboss/ws/tools/schema/SchemaTypeCreator.java
Log:
Check so variables are not mapped mutliple times for JBWS-1538

Modified: branches/dlofthouse/JBWS-1538/jbossws-core/src/main/java/org/jboss/ws/tools/schema/SchemaTypeCreator.java
===================================================================
--- branches/dlofthouse/JBWS-1538/jbossws-core/src/main/java/org/jboss/ws/tools/schema/SchemaTypeCreator.java	2007-02-27 23:49:17 UTC (rev 2478)
+++ branches/dlofthouse/JBWS-1538/jbossws-core/src/main/java/org/jboss/ws/tools/schema/SchemaTypeCreator.java	2007-02-28 00:40:40 UTC (rev 2479)
@@ -347,7 +347,8 @@
       JBossXSModelGroup group = (JBossXSModelGroup)complexType.getParticle().getTerm();
       group.setParticles(particles);
 
-      if(log.isDebugEnabled()) log.debug("generateNewType: " + sutils.write(complexType));
+      if (log.isDebugEnabled())
+         log.debug("generateNewType: " + sutils.write(complexType));
       return complexType;
    }
 
@@ -485,10 +486,9 @@
             continue;
          }
 
-         
          String name = term.getName();
-         String variableName = name; 
-         if (reversedNames != null && reversedNames.get(name) != null) 
+         String variableName = name;
+         if (reversedNames != null && reversedNames.get(name) != null)
             variableName = reversedNames.get(name);
 
          VariableMapping mapping = new VariableMapping(javaXmlTypeMapping);
@@ -497,10 +497,42 @@
          mapping.setXmlElementName(name);
          mapping.setDataMember(utils.doesPublicFieldExist(javaType, variableName));
 
-         javaXmlTypeMapping.addVariableMapping(mapping);
+         if (isAlreadyMapped(javaXmlTypeMapping, mapping) == false)
+         {
+            javaXmlTypeMapping.addVariableMapping(mapping);
+         }
       }
    }
 
+   private boolean isAlreadyMapped(JavaXmlTypeMapping jxtm, VariableMapping vm)
+   {
+      String javaVariableName = vm.getJavaVariableName();
+      String attributeName = vm.getXmlAttributeName();
+      String elementName = vm.getXmlElementName();
+
+      for (VariableMapping current : jxtm.getVariableMappings())
+      {
+         boolean matched = checkStringEquality(javaVariableName, current.getJavaVariableName());
+
+         if (matched)
+         {
+            matched = checkStringEquality(attributeName, current.getXmlAttributeName());
+         }
+
+         if (matched)
+         {
+            matched = checkStringEquality(elementName, current.getXmlElementName());
+         }
+
+         if (matched)
+         {
+            return true;
+         }
+      }
+
+      return false;
+   }
+
    private List<XSParticle> getXSParticlesForPublicFields(String typeNamespace, Class javaType, Map<String, QName> elementNames)
    {
       List<XSParticle> particles = new ArrayList<XSParticle>();
@@ -579,10 +611,10 @@
          String fieldname = prop.getName();
          Class fieldType = prop.getPropertyType();
 
-         if (prop instanceof IndexedPropertyDescriptor && fieldType==null)
+         if (prop instanceof IndexedPropertyDescriptor && fieldType == null)
          {
-        	 log.warn("Indexed Properties without non-indexed accessors are not supported skipping: " + javaType.getName() + "." + fieldname);
-        	 continue;
+            log.warn("Indexed Properties without non-indexed accessors are not supported skipping: " + javaType.getName() + "." + fieldname);
+            continue;
          }
 
          // Skip magic work around property used in ParameterWrapping
@@ -710,7 +742,7 @@
 
       List<XSParticle> particles = new ArrayList<XSParticle>(0);
       List<Class> types = new ArrayList<Class>(0);
-      JBossXSComplexTypeDefinition complexType = new JBossXSComplexTypeDefinition();      
+      JBossXSComplexTypeDefinition complexType = new JBossXSComplexTypeDefinition();
       complexType.setName(name);
       complexType.setNamespace(namespace);
 
@@ -718,14 +750,14 @@
       xsModel.addXSElementDeclaration(sutils.createGlobalXSElementDeclaration(name, complexType, namespace));
       typeMapping.register(javaType, new QName(namespace, name), null, null);
       registerJavaTypeMapping(new QName(namespace, name), javaType, "complexType", particles, null);
-      
+
       Class superClass = javaType.getSuperclass();
       if (!Exception.class.equals(superClass) || Throwable.class.equals(superClass))
       {
          JBossXSTypeDefinition baseType = generateType(null, superClass);
          complexType.setBaseType(baseType);
       }
-            
+
       generateExceptionParticles(namespace, javaType, types, particles);
 
       boolean found = hasConstructor(javaType, types);
@@ -750,7 +782,7 @@
          }
       }
 
-      complexType.setParticle(createGroupParticle(namespace, particles));      
+      complexType.setParticle(createGroupParticle(namespace, particles));
 
       return complexType;
    }
@@ -876,4 +908,15 @@
 
       return sutils.createXSParticle(targetNS, isArray, xsel);
    }
+
+   private boolean checkStringEquality(String str1, String str2)
+   {
+      if (str1 == null && str2 == null)
+         return true;
+      if (str1 == null && str2 != null)
+         return false;
+      if (str1 != null && str2 == null)
+         return false;
+      return str1.equals(str2);
+   }
 }
\ No newline at end of file




More information about the jbossws-commits mailing list