You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2004/02/03 17:24:02 UTC

cvs commit: ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl JAXBSchemaSG.java

jochen      2004/02/03 08:24:02

  Modified:    .        status.xml
               src/jaxme/org/apache/ws/jaxme/generator/sg/impl
                        JAXBSchemaSG.java
  Log:
  The object factory has not been able to create global types.
  Obtained from: Colin Bendell <cb...@point2.com>
  
  Revision  Changes    Path
  1.9       +5 -0      ws-jaxme/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/status.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- status.xml	31 Jan 2004 17:34:04 -0000	1.8
  +++ status.xml	3 Feb 2004 16:24:02 -0000	1.9
  @@ -46,6 +46,11 @@
         	Fixed a bug in the JAXBSchemaSG's handling of global simple types.
         	(Chris Kirk <mr...@yahoo.co.uk>)
         </action>
  +      <action dev="JW" type="fix" context="generator">
  +      	The object factory has not been able to generate global types.
  +      	Local types are still missing, though.
  +      	(Colin Bendell <cb...@point2.com>)
  +      </action>
       </release>
     </changes>
   </status>
  
  
  
  1.8       +34 -14    ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBSchemaSG.java
  
  Index: JAXBSchemaSG.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBSchemaSG.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JAXBSchemaSG.java	31 Jan 2004 17:34:04 -0000	1.7
  +++ JAXBSchemaSG.java	3 Feb 2004 16:24:02 -0000	1.8
  @@ -51,9 +51,11 @@
   import java.io.StringWriter;
   import java.util.ArrayList;
   import java.util.HashMap;
  +import java.util.HashSet;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  +import java.util.Set;
   
   import javax.xml.XMLConstants;
   import javax.xml.bind.JAXBContext;
  @@ -451,7 +453,7 @@
       }
   
   
  -    Map packages = new HashMap();
  +    Set packages = new HashSet();
       for (Iterator iter = contextList.iterator();  iter.hasNext();  ) {
         Object o = iter.next();
         Context ctx;
  @@ -461,13 +463,13 @@
           ctx = ((TypeSG) o).getComplexTypeSG().getClassContext();
         }
         String packageName = ctx.getXMLInterfaceName().getPackageName();
  -      if (packages.containsKey(packageName)) {
  +      if (packages.contains(packageName)) {
           continue;
         }
   
         TextFile textFile = pController.getJavaSourceFactory().newTextFile(packageName, "jaxb.properties");
         textFile.addLine(JAXBContext.JAXB_CONTEXT_FACTORY + "=" + JAXBContextImpl.class.getName());
  -      packages.put(packageName, textFile);
  +      packages.add(packageName);
   
         String configFile = generateConfigFile(pController, packageName, contextList);
         TextFile confFile = pController.getJavaSourceFactory().newTextFile(packageName, "Configuration.xml");
  @@ -513,24 +515,42 @@
         setPropertyMethod.addLine(properties, ".put(", pName, ", ", pValue, ");");
       }
   
  +    Set contextSet = new HashSet();
       for (Iterator iter = pContextList.iterator();  iter.hasNext();  ) {
         Object o = iter.next();
  -      if (!(o instanceof ObjectSG)) {
  +      TypeSG typeSG;
  +      if (o instanceof ObjectSG) {
  +        ObjectSG objectSG = ((ObjectSG) o);
  +        typeSG = objectSG.getTypeSG();
  +        generateCreateMethod(js, objectSG.getClassContext());
  +        //NB: we don't have to check for duplicate element names since that would violate the XSD spec
  +      } else if (o instanceof TypeSG) {
  +        typeSG = (TypeSG) o;
  +      } else {
           continue;
         }
  -      ObjectSG objectSG = (ObjectSG) o;
  -      TypeSG typeSG = objectSG.getTypeSG();
  -      if (!typeSG.isComplex()) {
  -        continue;
  +
  +      if (typeSG.isComplex() && !contextSet.contains(typeSG)) {
  +        // many global elements may have the same global complex type so must check first
  +        generateCreateMethod(js, typeSG.getComplexTypeSG().getClassContext());
  +        contextSet.add(typeSG);
         }
  -      JavaQName resultName = objectSG.getClassContext().getXMLInterfaceName();
  -      String className = resultName.getClassName();
  -      String methodName = "create" + Character.toUpperCase(className.charAt(0)) + className.substring(1);
  -      JavaMethod createMethod = js.newJavaMethod(methodName, resultName, "public");
  -      createMethod.addThrows(JAXBException.class);
  -      createMethod.addLine("return (", resultName, ") newInstance(", resultName, ".class);");
       }
       
       return js;
  +  }
  +
  +  /**
  +   * Generic util method for generating the create<NAME> methods for the object factory.
  +   * @param pSource the java source object to add the method
  +   * @param pContext the Class Context from either an ObjectSG or a TypeSG
  +   */
  +  private void generateCreateMethod(JavaSource pSource, Context pContext) {
  +    JavaQName resultName = pContext.getXMLInterfaceName();
  +    String className = resultName.getClassName();
  +    String methodName = "create" + Character.toUpperCase(className.charAt(0)) + className.substring(1);
  +    JavaMethod createMethod = pSource.newJavaMethod(methodName, resultName, "public");
  +    createMethod.addThrows(JAXBException.class);
  +    createMethod.addLine("return (", resultName, ") newInstance(", resultName, ".class);");
     }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org