[Jiemamy-notify:1932] commit [3098] リファクタリング

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 4月 4日 (土) 15:50:37 JST


Revision: 3098
          http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=3098
Author:   j5ik2o
Date:     2009-04-04 15:50:37 +0900 (Sat, 04 Apr 2009)

Log Message:
-----------
リファクタリング

Modified Paths:
--------------
    charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/JpaImporter.java
    charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImpl.java


-------------- next part --------------
Modified: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/JpaImporter.java
===================================================================
--- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/JpaImporter.java	2009-04-04 06:50:16 UTC (rev 3097)
+++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/JpaImporter.java	2009-04-04 06:50:37 UTC (rev 3098)
@@ -15,6 +15,7 @@
 package org.jiemamy.composer.importer;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.List;
 
 import org.apache.commons.lang.Validate;
@@ -60,26 +61,30 @@
 		Validate.notEmpty(config.getIgnoreEntityClassNamePatterns());
 		
 		EntityMetaReaderContext context = new EntityMetaReaderContext();
+		EntityMetaReader entityMetaReader = new EntityMetaReaderImpl(context);
 		
-		List<File> classPathFiles = CollectionsUtil.newArrayList();
-		for (String classPathDir : config.getClassPathDirs()) {
-			classPathFiles.add(new File(classPathDir));
-		}
-		context.setClassPathDirs(classPathFiles);
-		List<File> javaFileSrcDirs = CollectionsUtil.newArrayList();
-		for (String javaFileSrcDir : config.getJavaFileSrcDirs()) {
-			javaFileSrcDirs.add(new File(javaFileSrcDir));
-		}
-		context.setJavaFileSrcDirs(javaFileSrcDirs);
+		context.setClassPathDirs(toFiles(config.getClassPathDirs()));
+		context.setJavaFileSrcDirs(toFiles(config.getJavaFileSrcDirs()));
 		context.setPackageName(ClassUtil.concatName(config.getRootPackageName(), config.getEntityPackageName()));
-		
 		context.setJavaFileEncoding(config.getJavaFileEncoding());
 		
-		EntityMetaReader entityMetaReader = new EntityMetaReaderImpl(context);
-		List<EntityMeta> entityMetas = entityMetaReader.read();
-		for (EntityMeta em : entityMetas) {
-			logger.debug(LogMarker.DETAIL, em.toString());
+		try {
+			List<EntityMeta> entityMetas = entityMetaReader.read();
+			for (EntityMeta em : entityMetas) {
+				logger.debug(LogMarker.DETAIL, em.toString());
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
 		}
+		
 		return false;
 	}
+	
+	private List<File> toFiles(List<String> paths) {
+		List<File> result = CollectionsUtil.newArrayList();
+		for (String path : paths) {
+			result.add(new File(path));
+		}
+		return result;
+	}
 }

Modified: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImpl.java
===================================================================
--- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImpl.java	2009-04-04 06:50:16 UTC (rev 3097)
+++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImpl.java	2009-04-04 06:50:37 UTC (rev 3098)
@@ -18,16 +18,24 @@
  */
 package org.jiemamy.composer.importer.meta.impl;
 
+import java.io.File;
+import java.io.IOException;
 import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.lang.Validate;
 
 import org.jiemamy.composer.importer.meta.EntityMeta;
+import org.jiemamy.composer.importer.meta.EntityMetaFactory;
 import org.jiemamy.composer.importer.meta.EntityMetaReader;
 import org.jiemamy.composer.importer.meta.EntityMetaReaderContext;
+import org.jiemamy.composer.importer.utils.ClassLoaderUtil;
+import org.jiemamy.composer.importer.utils.ClassTraversal;
 import org.jiemamy.composer.importer.utils.CollectionsUtil;
+import org.jiemamy.composer.importer.utils.FileUtil;
+import org.jiemamy.composer.importer.utils.ClassTraversal.ClassHandler;
 
 /**
  * {@link EntityMetaReader}の実装クラス。
@@ -52,32 +60,37 @@
 		Validate.notEmpty(entityMetaReaderContext.getJavaFileSrcDirs());
 		Validate.notNull(entityMetaReaderContext.getJavaFileEncoding());
 		Validate.notNull(entityMetaReaderContext.getPackageName());
-		//	Validate.notNull(entityMetaReaderContext.getShortClassNamePattern());
-		Validate.notNull(entityMetaReaderContext.getIgnoreShortClassNamePattern());
-		
+		Validate.notNull(entityMetaReaderContext.getShortClassNamePatterns());
+		Validate.notNull(entityMetaReaderContext.getIgnoreShortClassNamePatterns());
 		this.entityMetaReaderContext = entityMetaReaderContext;
 	}
 	
-	public List<EntityMeta> read() {
-		List<EntityMeta> entityMetas = CollectionsUtil.newArrayList();
+	public List<EntityMeta> read() throws IOException {
+		final List<EntityMeta> entityMetas = CollectionsUtil.newArrayList();
 		final String entityFullPackageName = entityMetaReaderContext.getPackageName();
-		final List<Class<?>> classes = new ArrayList<Class<?>>();
 		List<URL> urlList = new ArrayList<URL>();
-//		for (File classPathDir : entityMetaReaderContext.getClassPathDirs()) {
-//			urlList.add(FileUtil.toURL(classPathDir));
-//			final URLClassLoader urlClassLoader = new URLClassLoader(urlList.toArray(new URL[1]));
-//			ClassTraversal.forEach(classPathDir, new ClassHandler() {
-//				
-//				public void processClass(String packageName, String shortClassName) {
-//					if (!packageName.equals(entityFullPackageName)) {
-//						return;
-//					}
-//					Class<?> clazz = ClassLoaderUtil.loadClass(urlClassLoader, packageName + "." + shortClassName);
-//					System.out.println(packageName + "." + shortClassName);
-//					classes.add(clazz);
-//				}
-//			});
-//		}
+		for (File classPathDir : entityMetaReaderContext.getClassPathDirs()) {
+			urlList.add(FileUtil.toURL(classPathDir));
+			final URLClassLoader urlClassLoader = new URLClassLoader(urlList.toArray(new URL[1]));
+			ClassTraversal.forEach(classPathDir, new ClassHandler() {
+				
+				public void processClass(String packageName, String shortClassName) {
+					if (!packageName.equals(entityFullPackageName)) {
+						return;
+					}
+					try {
+						Class<?> entityClass =
+								ClassLoaderUtil.loadClass(urlClassLoader, packageName + "." + shortClassName);
+						EntityMetaFactory factory = entityMetaReaderContext.getEntityMetaFactory();
+						EntityMeta entityMeta = factory.getEntityMeta(entityClass);
+						System.out.println(packageName + "." + shortClassName);
+						entityMetas.add(entityMeta);
+					} catch (ClassNotFoundException ignore) {
+						// ignore
+					}
+				}
+			});
+		}
 		
 		return entityMetas;
 	}



Jiemamy-notify メーリングリストの案内
Back to archive index