[Jiemamy-notify:1362] commit [2612] バリデータ整備 /

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 2月 4日 (水) 02:13:06 JST


Revision: 2612
          http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2612
Author:   daisuke_m
Date:     2009-02-04 02:13:06 +0900 (Wed, 04 Feb 2009)

Log Message:
-----------
バリデータ整備 /
XML入出力調整。

Modified Paths:
--------------
    artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/SerializationTest.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/AllValidator.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomBuilder.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomParser.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/EqualsUtil.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/ColumnValidator.java
    zeus/trunk/jiemamy-spec-core/src/main/resources/sample.xml

Added Paths:
-----------
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/IndexValidator.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/TableValidator.java

Removed Paths:
-------------
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/TableValidator.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-03 16:06:44 UTC (rev 2611)
+++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/SerializationTest.java	2009-02-03 17:13:06 UTC (rev 2612)
@@ -239,10 +239,10 @@
 		boolean equals = EqualsUtil.equals(rootModel2, rootModel1);
 		
 		FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this, "null")
-				+ "_test1_gtree1.xml"), EqualsUtil.rightGTree, CharEncoding.UTF_8);
+				+ "_test1_gtree1.txt"), EqualsUtil.rightGTree, CharEncoding.UTF_8);
 		
 		FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this, "null")
-				+ "_test1_gtree2.xml"), EqualsUtil.leftGTree, CharEncoding.UTF_8);
+				+ "_test1_gtree2.txt"), EqualsUtil.leftGTree, CharEncoding.UTF_8);
 		
 		assertThat(equals, is(true));
 		assertThat(xml2, is(xml1));
@@ -279,10 +279,10 @@
 		boolean equals = EqualsUtil.equals(rootModel2, rootModel1);
 		
 		FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this, "null")
-				+ "_test2_gtree1.xml"), EqualsUtil.rightGTree, CharEncoding.UTF_8);
+				+ "_test2_gtree1.txt"), EqualsUtil.rightGTree, CharEncoding.UTF_8);
 		
 		FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this, "null")
-				+ "_test2_gtree2.xml"), EqualsUtil.leftGTree, CharEncoding.UTF_8);
+				+ "_test2_gtree2.txt"), EqualsUtil.leftGTree, CharEncoding.UTF_8);
 		
 		assertThat(equals, is(true));
 		assertThat(xml2, is(xml1));

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/AllValidator.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/AllValidator.java	2009-02-03 16:06:44 UTC (rev 2611)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/AllValidator.java	2009-02-03 17:13:06 UTC (rev 2612)
@@ -26,31 +26,37 @@
 import org.jiemamy.validator.impl.EntityNameCollisionValidator;
 import org.jiemamy.validator.impl.ForeignKeyValidator;
 import org.jiemamy.validator.impl.IdCollisionValidator;
+import org.jiemamy.validator.impl.IndexValidator;
 import org.jiemamy.validator.impl.InstanceCollisionValidator;
 import org.jiemamy.validator.impl.InstanceSpaceValidator;
 import org.jiemamy.validator.impl.KeyConstraintValidator;
 import org.jiemamy.validator.impl.PrimaryKeyValidator;
 import org.jiemamy.validator.impl.ReferenceValidator;
+import org.jiemamy.validator.impl.TableValidator;
 
 /**
- * TODO for daisuke
+ * 標準バリデータを全て動かすバリデータ。
  * 
  * @author daisuke
  */
 public class AllValidator extends CompositeValidator {
 	
+	/**
+	 * インスタンスを生成する。
+	 */
 	public AllValidator() {
 		List<Validator> validators = getValidators();
 		validators.add(new ColumnValidator());
 		validators.add(new EntityNameCollisionValidator());
 		validators.add(new ForeignKeyValidator());
 		validators.add(new IdCollisionValidator());
+		validators.add(new IndexValidator());
 		validators.add(new InstanceCollisionValidator());
 		validators.add(new InstanceSpaceValidator());
 		validators.add(new KeyConstraintValidator());
 		validators.add(new PrimaryKeyValidator());
 		validators.add(new ReferenceValidator());
-		
+		validators.add(new TableValidator());
 	}
 	
 }

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomBuilder.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomBuilder.java	2009-02-03 16:06:44 UTC (rev 2611)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomBuilder.java	2009-02-03 17:13:06 UTC (rev 2612)
@@ -268,13 +268,11 @@
 					for (Map.Entry<ColumnRef, String> entry2 : treeSet) {
 						String value = entry2.getValue();
 						Element columnDataElement;
-						if (value == null) {
-							columnDataElement = DomUtil.newChild(recordElement, COLUMN_REF);
-						} else {
-							columnDataElement = DomUtil.newChild(recordElement, COLUMN_REF, value);
+						columnDataElement = DomUtil.newChild(recordElement, COLUMN_REF, value);
+						if (columnDataElement != null) {
+							columnDataElement.setAttribute(CoreQName.REF.getQNameString(), entry2.getKey()
+								.getReferenceId().toString());
 						}
-						columnDataElement.setAttribute(CoreQName.REF.getQNameString(), entry2.getKey().getReferenceId()
-							.toString());
 					}
 				}
 			}
