[Jiemamy-notify:2266] commit [3311] @ TargetModelアノテーションを廃止。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 4月 18日 (土) 21:05:19 JST


Revision: 3311
          http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=3311
Author:   daisuke_m
Date:     2009-04-18 21:05:19 +0900 (Sat, 18 Apr 2009)

Log Message:
-----------
@TargetModelアノテーションを廃止。
thanks to shot6

Modified Paths:
--------------
    artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/JiemamyPropertyTest.java
    artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/JiemamyViewPropertyTest.java
    zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyProperty.java
    zeus/trunk/jiemamy-spec-view/src/main/java/org/jiemamy/JiemamyViewProperty.java

Removed Paths:
-------------
    zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/TargetModel.java


-------------- next part --------------
Modified: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/JiemamyPropertyTest.java
===================================================================
--- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/JiemamyPropertyTest.java	2009-04-18 10:21:07 UTC (rev 3310)
+++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/JiemamyPropertyTest.java	2009-04-18 12:05:19 UTC (rev 3311)
@@ -18,21 +18,19 @@
  */
 package org.jiemamy;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.util.Arrays;
 
 import org.apache.commons.lang.ClassUtils;
 import org.junit.Test;
 
-import org.jiemamy.JiemamyProperty;
-import org.jiemamy.TargetModel;
 import org.jiemamy.internal.model.attribute.constraint.AbstractConstraintModel;
+import org.jiemamy.model.JiemamyElement;
 import org.jiemamy.utils.ReflectionUtil;
 
 /**
@@ -54,10 +52,7 @@
 				continue;
 			}
 			
-			TargetModel annot = enumClass.getAnnotation(TargetModel.class);
-			assertThat("JiemamyPropertyの内部列挙型はTargetModelアノテーションを持たなければならない", annot, is(notNullValue()));
-			
-			Class<?> targetModelClass = annot.value();
+			Class<? extends JiemamyElement> targetModelClass = getTargetModelClass(enumClass);
 			for (Field field : enumClass.getFields()) {
 				String iserName = ReflectionUtil.convertFieldToAccessorName(field, "is");
 				String getterName = ReflectionUtil.convertFieldToAccessorName(field, "get");
@@ -92,10 +87,7 @@
 				continue;
 			}
 			
-			TargetModel annot = enumClass.getAnnotation(TargetModel.class);
-			assertThat("JiemamyPropertyの内部列挙型はTargetModelアノテーションを持たなければならない", annot, is(notNullValue()));
-			
-			Class<?> interfaceClass = annot.value();
+			Class<? extends JiemamyElement> interfaceClass = getTargetModelClass(enumClass);
 			String implClassName = interfaceClass.getName() + "Impl";
 			implClassName = implClassName.replace(".model.", ".internal.model.");
 			
@@ -137,8 +129,7 @@
 			if (Enum.class.isAssignableFrom(clazz) == false) {
 				continue;
 			}
-			TargetModel annot = clazz.getAnnotation(TargetModel.class);
-			Class<?> targetModelClass = annot.value();
+			Class<? extends JiemamyElement> targetModelClass = getTargetModelClass(clazz);
 			Method[] methods = targetModelClass.getDeclaredMethods();
 			for (Method method : methods) {
 				if (ReflectionUtil.isGetter(method) == false) {
@@ -154,6 +145,11 @@
 				}
 			}
 		}
-		
 	}
+	
+	private Class<? extends JiemamyElement> getTargetModelClass(Class<?> propImplementation) {
+		ParameterizedType pType = (ParameterizedType) propImplementation.getGenericSuperclass();
+		Type type = pType.getActualTypeArguments()[0];
+		return (Class<? extends JiemamyElement>) type;
+	}
 }

Modified: artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/JiemamyViewPropertyTest.java
===================================================================
--- artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/JiemamyViewPropertyTest.java	2009-04-18 10:21:07 UTC (rev 3310)
+++ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/JiemamyViewPropertyTest.java	2009-04-18 12:05:19 UTC (rev 3311)
@@ -18,23 +18,20 @@
  */
 package org.jiemamy;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 
 import org.apache.commons.lang.ClassUtils;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.jiemamy.JiemamyProperty;
-import org.jiemamy.JiemamyViewProperty;
-import org.jiemamy.TargetModel;
 import org.jiemamy.internal.model.attribute.constraint.AbstractConstraintModel;
