[Jiemamy-notify:1353] commit [2609] ModelAdapterのコンバータも実装。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 2月 3日 (火) 08:10:47 JST


Revision: 2609
          http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2609
Author:   daisuke_m
Date:     2009-02-03 08:10:47 +0900 (Tue, 03 Feb 2009)

Log Message:
-----------
ModelAdapterのコンバータも実装。

Modified Paths:
--------------
    artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/SerializationTest.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/EqualsUtil.java


-------------- next part --------------
Modified: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/SerializationTest.java
===================================================================
--- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/SerializationTest.java	2009-02-02 16:33:40 UTC (rev 2608)
+++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/SerializationTest.java	2009-02-02 23:10:47 UTC (rev 2609)
@@ -219,16 +219,14 @@
 		
 		// xml1 -> rootModel1
 		RootModel rootModel1 = convertXmlToRootModel(xml1, serializer1);
-		Collection<Problem> problems1 = validator.validate(rootModel1);
-		assertThat(problems1.size(), is(0)); // 一応バリデーションを行っておく
+		assertThat(validator.validate(rootModel1).size(), is(0)); // 一応バリデーションを行っておく
 		
 		// rootModel1 -> xml2
 		String xml2 = convertRootModelToXml(serializer2, rootModel1);
 		
 		// xml1 -> rootModel2
 		RootModel rootModel2 = convertXmlToRootModel(xml2, serializer2);
-		Collection<Problem> problems2 = validator.validate(rootModel2);
-		assertThat(problems2.size(), is(0)); // 一応バリデーションを行っておく
+		assertThat(validator.validate(rootModel2).size(), is(0)); // 一応バリデーションを行っておく
 		
 		// 参考のため、targetディレクトリに出力XMLを記録
 		FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this, "null")

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/EqualsUtil.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/EqualsUtil.java	2009-02-02 16:33:40 UTC (rev 2608)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/EqualsUtil.java	2009-02-02 23:10:47 UTC (rev 2609)
@@ -20,15 +20,20 @@
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 
 import org.apache.commons.lang.Validate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.jiemamy.Jiemamy;
+import org.jiemamy.exception.UnexpectedConditionError;
 import org.jiemamy.model.ElementReference;
 import org.jiemamy.model.LogicAdapter;
+import org.jiemamy.model.ModelAdapter;
 import org.jiemamy.model.attribute.ColumnRef;
 import org.jiemamy.model.datatype.DomainRef;
 import org.jiemamy.model.entity.TableRef;
@@ -36,6 +41,8 @@
 import org.jiemamy.utils.gtree.converter.ConverterDriver;
 import org.jiemamy.utils.gtree.converter.InterfaceBeanConverter;
 import org.jiemamy.utils.gtree.converter.ObjectConverter;
+import org.jiemamy.utils.gtree.model.Entry;
+import org.jiemamy.utils.gtree.model.Record;
 import org.jiemamy.utils.gtree.model.Terminal;
 import org.jiemamy.utils.gtree.model.Value;
 import org.jiemamy.utils.gtree.text.Emitter;
@@ -70,7 +77,16 @@
 		// コンバータを作る
 		ObjectConverter converter =
 				CachedObjectConverter.newInstance(Arrays.asList(new JiemamyPropertyConverter(),
-						new LogicAdapterConverter(), new ReferenceConverter(), new InterfaceBeanConverter()));
+						new AdapterConverter(), new ReferenceConverter(), new ConverterDriver() {
+							
+							public Value convert(Object object, ObjectConverter converter) {
+								if (object.getClass().getName().endsWith("DiagramPresentationsImpl")) {
+									return Terminal.of("");
+								}
+								return null;
+							}
+							
+						}, new InterfaceBeanConverter()));
 		
 		// コンバータでモデルをGeneric Treeに変換
 		Value leftGenericTree = converter.convert(left);
@@ -111,7 +127,7 @@
 		
 	}
 	
-	private static class LogicAdapterConverter implements ConverterDriver {
+	private static class AdapterConverter implements ConverterDriver {
 		
 		/**
 		 * {@inheritDoc}
@@ -119,7 +135,23 @@
 		public Value convert(Object object, ObjectConverter converter) {
 			if (object.getClass().getAnnotation(LogicAdapter.class) != null) {
 				return Terminal.of("<LogicAdapter>");
+			} else if (object.getClass().getAnnotation(ModelAdapter.class) != null) {
+				List<Entry> entries = new ArrayList<Entry>();
+				for (Field f : object.getClass().getDeclaredFields()) {
+					f.setAccessible(true);
+					try {
+						Object value = f.get(object);
+						Entry.of(Terminal.of(f.getName()), converter.convert(value));
+					} catch (IllegalArgumentException e) {
+						throw new UnexpectedConditionError("フィールドは存在するはず。");
+					} catch (IllegalAccessException e) {
+						throw new UnexpectedConditionError("setAccessible(true)したはず。");
+					}
+				}
+				
+				return Record.of(entries);
 			}
+			
 			return null;
 		}
 		



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