Update of /cvsroot/jaxme/JaxMe2/src/net/sf/jaxme/generator/javasg/types
In directory sc8-pr-cvs1:/tmp/cvs-serv5613/src/net/sf/jaxme/generator/javasg/types

Modified Files:
        TypeSGImpl.java DecimalTypeSG.java TypeSGProxy.java 
        DateTimeTypeSG.java PrimitiveNumericTypeSGImpl.java 
        ComplexTypeSGImpl.java AtomicTypeSG.java 
Log Message:
Added customization framework. See docs/Customization.html for
details. Added Marty Kube to the list of project members. See
docs/Design.html.


Index: TypeSGImpl.java
===================================================================
RCS file: 
/cvsroot/jaxme/JaxMe2/src/net/sf/jaxme/generator/javasg/types/TypeSGImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- TypeSGImpl.java     12 Feb 2003 18:55:44 -0000      1.6
+++ TypeSGImpl.java     21 Mar 2003 21:31:03 -0000      1.7
@@ -3,7 +3,9 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 import java.util.StringTokenizer;
 
@@ -58,14 +60,19 @@
     if (extQName != null) {
       js.addExtends(extQName);
     }
-    JavaQName[] interfaces = sc.getImplementedClassNames(pClassType);
-    for (int i = 0;  i < interfaces.length;  i++) {
-      js.addImplements(interfaces[i]);
+    for (Iterator iter = sctSG.getImplementedInterfaceNames(pType, pClassType);
+         iter.hasNext();  ) {
+      js.addImplements((JavaQName) iter.next());
     }
 
-    if (sc.isAbstract(pClassType)) {
+    if (sctSG.isAbstractClass(pType, pClassType)) {
       js.setAbstract(true);
     }
+
+    for (Iterator iter = sctSG.getRawSources(pType, pClassType);  iter.hasNext();  ) {
+      js.addRawJavaSource((String) iter.next());
+    }
+
     return js;
   }
 
@@ -82,13 +89,34 @@
     }
     JavaSource js = getFactory().getJavaSourceFactory().newJavaSource(qName, 
"public");
     js.setType(JavaSource.INTERFACE);
-    JavaQName extQName = pTypeSG.getExtendedClassName(pType, pClassType);
-    if (extQName != null) {
+
+    for (Iterator iter = pTypeSG.getExtendedInterfaceNames(pType, pClassType);
+         iter.hasNext();  ) {
+      JavaQName extQName = (JavaQName) iter.next();
       js.addExtends(extQName);
     }
+
+    for (Iterator iter = pTypeSG.getRawSources(pType, pClassType);  iter.hasNext();  
) {
+      js.addRawJavaSource((String) iter.next());
+    }
+
     return js;
   }
 