+import org.jiemamy.model.JiemamyElement;
 import org.jiemamy.utils.ReflectionUtil;
 
 /**
@@ -60,10 +57,8 @@
 				continue;
 			}
 			LOGGER.debug("target enumClass: " + enumClass.getSimpleName());
-			TargetModel annot = enumClass.getAnnotation(TargetModel.class);
-			assertThat("JiemamyPropertyの内部列挙型はTargetModelアノテーションを持たなければならない", annot, is(notNullValue()));
 			
-			Class<?> targetModelClass = annot.value();
+			Class<?> targetModelClass = getTargetModelClass(enumClass);
 			for (Field field : enumClass.getFields()) {
 				String iserName = ReflectionUtil.convertFieldToAccessorName(field, "is");
 				String getterName = ReflectionUtil.convertFieldToAccessorName(field, "get");
@@ -99,10 +94,8 @@
 			}
 			
 			LOGGER.debug("target enumClass: " + enumClass.getSimpleName());
-			TargetModel annot = enumClass.getAnnotation(TargetModel.class);
-			assertThat("JiemamyPropertyの内部列挙型はTargetModelアノテーションを持たなければならない", annot, is(notNullValue()));
 			
-			Class<?> interfaceClass = annot.value();
+			Class<?> interfaceClass = getTargetModelClass(enumClass);
 			String implClassName = interfaceClass.getName() + "Impl";
 			implClassName = implClassName.replace(".model.", ".internal.model.");
 			
@@ -150,8 +143,7 @@
 				continue;
 			}
 			LOGGER.debug("target enumClass: " + clazz.getSimpleName());
-			TargetModel annot = clazz.getAnnotation(TargetModel.class);
-			Class<?> targetModelClass = annot.value();
+			Class<?> targetModelClass = getTargetModelClass(clazz);
 			Method[] methods = targetModelClass.getDeclaredMethods();
 			for (Method method : methods) {
 				if (ReflectionUtil.isGetter(method) == false) {
@@ -167,4 +159,10 @@
 		}
 		
 	}
+	
+	private Class<? extends JiemamyElement> getTargetModelClass(Class<?> propImplementation) {
+		ParameterizedType pType = (ParameterizedType) propImplementation.getGenericSuperclass();
+		Type type = pType.getActualTypeArguments()[0];
+		return (Class<? extends JiemamyElement>) type;
+	}
 }

Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyProperty.java
===================================================================
--- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyProperty.java	2009-04-18 10:21:07 UTC (rev 3310)
+++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyProperty.java	2009-04-18 12:05:19 UTC (rev 3311)
@@ -67,7 +67,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(AttributeModel.class)
 	public enum AttributeProperty implements JiemamyProperty<AttributeModel> {
 		
 		/** {@link AttributeModel#getName()}で取得できるプロパティ */
@@ -85,7 +84,6 @@
 	 * 
 	 * @author daisuke
 	 */
