cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r601116 - in /cayenne/main/trunk/framework: cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/ cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ cayenn...
Date Tue, 04 Dec 2007 22:23:45 GMT
Author: aadamchik
Date: Tue Dec  4 14:23:44 2007
New Revision: 601116

URL: http://svn.apache.org/viewvc?rev=601116&view=rev
Log:
CAY-926 Refactoring class generator classes
(switching Modeler to the new generator)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction1_1.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationInfo.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClientModeController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorControllerBase.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferences.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java?rev=601116&r1=601115&r2=601116&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
Tue Dec  4 14:23:44 2007
@@ -26,7 +26,6 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.List;
 
 import org.apache.cayenne.CayenneDataObject;
 import org.apache.cayenne.CayenneRuntimeException;
@@ -49,7 +48,7 @@
     public static final String SUPERCLASS_PREFIX = "_";
     private static final String WILDCARD = "*";
 
-    protected List<ObjEntity> entities;
+    protected Collection<ObjEntity> entities;
     protected String superPkg;
     protected DataMap dataMap;
     protected ClassGeneratorMode mode;
@@ -74,15 +73,15 @@
         this.makePairs = true;
     }
 
-    protected String defaultSingleClassTemplate() {
+    public String defaultSingleClassTemplate() {
         return ClassGenerationAction.SINGLE_CLASS_TEMPLATE;
     }
 
-    protected String defaultSubclassTemplate() {
+    public String defaultSubclassTemplate() {
         return ClassGenerationAction.SUBCLASS_TEMPLATE;
     }
 
-    protected String defaultSuperclassTemplate() {
+    public String defaultSuperclassTemplate() {
         return ClassGenerationAction.SUPERCLASS_TEMPLATE;
     }
 
@@ -115,7 +114,7 @@
                     + stringUtils.stripPackageName(fqnSubClass);
 
             String superPackageName = this.superPkg;
-            if(superPackageName == null) {
+            if (superPackageName == null) {
                 superPackageName = subPackageName;
             }
             String fqnSuperClass = superPackageName + "." + superClassName;
@@ -152,7 +151,7 @@
         // TODO: andrus, 12/2/2007 - should we setup a dummy entity for an empty map in
         // DataMap mode?
         if (mode != ClassGeneratorMode.entity && !entities.isEmpty()) {
-            return Collections.singleton(entities.get(0));
+            return Collections.singleton(entities.iterator().next());
         }
         else {
             return this.entities;
@@ -489,7 +488,7 @@
         this.dataMap = dataMap;
     }
 
-    public List<ObjEntity> getEntities() {
+    public Collection<ObjEntity> getEntities() {
         return entities;
     }
 
@@ -498,7 +497,7 @@
      * list to allow its independent modification and also filters out entities that do
      * not require class generation.
      */
-    public void setEntities(List<ObjEntity> objEntities) {
+    public void setEntities(Collection<ObjEntity> objEntities) {
         this.entities = objEntities != null
                 ? new ArrayList<ObjEntity>(objEntities)
                 : new ArrayList<ObjEntity>();
@@ -508,6 +507,10 @@
         this.mode = mode;
     }
 
+    /**
+     * Sets an optional shared VelocityContext. Useful with tools like VPP that can set
+     * custom values in the context, not known to Cayenne.
+     */
     public void setContext(VelocityContext context) {
         this.context = context;
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction1_1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction1_1.java?rev=601116&r1=601115&r2=601116&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction1_1.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction1_1.java
Tue Dec  4 14:23:44 2007
@@ -36,17 +36,17 @@
     public static final String SUPERCLASS_TEMPLATE = "dotemplates/superclass.vm";
 
     @Override
-    protected String defaultSingleClassTemplate() {
+    public String defaultSingleClassTemplate() {
         return ClassGenerationAction1_1.SINGLE_CLASS_TEMPLATE;
     }
 
     @Override
-    protected String defaultSubclassTemplate() {
+    public String defaultSubclassTemplate() {
         return ClassGenerationAction1_1.SUBCLASS_TEMPLATE;
     }
 
     @Override
-    protected String defaultSuperclassTemplate() {
+    public String defaultSuperclassTemplate() {
         return ClassGenerationAction1_1.SUPERCLASS_TEMPLATE;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationInfo.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationInfo.java?rev=601116&r1=601115&r2=601116&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationInfo.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationInfo.java
Tue Dec  4 14:23:44 2007
@@ -32,6 +32,7 @@
  * 
  * @author Andrus Adamchik
  * @since 1.2
+ * @deprecated since 3.0, as class generator version 1.1 is deprecated.
  */
 public class ClassGenerationInfo {
 
@@ -114,7 +115,7 @@
      * @since 3.0
      */
     public String formatJavaTypeAsNonBooleanPrimitive(String type) {
-        String value = (String) ImportUtils.classesForPrimitives.get(type);
+        String value = ImportUtils.classesForPrimitives.get(type);
         return formatJavaType(value != null ? value : type);
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java?rev=601116&r1=601115&r2=601116&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
Tue Dec  4 14:23:44 2007
@@ -33,18 +33,18 @@
     public static final String SUPERCLASS_TEMPLATE = "dotemplates/v1_2/client-superclass.vm";
 
     @Override
-    protected String defaultSingleClassTemplate() {
+    public String defaultSingleClassTemplate() {
         throw new IllegalStateException(
                 "Default generation for single classes on the client is not supported.");
     }
 
     @Override
-    protected String defaultSubclassTemplate() {
+    public String defaultSubclassTemplate() {
         return ClientClassGenerationAction.SUBCLASS_TEMPLATE;
     }
 
     @Override
-    protected String defaultSuperclassTemplate() {
+    public String defaultSuperclassTemplate() {
         return ClientClassGenerationAction.SUPERCLASS_TEMPLATE;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java?rev=601116&r1=601115&r2=601116&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
Tue Dec  4 14:23:44 2007
@@ -105,8 +105,6 @@
     }
 
     /**
-     * Factory method to create internal class generator. Called from constructor.
-     * 
      * @deprecated since 3.0. Use {@link #createGeneratorAction()}.
      */
     protected DefaultClassGenerator createGenerator() {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java?rev=601116&r1=601115&r2=601116&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java
Tue Dec  4 14:23:44 2007
@@ -19,11 +19,15 @@
 
 package org.apache.cayenne.modeler;
 
+import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
-import org.apache.cayenne.gen.MapClassGenerator;
+import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.ClassGenerationAction1_1;
+import org.apache.cayenne.gen.ClassGenerator;
+import org.apache.cayenne.gen.ClientClassGenerationAction;
 import org.apache.cayenne.modeler.pref.FSPath;
 import org.apache.cayenne.pref.Domain;
 
@@ -36,78 +40,100 @@
 
     public static final String STANDARD_SERVER_SUPERCLASS = "Standard Server Superclass";
     public static final String STANDARD_SERVER_SUBCLASS = "Standard Server Subclass";
+    static final String STANDARD_CLIENT_SUPERCLASS = "Standard Client Superclass";
+    static final String STANDARD_CLIENT_SUBCLASS = "Standard Client Subclass";
 
-    protected Map standardSubclassTemplates;
-    protected Map standardSuperclassTemplates;
-    protected Map customTemplates;
+    protected List<String> standardSubclassTemplates;
+    protected List<String> standardSuperclassTemplates;
+    protected Map<String, String> customTemplates;
+    protected Map<String, String> standardTemplates;
+    protected Map<String, String> standardTemplates1_1;
 
     public static Domain getTemplateDomain(Application application) {
         return application.getPreferenceDomain().getSubdomain(CodeTemplateManager.class);
     }
 
     public CodeTemplateManager(Application application) {
-        standardSuperclassTemplates = new HashMap();
+        standardSuperclassTemplates = new ArrayList<String>(3);
 
-        standardSuperclassTemplates.put(
-                STANDARD_SERVER_SUPERCLASS,
-                MapClassGenerator.SUPERCLASS_TEMPLATE_1_1);
+        standardSuperclassTemplates.add(STANDARD_SERVER_SUPERCLASS);
+        standardSuperclassTemplates.add(STANDARD_CLIENT_SUPERCLASS);
 
-        standardSuperclassTemplates.put(
-                "Standard Client Superclass",
-                MapClassGenerator.CLIENT_SUPERCLASS_TEMPLATE_1_2);
+        standardSubclassTemplates = new ArrayList<String>(3);
+        standardSubclassTemplates.add(STANDARD_SERVER_SUBCLASS);
+        standardSubclassTemplates.add(STANDARD_CLIENT_SUBCLASS);
 
-        standardSubclassTemplates = new HashMap();
-        standardSubclassTemplates.put(
-                STANDARD_SERVER_SUBCLASS,
-                MapClassGenerator.SUBCLASS_TEMPLATE_1_1);
+        updateCustomTemplates(getTemplateDomain(application));
 
-        standardSubclassTemplates.put(
-                "Standard Client Subclass",
-                MapClassGenerator.CLIENT_SUBCLASS_TEMPLATE_1_2);
+        standardTemplates = new HashMap<String, String>();
+        standardTemplates.put(
+                STANDARD_SERVER_SUPERCLASS,
+                ClassGenerationAction.SUPERCLASS_TEMPLATE);
+        standardTemplates.put(
+                STANDARD_CLIENT_SUPERCLASS,
+                ClientClassGenerationAction.SUPERCLASS_TEMPLATE);
+        standardTemplates.put(
+                STANDARD_SERVER_SUBCLASS,
+                ClassGenerationAction.SUBCLASS_TEMPLATE);
+        standardTemplates.put(
+                STANDARD_CLIENT_SUBCLASS,
+                ClientClassGenerationAction.SUBCLASS_TEMPLATE);
 
-        updateCustomTemplates(getTemplateDomain(application));
+        standardTemplates1_1 = new HashMap<String, String>();
+        standardTemplates1_1.put(
+                STANDARD_SERVER_SUPERCLASS,
+                ClassGenerationAction1_1.SUPERCLASS_TEMPLATE);
+        standardTemplates1_1.put(
+                STANDARD_CLIENT_SUPERCLASS,
+                ClientClassGenerationAction.SUPERCLASS_TEMPLATE);
+        standardTemplates1_1.put(
+                STANDARD_SERVER_SUBCLASS,
+                ClassGenerationAction1_1.SUBCLASS_TEMPLATE);
+        standardTemplates1_1.put(
+                STANDARD_CLIENT_SUBCLASS,
+                ClientClassGenerationAction.SUBCLASS_TEMPLATE);
     }
 
     /**
      * Updates custom templates from preferences.
      */
     public void updateCustomTemplates(Domain preferenceDomain) {
-        Map templates = preferenceDomain.getDetailsMap(FSPath.class);
-        this.customTemplates = new HashMap(templates.size(), 1);
-        Iterator it = templates.entrySet().iterator();
-        while (it.hasNext()) {
-            Map.Entry entry = (Map.Entry) it.next();
+        Map<String, FSPath> templates = preferenceDomain.getDetailsMap(FSPath.class);
+        this.customTemplates = new HashMap<String, String>(templates.size(), 1);
 
+        for (Map.Entry<String, FSPath> entry : templates.entrySet()) {
             FSPath path = (FSPath) entry.getValue();
             customTemplates.put(entry.getKey(), path.getPath());
         }
     }
 
-    public String getTemplatePath(String name) {
+    public String getTemplatePath(String name, String version) {
         Object value = customTemplates.get(name);
         if (value != null) {
             return value.toString();
         }
 
-        value = standardSuperclassTemplates.get(name);
-
-        if (value != null) {
-            return value.toString();
+        Map<String, String> templates;
+        if (ClassGenerator.VERSION_1_1.equals(version)) {
+            templates = standardTemplates1_1;
+        }
+        else {
+            templates = standardTemplates;
         }
 
-        value = standardSubclassTemplates.get(name);
+        value = templates.get(name);
         return value != null ? value.toString() : null;
     }
 
-    public Map getCustomTemplates() {
+    public Map<String, String> getCustomTemplates() {
         return customTemplates;
     }
 
-    public Map getStandardSubclassTemplates() {
+    public List<String> getStandardSubclassTemplates() {
         return standardSubclassTemplates;
     }
 
-    public Map getStandardSuperclassTemplates() {
+    public List<String> getStandardSuperclassTemplates() {
         return standardSuperclassTemplates;
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClientModeController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClientModeController.java?rev=601116&r1=601115&r2=601116&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClientModeController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClientModeController.java
Tue Dec  4 14:23:44 2007
@@ -20,6 +20,8 @@
 package org.apache.cayenne.modeler.dialog.codegen;
 
 import org.apache.commons.collections.Predicate;
+import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.ClientClassGenerationAction;
 import org.apache.cayenne.gen.DefaultClassGenerator;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.modeler.pref.DataMapDefaults;
@@ -70,14 +72,9 @@
         return prefs;
     }
 
-    public DefaultClassGenerator createGenerator() {
-        DefaultClassGenerator generator = super.createGenerator();
-
-        if (generator != null) {
-            generator.setClient(true);
-        }
-
-        return generator;
+    @Override
+    protected ClassGenerationAction newGenerator() {
+        return new ClientClassGenerationAction();
     }
 
     public Predicate getDefaultEntityFilter() {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorController.java?rev=601116&r1=601115&r2=601116&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorController.java
Tue Dec  4 14:23:44 2007
@@ -23,12 +23,12 @@
 
 import javax.swing.JOptionPane;
 
-import org.apache.commons.collections.Predicate;
-import org.apache.commons.collections.PredicateUtils;
-import org.apache.cayenne.gen.DefaultClassGenerator;
+import org.apache.cayenne.gen.ClassGenerationAction;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.modeler.util.CayenneController;
 import org.apache.cayenne.swing.BindingBuilder;
+import org.apache.commons.collections.Predicate;
+import org.apache.commons.collections.PredicateUtils;
 
 /**
  * A controller for the class generator dialog.
@@ -118,7 +118,7 @@
     }
 
     public void generateAction() {
-        DefaultClassGenerator generator = generatorSelector.getGenerator();
+        ClassGenerationAction generator = generatorSelector.getGenerator();
 
         if (generator != null) {
             try {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorControllerBase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorControllerBase.java?rev=601116&r1=601115&r2=601116&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorControllerBase.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorControllerBase.java
Tue Dec  4 14:23:44 2007
@@ -105,8 +105,8 @@
         return modified;
     }
 
-    public List getSelectedEntities() {
-        List selected = new ArrayList(selectedEntities.size());
+    public List<ObjEntity> getSelectedEntities() {
+        List<ObjEntity> selected = new ArrayList<ObjEntity>(selectedEntities.size());
 
         Iterator it = entities.iterator();
         while (it.hasNext()) {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java?rev=601116&r1=601115&r2=601116&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java
Tue Dec  4 14:23:44 2007
@@ -28,8 +28,10 @@
 
 import javax.swing.DefaultComboBoxModel;
 
+import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.ClassGenerationAction1_1;
 import org.apache.cayenne.gen.ClassGenerator;
-import org.apache.cayenne.gen.DefaultClassGenerator;
+import org.apache.cayenne.gen.ClassGeneratorMode;
 import org.apache.cayenne.modeler.CodeTemplateManager;
 import org.apache.cayenne.modeler.dialog.pref.PreferenceDialog;
 import org.apache.cayenne.modeler.pref.DataMapDefaults;
@@ -51,7 +53,7 @@
     static final String DATA_MAP_MODE_LABEL = "One run per DataMap";
     static final String ENTITY_MODE_LABEL = "One run per each selected Entity";
 
-    static final Map modesByLabel = new HashMap();
+    static final Map<String, String> modesByLabel = new HashMap<String, String>();
     static {
         modesByLabel.put(DATA_MAP_MODE_LABEL, MODE_DATAMAP);
         modesByLabel.put(ENTITY_MODE_LABEL, MODE_ENTITY);
@@ -72,7 +74,7 @@
         view.getGenerationMode().setModel(new DefaultComboBoxModel(modeChoices));
 
         Object[] versionChoices = new Object[] {
-                ClassGenerator.VERSION_1_1, ClassGenerator.VERSION_1_2
+                ClassGenerator.VERSION_1_2, ClassGenerator.VERSION_1_1
         };
         view.getGeneratorVersion().setModel(new DefaultComboBoxModel(versionChoices));
 
@@ -92,7 +94,7 @@
         }
 
         if (Util.isEmptyString(preferences.getProperty("version"))) {
-            preferences.setProperty("version", ClassGenerator.VERSION_1_1);
+            preferences.setProperty("version", ClassGenerator.VERSION_1_2);
         }
 
         if (Util.isEmptyString(preferences.getProperty("overwrite"))) {
@@ -171,20 +173,18 @@
     protected void updateTemplates() {
         this.templateManager = getApplication().getCodeTemplateManager();
 
-        List customTemplates = new ArrayList(templateManager
+        List<String> customTemplates = new ArrayList<String>(templateManager
                 .getCustomTemplates()
                 .keySet());
         Collections.sort(customTemplates);
 
-        List superTemplates = new ArrayList(templateManager
-                .getStandardSuperclassTemplates()
-                .keySet());
+        List<String> superTemplates = new ArrayList<String>(templateManager
+                .getStandardSuperclassTemplates());
         Collections.sort(superTemplates);
         superTemplates.addAll(customTemplates);
 
-        List subTemplates = new ArrayList(templateManager
-                .getStandardSubclassTemplates()
-                .keySet());
+        List<String> subTemplates = new ArrayList<String>(templateManager
+                .getStandardSubclassTemplates());
         Collections.sort(subTemplates);
         subTemplates.addAll(customTemplates);
 
@@ -206,29 +206,35 @@
         return view;
     }
 
-    public DefaultClassGenerator createGenerator() {
+    private String getVersion() {
+        return (String) view.getGeneratorVersion().getSelectedItem();
+    }
+
+    @Override
+    protected ClassGenerationAction newGenerator() {
+        return ClassGenerator.VERSION_1_1.equals(getVersion())
+                ? new ClassGenerationAction1_1()
+                : new ClassGenerationAction();
+    }
+
+    public ClassGenerationAction createGenerator() {
 
-        DefaultClassGenerator generator = super.createGenerator();
+        ClassGenerationAction generator = super.createGenerator();
 
         String mode = modesByLabel
                 .get(view.getGenerationMode().getSelectedItem())
                 .toString();
-        generator.setMode(mode);
+        generator.setMode(ClassGeneratorMode.valueOf(mode));
+        
+        String version = getVersion();
 
         String superKey = view.getSuperclassTemplate().getSelectedItem().toString();
-        String superTemplate = templateManager.getTemplatePath(superKey);
+        String superTemplate = templateManager.getTemplatePath(superKey, version);
         generator.setSuperTemplate(superTemplate);
 
         String subKey = view.getSubclassTemplate().getSelectedItem().toString();
-        String subTemplate = templateManager.getTemplatePath(subKey);
+        String subTemplate = templateManager.getTemplatePath(subKey, version);
         generator.setTemplate(subTemplate);
-
-        if (view.getGeneratorVersion().getSelectedItem() != null) {
-            generator.setVersionString(view
-                    .getGeneratorVersion()
-                    .getSelectedItem()
-                    .toString());
-        }
 
         generator.setOverwrite(view.getOverwrite().isSelected());
         generator.setUsePkgPath(view.getUsePackagePath().isSelected());

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java?rev=601116&r1=601115&r2=601116&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java
Tue Dec  4 14:23:44 2007
@@ -21,6 +21,8 @@
 
 import java.awt.Component;
 import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 
 import javax.swing.JButton;
@@ -28,8 +30,7 @@
 import javax.swing.JOptionPane;
 import javax.swing.JTextField;
 
-import org.apache.commons.collections.Predicate;
-import org.apache.cayenne.gen.DefaultClassGenerator;
+import org.apache.cayenne.gen.ClassGenerationAction;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
@@ -47,6 +48,7 @@
 import org.apache.cayenne.validation.SimpleValidationFailure;
 import org.apache.cayenne.validation.ValidationFailure;
 import org.apache.cayenne.validation.ValidationResult;
+import org.apache.commons.collections.Predicate;
 
 /**
  * A mode-specific part of the code generation dialog.
@@ -96,9 +98,16 @@
     protected abstract DataMapDefaults createDefaults();
 
     /**
+     * Creates an appropriate subclass of {@link ClassGenerationAction}, returning it in
+     * an unconfigured state. Configuration is performed by {@link #createGenerator()}
+     * method.
+     */
+    protected abstract ClassGenerationAction newGenerator();
+
+    /**
      * Creates a class generator for provided selections.
      */
-    public DefaultClassGenerator createGenerator() {
+    public ClassGenerationAction createGenerator() {
 
         File outputDir = getOutputDir();
 
@@ -125,14 +134,25 @@
             return null;
         }
 
-        DefaultClassGenerator generator = new DefaultClassGenerator(getParentController()
-                .getDataMap(), getParentController().getSelectedEntities());
+        // remove generic entities...
+        Collection<ObjEntity> entities = new ArrayList<ObjEntity>(getParentController()
+                .getSelectedEntities());
+        Iterator<ObjEntity> it = entities.iterator();
+        while (it.hasNext()) {
+            if (it.next().isGeneric()) {
+                it.remove();
+            }
+        }
+
+        ClassGenerationAction generator = newGenerator();
+        generator.setDataMap(getParentController().getDataMap());
+        generator.setEntities(entities);
 
         // configure encoding from preferences
         Domain generatorPrefs = Application
                 .getInstance()
                 .getPreferenceDomain()
-                .getSubdomain(DefaultClassGenerator.class);
+                .getSubdomain(ClassGenerationAction.class);
 
         PreferenceDetail detail = generatorPrefs.getDetail(
                 GeneralPreferences.ENCODING_PREFERENCE,

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java?rev=601116&r1=601115&r2=601116&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java
Tue Dec  4 14:23:44 2007
@@ -23,7 +23,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.cayenne.gen.DefaultClassGenerator;
+import org.apache.cayenne.gen.ClassGenerationAction;
 import org.apache.cayenne.modeler.util.CayenneController;
 import org.apache.cayenne.pref.PreferenceDetail;
 import org.apache.cayenne.swing.BindingBuilder;
@@ -108,7 +108,7 @@
         return (GeneratorController) controllers.get(name);
     }
 
-    public DefaultClassGenerator getGenerator() {
+    public ClassGenerationAction getGenerator() {
         GeneratorController modeController = getGeneratorController();
         return (modeController != null) ? modeController.createGenerator() : null;
     }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java?rev=601116&r1=601115&r2=601116&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java
Tue Dec  4 14:23:44 2007
@@ -21,6 +21,7 @@
 
 import java.awt.Component;
 
+import org.apache.cayenne.gen.ClassGenerationAction;
 import org.apache.cayenne.modeler.pref.DataMapDefaults;
 import org.apache.cayenne.swing.BindingBuilder;
 
@@ -58,5 +59,10 @@
 
     public Component getView() {
         return view;
+    }
+    
+    @Override
+    protected ClassGenerationAction newGenerator() {
+        return new ClassGenerationAction();
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferences.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferences.java?rev=601116&r1=601115&r2=601116&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferences.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferences.java
Tue Dec  4 14:23:44 2007
@@ -21,7 +21,7 @@
 
 import java.awt.Component;
 
-import org.apache.cayenne.gen.DefaultClassGenerator;
+import org.apache.cayenne.gen.ClassGenerationAction;
 import org.apache.cayenne.modeler.util.CayenneController;
 import org.apache.cayenne.pref.CayennePreferenceEditor;
 import org.apache.cayenne.pref.CayennePreferenceService;
@@ -71,7 +71,7 @@
     protected void initBindings() {
         // init model objects
         Domain classGeneratorDomain = editor.editableInstance(getApplication()
-                .getPreferenceDomain()).getSubdomain(DefaultClassGenerator.class);
+                .getPreferenceDomain()).getSubdomain(ClassGenerationAction.class);
         this.classGeneratorPreferences = classGeneratorDomain
                 .getDetail(ENCODING_PREFERENCE, true);
 



Mime
View raw message