+  /** <p>Returns Strings with Java sources being included into the
+   * generated class.</p>
+   */
+  public Iterator getRawSources(SchemaType pType, String pClassType)
+      throws SchemaException {
+    SchemaClass sc = pType.getSchemaClass();
+    String[] sources = sc.getJavaSources(pClassType);
+    if (sources != null) {
+      return Arrays.asList(sources).iterator();
+    } else {
+      return Collections.EMPTY_LIST.iterator();
+    }
+  }
+
   public static String getPackageNameFromURL(URL pURL) {
     List tokens = new ArrayList();
     for (StringTokenizer st = new StringTokenizer(pURL.getHost(), ".");
@@ -174,6 +202,78 @@
     return result;
   }
 
+  public Iterator getImplementedInterfaceNames(SchemaType pType,
+                                                String pClassType)
+      throws SchemaException {
+    SchemaClass sc = pType.getSchemaClass();
+    SchemaClass.ClassDeclaration[] interfaces =
+      sc.getImplementedInterfaceNames(pClassType);
+    if (interfaces != null) {
+      List list = new ArrayList();
+      for (int i = 0;  i < interfaces.length;  i++) {
+        SchemaClass.ClassDeclaration cd = interfaces[i];
+        String className = cd.getClassName();
+        String packageName = cd.getPackageName();
+        if (packageName == null) {
+          packageName = getPackageName(pType);
+        }
+        list.add(JavaQNameImpl.getInstance(packageName, className));
+      }
+      return list.iterator();
+    } else {
+      if (SchemaClass.CLASS_TYPE_XML.equals(pClassType)) {
+        return Collections.EMPTY_LIST.iterator();
+      } else if (SchemaClass.CLASS_TYPE_ENUMERATION.equals(pClassType)) {
+        return Collections.EMPTY_LIST.iterator();
+      } else if (SchemaClass.CLASS_TYPE_MANAGER.equals(pClassType)) {
+        return Collections.EMPTY_LIST.iterator();
+      } else if (SchemaClass.CLASS_TYPE_MARSHALLER.equals(pClassType)) {
+        return Collections.EMPTY_LIST.iterator();
+      } else if (SchemaClass.CLASS_TYPE_UNMARSHALLER.equals(pClassType)) {
+        return Collections.EMPTY_LIST.iterator();
+      } else if (SchemaClass.CLASS_TYPE_VALIDATOR.equals(pClassType)) {
+        return Collections.EMPTY_LIST.iterator();
+      } else {
+        throw new IllegalArgumentException("Unknown class type: " + pClassType);
+      }
+    }
+  }
+
+  public Iterator getExtendedInterfaceNames(SchemaType pType,
+                                             String pClassType)
+      throws SchemaException {
+    SchemaClass sc = pType.getSchemaClass();
+    SchemaClass.ClassDeclaration[] interfaces = 
sc.getExtendedInterfaceNames(pClassType);
+    if (interfaces != null) {
+      List list = new ArrayList();
+      for (int i = 0;  i < interfaces.length;  i++) {
+        SchemaClass.ClassDeclaration cd = interfaces[i];
+        String className = cd.getClassName();
+        String packageName = cd.getPackageName();
+        if (packageName == null) {
+          packageName = getPackageName(pType);
+        }
+        list.add(JavaQNameImpl.getInstance(packageName, className));
+      }
+      return list.iterator();
+    } else {
+      if (SchemaClass.CLASS_TYPE_XML_INTERFACE.equals(pClassType)) {
+        List list = new ArrayList();
+        list.add(JavaQNameImpl.getInstance(JMElement.class));
+        return list.iterator();
+      } else {
+        throw new IllegalArgumentException("Unknown class type: " + pClassType);
+      }
+    }
+  }
+
+  public boolean isAbstractClass(SchemaType pType, String pClassType)
+      throws SchemaException {
+    SchemaClass sc = pType.getSchemaClass();
+    Boolean result = sc.isAbstract(pClassType);
+    return (result == null) ? false : result.booleanValue();
+  }
+
   public JavaQName getExtendedClassName(SchemaType pType,
                                          String pClassType) throws SchemaException {
     SchemaClass sc = pType.getSchemaClass();
@@ -181,8 +281,6 @@
     if (cd == null  ||  cd.getClassName() == null) {
       if (SchemaClass.CLASS_TYPE_XML.equals(pClassType)) {
         return JavaQNameImpl.getInstance(JMElementImpl.class);
-      } else if (SchemaClass.CLASS_TYPE_XML_INTERFACE.equals(pClassType)) {
-        return JavaQNameImpl.getInstance(JMElement.class);
       } else if (SchemaClass.CLASS_TYPE_MANAGER.equals(pClassType)) {
         return JavaQNameImpl.getInstance(JMManager.class);
       } else if (SchemaClass.CLASS_TYPE_MARSHALLER.equals(pClassType)) {

Index: DecimalTypeSG.java
===================================================================
RCS file: 
/cvsroot/jaxme/JaxMe2/src/net/sf/jaxme/generator/javasg/types/DecimalTypeSG.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- DecimalTypeSG.java  31 Jan 2003 20:15:54 -0000      1.4
+++ DecimalTypeSG.java  21 Mar 2003 21:31:03 -0000      1.5
@@ -90,12 +90,11 @@
 
     for (int i = 0;  i < values.length;  i++) {
       SchemaSimpleType.EnumerationValue value = values[i];
-      JavaComment jc = new JavaComment();
-      jc.addLine("The value \"" + value + "\".");
       jf = pJs.newJavaField(value.getName(), pJs.getQName(), "public");
+      JavaComment jc = jf.newComment();
+      jc.addLine("The value \"" + value + "\".");
       jf.setFinal(true);
       jf.setStatic(true);
-      jf.setComment(jc);
       jf.addLine("new ", pJs.getQName(), "(", JavaSource.getQuoted(value.getName()), 
", ",
                  getCastedString(value.getValue()));
     }

Index: TypeSGProxy.java
===================================================================
RCS file: 
/cvsroot/jaxme/JaxMe2/src/net/sf/jaxme/generator/javasg/types/TypeSGProxy.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- TypeSGProxy.java    31 Jan 2003 20:15:55 -0000      1.3
+++ TypeSGProxy.java    21 Mar 2003 21:31:04 -0000      1.4
@@ -1,5 +1,7 @@
 package net.sf.jaxme.generator.javasg.types;
 
+import java.util.Iterator;
+
 import net.sf.jaxme.generator.SchemaException;
 import net.sf.jaxme.generator.javasg.ComplexTypeSG;
 import net.sf.jaxme.generator.javasg.PrimitiveNumericTypeSG;
@@ -27,25 +29,17 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Jochen Wiedmann</a>
  * @version $Id$
  */
-public abstract class TypeSGProxy extends TypeSGBase
+public class TypeSGProxy extends TypeSGBase
     implements SimpleTypeSG, ComplexTypeSG, PrimitiveNumericTypeSG {
   private TypeSG typeSG;
 
-  private TypeSGProxy(TypeSG pTypeSG) {
+  protected TypeSGProxy(TypeSG pTypeSG) {
     typeSG = pTypeSG;
     SGFactory factory = typeSG.getFactory();
     if (factory != null) {
       super.setFactory(factory);
     }
   }
-    
-  protected TypeSGProxy(SimpleTypeSG pTypeSG) {
-    this((TypeSG) pTypeSG);
-  }
-
-  protected TypeSGProxy(ComplexTypeSG pTypeSG) {
-    this((TypeSG) pTypeSG);
-  }
 
   public void setFactory(SGFactory pFactory) {
     super.setFactory(pFactory);
@@ -90,6 +84,21 @@
     return typeSG.getExtendedClassName(pType, pClassType);
   }
 
+  public boolean isAbstractClass(SchemaType pType, String pClassType)
+      throws SchemaException {
+    return typeSG.isAbstractClass(pType, pClassType);
+  }
+
+  public Iterator getRawSources(SchemaType pType, String pClassType)
+      throws SchemaException {
+    return typeSG.getRawSources(pType, pClassType);
+  }
+
+  public Iterator getImplementedInterfaceNames(SchemaType pType, String pClassType)
+      throws SchemaException {
+    return typeSG.getImplementedInterfaceNames(pType, pClassType);
+  }
+
   public JavaField getXMLFieldFor(SGData pData, SchemaObject pObject)
       throws SchemaException {
     return typeSG.getXMLFieldFor(pData, pObject);
@@ -135,6 +144,11 @@
     return typeSG.getIsSetMethodName(pType);
   }
 
+  public Iterator getExtendedInterfaceNames(SchemaType pType, String pClassType)
+      throws SchemaException {
+    return typeSG.getExtendedInterfaceNames(pType, pClassType);
+  }
+
   public void generateXMLProperty(SGData pData, SchemaObject pObject)
       throws SchemaException {
     typeSG.generateXMLProperty(pData, pObject);
@@ -228,10 +242,9 @@
     return ((SimpleTypeSG) typeSG).isTypesafeEnumeration(pType);
   }
 
-  public JavaMethod getHandlersStartElementMethod(SchemaComplexType pType,
-                                                   UnmarshallerSGData pData)
+  public JavaSource getEnumerationClass(SchemaSimpleType pType)
       throws SchemaException {
-    return ((ComplexTypeSG) typeSG).getHandlersStartElementMethod(pType, pData);
+    return ((SimpleTypeSG) typeSG).getEnumerationClass(pType);
   }
 
   public JavaMethod getHandlersInitMethod(SchemaComplexType pType,
@@ -351,4 +364,9 @@
                                      Object pValue) throws SchemaException {
     return ((PrimitiveNumericTypeSG) typeSG).getParsedObjectCode(pType, pValue);
   }
-}
+
+  public JavaMethod getHandlersStartElementMethod(SchemaComplexType pType,
+                                                   UnmarshallerSGData pData)
+      throws SchemaException {
+    return ((ComplexTypeSG) typeSG).getHandlersStartElementMethod(pType, pData);
+  }
}

Index: DateTimeTypeSG.java
===================================================================
RCS file: 
/cvsroot/jaxme/JaxMe2/src/net/sf/jaxme/generator/javasg/types/DateTimeTypeSG.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- DateTimeTypeSG.java 31 Jan 2003 20:15:55 -0000      1.4
+++ DateTimeTypeSG.java 21 Mar 2003 21:31:04 -0000      1.5
@@ -176,12 +176,11 @@
 
     for (int i = 0;  i < values.length;  i++) {
       SchemaSimpleType.EnumerationValue value = values[i];
-      JavaComment jc = new JavaComment();
-      jc.addLine("The value \"" + value + "\".");
       jf = pJs.newJavaField(value.getName(), pJs.getQName(), "public");
+      JavaComment jc = jf.newComment();
+      jc.addLine("The value \"" + value + "\".");
       jf.setFinal(true);
       jf.setStatic(true);
-      jf.setComment(jc);
       jf.addLine("new ", pJs.getQName(), "(", JavaSource.getQuoted(value.getName()), 
", ",
                  JavaSource.getQuoted(value.getValue()), ")");
     }

Index: PrimitiveNumericTypeSGImpl.java
===================================================================
RCS file: 
/cvsroot/jaxme/JaxMe2/src/net/sf/jaxme/generator/javasg/types/PrimitiveNumericTypeSGImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- PrimitiveNumericTypeSGImpl.java     31 Jan 2003 20:15:55 -0000      1.3
+++ PrimitiveNumericTypeSGImpl.java     21 Mar 2003 21:31:04 -0000      1.4
@@ -105,31 +105,30 @@
       SchemaSimpleType.EnumerationValue value = values[i];
       Object o = getParsedObjectCode(type, JavaSource.getQuoted(value.getValue()));
 
-      JavaComment jc = new JavaComment();
+      jf = pJs.newJavaField("_PRIMITIVE_" + value.getName(),
+                            type.getPrimitiveRuntimeClass(), JavaSource.PUBLIC);
+      JavaComment jc = jf.newComment();
       jc.addLine(JavaSource.getQuoted("The constant ") +
                  value.getName() + JavaSource.getQuoted(" with value ") +
                  value.getValue() + JavaSource.getQuoted(", as a primitive."));
       jc.addSee("#" + value.getName());
       jc.addSee("#_" + value.getName());
-      jf = pJs.newJavaField("_PRIMITIVE_" + value.getName(),
-                            type.getPrimitiveRuntimeClass(), JavaSource.PUBLIC);
       jf.setFinal(true);
       jf.setStatic(true);
-      jf.setComment(jc);
       jf.addLine(getParsedPrimitiveCode(type, 
JavaSource.getQuoted(value.getValue())));
 
-      jc = new JavaComment();
+      jf = pJs.newJavaField("_" + value.getName(), type.getRuntimeType(), "public");
+      jc = jf.newComment();
       jc.addLine(JavaSource.getQuoted("The constant ") +
                  value.getName() + JavaSource.getQuoted(" with value ") +
                  value.getValue() + JavaSource.getQuoted(", as a numeric object."));
       jc.addSee("#" + value.getName());
-      jf = pJs.newJavaField("_" + value.getName(), type.getRuntimeType(), "public");
       jf.setFinal(true);
       jf.setStatic(true);
-      jf.setComment(jc);
       jf.addLine("new ", type.getRuntimeType(), "(_PRIMITIVE_", value.getName(), 
");");
 
-      jc = new JavaComment();
+      jf = pJs.newJavaField(value.getName(), pJs.getQName(), "public");
+      jc = jf.newComment();
       if (value.getJavadoc() == null) {
         jc.addLine(JavaSource.getQuoted("The constant ") +
                    value.getName() + JavaSource.getQuoted(" with value ") +
@@ -137,10 +136,8 @@
       } else {
         jc.addLine(value.getJavadoc());
       }
-      jf = pJs.newJavaField(value.getName(), pJs.getQName(), "public");
       jf.setFinal(true);
       jf.setStatic(true);
-      jf.setComment(jc);
       jf.addLine("new ", pJs.getQName(), "(", JavaSource.getQuoted(value.getName()),
                  ", ", "_" + value.getName(), ");");
 

Index: ComplexTypeSGImpl.java
===================================================================
RCS file: 
/cvsroot/jaxme/JaxMe2/src/net/sf/jaxme/generator/javasg/types/ComplexTypeSGImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- ComplexTypeSGImpl.java      12 Feb 2003 18:55:44 -0000      1.5
+++ ComplexTypeSGImpl.java      21 Mar 2003 21:31:04 -0000      1.6
@@ -580,20 +580,18 @@
 
     ComplexTypeSG jsg = getFactory().getComplexTypeSG(pType);
 
-    jm.addLine("if (", pData.getHandlerVar(), " == null) {");
-    jm.indent();
-    jm.addLine("if (", pData.getLevelVar(), " != 1) {");
-    jm.indent();
-    jm.addLine("super.endElement(pNamespaceURI, pLocalName, pQName);");
-    jm.unindent();
-    jm.addLine("}");
-    jm.unindent();
-    jm.addLine("} else {");
-    jm.indent();
-    jm.addLine(pData.getHandlerVar(),
-               ".endElement(pNamespaceURI, pLocalName, pQName);");
-    jm.unindent();
-    jm.addLine("}");
+    if (pData.hasSimpleContent()  ||  pData.hasChilds()) {
+      jm.addIf(pData.getHandlerVar(), " == null");
+
+      jm.addIf(pData.getLevelVar(), " != 1");
+      jm.addLine("super.endElement(pNamespaceURI, pLocalName, pQName);");
+      jm.addEndIf();
+
+      jm.addElse();
+      jm.addLine(pData.getHandlerVar(),
+                 ".endElement(pNamespaceURI, pLocalName, pQName);");
+      jm.addEndIf();
+    }
 
     jm.addLine("switch (--", pData.getLevelVar(), ") {");
     jm.indent();
@@ -748,7 +746,8 @@
       throws SchemaException {
     JavaSource js = pData.getJavaSource();
     if (pData.hasChilds()) {
-      JavaComment jc = new JavaComment();
+      JavaField jf = js.newJavaField(pData.getStateVar(), "int", "private");
+      JavaComment jc = jf.newComment();
       jc.addLine("The current state. The following values are valid states:");
       jc.addLine(" 0 = Before parsing the element");
       jc.addLine(" 1 = Parsing an unknown element");
@@ -757,19 +756,15 @@
         jc.addLine(" " + pData.getState(i) + " = While parsing the child element " +
                    pData.getChild(i).getQName());
       }
-      JavaField jf = js.newJavaField(pData.getStateVar(), "int", "private");
-      jf.setComment(jc);
     }
     if (pData.hasSimpleContent()  ||  pData.hasChilds()) {
-      JavaComment jc = new JavaComment();
-      jc.addLine("The current handler for parsing child elements or simple content.");
       JavaField jf = js.newJavaField(pData.getHandlerVar(), JMHandler.class, 
JavaSource.PRIVATE);
-      jf.setComment(jc);
+      JavaComment jc = jf.newComment();
+      jc.addLine("The current handler for parsing child elements or simple content.");
     }
-    JavaComment jc = new JavaComment();
-    jc.addLine("The current level of nested elements. 0, if outside the root 
element.");
     JavaField jf = js.newJavaField(pData.getLevelVar(), "int", "private");
-    jf.setComment(jc);
+    JavaComment jc = jf.newComment();
+    jc.addLine("The current level of nested elements. 0, if outside the root 
element.");
 
     getHandlersInitMethod(pType, pData);
     getHandlersAddAttributeMethod(pType, pData);

Index: AtomicTypeSG.java
===================================================================
RCS file: 
/cvsroot/jaxme/JaxMe2/src/net/sf/jaxme/generator/javasg/types/AtomicTypeSG.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- AtomicTypeSG.java   9 Feb 2003 17:51:57 -0000       1.3
+++ AtomicTypeSG.java   21 Mar 2003 21:31:06 -0000      1.4
@@ -128,18 +128,18 @@
     for (int i = 0;  i < values.length;  i++) {
       SchemaSimpleType.EnumerationValue value = values[i];
       String name = value.getName();
-      JavaComment jc = new JavaComment();
+      jf = pJs.newJavaField("_" + value.getName(), pType.getRuntimeType(), "public");
+      JavaComment jc = jf.newComment();
       jc.addLine(JavaSource.getQuoted("The constants ") +
                  value.getName() + JavaSource.getQuoted(" value: ") +
                  JavaSource.getQuoted(value.getValue()));
       jc.addSee("#" + value.getName());
-      jf = pJs.newJavaField("_" + value.getName(), pType.getRuntimeType(), "public");
       jf.setFinal(true);
       jf.setStatic(true);
-      jf.setComment(jc);
       jf.addLine(JavaSource.getQuoted(value.getValue()));
 
-      jc = new JavaComment();
+      jf = pJs.newJavaField(name, pJs.getQName(), "public");
+      jc = jf.newComment();
       if (value.getJavadoc() == null) {
         jc.addLine(JavaSource.getQuoted("The constant ") +
                    value.getName() + JavaSource.getQuoted(" with value ") +
@@ -147,10 +147,8 @@
       } else {
         jc.addLine(value.getJavadoc());
       }
-      jf = pJs.newJavaField(name, pJs.getQName(), "public");
       jf.setFinal(true);
       jf.setStatic(true);
-      jf.setComment(jc);
       jf.addLine("new ", pJs.getQName(), "(", JavaSource.getQuoted(name), ", ",
                  "_" + value.getName(), ")");
     }




-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open! 
Get cracking and register here for some mind boggling fun and 
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
_______________________________________________
Jaxme-jaxb-dev mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxme-jaxb-dev

Reply via email to