[Jiemamy-notify:2072] commit [3180] コメントから論理名を取得できるようにしました。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 4月 8日 (水) 12:54:20 JST


Revision: 3180
          http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=3180
Author:   j5ik2o
Date:     2009-04-08 12:54:20 +0900 (Wed, 08 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/EntityMeta.java
    charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMetaReader.java
    charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/PropertyMeta.java
    charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImpl.java
    charon/jiemamy-jpa-importer/trunk/src/test/java/example/entity/Depertment.java
    charon/jiemamy-jpa-importer/trunk/src/test/java/example/entity/Employee.java
    charon/jiemamy-jpa-importer/trunk/src/test/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImplTest.java

Added Paths:
-----------
    charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/ColumnUtil.java
    charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/DocletUnavailableException.java
    charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMetaUtil.java
    charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/PropertyMetaUtil.java
    charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDoclet.java
    charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDocletContext.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-07 22:53:51 UTC (rev 3179)
+++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/JpaImporter.java	2009-04-08 03:54:20 UTC (rev 3180)
@@ -25,6 +25,7 @@
 
 import org.jiemamy.composer.ImportException;
 import org.jiemamy.composer.Importer;
+import org.jiemamy.composer.importer.meta.DocletUnavailableException;
 import org.jiemamy.composer.importer.meta.EntityClassNotFoundException;
 import org.jiemamy.composer.importer.meta.EntityMeta;
 import org.jiemamy.composer.importer.meta.EntityMetaReader;
@@ -52,7 +53,7 @@
 	
 	private static final Logger LOG = LoggerFactory.getLogger(JpaImporter.class);
 	
-	private static final TableModelConverter DEFAULT_TABLE_CONVERTER = new DefaultTableModelConverter();
+	private static final TableModelConverter DEFALUT_TABLE_CONVETER = new DefaultTableModelConverter();
 	
 
 	public String getName() {
@@ -69,7 +70,7 @@
 		if (config.getTableModelConverter() != null) {
 			return config.getTableModelConverter();
 		}
-		return DEFAULT_TABLE_CONVERTER;
+		return DEFALUT_TABLE_CONVETER;
 	}
 	
 	public boolean importModel(RootModel rootModel, JpaImportConfig config) throws ImportException {
@@ -109,6 +110,8 @@
 			throw new ImportException(e);
 		} catch (EntityClassNotFoundException e) {
 			throw new ImportException(e);
+		} catch (DocletUnavailableException e) {
+			throw new ImportException(e);
 		}
 		return false;
 	}

Added: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/ColumnUtil.java
===================================================================
--- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/ColumnUtil.java	                        (rev 0)
+++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/ColumnUtil.java	2009-04-08 03:54:20 UTC (rev 3180)
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on Apr 5, 2009
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed 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.jiemamy.composer.importer.meta;
+
+/**
+ * カラムに関するユーティリティクラス。
+ * 
+ * @author j5ik2o
+ */
+public class ColumnUtil {
+	
+	/**
+	 * カラムのデータ型をフォーマットします。
+	 * <p>
+	 * カラムのデータ型に含まれる置換文字を置き換えます。
+	 * <ul>
+	 * <li>$l を長さで置き換えます。</li>
+	 * <li>$p を精度で置き換えます。</li>
+	 * <li>$s をスケールで置き換えます。</li>
+	 * </ul>
+	 * </p>
+	 * 
+	 * @param dataType カラムのデータ型
+	 * @param length 長さ
+	 * @param precision 精度
+	 * @param scale スケール
+	 * @return フォーマットされたカラムのデータ型
+	 */
+	public static String formatDataType(String dataType, int length, int precision, int scale) {
+		StringBuilder buf = new StringBuilder();
+		for (int i = 0; i < dataType.length(); i++) {
+			char c = dataType.charAt(i);
+			if (c == '$') {
+				i++;
+				if (i < dataType.length()) {
+					c = dataType.charAt(i);
+					switch (c) {
+						case 'l':
+							buf.append(length);
+							break;
+						case 'p':
+							buf.append(precision);
+							break;
+						case 's':
+							buf.append(scale);
+							break;
+						default:
+							buf.append('$');
+							buf.append(c);
+							break;
+					}
+				} else {
+					buf.append(c);
+				}
+			} else {
+				buf.append(c);
+			}
+		}
+		return buf.toString();
+	}
+	
+	/**
+	 * インスタンスを生成する。
+	 * 
+	 */
+	protected ColumnUtil() {
+	}
+}


Property changes on: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/ColumnUtil.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/DocletUnavailableException.java
===================================================================
--- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/DocletUnavailableException.java	                        (rev 0)
+++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/DocletUnavailableException.java	2009-04-08 03:54:20 UTC (rev 3180)
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on Apr 8, 2009
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed 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.jiemamy.composer.importer.meta;
+
+
+/**
+ * TODO for junichi
+ * 
+ * @author junichi
+ */
+public class DocletUnavailableException extends Exception {
+	
+}