@@ -292,19 +290,23 @@
 			newDataTypeElement(domainElement, domainModel.getDataType());
 			DomUtil.newChild(domainElement, DEFAULT_VALUE, domainModel.getDefaultValue());
 			
-			Element constraintsElement = DomUtil.newChild(domainElement, CONSTRAINTS);
-			for (ValueConstraintModel constraint : domainModel.getConstraints()) {
-				if (constraint instanceof NotNullConstraintModel) {
-					NotNullConstraintModel notNullConstraintModel = (NotNullConstraintModel) constraint;
-					Element notNullElement = DomUtil.newChild(constraintsElement, NOT_NULL);
-					notNullElement.setAttribute(CoreQName.ID.getQNameString(), notNullConstraintModel.getId()
-						.toString());
-					DomUtil.newChild(notNullElement, NAME, notNullConstraintModel.getName());
-					DomUtil.newChild(notNullElement, LOGICAL_NAME, notNullConstraintModel.getLogicalName());
-					DomUtil.newChild(notNullElement, DESCRIPTION, notNullConstraintModel.getDescription());
+			if (domainModel.getConstraints().size() > 0) {
+				Element constraintsElement = DomUtil.newChild(domainElement, CONSTRAINTS);
+				for (ValueConstraintModel constraint : domainModel.getConstraints()) {
+					if (constraint instanceof NotNullConstraintModel) {
+						NotNullConstraintModel notNullConstraintModel = (NotNullConstraintModel) constraint;
+						Element notNullElement = DomUtil.newChild(constraintsElement, NOT_NULL);
+						notNullElement.setAttribute(CoreQName.ID.getQNameString(), notNullConstraintModel.getId()
+							.toString());
+						DomUtil.newChild(notNullElement, NAME, notNullConstraintModel.getName());
+						DomUtil.newChild(notNullElement, LOGICAL_NAME, notNullConstraintModel.getLogicalName());
+						DomUtil.newChild(notNullElement, DESCRIPTION, notNullConstraintModel.getDescription());
 //					writeNotNullConstrait(constraintsElement, notNullConstraintModel);
-				} else if (constraint instanceof CheckConstraintModel) {
-					writeCheckConstrait(constraintsElement, (CheckConstraintModel) constraint);
+					} else if (constraint instanceof CheckConstraintModel) {
+						writeCheckConstrait(constraintsElement, (CheckConstraintModel) constraint);
+					} else {
+						logger.warn("unknown domain constraint: " + constraint.getClass().getName());
+					}
 				}
 			}
 			

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomParser.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomParser.java	2009-02-03 16:06:44 UTC (rev 2611)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/DomParser.java	2009-02-03 17:13:06 UTC (rev 2612)
@@ -121,17 +121,18 @@
 						Field field = adapter.getClass().getDeclaredField(fieldName);
 						field.setAccessible(true);
 						String value = propertyElement.getTextContent();
-						if (field.getType() == Integer.class || field.getType() == int.class) {
+						Class<?> type = field.getType();
+						if (type == Integer.class || type == int.class) {
 							field.set(adapter, NumberUtils.toInt(value));
-						} else if (field.getType() == Long.class || field.getType() == long.class) {
+						} else if (type == Long.class || type == long.class) {
 							field.set(adapter, NumberUtils.toLong(value));
-						} else if (field.getType() == Float.class || field.getType() == float.class) {
+						} else if (type == Float.class || type == float.class) {
 							field.set(adapter, NumberUtils.toFloat(value));
-						} else if (field.getType() == Double.class || field.getType() == double.class) {
+						} else if (type == Double.class || type == double.class) {
 							field.set(adapter, NumberUtils.toDouble(value));
-						} else if (field.getType() == Boolean.class || field.getType() == boolean.class) {
+						} else if (type == Boolean.class || type == boolean.class) {
 							field.set(adapter, BooleanUtils.toBoolean(value));
-						} else if (field.getType() == String.class) {
+						} else if (type == String.class) {
 							field.set(adapter, value);
 						} else {
 							logger.warn("unsupported model adapter field data type: " + field.getType().getName());

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-03 16:06:44 UTC (rev 2611)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/EqualsUtil.java	2009-02-03 17:13:06 UTC (rev 2612)
@@ -37,6 +37,7 @@
 import org.jiemamy.model.attribute.ColumnRef;
 import org.jiemamy.model.datatype.DomainRef;
 import org.jiemamy.model.entity.TableRef;
+import org.jiemamy.utils.AnnotationUtil;
 import org.jiemamy.utils.gtree.converter.CachedObjectConverter;
 import org.jiemamy.utils.gtree.converter.ConverterDriver;
 import org.jiemamy.utils.gtree.converter.InterfaceBeanConverter;
@@ -110,19 +111,13 @@
 		 * {@inheritDoc}
 		 */
 		public Value convert(Object object, ObjectConverter converter) {
-			Adapter annotation = object.getClass().getAnnotation(Adapter.class);
+			Adapter annotation = AnnotationUtil.getTypeAnnotation(object, Adapter.class);
 			if (annotation == null) {
 				return null;
 			}
 			if (annotation.value() == AdapterType.LOGIC) {
 				return Terminal.of("<LogicAdapter>");
 			} else if (annotation.value() == AdapterType.MODEL) {
-				for (Class<?> interf : object.getClass().getInterfaces()) {
-					if (interf.getName().equals("org.jiemamy.model.DiagramPresentationModel")) {
-						return null;
-					}
-				}
-				
 				List<Entry> entries = new ArrayList<Entry>();
 				for (Field f : object.getClass().getDeclaredFields()) {
 					f.setAccessible(true);

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/ColumnValidator.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/ColumnValidator.java	2009-02-03 16:06:44 UTC (rev 2611)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/ColumnValidator.java	2009-02-03 17:13:06 UTC (rev 2612)
@@ -21,7 +21,10 @@
 import java.util.Collection;
 import java.util.Locale;
 
+import org.apache.commons.lang.StringUtils;
+
 import org.jiemamy.model.RootModel;
+import org.jiemamy.model.attribute.ColumnModel;
 import org.jiemamy.model.entity.TableModel;
 import org.jiemamy.utils.model.RootModelUtil;
 import org.jiemamy.utils.model.TableUtil;
@@ -46,26 +49,34 @@
 		Collection<Problem> result = super.validate(rootModel);
 		Collection<TableModel> tableModels = RootModelUtil.getEntities(rootModel, TableModel.class);
 		for (TableModel tableModel : tableModels) {
-			int size = TableUtil.getColumns(tableModel).size();
-			if (size == 0) {
-				result.add(new NoColumnProblem(tableModel));
+			int index = 0;
+			for (ColumnModel column : TableUtil.getColumns(tableModel)) {
+				if (StringUtils.isEmpty(column.getName())) {
+					result.add(new EmptyColumnNameProblem(tableModel, index));
+				}
+				if (column.getDataType() == null) {
+					result.add(new EmptyDataTypeProblem(tableModel, column));
+				}
+				index++;
 			}
 		}
 		return result;
 	}
 	
 
-	static class NoColumnProblem extends AbstractProblem {
+	static class EmptyColumnNameProblem extends AbstractProblem {
 		
 		/**
 		 * インスタンスを生成する。
 		 * @param tableModel 
+		 * @param index 
 		 */
-		public NoColumnProblem(TableModel tableModel) {
+		public EmptyColumnNameProblem(TableModel tableModel, int index) {
 			super("X0000"); // TODO エラーコード設定
-			registerMessage(Locale.JAPAN, "テーブル{0}においてカラムが存在しません");
+			registerMessage(Locale.JAPAN, "テーブル{0}のカラム{1}に名前がありません");
 			setArguments(new Object[] {
-				tableModel.getName()
+				tableModel.getName(),
+				index
 			});
 		}
 		
@@ -73,8 +84,33 @@
 		 * {@inheritDoc}
 		 */
 		public Severity getSeverity() {
-			return Severity.WARN;
+			return Severity.ERROR;
 		}
 		
 	}
+	
+	static class EmptyDataTypeProblem extends AbstractProblem {
+		
+		/**
+		 * インスタンスを生成する。
+		 * @param tableModel 
+		 * @param columnModel 
+		 */
+		public EmptyDataTypeProblem(TableModel tableModel, ColumnModel columnModel) {
+			super("X0000"); // TODO エラーコード設定
+			registerMessage(Locale.JAPAN, "テーブル{0}のカラム{1}にデータ型が設定されていません");
+			setArguments(new Object[] {
+				tableModel.getName(),
+				columnModel.getName()
+			});
+		}
+		
+		/**
+		 * {@inheritDoc}
+		 */
+		public Severity getSeverity() {
+			return Severity.ERROR;
+		}
+		
+	}
 }

Copied: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/IndexValidator.java (from rev 2611, artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/TableValidator.java)
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/IndexValidator.java	                        (rev 0)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/IndexValidator.java	2009-02-03 17:13:06 UTC (rev 2612)
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on 2009/01/26
+ *
+ * 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.validator.impl;
+
+import java.util.Collection;
+import java.util.Locale;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.jiemamy.model.RootModel;
+import org.jiemamy.model.attribute.ColumnModel;
+import org.jiemamy.model.attribute.ColumnRef;
+import org.jiemamy.model.entity.TableModel;
+import org.jiemamy.model.index.IndexColumnModel;
+import org.jiemamy.model.index.IndexModel;
+import org.jiemamy.utils.CollectionsUtil;
+import org.jiemamy.utils.model.RootModelUtil;
+import org.jiemamy.utils.model.TableUtil;
+import org.jiemamy.validator.AbstractProblem;
+import org.jiemamy.validator.AbstractValidator;
+import org.jiemamy.validator.Problem;
+
+/**
+ * {@link IndexModel}の構成を調べるバリデータ。
+ * 
+ * @author daisuke
+ */
+public class IndexValidator extends AbstractValidator {
+	
+	private static Logger logger = LoggerFactory.getLogger(IndexValidator.class);
+	
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public Collection<Problem> validate(RootModel rootModel) {
+		Collection<Problem> result = super.validate(rootModel);
+		for (TableModel tableModel : RootModelUtil.getEntities(rootModel, TableModel.class)) {
+			Collection<UUID> columnIds = CollectionsUtil.newArrayList();
+			for (ColumnModel columnModel : TableUtil.getColumns(tableModel)) {
+				columnIds.add(columnModel.getId());
+			}
+			
+			for (IndexModel indexModel : tableModel.getIndexes()) {
+				for (IndexColumnModel indexColumnModel : indexModel.getColumns()) {
+					ColumnRef columnRef = indexColumnModel.getColumn();
+					if (columnIds.contains(columnRef.getReferenceId()) == false) {
+						logger.error("illegal index (" + indexColumnModel.getId() + ")");
+						result.add(new IllegalIndexColumnRefProblem(tableModel, indexModel, columnRef));
+						
+					}
+				}
+			}
+		}
+		return result;
+	}
+	
+
+	/**
+	 * TODO for daisuke
+	 * 
+	 * @author daisuke
+	 */
+	static class IllegalIndexColumnRefProblem extends AbstractProblem {
+		
+		/**
+		 * インスタンスを生成する。
+		 * @param columnRef 
+		 * @param indexModel 
+		 * @param tableModel 
+		 */
+		private IllegalIndexColumnRefProblem(TableModel tableModel, IndexModel indexModel, ColumnRef columnRef) {
+			super("X0000"); // TODO エラーコード設定
+			registerMessage(Locale.JAPAN, "テーブル{0}({1})にインデックス{2}({3})が参照するカラム{4}は存在しません");
+			setArguments(new Object[] {
+				tableModel.getName(),
+				tableModel.getId().toString(),
+				indexModel.getName(),
+				indexModel.getId().toString(),
+				columnRef.getReferenceId().toString()
+			});
+		}
+		
+		public Severity getSeverity() {
+			return Severity.ERROR;
+		}
+	}
+}


Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/IndexValidator.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Deleted: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/TableValidator.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/TableValidator.java	2009-02-03 16:06:44 UTC (rev 2611)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/TableValidator.java	2009-02-03 17:13:06 UTC (rev 2612)
@@ -1,107 +0,0 @@
-/*
- * Copyright 2007-2009 Jiemamy Project and the Others.
- * Created on 2009/01/26
- *
- * 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.validator.impl;
-
-import java.util.Collection;
-import java.util.Locale;
-import java.util.UUID;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.jiemamy.model.RootModel;
-import org.jiemamy.model.attribute.ColumnModel;
-import org.jiemamy.model.attribute.ColumnRef;
-import org.jiemamy.model.entity.TableModel;
-import org.jiemamy.model.index.IndexColumnModel;
-import org.jiemamy.model.index.IndexModel;
-import org.jiemamy.utils.CollectionsUtil;
-import org.jiemamy.utils.model.RootModelUtil;
-import org.jiemamy.utils.model.TableUtil;
-import org.jiemamy.validator.AbstractProblem;
-import org.jiemamy.validator.AbstractValidator;
-import org.jiemamy.validator.Problem;
-
-/**
- * {@link TableModel}の構成を調べるバリデータ。
- * 
- * @author daisuke
- */
-public class TableValidator extends AbstractValidator {
-	
-	private static Logger logger = LoggerFactory.getLogger(TableValidator.class);
-	
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public Collection<Problem> validate(RootModel rootModel) {
-		Collection<Problem> result = super.validate(rootModel);
-		for (TableModel tableModel : RootModelUtil.getEntities(rootModel, TableModel.class)) {
-			Collection<UUID> columnIds = CollectionsUtil.newArrayList();
-			for (ColumnModel columnModel : TableUtil.getColumns(tableModel)) {
-				columnIds.add(columnModel.getId());
-			}
-			
-			for (IndexModel indexModel : tableModel.getIndexes()) {
-				for (IndexColumnModel indexColumnModel : indexModel.getColumns()) {
-					ColumnRef columnRef = indexColumnModel.getColumn();
-					if (columnIds.contains(columnRef.getReferenceId()) == false) {
-						logger.error("illegal index (" + indexColumnModel.getId() + ")");
-						result.add(new IllegalIndexColumnRefProblem(tableModel, indexModel, columnRef));
-						
-					}
-				}
-			}
-		}
-		return result;
-	}
-	
-
-	/**
-	 * TODO for daisuke
-	 * 
-	 * @author daisuke
-	 */
-	static class IllegalIndexColumnRefProblem extends AbstractProblem {
-		
-		/**
-		 * インスタンスを生成する。
-		 * @param columnRef 
-		 * @param indexModel 
-		 * @param tableModel 
-		 */
-		private IllegalIndexColumnRefProblem(TableModel tableModel, IndexModel indexModel, ColumnRef columnRef) {
-			super("X0000"); // TODO エラーコード設定
-			registerMessage(Locale.JAPAN, "テーブル{0}({1})にインデックス{2}({3})が参照するカラム{4}は存在しません");
-			setArguments(new Object[] {
-				tableModel.getName(),
-				tableModel.getId().toString(),
-				indexModel.getName(),
-				indexModel.getId().toString(),
-				columnRef.getReferenceId().toString()
-			});
-		}
-		
-		public Severity getSeverity() {
-			return Severity.ERROR;
-		}
-	}
-}

Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/TableValidator.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/TableValidator.java	                        (rev 0)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/validator/impl/TableValidator.java	2009-02-03 17:13:06 UTC (rev 2612)
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on 2009/01/26
+ *
+ * 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.validator.impl;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.commons.lang.StringUtils;
+
+import org.jiemamy.model.RootModel;
+import org.jiemamy.model.attribute.ColumnModel;
+import org.jiemamy.model.entity.TableModel;
+import org.jiemamy.utils.model.RootModelUtil;
+import org.jiemamy.utils.model.TableUtil;
+import org.jiemamy.validator.AbstractProblem;
+import org.jiemamy.validator.AbstractValidator;
+import org.jiemamy.validator.Problem;
+
+/**
+ * テーブルのバリデータ。
+ * 
+ * @author daisuke
+ */
+public class TableValidator extends AbstractValidator {
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public Collection<Problem> validate(RootModel rootModel) {
+		Collection<Problem> result = super.validate(rootModel);
+		Collection<TableModel> tableModels = RootModelUtil.getEntities(rootModel, TableModel.class);
+		for (TableModel tableModel : tableModels) {
+			List<ColumnModel> columns = TableUtil.getColumns(tableModel);
+			if (columns.size() == 0) {
+				result.add(new NoColumnProblem(tableModel));
+			}
+			if (StringUtils.isEmpty(tableModel.getName())) {
+				result.add(new EmptyTableNameProblem(tableModel));
+			}
+		}
+		return result;
+	}
+	
+
+	static class EmptyTableNameProblem extends AbstractProblem {
+		
+		/**
+		 * インスタンスを生成する。
+		 * @param tableModel 
+		 */
+		public EmptyTableNameProblem(TableModel tableModel) {
+			super("X0000"); // TODO エラーコード設定
+			registerMessage(Locale.JAPAN, "テーブル({0})に名前がありません");
+			setArguments(new Object[] {
+				tableModel.getId().toString()
+			});
+		}
+		
+		/**
+		 * {@inheritDoc}
+		 */
+		public Severity getSeverity() {
+			return Severity.ERROR;
+		}
+		
+	}
+	
+	static class NoColumnProblem extends AbstractProblem {
+		
+		/**
+		 * インスタンスを生成する。
+		 * @param tableModel 
+		 */
+		public NoColumnProblem(TableModel tableModel) {
+			super("X0000"); // TODO エラーコード設定
+			registerMessage(Locale.JAPAN, "テーブル{0}においてカラムが存在しません");
+			setArguments(new Object[] {
+				tableModel.getName()
+			});
+		}
+		
+		/**
+		 * {@inheritDoc}
+		 */
+		public Severity getSeverity() {
+			return Severity.WARN;
+		}
+		
+	}
+}

Modified: zeus/trunk/jiemamy-spec-core/src/main/resources/sample.xml
===================================================================
--- zeus/trunk/jiemamy-spec-core/src/main/resources/sample.xml	2009-02-03 16:06:44 UTC (rev 2611)
+++ zeus/trunk/jiemamy-spec-core/src/main/resources/sample.xml	2009-02-03 17:13:06 UTC (rev 2612)
@@ -308,7 +308,6 @@
           <columnRef ref="44c8e93d-b7ad-46cc-9b29-88c3a7d6c33e">3</columnRef>
           <columnRef ref="248a429b-2159-4ebd-a791-eee42a059374">30</columnRef>
           <columnRef ref="0e51b6df-43ab-408c-90ef-de13c6aab881">WARD</columnRef>
-          <columnRef ref="3d21a85a-72de-41b3-99dd-f4cb94e58d84"/>
           <columnRef ref="f0b57eed-98ab-4c21-9855-218c592814dc">1993-12-05</columnRef>
           <columnRef ref="80786549-dc2c-4c1c-bcbd-9f6fdec911d2">60</columnRef>
           <columnRef ref="4ae69b7a-7a0e-422a-89dc-0f0cff77565b">4</columnRef>
@@ -411,7 +410,6 @@
           <columnRef ref="44c8e93d-b7ad-46cc-9b29-88c3a7d6c33e">3</columnRef>
           <columnRef ref="248a429b-2159-4ebd-a791-eee42a059374">30</columnRef>
           <columnRef ref="0e51b6df-43ab-408c-90ef-de13c6aab881">村瀬 武彦</columnRef>
-          <columnRef ref="3d21a85a-72de-41b3-99dd-f4cb94e58d84"/>
           <columnRef ref="f0b57eed-98ab-4c21-9855-218c592814dc">1993-12-05</columnRef>
           <columnRef ref="80786549-dc2c-4c1c-bcbd-9f6fdec911d2">60</columnRef>
           <columnRef ref="4ae69b7a-7a0e-422a-89dc-0f0cff77565b">4</columnRef>



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