cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r600349 - in /cayenne/main/trunk/framework: cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/ maven-cayenne-plugin/ maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/
Date Sun, 02 Dec 2007 17:47:32 GMT
Author: aadamchik
Date: Sun Dec  2 09:47:31 2007
New Revision: 600349

URL: http://svn.apache.org/viewvc?rev=600349&view=rev
Log:
CAY-926 Refactoring class generator classes
(replacing CayenneGeneratorUtil with CayenneGeneratorMapLoader to streamline generation flow:
refactopring - split into loader and filter actions)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorEntityFilterAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMapLoaderAction.java
Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGenerationMapLoader.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
    cayenne/main/trunk/framework/maven-cayenne-plugin/pom.xml
    cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorEntityFilterAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorEntityFilterAction.java?rev=600349&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorEntityFilterAction.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorEntityFilterAction.java
Sun Dec  2 09:47:31 2007
@@ -0,0 +1,73 @@
+/*****************************************************************
+ *   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.tools;
+
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.ObjEntity;
+
+/**
+ * Performs entity filtering to build a collection of entities that should be used in
+ * class generation.
+ * 
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+class CayenneGeneratorEntityFilterAction {
+
+    private NamePatternMatcher nameFilter;
+    private boolean client;
+
+    Collection<ObjEntity> getFilteredEntities(DataMap mainDataMap)
+            throws MalformedURLException {
+
+        List<ObjEntity> entities = new ArrayList<ObjEntity>(mainDataMap.getObjEntities());
+
+        // filter out excluded entities...
+        Iterator<ObjEntity> it = entities.iterator();
+
+        while (it.hasNext()) {
+            ObjEntity e = it.next();
+            if (e.isGeneric()) {
+                it.remove();
+            }
+            else if (client && !e.isClientAllowed()) {
+                it.remove();
+            }
+            else if (!nameFilter.isIncluded(e.getName())) {
+                it.remove();
+            }
+        }
+
+        return entities;
+    }
+
+    void setClient(boolean client) {
+        this.client = client;
+    }
+
+    public void setNameFilter(NamePatternMatcher nameFilter) {
+        this.nameFilter = nameFilter;
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMapLoaderAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMapLoaderAction.java?rev=600349&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMapLoaderAction.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMapLoaderAction.java
Sun Dec  2 09:47:31 2007
@@ -0,0 +1,80 @@
+/*****************************************************************
+ *   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.tools;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.map.MapLoader;
+import org.xml.sax.InputSource;
+
+/**
+ * Loads a DataMap and a shared entity namespace.
+ * 
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+class CayenneGeneratorMapLoaderAction {
+
+    private File mainDataMapFile;
+    private File[] additionalDataMapFiles;
+    private DataMap mainDataMap;
+
+    DataMap getMainDataMap() throws MalformedURLException {
+        if (mainDataMap == null) {
+            MapLoader mapLoader = new MapLoader();
+
+            DataMap mainDataMap = loadDataMap(mapLoader, mainDataMapFile);
+
+            if (additionalDataMapFiles != null) {
+
+                EntityResolver entityResolver = new EntityResolver();
+                entityResolver.addDataMap(mainDataMap);
+                mainDataMap.setNamespace(entityResolver);
+
+                for (int i = 0; i < additionalDataMapFiles.length; i++) {
+
+                    DataMap dataMap = loadDataMap(mapLoader, additionalDataMapFiles[i]);
+                    entityResolver.addDataMap(dataMap);
+                    dataMap.setNamespace(entityResolver);
+                }
+            }
+
+            this.mainDataMap = mainDataMap;
+        }
+
+        return mainDataMap;
+    }
+
+    protected DataMap loadDataMap(MapLoader mapLoader, File dataMapFile)
+            throws MalformedURLException {
+        InputSource in = new InputSource(dataMapFile.toURL().toString());
+        return mapLoader.loadDataMap(in);
+    }
+
+    void setMainDataMapFile(File mainDataMapFile) {
+        this.mainDataMapFile = mainDataMapFile;
+    }
+
+    void setAdditionalDataMapFiles(File[] additionalDataMapFiles) {
+        this.additionalDataMapFiles = additionalDataMapFiles;
+    }
+}

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=600349&r1=600348&r2=600349&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
Sun Dec  2 09:47:31 2007
@@ -70,18 +70,23 @@
         }
 
         ILog logger = new AntTaskLogger(this);
-        CayenneGenerationMapLoader mapLoader = new CayenneGenerationMapLoader();
-        mapLoader.setNameFilter(new NamePatternMatcher(
+        CayenneGeneratorMapLoaderAction loadAction = new CayenneGeneratorMapLoaderAction();
+
+        loadAction.setMainDataMapFile(map);
+        loadAction.setAdditionalDataMapFiles(additionalMaps);
+
+        CayenneGeneratorEntityFilterAction filterAction = new CayenneGeneratorEntityFilterAction();
+        filterAction.setClient(generator.isClient());
+        filterAction.setNameFilter(new NamePatternMatcher(
                 logger,
                 includeEntitiesPattern,
                 excludeEntitiesPattern));
-        mapLoader.setMainDataMapFile(map);
-        mapLoader.setAdditionalDataMapFiles(additionalMaps);
 
         try {
             generator.setTimestamp(map.lastModified());
-            generator.setDataMap(mapLoader.getMainDataMap());
-            generator.setObjEntities((List<ObjEntity>) mapLoader.getFilteredEntities());
+            generator.setDataMap(loadAction.getMainDataMap());
+            generator.setObjEntities((List<ObjEntity>) filterAction
+                    .getFilteredEntities(loadAction.getMainDataMap()));
             generator.validateAttributes();
             generator.execute();
         }

Modified: cayenne/main/trunk/framework/maven-cayenne-plugin/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/maven-cayenne-plugin/pom.xml?rev=600349&r1=600348&r2=600349&view=diff
==============================================================================
--- cayenne/main/trunk/framework/maven-cayenne-plugin/pom.xml (original)
+++ cayenne/main/trunk/framework/maven-cayenne-plugin/pom.xml Sun Dec  2 09:47:31 2007
@@ -95,5 +95,17 @@
 			<scope>compile</scope>
 		</dependency>
 	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.5</source>
+					<target>1.5</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
 </project>
 

Modified: cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java?rev=600349&r1=600348&r2=600349&view=diff
==============================================================================
--- cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
(original)
+++ cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
Sun Dec  2 09:47:31 2007
@@ -208,18 +208,21 @@
 		generator = createGenerator();
 
 		ILog logger = new MavenLogger(this);
-		CayenneGenerationMapLoader mapLoader = new CayenneGenerationMapLoader();
-		mapLoader.setNameFilter(new NamePatternMatcher(logger,
+		CayenneGeneratorMapLoaderAction loaderAction = new CayenneGeneratorMapLoaderAction();
+		loaderAction.setMainDataMapFile(map);
+
+		CayenneGeneratorEntityFilterAction filterAction = new CayenneGeneratorEntityFilterAction();
+		filterAction.setClient(client);
+		filterAction.setNameFilter(new NamePatternMatcher(logger,
 				includeEntitiesPattern, excludeEntitiesPattern));
-		mapLoader.setMainDataMapFile(map);
 
 		try {
-			mapLoader.setAdditionalDataMapFiles(convertAdditionalDataMaps());
+			loaderAction.setAdditionalDataMapFiles(convertAdditionalDataMaps());
 
 			generator.setTimestamp(map.lastModified());
-			generator.setDataMap(mapLoader.getMainDataMap());
-			generator.setObjEntities((List<ObjEntity>) mapLoader
-					.getFilteredEntities());
+			generator.setDataMap(loaderAction.getMainDataMap());
+			generator.setObjEntities((List<ObjEntity>) filterAction
+					.getFilteredEntities(loaderAction.getMainDataMap()));
 			generator.validateAttributes();
 			generator.execute();
 		} catch (Exception e) {



Mime
View raw message