Property changes on: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/DocletUnavailableException.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMeta.java
===================================================================
--- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMeta.java	2009-04-07 22:53:51 UTC (rev 3179)
+++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMeta.java	2009-04-08 03:54:20 UTC (rev 3180)
@@ -60,8 +60,21 @@
 	
 	private Map<String, Map<String, PropertyMeta>> mappedByPropertyMetas = CollectionsUtil.newHashMap();
 	
+	private Map<String, Object> additionalInfo = CollectionsUtil.newHashMap();
+	
 
 	/**
+	 * 追加情報を追加する。
+	 * 
+	 * @param <T> 値の型
+	 * @param key キー
+	 * @param value 値
+	 */
+	public <T>void addAdditionalInfo(String key, T value) {
+		additionalInfo.put(key, value);
+	}
+	
+	/**
 	 * {@link PropertyMeta}を追加する。
 	 * 
 	 * @param propertyMeta {@link PropertyMeta}
@@ -99,6 +112,18 @@
 	}
 	
 	/**
+	 * 追加情報を取得する。
+	 * 
+	 * @param <T> 値の型
+	 * @param key キー
+	 * @return 値
+	 */
+	@SuppressWarnings("unchecked")
+	public <T>T getAdditionalInfo(String key) {
+		return (T) additionalInfo.get(key);
+	}
+	
+	/**
 	 * カラムに結びつく全てのプロパティメタデータの{@link Iterable}を返します。
 	 * 
 	 * @return カラムに結びつく全てのプロパティメタデータの{@link Iterable}

Modified: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMetaReader.java
===================================================================
--- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMetaReader.java	2009-04-07 22:53:51 UTC (rev 3179)
+++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMetaReader.java	2009-04-08 03:54:20 UTC (rev 3180)
@@ -35,6 +35,7 @@
 	 * @return {@link EntityMeta}のリスト
 	 * @throws IOException 入出力が失敗した場合
 	 * @throws EntityClassNotFoundException エンティティクラスがみつからなかった場合
+	 * @throws DocletUnavailableException docletが使えない場合
 	 */
-	List<EntityMeta> read() throws IOException, EntityClassNotFoundException;
+	List<EntityMeta> read() throws IOException, EntityClassNotFoundException, DocletUnavailableException;
 }

Added: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMetaUtil.java
===================================================================
--- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMetaUtil.java	                        (rev 0)
+++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMetaUtil.java	2009-04-08 03:54:20 UTC (rev 3180)
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on Apr 5, 2009
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed 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.jiemamy.composer.importer.meta;
+
+import org.jiemamy.exception.JiemamyError;
+
+/**
+ * {@link EntityMeta}に関するユーティリティクラスです。
+ * 
+ * @author taedium
+ */
+public class EntityMetaUtil {
+	
+	/** コメントのキー */
+	protected static String commentKey = EntityMetaUtil.class.getName() + "_comment";
+	
+
+	/**
+	 * コメントを取得する。
+	 * 
+	 * @param entityMeta エンティティメタデータ
+	 * @return コメント
+	 */
+	public static String getComment(EntityMeta entityMeta) {
+		return (String) entityMeta.getAdditionalInfo(commentKey);
+	}
+	
+	/**
+	 * コメントを設定する。
+	 * 
+	 * @param entityMeta エンティティメタデータ
+	 * @param comment コメント
+	 */
+	public static void setComment(EntityMeta entityMeta, String comment) {
+		entityMeta.addAdditionalInfo(commentKey, comment);
+	}
+	
+	/**
+	 * インスタンスを生成する。
+	 * 
+	 */
+	protected EntityMetaUtil() {
+		throw new JiemamyError("不到達ポイント");
+	}
+}


Property changes on: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/EntityMetaUtil.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/PropertyMeta.java
===================================================================
--- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/PropertyMeta.java	2009-04-07 22:53:51 UTC (rev 3179)
+++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/PropertyMeta.java	2009-04-08 03:54:20 UTC (rev 3180)
@@ -21,6 +21,7 @@
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import javax.persistence.EnumType;
 import javax.persistence.FetchType;
@@ -32,6 +33,7 @@
 import org.jiemamy.composer.importer.meta.generator.IdentityIdGeneratorMeta;
 import org.jiemamy.composer.importer.meta.generator.SequenceIdGeneratorMeta;
 import org.jiemamy.composer.importer.meta.generator.TableIdGeneratorMeta;
+import org.jiemamy.utils.CollectionsUtil;
 
 /**
  * JPA用のプロパティメタデータクラス。
@@ -97,8 +99,22 @@
 	/** {@link TableIdGeneratorMeta} */
 	private TableIdGeneratorMeta tableIdGenerator;
 	