-	@TargetModel(CheckConstraint.class)
 	public enum CheckConstraintProperty implements JiemamyProperty<CheckConstraint> {
 		
 		/** {@link CheckConstraint#getExpression()}で取得できるプロパティ */
@@ -98,7 +96,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(ColumnCheckConstraint.class)
 	public enum ColumnCheckModelProperty implements JiemamyProperty<ColumnCheckConstraint> {
 		
 	}
@@ -109,7 +106,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(ColumnModel.class)
 	public enum ColumnProperty implements JiemamyProperty<ColumnModel> {
 		
 		/** {@link ColumnModel#getDataType()}で取得できるプロパティ */
@@ -137,7 +133,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(ConstraintModel.class)
 	public enum ConstraintProperty implements JiemamyProperty<ConstraintModel> {
 		
 		/** {@link ConstraintModel#getName()}で取得できるプロパティ */
@@ -150,7 +145,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(DataSetModel.class)
 	public enum DataSetProperty implements JiemamyProperty<DataSetModel> {
 		
 		/** {@link DataSetModel#getName()}で取得できるプロパティ */
@@ -166,7 +160,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(Deferrability.class)
 	public enum DeferrabilityProperty implements JiemamyProperty<Deferrability> {
 		
 		/** {@link Deferrability#isDeferrable()}で取得できるプロパティ */
@@ -182,7 +175,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(DomainModel.class)
 	public enum DomainProperty implements JiemamyProperty<DomainModel> {
 		
 		/** {@link DomainModel#getName()}で取得できるプロパティ */
@@ -210,7 +202,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(EntityModel.class)
 	public enum EntityProperty implements JiemamyProperty<EntityModel> {
 		/** {@link EntityModel#getName()}で取得できるプロパティ */
 		name,
@@ -234,7 +225,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(ForeignKey.class)
 	public enum ForeignKeyProperty implements JiemamyProperty<ForeignKey> {
 		
 		/** {@link ForeignKey#getReferenceColumns()}で取得できるプロパティ */
@@ -256,7 +246,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(IndexColumnModel.class)
 	public enum IndexColumnProperty implements JiemamyProperty<IndexColumnModel> {
 		
 		/** {@link IndexColumnModel#getColumnRef()}で取得できるプロパティ */
@@ -272,7 +261,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(IndexModel.class)
 	public enum IndexProperty implements JiemamyProperty<IndexModel> {
 		
 		/** {@link IndexModel#getName()}で取得できるプロパティ */
@@ -291,7 +279,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(KeyConstraint.class)
 	public enum KeyConstraintModelProperty implements JiemamyProperty<KeyConstraint> {
 		
 		/** {@link KeyConstraint#getDeferrability()}で取得できるプロパティ */
@@ -307,7 +294,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(NotNullConstraint.class)
 	public enum NotNullConstraintProperty implements JiemamyProperty<NotNullConstraint> {
 		
 	}
@@ -318,7 +304,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(PrimaryKey.class)
 	public enum PrimaryKeyProperty implements JiemamyProperty<PrimaryKey> {
 		
 	}
@@ -329,7 +314,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(RecordModel.class)
 	public enum RecordProperty implements JiemamyProperty<RecordModel> {
 		
 		/** {@link RecordModel#getValues()}で取得できるプロパティ */
@@ -342,7 +326,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(RootModel.class)
 	public enum RootProperty implements JiemamyProperty<RootModel> {
 		
 		/** {@link RootModel#getDialectClassName()}で取得できるプロパティ */
@@ -376,7 +359,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(TableCheckConstraint.class)
 	public enum TableCheckModelProperty implements JiemamyProperty<TableCheckConstraint> {
 		
 	}
@@ -387,7 +369,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(TableModel.class)
 	public enum TableProperty implements JiemamyProperty<TableModel> {
 		
 		/** {@link TableModel#getAttributes()}で取得できるプロパティ */
@@ -403,7 +384,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(UniqueKey.class)
 	public enum UniqueKeyProperty implements JiemamyProperty<UniqueKey> {
 		
 	}
@@ -414,7 +394,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(ValueConstraint.class)
 	public enum ValueConstraintProperty implements JiemamyProperty<ValueConstraint> {
 		
 	}
@@ -425,7 +404,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(ViewModel.class)
 	public enum ViewProperty implements JiemamyProperty<ViewModel> {
 		
 		/** {@link ViewModel#getDefinition()}で取得できるプロパティ */

Deleted: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/TargetModel.java
===================================================================
--- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/TargetModel.java	2009-04-18 10:21:07 UTC (rev 3310)
+++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/TargetModel.java	2009-04-18 12:05:19 UTC (rev 3311)
@@ -1,41 +0,0 @@
-/*
- * Copyright 2007-2009 Jiemamy Project and the Others.
- * Created on 2009/02/10
- *
- * 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;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.jiemamy.model.JiemamyElement;
-
-/**
- * プロパティ記述対象のインターフェイスを表すアノテーション。
- * 
- * @since 0.2
- * @author daisuke
- */
- @ Target(ElementType.TYPE)
- @ Retention(RetentionPolicy.RUNTIME)
- @ interface TargetModel {
-	
-	/** プロパティ記述対象のインターフェイス */
-	Class<? extends JiemamyElement> value();
-	
-}

Modified: zeus/trunk/jiemamy-spec-view/src/main/java/org/jiemamy/JiemamyViewProperty.java
===================================================================
--- zeus/trunk/jiemamy-spec-view/src/main/java/org/jiemamy/JiemamyViewProperty.java	2009-04-18 10:21:07 UTC (rev 3310)
+++ zeus/trunk/jiemamy-spec-view/src/main/java/org/jiemamy/JiemamyViewProperty.java	2009-04-18 12:05:19 UTC (rev 3311)
@@ -39,7 +39,6 @@
 	 * @since 0.2
 	 * @author shin1ogawa
 	 */
-	@TargetModel(ConnectionProfile.class)
 	public enum ConnectionProfileProperty implements JiemamyViewProperty<ConnectionProfile> {
 		
 		/** {@link ConnectionProfile#getBendpoints()}で取得できるプロパティ */
@@ -55,7 +54,6 @@
 	 * @since 0.2
 	 * @author shin1ogawa
 	 */
-	@TargetModel(DiagramPresentationModel.class)
 	public enum DiagramPresentationProperty implements JiemamyViewProperty<DiagramPresentationModel> {
 		
 		/** {@link DiagramPresentationModel#getConnectionProfiles()}で取得できるプロパティ */
@@ -80,7 +78,6 @@
 	 * @since 0.2
 	 * @author shin1ogawa
 	 */
-	@TargetModel(NodeProfile.class)
 	public enum NodeProfileProperty implements JiemamyViewProperty<NodeProfile> {
 		
 		/** {@link NodeProfile#getBoundary()}で取得できるプロパティ */
@@ -96,7 +93,6 @@
 	 * @since 0.2
 	 * @author daisuke
 	 */
-	@TargetModel(StickyModel.class)
 	public enum StickyProperty implements JiemamyViewProperty<StickyModel> {
 		
 		/** {@link StickyModel#getContents()}で取得できるプロパティ */



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