cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r602674 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen: ClassGenerationAction.java ClientClassGenerationAction.java EntityUtils.java GenerationMetadata.java
Date Sun, 09 Dec 2007 14:27:07 GMT
Author: aadamchik
Date: Sun Dec  9 06:27:06 2007
New Revision: 602674

URL: http://svn.apache.org/viewvc?rev=602674&view=rev
Log:
CAY-926 Refactoring class generator classes

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/GenerationMetadata.java
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/ClientClassGenerationAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.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=602674&r1=602673&r2=602674&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
Sun Dec  9 06:27:06 2007
@@ -128,6 +128,36 @@
         return ClassGenerationAction.SUPERCLASS_PREFIX;
     }
 
+    protected GenerationMetadata initContext(ObjEntity entity) {
+        StringUtils stringUtils = StringUtils.getInstance();
+        String fqnSubClass = entity.getClassName();
+        String fqnBaseClass = (entity.getSuperClassName() != null) ? entity
+                .getSuperClassName() : CayenneDataObject.class.getName();
+
+        String subPackageName = stringUtils.stripClass(fqnSubClass);
+        String superClassName = getSuperclassPrefix()
+                + stringUtils.stripPackageName(fqnSubClass);
+
+        String superPackageName = this.superPkg;
+        if (superPackageName == null) {
+            superPackageName = subPackageName;
+        }
+        String fqnSuperClass = superPackageName + "." + superClassName;
+
+        EntityUtils metadata = new EntityUtils(
+                dataMap,
+                entity,
+                fqnBaseClass,
+                fqnSuperClass,
+                fqnSubClass);
+
+        context.put("objEntity", entity);
+        context.put("stringUtils", StringUtils.getInstance());
+        context.put("entityUtils", metadata);
+        context.put("importUtils", new ImportUtils());
+        return metadata;
+    }
+
     /**
      * Runs class generation. Produces a pair of Java classes for each ObjEntity in the
      * map. This allows developers to use generated <b>subclass </b> for their
custom
@@ -137,57 +167,22 @@
      */
     protected void generateClassPairs() throws Exception {
 
-        StringUtils stringUtils = StringUtils.getInstance();
         Template superTemplate = superclassTemplate();
         Template classTemplate = subclassTemplate();
-        String superPrefix = getSuperclassPrefix();
 
         for (ObjEntity entity : entitiesForCurrentMode()) {
 
-            String fqnSubClass = entity.getClassName();
-            String fqnBaseClass = (entity.getSuperClassName() != null) ? entity
-                    .getSuperClassName() : CayenneDataObject.class.getName();
-
-            String subClassName = stringUtils.stripPackageName(fqnSubClass);
-            String subPackageName = stringUtils.stripClass(fqnSubClass);
-
-            String superClassName = superPrefix
-                    + stringUtils.stripPackageName(fqnSubClass);
-
-            String superPackageName = this.superPkg;
-            if (superPackageName == null) {
-                superPackageName = subPackageName;
-            }
-            String fqnSuperClass = superPackageName + "." + superClassName;
-
-            Writer superOut = openWriter(superPackageName, superClassName);
+            GenerationMetadata metadata = initContext(entity);
+            Writer superOut = openWriter(metadata.getSuperPackageName(), metadata
+                    .getSuperClassName());
             if (superOut != null) {
-                context.put("objEntity", entity);
-                context.put("stringUtils", StringUtils.getInstance());
-                context.put("entityUtils", new EntityUtils(
-                        dataMap,
-                        entity,
-                        fqnBaseClass,
-                        fqnSuperClass,
-                        fqnSubClass));
-                context.put("importUtils", new ImportUtils());
-
                 superTemplate.merge(context, superOut);
                 superOut.close();
             }
 
-            Writer mainOut = openWriter(subPackageName, subClassName);
+            Writer mainOut = openWriter(metadata.getSubPackageName(), metadata
+                    .getSubClassName());
             if (mainOut != null) {
-                context.put("objEntity", entity);
-                context.put("stringUtils", StringUtils.getInstance());
-                context.put("entityUtils", new EntityUtils(
-                        dataMap,
-                        entity,
-                        fqnBaseClass,
-                        fqnSuperClass,
-                        fqnSubClass));
-                context.put("importUtils", new ImportUtils());
-
                 classTemplate.merge(context, mainOut);
                 mainOut.close();
             }
@@ -200,37 +195,13 @@
     protected void generateSingleClasses() throws Exception {
 
         Template classTemplate = singleClassTemplate();
-        String superPrefix = getSuperclassPrefix();
 
         for (ObjEntity entity : entitiesForCurrentMode()) {
 
-            String fqnSubClass = entity.getClassName();
-            String fqnBaseClass = (null != entity.getSuperClassName()) ? entity
-                    .getSuperClassName() : CayenneDataObject.class.getName();
-
-            StringUtils stringUtils = StringUtils.getInstance();
-
-            String subClassName = stringUtils.stripPackageName(fqnSubClass);
-            String subPackageName = stringUtils.stripClass(fqnSubClass);
-
-            String superClassName = superPrefix
-                    + stringUtils.stripPackageName(fqnSubClass);
-
-            String superPackageName = this.superPkg;
-            String fqnSuperClass = superPackageName + "." + superClassName;
-
-            Writer out = openWriter(subPackageName, subClassName);
+            GenerationMetadata metadata = initContext(entity);
+            Writer out = openWriter(metadata.getSubPackageName(), metadata
+                    .getSubClassName());
             if (out != null) {
-                context.put("objEntity", entity);
-                context.put("stringUtils", StringUtils.getInstance());
-                context.put("entityUtils", new EntityUtils(
-                        dataMap,
-                        entity,
-                        fqnBaseClass,
-                        fqnSuperClass,
-                        fqnSubClass));
-                context.put("importUtils", new ImportUtils());
-
                 classTemplate.merge(context, out);
                 out.close();
             }

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=602674&r1=602673&r2=602674&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
Sun Dec  9 06:27:06 2007
@@ -18,11 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.gen;
 
-import java.io.Writer;
-
 import org.apache.cayenne.PersistentObject;
 import org.apache.cayenne.map.ObjEntity;
-import org.apache.velocity.Template;
 
 /**
  * @since 3.0
@@ -50,73 +47,40 @@
     }
 
     @Override
-    protected void generateSingleClasses() throws Exception {
-        throw new IllegalStateException(
-                "Single classes generation is not supported for the client.");
-    }
+    protected GenerationMetadata initContext(ObjEntity entity) {
+        StringUtils stringUtils = StringUtils.getInstance();
 
-    @Override
-    protected void generateClassPairs() throws Exception {
+        // use client name, and if not specified use regular class name
+        String fqnSubClass = entity.getClientClassName();
+        if (fqnSubClass == null) {
+            fqnSubClass = entity.getClassName();
+        }
 
-        Template superTemplate = superclassTemplate();
-        Template classTemplate = subclassTemplate();
-        String superPrefix = getSuperclassPrefix();
-
-        for (ObjEntity entity : entitiesForCurrentMode()) {
-
-            // use client name, and if not specified use regular class name
-            String fqnSubClass = entity.getClientClassName();
-            if (fqnSubClass == null) {
-                fqnSubClass = entity.getClassName();
-            }
-
-            // use PersistentObject instead of CayenneDataObject as base ...
-            String fqnBaseClass = (entity.getClientSuperClassName() != null) ? entity
-                    .getClientSuperClassName() : PersistentObject.class.getName();
-
-            StringUtils stringUtils = StringUtils.getInstance();
-
-            String subClassName = stringUtils.stripPackageName(fqnSubClass);
-            String subPackageName = stringUtils.stripClass(fqnSubClass);
-
-            String superClassName = superPrefix
-                    + stringUtils.stripPackageName(fqnSubClass);
-
-            String superPackageName = this.superPkg;
-            String fqnSuperClass = superPackageName + "." + superClassName;
-
-            Writer superOut = openWriter(superPackageName, superClassName);
-
-            if (superOut != null) {
-                context.put("objEntity", entity);
-                context.put("stringUtils", StringUtils.getInstance());
-                context.put("entityUtils", new EntityUtils(
-                        dataMap,
-                        entity,
-                        fqnBaseClass,
-                        fqnSuperClass,
-                        fqnSubClass));
-                context.put("importUtils", new ImportUtils());
-
-                superTemplate.merge(context, superOut);
-                superOut.close();
-            }
-
-            Writer mainOut = openWriter(subPackageName, subClassName);
-            if (mainOut != null) {
-                context.put("objEntity", entity);
-                context.put("stringUtils", StringUtils.getInstance());
-                context.put("entityUtils", new EntityUtils(
-                        dataMap,
-                        entity,
-                        fqnBaseClass,
-                        fqnSuperClass,
-                        fqnSubClass));
-                context.put("importUtils", new ImportUtils());
-
-                classTemplate.merge(context, mainOut);
-                mainOut.close();
-            }
+        // use PersistentObject instead of CayenneDataObject as base ...
+        String fqnBaseClass = (entity.getClientSuperClassName() != null) ? entity
+                .getClientSuperClassName() : PersistentObject.class.getName();
+
+        String subPackageName = stringUtils.stripClass(fqnSubClass);
+        String superClassName = getSuperclassPrefix()
+                + stringUtils.stripPackageName(fqnSubClass);
+
+        String superPackageName = this.superPkg;
+        if (superPackageName == null) {
+            superPackageName = subPackageName;
         }
+        String fqnSuperClass = superPackageName + "." + superClassName;
+
+        EntityUtils metadata = new EntityUtils(
+                dataMap,
+                entity,
+                fqnBaseClass,
+                fqnSuperClass,
+                fqnSubClass);
+
+        context.put("objEntity", entity);
+        context.put("stringUtils", StringUtils.getInstance());
+        context.put("entityUtils", metadata);
+        context.put("importUtils", new ImportUtils());
+        return metadata;
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java?rev=602674&r1=602673&r2=602674&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java
Sun Dec  9 06:27:06 2007
@@ -31,7 +31,7 @@
  * @since 1.2
  * @author Mike Kienenberger
  */
-public class EntityUtils {
+public class EntityUtils implements GenerationMetadata {
 
     // template substitution values
     protected String subClassName;

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/GenerationMetadata.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/GenerationMetadata.java?rev=602674&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/GenerationMetadata.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/GenerationMetadata.java
Sun Dec  9 06:27:06 2007
@@ -0,0 +1,63 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.gen;
+
+/**
+ * Represents basic metadata associated with a code generation execution.
+ * 
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+public interface GenerationMetadata {
+
+    /**
+     * Returns class name (without a package) of the sub class associated with this
+     * generator.
+     */
+    String getSubClassName();
+
+    /**
+     * Returns the super class (without a package) of the data object class associated
+     * with this generator
+     */
+    String getSuperClassName();
+
+    /**
+     * Returns the base class (without a package) of the data object class associated with
+     * this generator. Class name must not include a package.
+     */
+    String getBaseClassName();
+
+    /**
+     * Returns Java package name of the class associated with this generator.
+     */
+    String getSubPackageName();
+
+    /**
+     * Returns <code>superPackageName</code> property that defines a superclass's
+     * package name.
+     */
+    String getSuperPackageName();
+
+    /**
+     * Returns <code>basePackageName</code> property that defines a baseclass's
+     * (superclass superclass) package name.
+     */
+    String getBasePackageName();
+}



Mime
View raw message