+	/** 追加情報 */
+	private Map<String, Object> additionalInfo = CollectionsUtil.newHashMap();
+	
 
 	/**
+	 * 追加情報を追加する。
+	 * 
+	 * @param <T> 値の型
+	 * @param key 追加情報のキー
+	 * @param value 値
+	 */
+	public <T>void addAdditionalInfo(String key, T value) {
+		additionalInfo.put(key, value);
+	}
+	
+	/**
 	 * 結合カラムメタデータを追加する。
 	 * 
 	 * @param joinColumnMeta 結合カラムメタデータ
@@ -108,6 +124,18 @@
 	}
 	
 	/**
+	 * 追加情報を取得する。
+	 * 
+	 * @param <T> 値の型
+	 * @param key キー
+	 * @return 値
+	 */
+	@SuppressWarnings("unchecked")
+	public <T>T getAdditionalInfo(String key) {
+		return (T) additionalInfo.get(key);
+	}
+	
+	/**
 	 * カラムメタを取得する。
 	 * 
 	 * @return {@link ColumnMeta}

Added: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/PropertyMetaUtil.java
===================================================================
--- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/PropertyMetaUtil.java	                        (rev 0)
+++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/PropertyMetaUtil.java	2009-04-08 03:54:20 UTC (rev 3180)
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on Apr 5, 2009
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed 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.jiemamy.composer.importer.meta;
+
+/**
+ * {@link PropertyMeta}に関するユーティリティクラス。
+ * 
+ * @author j5ik2o
+ */
+public class PropertyMetaUtil {
+	
+	/** コメントのキー */
+	protected static String commentKey = PropertyMetaUtil.class.getName() + "_comment";
+	
+
+	/**
+	 * コメントを取得する。
+	 * 
+	 * @param propertyMeta プロパティメタデータ
+	 * @return コメント
+	 */
+	public static String getComment(PropertyMeta propertyMeta) {
+		return propertyMeta.getAdditionalInfo(commentKey);
+	}
+	
+	/**
+	 * コメントを設定する。
+	 * 
+	 * @param propertyMeta プロパティメタデータ
+	 * @param comment コメント
+	 */
+	public static void setComment(PropertyMeta propertyMeta, String comment) {
+		propertyMeta.addAdditionalInfo(commentKey, comment);
+	}
+	
+	/**
+	 * インスタンスを生成する。
+	 * 
+	 */
+	protected PropertyMetaUtil() {
+		
+	}
+}


Property changes on: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/PropertyMetaUtil.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDoclet.java
===================================================================
--- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDoclet.java	                        (rev 0)
+++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDoclet.java	2009-04-08 03:54:20 UTC (rev 3180)
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on Apr 5, 2009
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed 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.jiemamy.composer.importer.meta.impl;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.MappedSuperclass;
+
+import com.sun.javadoc.AnnotationDesc;
+import com.sun.javadoc.ClassDoc;
+import com.sun.javadoc.Doclet;
+import com.sun.javadoc.FieldDoc;
+import com.sun.javadoc.LanguageVersion;
+import com.sun.javadoc.RootDoc;
+
+import org.jiemamy.composer.importer.meta.EntityMeta;
+import org.jiemamy.composer.importer.meta.EntityMetaUtil;
+import org.jiemamy.composer.importer.meta.PropertyMeta;
+import org.jiemamy.composer.importer.meta.PropertyMetaUtil;
+
+/**
+ * エンティティとプロパティのコメントを抽出する{@link Doclet}。
+ * 
+ * @author j5ik2o
+ */
+ @ SuppressWarnings("restriction")
+public class CommentDoclet extends Doclet {
+	
+	/**
+	 * エンティティクラスのコメントを処理する。
+	 * 
+	 * @param classDoc {@link ClassDoc}
+	 * @param entityMeta エンティティメタデータ
+	 */
+	protected static void doEntityComment(ClassDoc classDoc, EntityMeta entityMeta) {
+		EntityMetaUtil.setComment(entityMeta, classDoc.commentText());
+		Map<String, FieldDoc> fieldDocMap = getFieldDocMap(classDoc);
+		for (PropertyMeta propertyMeta : entityMeta.getAllPropertyMeta()) {
+			if (fieldDocMap.containsKey(propertyMeta.getName())) {
+				FieldDoc fieldDoc = fieldDocMap.get(propertyMeta.getName());
+				doPropertyComment(fieldDoc, propertyMeta);
+			}
+		}
+	}
+	
+	/**
+	 * プロパティのコメントを処理します。
+	 * 
+	 * @param fieldDoc {@link FieldDoc}
+	 * @param propertyMeta プロパティメタデータ
+	 */
+	protected static void doPropertyComment(FieldDoc fieldDoc, PropertyMeta propertyMeta) {
+		PropertyMetaUtil.setComment(propertyMeta, fieldDoc.commentText());
+	}
+	
+	/**
+	 * フィールド名をキー、 {@link FieldDoc}を値とするマップを返します。
+	 * 
+	 * @param classDoc {@link ClassDoc}
+	 * @return フィールド名をキー、 {@link FieldDoc}を値とするマップ
+	 */
+	protected static Map<String, FieldDoc> getFieldDocMap(ClassDoc classDoc) {
+		Map<String, FieldDoc> fieldMap = new HashMap<String, FieldDoc>();
+		for (FieldDoc fieldDoc : classDoc.fields(false)) {
+			fieldMap.put(fieldDoc.name(), fieldDoc);
+		}
+		for (ClassDoc superclassDoc = classDoc.superclass(); !Object.class.getName().equals(
+				superclassDoc.qualifiedName()); superclassDoc = superclassDoc.superclass()) {
+			if (isMappedSuperclass(superclassDoc)) {
+				for (FieldDoc fieldDoc : superclassDoc.fields()) {
+					if (!fieldMap.containsKey(fieldDoc.name())) {
+						fieldMap.put(fieldDoc.name(), fieldDoc);
+					}
+				}
+			}
+		}
+		return fieldMap;
+	}
+	
+	/**
+	 * {@link MappedSuperclass}を表す場合{@code true}を返します。
+	 * 
+	 * @param classDoc {@link ClassDoc}
+	 * @return {@link MappedSuperclass}を表す場合{@code true}
+	 */
+	protected static boolean isMappedSuperclass(ClassDoc classDoc) {
+		for (AnnotationDesc desc : classDoc.annotations()) {
+			if (MappedSuperclass.class.getName().equals(desc.annotationType().qualifiedName())) {
+				return true;
+			}
+		}
+		return false;
+	}
+	
+	public static LanguageVersion languageVersion() {
+		return LanguageVersion.JAVA_1_5;
+	}
+	
+	public static boolean start(RootDoc rootDoc) {
+		List<EntityMeta> entityMetaList = CommentDocletContext.getEntityMetaList();
+		if (entityMetaList == null) {
+			throw new NullPointerException("entityMetaList");
+		}
+		for (EntityMeta entityMeta : entityMetaList) {
+			ClassDoc classDoc = rootDoc.classNamed(entityMeta.getEntityClass().getName());
+			if (classDoc == null) {
+				continue;
+			}
+			doEntityComment(classDoc, entityMeta);
+		}
+		return true;
+	}
+	
+}


Property changes on: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDoclet.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDocletContext.java
===================================================================
--- charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDocletContext.java	                        (rev 0)
+++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDocletContext.java	2009-04-08 03:54:20 UTC (rev 3180)
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on Apr 5, 2009
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed 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.jiemamy.composer.importer.meta.impl;
+
+import java.util.List;
+
+import org.jiemamy.composer.importer.meta.EntityMeta;
+import org.jiemamy.exception.JiemamyError;
+
+/**
+ * {@link CommentDoclet}のためのコンテキスト情報。
+ * 
+ * @author j5ik2o
+ */
+public class CommentDocletContext {
+	
+	/** エンティティメタリーダのリストを格納する{@link ThreadLocal} */
+	protected static ThreadLocal<List<EntityMeta>> threadLocal = new ThreadLocal<List<EntityMeta>>();
+	
+
+	/**
+	 * エンティティメタデータのリストを取得する。
+	 * 
+	 * @return エンティティメタデータのリストを設定する。
+	 */
+	public static List<EntityMeta> getEntityMetaList() {
+		return threadLocal.get();
+	}
+	
+	/**
+	 * エンティティメタデータのリストを設定します。
+	 * 
+	 * @param entityMetaList エンティティメタデータのリスト
+	 */
+	public static void setEntityMetaList(List<EntityMeta> entityMetaList) {
+		threadLocal.set(entityMetaList);
+	}
+	
+	private CommentDocletContext() {
+		throw new JiemamyError("不到達ポイント");
+	}
+	
+}


Property changes on: charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/CommentDocletContext.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

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-07 22:53:51 UTC (rev 3179)
+++ charon/jiemamy-jpa-importer/trunk/src/main/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImpl.java	2009-04-08 03:54:20 UTC (rev 3180)
@@ -29,10 +29,13 @@
 
 import javax.persistence.Entity;
 
+import com.sun.javadoc.Doclet;
+
 import org.apache.commons.lang.Validate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import org.jiemamy.composer.importer.meta.DocletUnavailableException;
 import org.jiemamy.composer.importer.meta.EntityClassNotFoundException;
 import org.jiemamy.composer.importer.meta.EntityMeta;
 import org.jiemamy.composer.importer.meta.EntityMetaFactory;
@@ -53,18 +56,30 @@
  * 
  * @author j5ik2o
  */
+ @ SuppressWarnings("restriction")
 public class EntityMetaReaderImpl implements EntityMetaReader {
 	
 	private static final Logger LOG = LoggerFactory.getLogger(EntityMetaReaderImpl.class);
 	
 	private final EntityMetaReaderContext entityMetaReaderContext;
 	
+	/** {@link Doclet}が使用可能な場合{@code true} */
+	protected static boolean docletAvailable;
+	static {
+		try {
+			Class.forName("com.sun.javadoc.Doclet"); // tools.jar
+			docletAvailable = true;
+		} catch (final Throwable ignore) {
+			LOG.warn("", ignore);
+		}
+	}
+	
 
 	/**
-	 * インスタンスを生成する。
-	 * 
-	 * @param entityMetaReaderContext コンテキスト
-	 */
+	* インスタンスを生成する。
+	* 
+	* @param entityMetaReaderContext コンテキスト
+	*/
 	public EntityMetaReaderImpl(EntityMetaReaderContext entityMetaReaderContext) {
 		Validate.notNull(entityMetaReaderContext);
 		Validate.notNull(entityMetaReaderContext.getClassPathDirs());
@@ -87,6 +102,35 @@
 		return urlClassLoader;
 	}
 	
+	/**
+	 * {@link Doclet}の引数の配列を作成します。
+	 * 
+	 * @return {@link Doclet}の引数の配列
+	 * @throws IOException 入出力が失敗した場合
+	 */
+	protected String[] createDocletArgs() throws IOException {
+		StringBuilder srcDirListBuf = new StringBuilder();
+		for (File dir : entityMetaReaderContext.getJavaSrcFileDirs()) {
+			srcDirListBuf.append(FileUtil.getCanonicalPath(dir));
+			srcDirListBuf.append(File.pathSeparator);
+		}
+		srcDirListBuf.setLength(srcDirListBuf.length() - File.pathSeparator.length());
+		
+		List<String> args = new ArrayList<String>();
+		args.add("-doclet");
+		args.add(CommentDoclet.class.getName());
+		args.add("-sourcepath");
+		args.add(srcDirListBuf.toString());
+		args.add("-encoding");
+		args.add(entityMetaReaderContext.getJavaFileEncoding());
+		args.add("-subpackages");
+		args.add(entityMetaReaderContext.getPackageName());
+		if (LOG.isDebugEnabled()) {
+			args.add("-verbose");
+		}
+		return args.toArray(new String[args.size()]);
+	}
+	
 	private boolean isIgnoreShortClassName(String shortClassName) {
 		if (entityMetaReaderContext.getIgnoreShortClassNamePatterns().isEmpty()) {
 			return false;
@@ -112,7 +156,7 @@
 		
 	}
 	
-	public List<EntityMeta> read() throws IOException, EntityClassNotFoundException {
+	public List<EntityMeta> read() throws IOException, EntityClassNotFoundException, DocletUnavailableException {
 		final EntityMetaFactory factory = entityMetaReaderContext.getEntityMetaFactory();
 		try {
 			final List<EntityMeta> entityMetas = CollectionsUtil.newArrayList();
@@ -166,8 +210,31 @@
 		}
 	}
 	
-	private void readComment(List<EntityMeta> entityMetas) {
-		// TODO Auto-generated method stub	
+	/**
+	 * コメントを読みコメントをメタデータに設定します。
+	 * 
+	 * @param entityMetaList エンティティメタデータのリスト
+	 * @throws DocletUnavailableException {@link Doclet}が使えない場合
+	 * @throws IOException 入出力が失敗した場合
+	 */
+	protected void readComment(List<EntityMeta> entityMetaList) throws DocletUnavailableException, IOException {
+		if (!docletAvailable) {
+			throw new DocletUnavailableException();
+		}
+		String[] args = createDocletArgs();
+		if (LOG.isDebugEnabled()) {
+			StringBuilder buf = new StringBuilder();
+			for (String arg : args) {
+				buf.append(arg).append(" ");
+			}
+			LOG.debug(String.format("Doclet Arguments = %s", buf.toString()));
+		}
+		CommentDocletContext.setEntityMetaList(entityMetaList);
+		try {
+			com.sun.tools.javadoc.Main.execute(args);
+		} finally {
+			CommentDocletContext.setEntityMetaList(null);
+		}
 	}
 	
 	private List<URL> toURLs(List<File> files) throws MalformedURLException {

Modified: charon/jiemamy-jpa-importer/trunk/src/test/java/example/entity/Depertment.java
===================================================================
--- charon/jiemamy-jpa-importer/trunk/src/test/java/example/entity/Depertment.java	2009-04-07 22:53:51 UTC (rev 3179)
+++ charon/jiemamy-jpa-importer/trunk/src/test/java/example/entity/Depertment.java	2009-04-08 03:54:20 UTC (rev 3180)
@@ -25,12 +25,14 @@
 /**
  * 部署
  * 
- * @author j5ik2oß
+ * @author j5ik2o
  */
 @Entity
 public class Depertment {
 	
-	/** 部署ID */
+	/** 
+	 * 部署ID
+	 */
 	@Id
 	private Long depertmentId;
 	

Modified: charon/jiemamy-jpa-importer/trunk/src/test/java/example/entity/Employee.java
===================================================================
--- charon/jiemamy-jpa-importer/trunk/src/test/java/example/entity/Employee.java	2009-04-07 22:53:51 UTC (rev 3179)
+++ charon/jiemamy-jpa-importer/trunk/src/test/java/example/entity/Employee.java	2009-04-08 03:54:20 UTC (rev 3180)
@@ -39,6 +39,7 @@
 	/** 従業員名 */
 	private String employeeName;
 	
+	/** 部署ID */
 	private Long depertmentId;
 	
 	/** バージョン */

Modified: charon/jiemamy-jpa-importer/trunk/src/test/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImplTest.java
===================================================================
--- charon/jiemamy-jpa-importer/trunk/src/test/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImplTest.java	2009-04-07 22:53:51 UTC (rev 3179)
+++ charon/jiemamy-jpa-importer/trunk/src/test/java/org/jiemamy/composer/importer/meta/impl/EntityMetaReaderImplTest.java	2009-04-08 03:54:20 UTC (rev 3180)
@@ -23,7 +23,6 @@
 import static org.junit.Assert.assertThat;
 
 import java.io.File;
-import java.io.IOException;
 import java.util.List;
 
 import org.junit.Test;
@@ -31,15 +30,13 @@
 import org.slf4j.LoggerFactory;
 
 import org.jiemamy.composer.importer.JpaImporterTestUtil;
-import org.jiemamy.composer.importer.meta.EntityClassNotFoundException;
 import org.jiemamy.composer.importer.meta.EntityMeta;
 import org.jiemamy.composer.importer.meta.EntityMetaReader;
 import org.jiemamy.composer.importer.meta.EntityMetaReaderContext;
-import org.jiemamy.composer.importer.meta.JoinColumnMeta;
-import org.jiemamy.composer.importer.meta.PropertyMeta;
+import org.jiemamy.composer.importer.meta.EntityMetaUtil;
+import org.jiemamy.composer.importer.meta.PropertyMetaUtil;
 import org.jiemamy.composer.importer.meta.RelationshipType;
 import org.jiemamy.utils.CollectionsUtil;
-import org.jiemamy.utils.PropertyNotFoundException;
 
 /**
  * {@link EntityMetaReaderImpl}のテスト。
@@ -55,76 +52,111 @@
 
 	/**
 	 * Test method for {@link org.jiemamy.composer.importer.meta.impl.EntityMetaReaderImpl#read()}.
-	 * @throws EntityClassNotFoundException 
-	 * @throws IOException 
-	 * @throws PropertyNotFoundException 
+	 * @throws Exception 例外
 	 */
 	@Test
-	public void testRead() throws IOException, EntityClassNotFoundException, PropertyNotFoundException {
+	public void testRead() throws Exception {
 		EntityMetaReaderContext context = new EntityMetaReaderContext();
 		context.setJavaFileEncoding("UTF-8");
 		List<File> classPathDirs = CollectionsUtil.newArrayList();
 		classPathDirs.add(new File(JpaImporterTestUtil.getBuildDirNoException()));
 		context.setClassPathDirs(classPathDirs);
 		context.setPackageName("example.entity");
+		context.setReadComment(true);
+		List<File> javaFileSrcDirs = CollectionsUtil.newArrayList();
+		javaFileSrcDirs.add(new File("src/test/java"));
+		context.setJavaSrcFileDirs(javaFileSrcDirs);
 		context.setEntityMetaFactory(new EntityMetaFactoryImpl(new TableMetaFactoryImpl(), new PropertyMetaFactoryImpl(
 				new ColumnMetaFactoryImpl())));
 		entityMetaReader = new EntityMetaReaderImpl(context);
 		List<EntityMeta> entityMetas = entityMetaReader.read();
-		for (EntityMeta em : entityMetas) {
-			LOG.debug("entityName = " + em.getName());
-			
-			if ("depertment".equals(em.getName())) {
-				assertThat(em.getPropertyMeta("depertmentId"), is(notNullValue()));
-				assertThat(em.getPropertyMeta("depertmentName"), is(notNullValue()));
-				assertThat(em.getPropertyMeta("version"), is(notNullValue()));
-				assertThat(em.getPropertyMeta("depertmentId").getName(), is(notNullValue()));
-				assertThat(em.getPropertyMeta("depertmentName").getName(), is(notNullValue()));
-				assertThat(em.getPropertyMeta("version").getName(), is(notNullValue()));
-				assertThat(em.getPropertyMeta("depertmentId").getName(), is("depertmentId"));
-				assertThat(em.getPropertyMeta("depertmentName").getName(), is("depertmentName"));
-				assertThat(em.getPropertyMeta("version").getName(), is("version"));
-				assertThat(em.getPropertyMeta("depertmentId").getColumnMeta().getName(), is("DEPERTMENT_ID"));
-				assertThat(em.getPropertyMeta("depertmentName").getColumnMeta().getName(), is("DEPERTMENT_NAME"));
-				assertThat(em.getPropertyMeta("version").getColumnMeta().getName(), is("VERSION"));
-				assertThat(em.getPropertyMeta("depertmentId").isId(), is(true));
-				assertThat(em.getPropertyMeta("version").isVersion(), is(true));
-			}
-			if ("employee".equals(em.getName())) {
-				assertThat(em.getPropertyMeta("employeeId"), is(notNullValue()));
-				assertThat(em.getPropertyMeta("employeeName"), is(notNullValue()));
-				assertThat(em.getPropertyMeta("version"), is(notNullValue()));
-				assertThat(em.getPropertyMeta("depertment"), is(notNullValue()));
-				assertThat(em.getPropertyMeta("depertment").isRelationship(), is(true));
-				assertThat(em.getPropertyMeta("depertment").getRelationshipClass(), is(notNullValue()));
-				assertThat(em.getPropertyMeta("depertment").getRelationshipType(), is(notNullValue()));
-				assertThat(em.getPropertyMeta("depertment").getRelationshipClass().getName(),
-						is("example.entity.Depertment"));
-				assertThat(em.getPropertyMeta("depertment").getRelationshipType(), is(RelationshipType.MANY_TO_ONE));
-				assertThat(em.getPropertyMeta("employeeId").getName(), is(notNullValue()));
-				assertThat(em.getPropertyMeta("employeeName").getName(), is(notNullValue()));
-				assertThat(em.getPropertyMeta("version").getName(), is(notNullValue()));
-				assertThat(em.getPropertyMeta("employeeId").getName(), is("employeeId"));
-				assertThat(em.getPropertyMeta("employeeName").getName(), is("employeeName"));
-				assertThat(em.getPropertyMeta("version").getName(), is("version"));
-				assertThat(em.getPropertyMeta("employeeId").getColumnMeta().getName(), is("EMPLOYEE_ID"));
-				assertThat(em.getPropertyMeta("employeeName").getColumnMeta().getName(), is("EMPLOYEE_NAME"));
-				assertThat(em.getPropertyMeta("version").getColumnMeta().getName(), is("VERSION"));
-				assertThat(em.getPropertyMeta("employeeId").isId(), is(true));
-				assertThat(em.getPropertyMeta("version").isVersion(), is(true));
-			}
-			
-			for (PropertyMeta pm : em.getAllPropertyMeta()) {
-				if (pm.isRelationship() == false) {
-					LOG.debug(String.format("propertyName = %s, columnName = %s", pm.getName(), pm.getColumnMeta()
-						.getName()));
-				}
-				for (JoinColumnMeta jcm : pm.getJoinColumnMetaList()) {
-					LOG.debug(String.format("name = %s, referencedColumnName = %s", jcm.getName(), jcm
-						.getReferencedColumnName()));
-				}
-			}
-			
-		}
+		
+		EntityMeta em = entityMetas.get(0);
+		// entity name null check
+		assertThat(em.getName(), is(notNullValue()));
+		// entity name equal check
+		assertThat(em.getName(), is("depertment"));
+		LOG.debug(em.toString());
+		
+		// property null check
+		assertThat(em.getPropertyMeta("depertmentId"), is(notNullValue()));
+		assertThat(em.getPropertyMeta("depertmentName"), is(notNullValue()));
+		assertThat(em.getPropertyMeta("version"), is(notNullValue()));
+		// comment null check
+		assertThat(EntityMetaUtil.getComment(em), is(notNullValue()));
+		assertThat(PropertyMetaUtil.getComment(em.getPropertyMeta("depertmentId")), is(notNullValue()));
+		assertThat(PropertyMetaUtil.getComment(em.getPropertyMeta("depertmentName")), is(notNullValue()));
+		assertThat(PropertyMetaUtil.getComment(em.getPropertyMeta("version")), is(notNullValue()));
+		// comment equal check
+		assertThat(EntityMetaUtil.getComment(em), is("部署"));
+		assertThat(PropertyMetaUtil.getComment(em.getPropertyMeta("depertmentId")), is("部署ID"));
+		assertThat(PropertyMetaUtil.getComment(em.getPropertyMeta("depertmentName")), is("部署名"));
+		assertThat(PropertyMetaUtil.getComment(em.getPropertyMeta("version")), is("バージョン"));
+		// property name null check
+		assertThat(em.getPropertyMeta("depertmentId").getName(), is(notNullValue()));
+		assertThat(em.getPropertyMeta("depertmentName").getName(), is(notNullValue()));
+		assertThat(em.getPropertyMeta("version").getName(), is(notNullValue()));
+		// property name equal check
+		assertThat(em.getPropertyMeta("depertmentId").getName(), is("depertmentId"));
+		assertThat(em.getPropertyMeta("depertmentName").getName(), is("depertmentName"));
+		assertThat(em.getPropertyMeta("version").getName(), is("version"));
+		// column name null check
+		assertThat(em.getPropertyMeta("depertmentId").getColumnMeta().getName(), is(notNullValue()));
+		assertThat(em.getPropertyMeta("depertmentName").getColumnMeta().getName(), is(notNullValue()));
+		assertThat(em.getPropertyMeta("version").getColumnMeta().getName(), is(notNullValue()));
+		// column name equal check
+		assertThat(em.getPropertyMeta("depertmentId").getColumnMeta().getName(), is("DEPERTMENT_ID"));
+		assertThat(em.getPropertyMeta("depertmentName").getColumnMeta().getName(), is("DEPERTMENT_NAME"));
+		assertThat(em.getPropertyMeta("version").getColumnMeta().getName(), is("VERSION"));
+		// property attribute check
+		assertThat(em.getPropertyMeta("depertmentId").isId(), is(true));
+		assertThat(em.getPropertyMeta("version").isVersion(), is(true));
+		em = entityMetas.get(1);
+		
+		// entity name null check
+		assertThat(em.getName(), is(notNullValue()));
+		// entity name equal check
+		assertThat(em.getName(), is("employee"));
+		LOG.debug(em.toString());
+		// property null check
+		assertThat(em.getPropertyMeta("employeeId"), is(notNullValue()));
+		assertThat(em.getPropertyMeta("employeeName"), is(notNullValue()));
+		assertThat(em.getPropertyMeta("version"), is(notNullValue()));
+		assertThat(em.getPropertyMeta("depertment"), is(notNullValue()));
+		// comment null check
+		assertThat(EntityMetaUtil.getComment(em), is("従業員"));
+		assertThat(PropertyMetaUtil.getComment(em.getPropertyMeta("employeeId")), is(notNullValue()));
+		assertThat(PropertyMetaUtil.getComment(em.getPropertyMeta("employeeName")), is(notNullValue()));
+		assertThat(PropertyMetaUtil.getComment(em.getPropertyMeta("version")), is(notNullValue()));
+		// comment equal check
+		assertThat(EntityMetaUtil.getComment(em), is("従業員"));
+		assertThat(PropertyMetaUtil.getComment(em.getPropertyMeta("employeeId")), is("従業員ID"));
+		assertThat(PropertyMetaUtil.getComment(em.getPropertyMeta("employeeName")), is("従業員名"));
+		assertThat(PropertyMetaUtil.getComment(em.getPropertyMeta("version")), is("バージョン"));
+		// property name null check
+		assertThat(em.getPropertyMeta("employeeId").getName(), is(notNullValue()));
+		assertThat(em.getPropertyMeta("employeeName").getName(), is(notNullValue()));
+		assertThat(em.getPropertyMeta("version").getName(), is(notNullValue()));
+		// property name equal check
+		assertThat(em.getPropertyMeta("employeeId").getName(), is("employeeId"));
+		assertThat(em.getPropertyMeta("employeeName").getName(), is("employeeName"));
+		assertThat(em.getPropertyMeta("version").getName(), is("version"));
+		// column name null check
+		assertThat(em.getPropertyMeta("employeeId").getColumnMeta().getName(), is(notNullValue()));
+		assertThat(em.getPropertyMeta("employeeName").getColumnMeta().getName(), is(notNullValue()));
+		assertThat(em.getPropertyMeta("version").getColumnMeta().getName(), is(notNullValue()));
+		// column name equal check
+		assertThat(em.getPropertyMeta("employeeId").getColumnMeta().getName(), is("EMPLOYEE_ID"));
+		assertThat(em.getPropertyMeta("employeeName").getColumnMeta().getName(), is("EMPLOYEE_NAME"));
+		assertThat(em.getPropertyMeta("version").getColumnMeta().getName(), is("VERSION"));
+		// property attribute check
+		assertThat(em.getPropertyMeta("employeeId").isId(), is(true));
+		assertThat(em.getPropertyMeta("version").isVersion(), is(true));
+		assertThat(em.getPropertyMeta("depertment").isRelationship(), is(true));
+		assertThat(em.getPropertyMeta("depertment").getRelationshipClass(), is(notNullValue()));
+		assertThat(em.getPropertyMeta("depertment").getRelationshipType(), is(notNullValue()));
+		assertThat(em.getPropertyMeta("depertment").getRelationshipClass().getName(), is("example.entity.Depertment"));
+		assertThat(em.getPropertyMeta("depertment").getRelationshipType(), is(RelationshipType.MANY_TO_ONE));
+		
 	}
 }



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