cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r921861 [1/2] - in /cayenne/main/trunk/framework: cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ cayenne-project-unpublished/src/main/java/org/apache/cayenne/projec...
Date Thu, 11 Mar 2010 14:19:26 GMT
Author: aadamchik
Date: Thu Mar 11 14:19:25 2010
New Revision: 921861

URL: http://svn.apache.org/viewvc?rev=921861&view=rev
Log:
CAY-1339 Remove org.apache.cayenne.project package from runtime

* cleaning up validation API
* fixing use of deprecated DataSourceFactories

Added:
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ConfigurationNodeValidator.java
      - copied, changed from r921859, cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ProjectValidator.java
Modified:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportEOModelAction.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataChannelValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataMapValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataNodeValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbAttributeValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbEntityValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbRelationshipValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DefaultProjectValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EJBQLQueryValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EmbeddableAttributeValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EmbeddableValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/NameValidationHelper.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjAttributeValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjEntityValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjRelationshipValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ProcedureParameterValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ProcedureQueryValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ProcedureValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ProjectValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/SQLTemplateValidator.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/SelectQueryValidator.java

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java Thu Mar 11 14:19:25 2010
@@ -238,9 +238,13 @@ public class Application {
     }
 
     public static Preferences getMainPreferenceForProject() {
-        String path = CayennePreference
-                .filePathToPrefereceNodePath(((DataChannelDescriptor) getProject()
-                        .getRootNode()).getConfigurationSource().getURL().getPath());
+
+        DataChannelDescriptor descriptor = (DataChannelDescriptor) getProject()
+                .getRootNode();
+        String path = CayennePreference.filePathToPrefereceNodePath(descriptor
+                .getConfigurationSource()
+                .getURL()
+                .getPath());
         Preferences pref = Application.getInstance().getPreferencesNode(
                 getProject().getClass(),
                 "");

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java Thu Mar 11 14:19:25 2010
@@ -22,10 +22,10 @@ package org.apache.cayenne.modeler.actio
 import java.awt.event.ActionEvent;
 
 import org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy;
-import org.apache.cayenne.conf.DriverDataSourceFactory;
-import org.apache.cayenne.configuration.event.DataNodeEvent;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
+import org.apache.cayenne.configuration.XMLPoolingDataSourceFactory;
+import org.apache.cayenne.configuration.event.DataNodeEvent;
 import org.apache.cayenne.conn.DataSourceInfo;
 import org.apache.cayenne.map.event.MapEvent;
 import org.apache.cayenne.modeler.Application;
@@ -104,7 +104,7 @@ public class CreateNodeAction extends Ca
         node.setDataSourceDescriptor(src);
         
         // by default create JDBC Node
-        node.setDataSourceFactoryType(DriverDataSourceFactory.class.getName());
+        node.setDataSourceFactoryType(XMLPoolingDataSourceFactory.class.getName());
         node.setSchemaUpdateStrategyType(SkipSchemaUpdateStrategy.class.getName());
 
         return node;

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportEOModelAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportEOModelAction.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportEOModelAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportEOModelAction.java Thu Mar 11 14:19:25 2010
@@ -33,10 +33,10 @@ import javax.swing.JDialog;
 import javax.swing.JFileChooser;
 import javax.swing.filechooser.FileFilter;
 
-import org.apache.cayenne.conf.DriverDataSourceFactory;
-import org.apache.cayenne.conf.JNDIDataSourceFactory;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
+import org.apache.cayenne.configuration.JNDIDataSourceFactory;
+import org.apache.cayenne.configuration.XMLPoolingDataSourceFactory;
 import org.apache.cayenne.configuration.event.DataNodeEvent;
 import org.apache.cayenne.configuration.event.QueryEvent;
 import org.apache.cayenne.conn.DataSourceInfo;
@@ -171,7 +171,7 @@ public class ImportEOModelAction extends
                     }
                 }
 
-                node.setDataSourceFactoryType(DriverDataSourceFactory.class.getName());
+                node.setDataSourceFactoryType(XMLPoolingDataSourceFactory.class.getName());
 
                 DataSourceInfo dsi = node.getDataSourceDescriptor();
                 

Copied: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ConfigurationNodeValidator.java (from r921859, cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ProjectValidator.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ConfigurationNodeValidator.java?p2=cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ConfigurationNodeValidator.java&p1=cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ProjectValidator.java&r1=921859&r2=921861&rev=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ProjectValidator.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ConfigurationNodeValidator.java Thu Mar 11 14:19:25 2010
@@ -18,10 +18,23 @@
  ****************************************************************/
 package org.apache.cayenne.project2.validation;
 
-import org.apache.cayenne.configuration.ConfigurationNode;
+import org.apache.cayenne.validation.SimpleValidationFailure;
 import org.apache.cayenne.validation.ValidationResult;
 
-public interface ProjectValidator {
+/**
+ * A base superclass of various node validators.
+ * 
+ * @since 3.1
+ */
+abstract class ConfigurationNodeValidator {
 
-    public ValidationResult validate(ConfigurationNode node);
+    void addFailure(
+            ValidationResult validationResult,
+            Object source,
+            String messageFormat,
+            Object... messageParameters) {
+
+        String message = String.format(messageFormat, messageParameters);
+        validationResult.addFailure(new SimpleValidationFailure(source, message));
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataChannelValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataChannelValidator.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataChannelValidator.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataChannelValidator.java Thu Mar 11 14:19:25 2010
@@ -20,19 +20,15 @@ package org.apache.cayenne.project2.vali
 
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.util.Util;
+import org.apache.cayenne.validation.ValidationResult;
 
-class DataChannelValidator {
+class DataChannelValidator extends ConfigurationNodeValidator {
 
-    void validate(Object object, ValidationVisitor validationVisitor) {
+    void validate(DataChannelDescriptor domain, ValidationResult validationResult) {
 
-        // check for empty name
-        DataChannelDescriptor domain = (DataChannelDescriptor) object;
         String name = domain.getName();
         if (Util.isEmptyString(name)) {
-            validationVisitor.registerError("Unnamed DataDomain.", object);
-
-            // no more name assertions
-            return;
+            addFailure(validationResult, domain, "Unnamed DataDomain");
         }
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataMapValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataMapValidator.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataMapValidator.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataMapValidator.java Thu Mar 11 14:19:25 2010
@@ -22,18 +22,16 @@ import org.apache.cayenne.configuration.
 import org.apache.cayenne.configuration.DataNodeDescriptor;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.util.Util;
+import org.apache.cayenne.validation.ValidationResult;
 
-class DataMapValidator {
+class DataMapValidator extends ConfigurationNodeValidator {
 
-    void validate(Object object, ValidationVisitor validationVisitor) {
-        DataMap map = (DataMap) object;
-        validateName(map, object, validationVisitor);
-
-        // check if data map is not attached to any nodes
-        validateNodeLinks(map, object, validationVisitor);
+    void validate(DataMap map, ValidationResult validationResult) {
+        validateName(map, validationResult);
+        validateNodeLinks(map, validationResult);
     }
 
-    void validateNodeLinks(DataMap map, Object object, ValidationVisitor validationVisitor) {
+    void validateNodeLinks(DataMap map, ValidationResult validationResult) {
         DataChannelDescriptor domain = map.getDataChannelDescriptor();
         if (domain == null) {
             return;
@@ -41,7 +39,7 @@ class DataMapValidator {
 
         boolean unlinked = true;
         int nodeCount = 0;
-        for (final DataNodeDescriptor node : domain.getNodeDescriptors()) {
+        for (DataNodeDescriptor node : domain.getNodeDescriptors()) {
             nodeCount++;
             if (node.getDataMapNames().contains(map.getName())) {
                 unlinked = false;
@@ -50,17 +48,15 @@ class DataMapValidator {
         }
 
         if (unlinked && nodeCount > 0) {
-            validationVisitor.registerWarning(
-                    "DataMap is not linked to any DataNodes.",
-                    object);
+            addFailure(validationResult, map, "DataMap is not linked to any DataNodes");
         }
     }
 
-    void validateName(DataMap map, Object object, ValidationVisitor validationVisitor) {
+    void validateName(DataMap map, ValidationResult validationResult) {
         String name = map.getName();
 
         if (Util.isEmptyString(name)) {
-            validationVisitor.registerError("Unnamed DataMap.", object);
+            addFailure(validationResult, map, "Unnamed DataMap");
             return;
         }
 
@@ -70,18 +66,15 @@ class DataMapValidator {
         }
 
         // check for duplicate names in the parent context
-        for (final DataMap otherMap : domain.getDataMaps()) {
+        for (DataMap otherMap : domain.getDataMaps()) {
             if (otherMap == map) {
                 continue;
             }
 
             if (name.equals(otherMap.getName())) {
-                validationVisitor.registerError(
-                        "Duplicate DataMap name: " + name + ".",
-                        object);
+                addFailure(validationResult, map, "Duplicate DataMap name: %s", name);
                 return;
             }
         }
     }
-
 }

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataNodeValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataNodeValidator.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataNodeValidator.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DataNodeValidator.java Thu Mar 11 14:19:25 2010
@@ -18,63 +18,56 @@
  ****************************************************************/
 package org.apache.cayenne.project2.validation;
 
-import org.apache.cayenne.conf.DriverDataSourceFactory;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
+import org.apache.cayenne.configuration.XMLPoolingDataSourceFactory;
 import org.apache.cayenne.util.Util;
+import org.apache.cayenne.validation.ValidationResult;
 
-class DataNodeValidator {
+class DataNodeValidator extends ConfigurationNodeValidator {
 
-    void validate(Object object, ValidationVisitor validationVisitor) {
-        DataNodeDescriptor node = (DataNodeDescriptor) object;
-        validateName(node, object, validationVisitor);
-        validateConnection(node, object, validationVisitor);
+    void validate(DataNodeDescriptor node, ValidationResult validationResult) {
+        validateName(node, validationResult);
+        validateConnection(node, validationResult);
     }
 
-    void validateConnection(
-            DataNodeDescriptor node,
-            Object object,
-            ValidationVisitor validationVisitor) {
+    void validateConnection(DataNodeDescriptor node, ValidationResult validationResult) {
+
         String factory = node.getDataSourceFactoryType();
 
-        // If direct factory, make sure the location is a valid file name.
-        if (Util.isEmptyString(factory)) {
-            validationVisitor.registerError("No DataSource factory.", object);
-        }
-        else if (!DriverDataSourceFactory.class.getName().equals(factory)) {
-            String location = node.getParameters();
-            if (Util.isEmptyString(location)) {
-                validationVisitor.registerError(
-                        "DataNode has no location parameter.",
-                        object);
+        // TODO: andrus 03/10/2010 - null factory is allowed, however
+        // 'getDataSourceDescriptor' must ne not null in this case
+
+        if (factory != null
+                && !XMLPoolingDataSourceFactory.class.getName().equals(factory)) {
+            String parameters = node.getParameters();
+            if (Util.isEmptyString(parameters)) {
+                addFailure(
+                        validationResult,
+                        node,
+                        "DataNode has empty 'parameters' string");
             }
         }
     }
 
-    void validateName(
-            DataNodeDescriptor node,
-            Object object,
-            ValidationVisitor validationVisitor) {
+    void validateName(DataNodeDescriptor node, ValidationResult validationResult) {
         String name = node.getName();
 
         if (Util.isEmptyString(name)) {
-            validationVisitor.registerError("Unnamed DataNode.", object);
+            addFailure(validationResult, node, "Unnamed DataNode");
             return;
         }
 
         DataChannelDescriptor dataChannelDescriptor = node.getDataChannelDescriptor();
-        
+
         // check for duplicate names in the parent context
-        for (final DataNodeDescriptor otherNode : dataChannelDescriptor
-                .getNodeDescriptors()) {
+        for (DataNodeDescriptor otherNode : dataChannelDescriptor.getNodeDescriptors()) {
             if (otherNode == node) {
                 continue;
             }
 
             if (name.equals(otherNode.getName())) {
-                validationVisitor.registerError(
-                        "Duplicate DataNode name: " + name + ".",
-                        object);
+                addFailure(validationResult, node, "Duplicate DataNode name: %s", name);
                 break;
             }
         }

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbAttributeValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbAttributeValidator.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbAttributeValidator.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbAttributeValidator.java Thu Mar 11 14:19:25 2010
@@ -21,15 +21,15 @@ package org.apache.cayenne.project2.vali
 import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.util.Util;
+import org.apache.cayenne.validation.ValidationResult;
 
-class DbAttributeValidator {
+class DbAttributeValidator extends ConfigurationNodeValidator {
 
-    void validate(Object object, ValidationVisitor validationVisitor) {
-        DbAttribute attribute = (DbAttribute) object;
+    void validate(DbAttribute attribute, ValidationResult validationResult) {
 
         // Must have name
         if (Util.isEmptyString(attribute.getName())) {
-            validationVisitor.registerError("Unnamed DbAttribute.", object);
+            addFailure(validationResult, attribute, "Unnamed DbAttribute");
         }
         else {
             NameValidationHelper helper = NameValidationHelper.getInstance();
@@ -37,24 +37,29 @@ class DbAttributeValidator {
                     .getName());
 
             if (invalidChars != null) {
-                validationVisitor.registerWarning(
-                        "DbAttribute name contains invalid characters: " + invalidChars,
-                        object);
+                addFailure(
+                        validationResult,
+                        attribute,
+                        "DbAttribute name '%s' contains invalid characters: %s",
+                        attribute.getName(),
+                        invalidChars);
             }
         }
 
         // all attributes must have type
         if (attribute.getType() == TypesMapping.NOT_DEFINED) {
-            validationVisitor.registerWarning("DbAttribute has no type.", object);
+            addFailure(validationResult, attribute, "DbAttribute has no type");
         }
 
         // VARCHAR and CHAR attributes must have max length
         else if (attribute.getMaxLength() < 0
                 && (attribute.getType() == java.sql.Types.VARCHAR || attribute.getType() == java.sql.Types.CHAR)) {
 
-            validationVisitor.registerWarning(
-                    "Character DbAttribute doesn't have max length.",
-                    object);
+            addFailure(
+                    validationResult,
+                    attribute,
+                    "Character DbAttribute '%s' doesn't have max length",
+                    attribute.getName());
         }
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbEntityValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbEntityValidator.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbEntityValidator.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbEntityValidator.java Thu Mar 11 14:19:25 2010
@@ -20,31 +20,32 @@ package org.apache.cayenne.project2.vali
 
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.util.Util;
+import org.apache.cayenne.validation.ValidationResult;
 
-class DbEntityValidator {
+class DbEntityValidator extends ConfigurationNodeValidator {
 
-    void validate(Object object, ValidationVisitor validationVisitor) {
-        DbEntity ent = (DbEntity) object;
-        validateName(ent, object, validationVisitor);
-        validateAttributes(ent, object, validationVisitor);
-        validatePK(ent, object, validationVisitor);
+    void validate(DbEntity entity, ValidationResult validationResult) {
+        validateName(entity, validationResult);
+        validateAttributes(entity, validationResult);
+        validatePK(entity, validationResult);
     }
 
     /**
      * Validates the presence of the primary key. A warning is given only if the parent
-     * map also conatins an ObjEntity mapped to this entity, since unmapped primary key is
+     * map also contains an ObjEntity mapped to this entity, since unmapped primary key is
      * ok if working with data rows.
      */
-    void validatePK(DbEntity ent, Object object, ValidationVisitor validationVisitor) {
-        if (ent.getAttributes().size() > 0 && ent.getPrimaryKeys().size() == 0) {
-            DataMap map = ent.getDataMap();
-            if (map != null && map.getMappedEntities(ent).size() > 0) {
-                // there is an objentity, so complain about no pk
-                validationVisitor.registerWarning("DbEntity \""
-                        + ent.getName()
-                        + "\" has no primary key attributes defined.", object);
+    void validatePK(DbEntity entity, ValidationResult validationResult) {
+        if (entity.getAttributes().size() > 0 && entity.getPrimaryKeys().size() == 0) {
+            DataMap map = entity.getDataMap();
+            if (map != null && map.getMappedEntities(entity).size() > 0) {
+
+                addFailure(
+                        validationResult,
+                        entity,
+                        "DbEntity '%s' has no primary key attributes defined",
+                        entity.getName());
             }
         }
     }
@@ -52,45 +53,39 @@ class DbEntityValidator {
     /**
      * Tables must have columns.
      */
-    void validateAttributes(
-            DbEntity ent,
-            Object object,
-            ValidationVisitor validationVisitor) {
-        if (ent.getAttributes().size() == 0) {
-            // complain about missing attributes
-            validationVisitor.registerWarning("DbEntity \""
-                    + ent.getName()
-                    + "\" has no attributes defined.", object);
+    void validateAttributes(DbEntity entity, ValidationResult validationResult) {
+        if (entity.getAttributes().size() == 0) {
+            addFailure(
+                    validationResult,
+                    entity,
+                    "DbEntity '%s' has no attributes defined",
+                    entity.getName());
         }
     }
 
-    void validateName(DbEntity ent, Object object, ValidationVisitor validationVisitor) {
-        String name = ent.getName();
+    void validateName(DbEntity entity, ValidationResult validationResult) {
+        String name = entity.getName();
 
         // Must have name
         if (Util.isEmptyString(name)) {
-            validationVisitor.registerError("Unnamed DbEntity.", object);
+            addFailure(validationResult, entity, "Unnamed DbEntity");
             return;
         }
 
-        if (object instanceof Entity) {
-            DataMap map = ((Entity) object).getDataMap();
-            if (map == null) {
-                return;
+        DataMap map = entity.getDataMap();
+        if (map == null) {
+            return;
+        }
+
+        // check for duplicate names in the parent context
+        for (DbEntity otherEntity : map.getDbEntities()) {
+            if (otherEntity == entity) {
+                continue;
             }
 
-            // check for duplicate names in the parent context
-            for (final DbEntity otherEnt : map.getDbEntities()) {
-                if (otherEnt == ent) {
-                    continue;
-                }
-
-                if (name.equals(otherEnt.getName())) {
-                    validationVisitor.registerError("Duplicate DbEntity name: "
-                            + name
-                            + ".", object);
-                    break;
-                }
+            if (name.equals(otherEntity.getName())) {
+                addFailure(validationResult, entity, "Duplicate DbEntity name: %s", name);
+                break;
             }
         }
     }

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbRelationshipValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbRelationshipValidator.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbRelationshipValidator.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DbRelationshipValidator.java Thu Mar 11 14:19:25 2010
@@ -21,73 +21,86 @@ package org.apache.cayenne.project2.vali
 import org.apache.cayenne.map.DbJoin;
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.util.Util;
+import org.apache.cayenne.validation.ValidationResult;
 
-class DbRelationshipValidator {
+class DbRelationshipValidator extends ConfigurationNodeValidator {
 
-    void validate(Object object, ValidationVisitor validationVisitor) {
-        DbRelationship rel = (DbRelationship) object;
+    void validate(DbRelationship relationship, ValidationResult validationResult) {
 
-        if (rel.getTargetEntity() == null) {
-            validationVisitor.registerWarning("DbRelationship "
-                    + dbRelationshipIdentifier(rel)
-                    + " has no target entity.", object);
-        }
-        else if (rel.getJoins().size() == 0) {
-            validationVisitor.registerWarning("DbRelationship "
-                    + dbRelationshipIdentifier(rel)
-                    + " has no joins.", object);
+        if (relationship.getTargetEntity() == null) {
+            addFailure(
+                    validationResult,
+                    relationship,
+                    "DbRelationship '%s' has no target entity",
+                    toString(relationship));
+        }
+        else if (relationship.getJoins().isEmpty()) {
+            addFailure(
+                    validationResult,
+                    relationship,
+                    "DbRelationship '%s' has no joins",
+                    toString(relationship));
         }
         else {
             // validate joins
-            for (final DbJoin join : rel.getJoins()) {
+            for (DbJoin join : relationship.getJoins()) {
                 if (join.getSource() == null && join.getTarget() == null) {
-                    validationVisitor
-                            .registerWarning(
-                                    "DbRelationship "
-                                            + dbRelationshipIdentifier(rel)
-                                            + " join has no source and target attributes selected.",
-                                    object);
+                    addFailure(
+                            validationResult,
+                            relationship,
+                            "DbRelationship '%s' has a join with no source and target attributes selected",
+                            toString(relationship));
                 }
                 else if (join.getSource() == null) {
-                    validationVisitor.registerWarning("DbRelationship "
-                            + dbRelationshipIdentifier(rel)
-                            + " join has no source attribute selected.", object);
+                    addFailure(
+                            validationResult,
+                            relationship,
+                            "DbRelationship '%s' has a join with no source attribute selected",
+                            toString(relationship));
                 }
                 else if (join.getTarget() == null) {
-                    validationVisitor.registerWarning("DbRelationship "
-                            + dbRelationshipIdentifier(rel)
-                            + " join has no target attribute selected.", object);
+                    addFailure(
+                            validationResult,
+                            relationship,
+                            "DbRelationship '%s' has a join with no target attribute selected",
+                            toString(relationship));
                 }
             }
         }
 
-        if (Util.isEmptyString(rel.getName())) {
-            validationVisitor.registerError("Unnamed DbRelationship.", object);
+        if (Util.isEmptyString(relationship.getName())) {
+            addFailure(validationResult, relationship, "Unnamed DbRelationship");
         }
         // check if there are attributes having the same name
-        else if (rel.getSourceEntity().getAttribute(rel.getName()) != null) {
-            validationVisitor.registerError("DbRelationship "
-                    + dbRelationshipIdentifier(rel)
-                    + " has the same name as one of DbAttributes", object);
+        else if (relationship.getSourceEntity().getAttribute(relationship.getName()) != null) {
+            addFailure(
+                    validationResult,
+                    relationship,
+                    "Name of DbRelationship '%s' conflicts with the name of one of DbAttributes in the same entity",
+                    toString(relationship));
         }
         else {
             NameValidationHelper helper = NameValidationHelper.getInstance();
-            String invalidChars = helper.invalidCharsInDbPathComponent(rel.getName());
+            String invalidChars = helper.invalidCharsInDbPathComponent(relationship
+                    .getName());
 
             if (invalidChars != null) {
-                validationVisitor.registerWarning("DbRelationship "
-                        + dbRelationshipIdentifier(rel)
-                        + " name contains invalid characters: "
-                        + invalidChars, object);
+                addFailure(
+                        validationResult,
+                        relationship,
+                        "Name of DbRelationship '%s' contains invalid characters: %s",
+                        toString(relationship),
+                        invalidChars);
             }
         }
     }
 
-    String dbRelationshipIdentifier(DbRelationship rel) {
-        if (null == rel.getSourceEntity()) {
-            return "<[null source entity]." + rel.getName() + ">";
+    private String toString(DbRelationship relationship) {
+        if (relationship.getSourceEntity() == null) {
+            return "[null source entity]." + relationship.getName();
         }
-        return "<" + rel.getSourceEntity().getName() + "." + rel.getName() + ">";
+
+        return relationship.getSourceEntity().getName() + "." + relationship.getName();
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DefaultProjectValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DefaultProjectValidator.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DefaultProjectValidator.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/DefaultProjectValidator.java Thu Mar 11 14:19:25 2010
@@ -40,12 +40,13 @@ import org.apache.cayenne.query.Procedur
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.validation.SimpleValidationFailure;
 import org.apache.cayenne.validation.ValidationResult;
 
+/**
+ * @since 3.1
+ */
 public class DefaultProjectValidator implements ProjectValidator {
 
-    /* Validators */
     private DataChannelValidator dataChannelValidator;
     private DataNodeValidator nodeValidator;
     private DataMapValidator mapValidator;
@@ -85,288 +86,187 @@ public class DefaultProjectValidator imp
     }
 
     public ValidationResult validate(ConfigurationNode node) {
-        ValidationVisitor vis = new ValidationVisitor(this);
-        return node.acceptVisitor(vis);
+        return node.acceptVisitor(new ValidationVisitor());
     }
 
-    DataChannelValidator getDataChannelValidator() {
-        return dataChannelValidator;
-    }
-
-    DataNodeValidator getNodeValidator() {
-        return nodeValidator;
-    }
-
-    DataMapValidator getMapValidator() {
-        return mapValidator;
-    }
-
-    ObjEntityValidator getObjEntityValidator() {
-        return objEntityValidator;
-    }
-
-    ObjAttributeValidator getObjAttrValidator() {
-        return objAttrValidator;
-    }
-
-    ObjRelationshipValidator getObjRelValidator() {
-        return objRelValidator;
-    }
-
-    DbEntityValidator getDbEntityValidator() {
-        return dbEntityValidator;
-    }
-
-    DbAttributeValidator getDbAttrValidator() {
-        return dbAttrValidator;
-    }
-
-    DbRelationshipValidator getDbRelValidator() {
-        return dbRelValidator;
-    }
+    class ValidationVisitor implements ConfigurationNodeVisitor<ValidationResult> {
 
-    EmbeddableAttributeValidator getEmbeddableAttributeValidator() {
-        return embeddableAttributeValidator;
-    }
+        private ValidationResult validationResult;
 
-    EmbeddableValidator getEmbeddableValidator() {
-        return embeddableValidator;
-    }
+        ValidationVisitor() {
+            validationResult = new ValidationResult();
+        }
 
-    ProcedureValidator getProcedureValidator() {
-        return procedureValidator;
-    }
+        public ValidationResult visitDataChannelDescriptor(
+                DataChannelDescriptor channelDescriptor) {
 
-    ProcedureParameterValidator getProcedureParameterValidator() {
-        return procedureParameterValidator;
-    }
+            dataChannelValidator.validate(channelDescriptor, validationResult);
 
-    SelectQueryValidator getSelectQueryValidator() {
-        return selectQueryValidator;
-    }
+            for (DataNodeDescriptor node : channelDescriptor.getNodeDescriptors()) {
+                visitDataNodeDescriptor(node);
+            }
 
-    ProcedureQueryValidator getProcedureQueryValidator() {
-        return procedureQueryValidator;
-    }
+            for (DataMap map : channelDescriptor.getDataMaps()) {
+                visitDataMap(map);
+            }
 
-    EJBQLQueryValidator getEjbqlQueryValidator() {
-        return ejbqlQueryValidator;
-    }
+            return validationResult;
+        }
 
-    SQLTemplateValidator getSqlTemplateValidator() {
-        return sqlTemplateValidator;
-    }
-}
+        public ValidationResult visitDataMap(DataMap dataMap) {
+            mapValidator.validate(dataMap, validationResult);
+            Iterator<Embeddable> itEmb = dataMap.getEmbeddables().iterator();
+            while (itEmb.hasNext()) {
+                Embeddable emb = itEmb.next();
+                visitEmbeddable(emb);
+            }
 
-class ValidationVisitor implements ConfigurationNodeVisitor<ValidationResult> {
+            Iterator<ObjEntity> itObjEnt = dataMap.getObjEntities().iterator();
+            while (itObjEnt.hasNext()) {
+                ObjEntity ent = itObjEnt.next();
+                visitObjEntity(ent);
+            }
 
-    private ValidationResult validationResults = new ValidationResult();
+            Iterator<DbEntity> itDbEnt = dataMap.getDbEntities().iterator();
+            while (itDbEnt.hasNext()) {
+                DbEntity ent = itDbEnt.next();
+                visitDbEntity(ent);
+            }
 
-    private DefaultProjectValidator defaultProjectValidator;
+            Iterator<Procedure> itProc = dataMap.getProcedures().iterator();
+            while (itProc.hasNext()) {
+                Procedure proc = itProc.next();
+                visitProcedure(proc);
+            }
 
-    ValidationVisitor(DefaultProjectValidator defaultProjectValidator) {
-        this.defaultProjectValidator = defaultProjectValidator;
-    }
+            Iterator<Query> itQuer = dataMap.getQueries().iterator();
+            while (itQuer.hasNext()) {
+                Query q = itQuer.next();
+                visitQuery(q);
+            }
 
-    public ValidationResult visitDataChannelDescriptor(
-            DataChannelDescriptor channelDescriptor) {
-        defaultProjectValidator.getDataChannelValidator().validate(
-                channelDescriptor,
-                this);
-        Iterator<DataNodeDescriptor> it = channelDescriptor
-                .getNodeDescriptors()
-                .iterator();
-        while (it.hasNext()) {
-            DataNodeDescriptor node = it.next();
-            visitDataNodeDescriptor(node);
-        }
-
-        Iterator<DataMap> itMap = channelDescriptor.getDataMaps().iterator();
-        while (itMap.hasNext()) {
-            DataMap map = itMap.next();
-            visitDataMap(map);
+            return validationResult;
         }
-        return validationResults;
-    }
 
-    public ValidationResult visitDataMap(DataMap dataMap) {
-        defaultProjectValidator.getMapValidator().validate(dataMap, this);
-        Iterator<Embeddable> itEmb = dataMap.getEmbeddables().iterator();
-        while (itEmb.hasNext()) {
-            Embeddable emb = itEmb.next();
-            visitEmbeddable(emb);
+        public ValidationResult visitDataNodeDescriptor(DataNodeDescriptor nodeDescriptor) {
+            nodeValidator.validate(nodeDescriptor, validationResult);
+            return validationResult;
         }
 
-        Iterator<ObjEntity> itObjEnt = dataMap.getObjEntities().iterator();
-        while (itObjEnt.hasNext()) {
-            ObjEntity ent = itObjEnt.next();
-            visitObjEntity(ent);
+        public ValidationResult visitDbAttribute(DbAttribute attribute) {
+            dbAttrValidator.validate(attribute, validationResult);
+            return validationResult;
         }
 
-        Iterator<DbEntity> itDbEnt = dataMap.getDbEntities().iterator();
-        while (itDbEnt.hasNext()) {
-            DbEntity ent = itDbEnt.next();
-            visitDbEntity(ent);
-        }
+        public ValidationResult visitDbEntity(DbEntity entity) {
+            dbEntityValidator.validate(entity, validationResult);
 
-        Iterator<Procedure> itProc = dataMap.getProcedures().iterator();
-        while (itProc.hasNext()) {
-            Procedure proc = itProc.next();
-            visitProcedure(proc);
-        }
+            Iterator<DbAttribute> itAttr = entity.getAttributes().iterator();
+            while (itAttr.hasNext()) {
+                DbAttribute attr = itAttr.next();
+                visitDbAttribute(attr);
+            }
 
-        Iterator<Query> itQuer = dataMap.getQueries().iterator();
-        while (itQuer.hasNext()) {
-            Query q = itQuer.next();
-            visitQuery(q);
+            Iterator<DbRelationship> itRel = entity.getRelationships().iterator();
+            while (itRel.hasNext()) {
+                DbRelationship rel = itRel.next();
+                visitDbRelationship(rel);
+            }
+            return validationResult;
         }
 
-        return validationResults;
-    }
-
-    public ValidationResult visitDataNodeDescriptor(DataNodeDescriptor nodeDescriptor) {
-        defaultProjectValidator.getNodeValidator().validate(nodeDescriptor, this);
-        return validationResults;
-    }
-
-    public ValidationResult visitDbAttribute(DbAttribute attribute) {
-        defaultProjectValidator.getDbAttrValidator().validate(attribute, this);
-        return validationResults;
-    }
-
-    public ValidationResult visitDbEntity(DbEntity entity) {
-        defaultProjectValidator.getDbEntityValidator().validate(entity, this);
-
-        Iterator<DbAttribute> itAttr = entity.getAttributes().iterator();
-        while (itAttr.hasNext()) {
-            DbAttribute attr = itAttr.next();
-            visitDbAttribute(attr);
+        public ValidationResult visitDbRelationship(DbRelationship relationship) {
+            dbRelValidator.validate(relationship, validationResult);
+            return validationResult;
         }
 
-        Iterator<DbRelationship> itRel = entity.getRelationships().iterator();
-        while (itRel.hasNext()) {
-            DbRelationship rel = itRel.next();
-            visitDbRelationship(rel);
+        public ValidationResult visitEmbeddable(Embeddable embeddable) {
+            embeddableValidator.validate(embeddable, validationResult);
+            Iterator<EmbeddableAttribute> it = embeddable.getAttributes().iterator();
+            while (it.hasNext()) {
+                EmbeddableAttribute attr = it.next();
+                visitEmbeddableAttribute(attr);
+            }
+            return validationResult;
         }
-        return validationResults;
-    }
 
-    public ValidationResult visitDbRelationship(DbRelationship relationship) {
-        defaultProjectValidator.getDbRelValidator().validate(relationship, this);
-        return validationResults;
-    }
-
-    public ValidationResult visitEmbeddable(Embeddable embeddable) {
-        defaultProjectValidator.getEmbeddableValidator().validate(embeddable, this);
-        Iterator<EmbeddableAttribute> it = embeddable.getAttributes().iterator();
-        while (it.hasNext()) {
-            EmbeddableAttribute attr = it.next();
-            visitEmbeddableAttribute(attr);
+        public ValidationResult visitEmbeddableAttribute(EmbeddableAttribute attribute) {
+            embeddableAttributeValidator.validate(attribute, validationResult);
+            return validationResult;
         }
-        return validationResults;
-    }
-
-    public ValidationResult visitEmbeddableAttribute(EmbeddableAttribute attribute) {
-        defaultProjectValidator.getEmbeddableAttributeValidator().validate(
-                attribute,
-                this);
-        return validationResults;
-    }
-
-    public ValidationResult visitObjAttribute(ObjAttribute attribute) {
-        defaultProjectValidator.getObjAttrValidator().validate(attribute, this);
-        return validationResults;
-    }
-
-    public ValidationResult visitObjEntity(ObjEntity entity) {
-        defaultProjectValidator.getObjEntityValidator().validate(entity, this);
 
-        Iterator<ObjAttribute> itAttr = entity.getAttributes().iterator();
-        while (itAttr.hasNext()) {
-            ObjAttribute attr = itAttr.next();
-            visitObjAttribute(attr);
+        public ValidationResult visitObjAttribute(ObjAttribute attribute) {
+            objAttrValidator.validate(attribute, validationResult);
+            return validationResult;
         }
 
-        Iterator<ObjRelationship> itRel = entity.getRelationships().iterator();
-        while (itRel.hasNext()) {
-            ObjRelationship rel = itRel.next();
-            visitObjRelationship(rel);
-        }
-        return validationResults;
-    }
+        public ValidationResult visitObjEntity(ObjEntity entity) {
+            objEntityValidator.validate(entity, validationResult);
 
-    public ValidationResult visitObjRelationship(ObjRelationship relationship) {
-        defaultProjectValidator.getObjRelValidator().validate(relationship, this);
-        return validationResults;
-    }
+            Iterator<ObjAttribute> itAttr = entity.getAttributes().iterator();
+            while (itAttr.hasNext()) {
+                ObjAttribute attr = itAttr.next();
+                visitObjAttribute(attr);
+            }
 
-    public ValidationResult visitProcedure(Procedure procedure) {
-        defaultProjectValidator.getProcedureValidator().validate(procedure, this);
-        ProcedureParameter parameter = procedure.getResultParam();
-        if (parameter != null) {
-            visitProcedureParameter(parameter);
+            Iterator<ObjRelationship> itRel = entity.getRelationships().iterator();
+            while (itRel.hasNext()) {
+                ObjRelationship rel = itRel.next();
+                visitObjRelationship(rel);
+            }
+            return validationResult;
         }
 
-        Iterator<ProcedureParameter> itPrOut = procedure
-                .getCallOutParameters()
-                .iterator();
-        while (itPrOut.hasNext()) {
-            ProcedureParameter procPar = itPrOut.next();
-            visitProcedureParameter(procPar);
+        public ValidationResult visitObjRelationship(ObjRelationship relationship) {
+            objRelValidator.validate(relationship, validationResult);
+            return validationResult;
         }
 
-        Iterator<ProcedureParameter> itPr = procedure.getCallParameters().iterator();
-        while (itPr.hasNext()) {
-            ProcedureParameter procPar = itPr.next();
-            visitProcedureParameter(procPar);
-        }
+        public ValidationResult visitProcedure(Procedure procedure) {
+            procedureValidator.validate(procedure, validationResult);
+            ProcedureParameter parameter = procedure.getResultParam();
+            if (parameter != null) {
+                visitProcedureParameter(parameter);
+            }
 
-        return validationResults;
-    }
+            Iterator<ProcedureParameter> itPrOut = procedure
+                    .getCallOutParameters()
+                    .iterator();
+            while (itPrOut.hasNext()) {
+                ProcedureParameter procPar = itPrOut.next();
+                visitProcedureParameter(procPar);
+            }
 
-    public ValidationResult visitProcedureParameter(ProcedureParameter parameter) {
-        defaultProjectValidator
-                .getProcedureParameterValidator()
-                .validate(parameter, this);
-        return validationResults;
-    }
+            Iterator<ProcedureParameter> itPr = procedure.getCallParameters().iterator();
+            while (itPr.hasNext()) {
+                ProcedureParameter procPar = itPr.next();
+                visitProcedureParameter(procPar);
+            }
 
-    public ValidationResult visitQuery(Query query) {
-        if (query instanceof SelectQuery) {
-            defaultProjectValidator.getSelectQueryValidator().validate(query, this);
-        }
-        else if (query instanceof SQLTemplate) {
-            defaultProjectValidator.getSqlTemplateValidator().validate(query, this);
-        }
-        else if (query instanceof ProcedureQuery) {
-            defaultProjectValidator.getProcedureQueryValidator().validate(query, this);
+            return validationResult;
         }
-        else if (query instanceof EJBQLQuery) {
-            defaultProjectValidator.getEjbqlQueryValidator().validate(query, this);
-        }
-        else {
-            // ignore unknown nodes
-            return null;
-        }
-        return validationResults;
-    }
-
-    /**
-     * Registers validation result. Increases internally stored max severity if
-     * <code>result</code> parameter has a higher severity then the current value. Leaves
-     * current value unchanged otherwise.
-     */
-    public void registerValidated(String message, Object object) {
 
-        SimpleValidationFailure result = new SimpleValidationFailure(object, message);
-        validationResults.addFailure(result);
-    }
+        public ValidationResult visitProcedureParameter(ProcedureParameter parameter) {
+            procedureParameterValidator.validate(parameter, validationResult);
+            return validationResult;
+        }
 
-    public void registerError(String message, Object object) {
-        registerValidated(message, object);
-    }
+        public ValidationResult visitQuery(Query query) {
+            if (query instanceof SelectQuery) {
+                selectQueryValidator.validate((SelectQuery) query, validationResult);
+            }
+            else if (query instanceof SQLTemplate) {
+                sqlTemplateValidator.validate((SQLTemplate) query, validationResult);
+            }
+            else if (query instanceof ProcedureQuery) {
+                procedureQueryValidator
+                        .validate((ProcedureQuery) query, validationResult);
+            }
+            else if (query instanceof EJBQLQuery) {
+                ejbqlQueryValidator.validate((EJBQLQuery) query, validationResult);
+            }
 
-    public void registerWarning(String message, Object object) {
-        registerValidated(message, object);
+            return validationResult;
+        }
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EJBQLQueryValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EJBQLQueryValidator.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EJBQLQueryValidator.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EJBQLQueryValidator.java Thu Mar 11 14:19:25 2010
@@ -19,20 +19,15 @@
 package org.apache.cayenne.project2.validation;
 
 import org.apache.cayenne.map.EntityResolver;
-import org.apache.cayenne.project.ProjectPath;
 import org.apache.cayenne.project2.validation.EJBQLStatementValidator.PositionException;
 import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.validation.ValidationResult;
 
-class EJBQLQueryValidator {
+class EJBQLQueryValidator extends ConfigurationNodeValidator {
 
-    void validate(Object object, ValidationVisitor validationVisitor) {
-        EJBQLQuery query = (EJBQLQuery) object;
+    void validate(EJBQLQuery query, ValidationResult validationResult) {
 
-        ProjectPath path = new ProjectPath(new Object[] {
-                query.getDataMap().getDataChannelDescriptor(), query.getDataMap(), query
-        });
-
-        PositionException message = (new EJBQLStatementValidator()).validateEJBQL(
+        PositionException message = new EJBQLStatementValidator().validateEJBQL(
                 query,
                 new EntityResolver(query
                         .getDataMap()
@@ -40,9 +35,8 @@ class EJBQLQueryValidator {
                         .getDataMaps()));
 
         if (message != null) {
-            validationVisitor.registerWarning("EJBQL query "
-                    + query.getName()
-                    + " has error.", path);
+            addFailure(validationResult, query, "Error in EJBQL query '%s' syntax", query
+                    .getName());
         }
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EmbeddableAttributeValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EmbeddableAttributeValidator.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EmbeddableAttributeValidator.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EmbeddableAttributeValidator.java Thu Mar 11 14:19:25 2010
@@ -20,21 +20,24 @@ package org.apache.cayenne.project2.vali
 
 import org.apache.cayenne.map.EmbeddableAttribute;
 import org.apache.cayenne.util.Util;
+import org.apache.cayenne.validation.ValidationResult;
 
-class EmbeddableAttributeValidator {
+class EmbeddableAttributeValidator extends ConfigurationNodeValidator {
 
-    void validate(Object object, ValidationVisitor validationVisitor) {
-
-        EmbeddableAttribute emAttribute = (EmbeddableAttribute) object;
+    void validate(EmbeddableAttribute attribute, ValidationResult validationResult) {
 
         // Must have name
-        if (Util.isEmptyString(emAttribute.getName())) {
-            validationVisitor.registerError("Unnamed EmbeddableAttribute.", object);
+        if (Util.isEmptyString(attribute.getName())) {
+            addFailure(validationResult, attribute, "Unnamed EmbeddableAttribute");
         }
 
         // all attributes must have type
-        if (Util.isEmptyString(emAttribute.getType())) {
-            validationVisitor.registerWarning("EmbeddableAttribute has no type.", object);
+        if (Util.isEmptyString(attribute.getType())) {
+            addFailure(
+                    validationResult,
+                    attribute,
+                    "EmbeddableAttribute '%s' has no type",
+                    attribute.getName());
         }
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EmbeddableValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EmbeddableValidator.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EmbeddableValidator.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/EmbeddableValidator.java Thu Mar 11 14:19:25 2010
@@ -22,44 +22,44 @@ import org.apache.cayenne.configuration.
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.Embeddable;
 import org.apache.cayenne.util.Util;
+import org.apache.cayenne.validation.ValidationResult;
 
-class EmbeddableValidator {
+class EmbeddableValidator extends ConfigurationNodeValidator {
 
-    void validate(Object object, ValidationVisitor validationVisitor) {
-        Embeddable emb = (Embeddable) object;
-        validateName(emb, object, validationVisitor);
-    }
+    void validate(Embeddable embeddable, ValidationResult validationResult) {
 
-    void validateName(Embeddable emb, Object object, ValidationVisitor validationVisitor) {
-        String name = emb.getClassName();
+        String name = embeddable.getClassName();
 
         // Must have name
         if (Util.isEmptyString(name)) {
-            validationVisitor.registerError("Unnamed Embeddable.", object);
+            addFailure(validationResult, embeddable, "Unnamed Embeddable");
             return;
         }
 
-        DataMap map = emb.getDataMap();
+        DataMap map = embeddable.getDataMap();
         if (map == null) {
             return;
         }
 
         // check for duplicate names in the parent context
         for (Embeddable otherEmb : map.getEmbeddables()) {
-            if (otherEmb == emb) {
+            if (otherEmb == embeddable) {
                 continue;
             }
 
             if (name.equals(otherEmb.getClassName())) {
-                validationVisitor.registerError("Duplicate Embeddable name: "
-                        + name
-                        + ".", object);
+
+                addFailure(
+                        validationResult,
+                        embeddable,
+                        "Duplicate Embeddable class name: %s",
+                        name);
                 break;
             }
         }
 
-        // check for dupliucates in other DataMaps
-        DataChannelDescriptor domain = emb.getDataMap().getDataChannelDescriptor();
+        // check for duplicates in other DataMaps
+        DataChannelDescriptor domain = map.getDataChannelDescriptor();
         if (domain != null) {
             for (DataMap nextMap : domain.getDataMaps()) {
                 if (nextMap == map) {
@@ -68,13 +68,11 @@ class EmbeddableValidator {
 
                 Embeddable conflictingEmbeddable = nextMap.getEmbeddable(name);
                 if (conflictingEmbeddable != null) {
-
-                    validationVisitor
-                            .registerWarning(
-                                    "Duplicate Embeddable name in another DataMap: "
-                                            + name
-                                            + ".",
-                                    object);
+                    addFailure(
+                            validationResult,
+                            embeddable,
+                            "Duplicate Embeddable name in another DataMap: %s",
+                            name);
                     break;
                 }
             }

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/NameValidationHelper.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/NameValidationHelper.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/NameValidationHelper.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/NameValidationHelper.java Thu Mar 11 14:19:25 2010
@@ -34,6 +34,7 @@ public class NameValidationHelper {
             "abstract",
             "assert",
             "default",
+            "enum",
             "if",
             "private",
             "this",

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjAttributeValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjAttributeValidator.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjAttributeValidator.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjAttributeValidator.java Thu Mar 11 14:19:25 2010
@@ -18,8 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.project2.validation;
 
-import java.util.Collection;
-import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.cayenne.map.Embeddable;
@@ -28,15 +26,15 @@ import org.apache.cayenne.map.EmbeddedAt
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.util.Util;
+import org.apache.cayenne.validation.ValidationResult;
 
-class ObjAttributeValidator {
+class ObjAttributeValidator extends ConfigurationNodeValidator {
 
-    void validate(Object object, ValidationVisitor validationVisitor) {
-        ObjAttribute attribute = (ObjAttribute) object;
+    void validate(ObjAttribute attribute, ValidationResult validationResult) {
 
         // Must have name
         if (Util.isEmptyString(attribute.getName())) {
-            validationVisitor.registerError("Unnamed ObjAttribute.", object);
+            addFailure(validationResult, attribute, "Unnamed ObjAttribute");
         }
         else {
             NameValidationHelper helper = NameValidationHelper.getInstance();
@@ -44,19 +42,29 @@ class ObjAttributeValidator {
                     .getName());
 
             if (invalidChars != null) {
-                validationVisitor.registerWarning(
-                        "ObjAttribute name contains invalid characters: " + invalidChars,
-                        object);
+                addFailure(
+                        validationResult,
+                        attribute,
+                        "ObjAttribute name '%s' contains invalid characters: %s",
+                        attribute.getName(),
+                        invalidChars);
             }
             else if (helper.invalidDataObjectProperty(attribute.getName())) {
-                validationVisitor.registerWarning("ObjAttribute name is invalid: "
-                        + attribute.getName(), object);
+                addFailure(
+                        validationResult,
+                        attribute,
+                        "ObjAttribute name '%s' is invalid",
+                        attribute.getName());
             }
         }
 
         // all attributes must have type
         if (Util.isEmptyString(attribute.getType())) {
-            validationVisitor.registerWarning("ObjAttribute has no type.", object);
+            addFailure(
+                    validationResult,
+                    attribute,
+                    "ObjAttribute '%s' has no Java type",
+                    attribute.getName());
         }
 
         if (attribute.getEntity() instanceof ObjEntity
@@ -66,62 +74,79 @@ class ObjAttributeValidator {
         else if (attribute instanceof EmbeddedAttribute) {
             Map<String, String> attrOverrides = ((EmbeddedAttribute) attribute)
                     .getAttributeOverrides();
-            Embeddable emb = ((EmbeddedAttribute) attribute).getEmbeddable();
-            if (emb == null && ((EmbeddedAttribute) attribute).getType() != null) {
-                validationVisitor.registerWarning(
-                        "EmbeddedAttribute has incorrect Embeddable.",
-                        object);
+
+            Embeddable embeddable = ((EmbeddedAttribute) attribute).getEmbeddable();
+            if (embeddable == null && ((EmbeddedAttribute) attribute).getType() != null) {
+
+                addFailure(
+                        validationResult,
+                        attribute,
+                        "EmbeddedAttribute '%s' has incorrect Embeddable",
+                        attribute.getName());
             }
-            else if (emb == null && ((EmbeddedAttribute) attribute).getType() == null) {
-                validationVisitor.registerWarning(
-                        "EmbeddedAttribute has no Embeddable.",
-                        object);
+            else if (embeddable == null
+                    && ((EmbeddedAttribute) attribute).getType() == null) {
+                addFailure(
+                        validationResult,
+                        attribute,
+                        "EmbeddedAttribute '%s' has no Embeddable",
+                        attribute.getName());
             }
 
-            if (emb != null) {
-                Collection<EmbeddableAttribute> embAttributes = emb.getAttributes();
+            if (embeddable != null) {
 
-                Iterator<EmbeddableAttribute> it = embAttributes.iterator();
-                while (it.hasNext()) {
-                    EmbeddableAttribute embAttr = (EmbeddableAttribute) it.next();
+                for (EmbeddableAttribute embeddableAttribute : embeddable.getAttributes()) {
                     String dbAttributeName;
                     if (attrOverrides.size() > 0
-                            && attrOverrides.containsKey(embAttr.getName())) {
-                        dbAttributeName = attrOverrides.get(embAttr.getName());
+                            && attrOverrides.containsKey(embeddableAttribute.getName())) {
+                        dbAttributeName = attrOverrides
+                                .get(embeddableAttribute.getName());
                     }
                     else {
-                        dbAttributeName = embAttr.getDbAttributeName();
+                        dbAttributeName = embeddableAttribute.getDbAttributeName();
                     }
 
                     if (dbAttributeName == "" || dbAttributeName == null) {
-                        validationVisitor.registerWarning(
-                                "EmbeddedAttribute has no DbAttribute mapping.",
-                                object);
+
+                        addFailure(
+                                validationResult,
+                                attribute,
+                                "EmbeddedAttribute '%s' has no DbAttribute mapping",
+                                attribute.getName());
                     }
                     else if (((ObjEntity) attribute.getEntity())
                             .getDbEntity()
                             .getAttribute(dbAttributeName) == null) {
-                        validationVisitor.registerWarning(
-                                "EmbeddedAttribute has incorrect DbAttribute mapping.",
-                                object);
+
+                        addFailure(
+                                validationResult,
+                                attribute,
+                                "EmbeddedAttribute '%s' has incorrect DbAttribute mapping",
+                                attribute.getName());
                     }
                 }
             }
 
         }
         else if (attribute.getDbAttribute() == null) {
-            validationVisitor.registerWarning(
-                    "ObjAttribute has no DbAttribute mapping.",
-                    object);
+            addFailure(
+                    validationResult,
+                    attribute,
+                    "ObjAttribute '%s' has no DbAttribute mapping",
+                    attribute.getName());
         }
         // can't support generated meaningful attributes for now; besides they don't make
         // sense.
+        // TODO: andrus 03/10/2010 - is that really so? I think those are supported...
         else if (attribute.getDbAttribute().isPrimaryKey()
                 && attribute.getDbAttribute().isGenerated()) {
-            validationVisitor.registerWarning(
-                    "ObjAttribute is mapped to a generated PK: "
-                            + attribute.getDbAttributeName(),
-                    object);
+
+            addFailure(
+                    validationResult,
+                    attribute,
+                    "ObjAttribute '%s' is mapped to a generated PK: %s",
+                    attribute.getName(),
+                    attribute.getDbAttributeName());
         }
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjEntityValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjEntityValidator.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjEntityValidator.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjEntityValidator.java Thu Mar 11 14:19:25 2010
@@ -22,29 +22,29 @@ import org.apache.cayenne.configuration.
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.util.Util;
+import org.apache.cayenne.validation.ValidationResult;
 
-class ObjEntityValidator {
+class ObjEntityValidator extends ConfigurationNodeValidator {
 
-    void validate(Object object, ValidationVisitor validationVisitor) {
-        ObjEntity ent = (ObjEntity) object;
+    void validate(ObjEntity entity, ValidationResult validationResult) {
 
-        validateName(ent, object, validationVisitor);
-        validateClassName(ent, object, validationVisitor);
-        validateSuperClassName(ent, object, validationVisitor);
+        validateName(entity, validationResult);
+        validateClassName(entity, validationResult);
+        validateSuperClassName(entity, validationResult);
 
         // validate DbEntity presence
-        if (ent.getDbEntity() == null && !ent.isAbstract()) {
-            validationVisitor.registerWarning(
-                    "ObjEntity has no DbEntity mapping.",
-                    object);
+        if (entity.getDbEntity() == null && !entity.isAbstract()) {
+
+            addFailure(
+                    validationResult,
+                    entity,
+                    "ObjEntity '%s' has no DbEntity mapping",
+                    entity.getName());
         }
     }
 
-    void validateClassName(
-            ObjEntity ent,
-            Object object,
-            ValidationVisitor validationVisitor) {
-        String className = ent.getClassName();
+    void validateClassName(ObjEntity entity, ValidationResult validationResult) {
+        String className = entity.getClassName();
 
         // if mapped to default class, ignore...
         if (Util.isEmptyString(className)) {
@@ -55,26 +55,34 @@ class ObjEntityValidator {
         String invalidChars = helper.invalidCharsInJavaClassName(className);
 
         if (invalidChars != null) {
-            validationVisitor.registerWarning(
-                    "ObjEntity Java class contains invalid characters: " + invalidChars,
-                    object);
+            addFailure(
+                    validationResult,
+                    entity,
+                    "ObjEntity '%s' Java class '%s' contains invalid characters: %s",
+                    entity.getName(),
+                    className,
+                    invalidChars);
         }
         else if (helper.invalidDataObjectClass(className)) {
-            validationVisitor.registerWarning("ObjEntity Java class is invalid: "
-                    + className, object);
+            addFailure(
+                    validationResult,
+                    entity,
+                    "Java class '%s' of ObjEntity '%s' is a reserved word",
+                    className,
+                    entity.getName());
         }
         else if (className.indexOf('.') < 0) {
-            validationVisitor.registerWarning(
-                    "Placing Java class in default package is discouraged: " + className,
-                    object);
+            addFailure(
+                    validationResult,
+                    entity,
+                    "Java class '%s' of ObjEntity '%s' is in a default package",
+                    className,
+                    entity.getName());
         }
     }
 
-    void validateSuperClassName(
-            ObjEntity ent,
-            Object object,
-            ValidationVisitor validationVisitor) {
-        String superClassName = ent.getSuperClassName();
+    void validateSuperClassName(ObjEntity entity, ValidationResult validationResult) {
+        String superClassName = entity.getSuperClassName();
 
         if (Util.isEmptyString(superClassName)) {
             return; // null is Ok
@@ -84,28 +92,35 @@ class ObjEntityValidator {
         String invalidChars = helper.invalidCharsInJavaClassName(superClassName);
 
         if (invalidChars != null) {
-            validationVisitor.registerWarning(
-                    "ObjEntity Java superclass contains invalid characters: "
-                            + invalidChars,
-                    object);
+            addFailure(
+                    validationResult,
+                    entity,
+                    "ObjEntity '%s' Java superclass '%s' contains invalid characters: %s",
+                    entity.getName(),
+                    superClassName,
+                    invalidChars);
         }
         else if (helper.invalidDataObjectClass(superClassName)) {
-            validationVisitor.registerWarning("ObjEntity Java superclass is invalid: "
-                    + superClassName, object);
+            addFailure(
+                    validationResult,
+                    entity,
+                    "ObjEntity '%s' Java superclass '%s' is a reserved word",
+                    entity.getName(),
+                    superClassName);
         }
 
-        DataMap map = ent.getDataMap();
+        DataMap map = entity.getDataMap();
         if (map == null) {
             return;
         }
     }
 
-    void validateName(ObjEntity entity, Object object, ValidationVisitor validationVisitor) {
+    void validateName(ObjEntity entity, ValidationResult validationResult) {
         String name = entity.getName();
 
         // Must have name
         if (Util.isEmptyString(name)) {
-            validationVisitor.registerError("Unnamed ObjEntity.", object);
+            addFailure(validationResult, entity, "Unnamed ObjEntity");
             return;
         }
 
@@ -121,14 +136,16 @@ class ObjEntityValidator {
             }
 
             if (name.equals(otherEnt.getName())) {
-                validationVisitor.registerError(
-                        "Duplicate ObjEntity name: " + name + ".",
-                        object);
+                addFailure(
+                        validationResult,
+                        entity,
+                        "Duplicate ObjEntity name: '%s'",
+                        name);
                 break;
             }
         }
 
-        // check for dupliucates in other DataMaps
+        // check for duplicates in other DataMaps
         DataChannelDescriptor domain = entity.getDataMap().getDataChannelDescriptor();
         if (domain != null) {
             for (DataMap nextMap : domain.getDataMaps()) {
@@ -141,11 +158,11 @@ class ObjEntityValidator {
 
                     if (!Util.nullSafeEquals(conflictingEntity.getClassName(), entity
                             .getClassName())) {
-                        validationVisitor.registerWarning(
-                                "Duplicate ObjEntity name in another DataMap: "
-                                        + name
-                                        + ".",
-                                object);
+                        addFailure(
+                                validationResult,
+                                entity,
+                                "Duplicate ObjEntity name in another DataMap: '%s'",
+                                name);
                         break;
                     }
                 }

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjRelationshipValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjRelationshipValidator.java?rev=921861&r1=921860&r2=921861&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjRelationshipValidator.java (original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/validation/ObjRelationshipValidator.java Thu Mar 11 14:19:25 2010
@@ -28,71 +28,88 @@ import org.apache.cayenne.map.DeleteRule
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.util.Util;
+import org.apache.cayenne.validation.ValidationResult;
 
-class ObjRelationshipValidator {
+class ObjRelationshipValidator extends ConfigurationNodeValidator {
 
-    void validate(Object object, ValidationVisitor validationVisitor) {
-        ObjRelationship rel = (ObjRelationship) object;
+    void validate(ObjRelationship relationship, ValidationResult validationResult) {
 
-        if (Util.isEmptyString(rel.getName())) {
-            validationVisitor.registerError("Unnamed ObjRelationship.", object);
+        if (Util.isEmptyString(relationship.getName())) {
+            addFailure(validationResult, relationship, "Unnamed ObjRelationship");
         }
+
         // check if there are attributes having the same name
-        else if (rel.getSourceEntity().getAttribute(rel.getName()) != null) {
-            validationVisitor.registerWarning("ObjRelationship "
-                    + objRelationshipIdentifier(rel)
-                    + " has the same name as one of ObjAttributes", object);
+        else if (relationship.getSourceEntity().getAttribute(relationship.getName()) != null) {
+            addFailure(
+                    validationResult,
+                    relationship,
+                    "ObjRelationship '%s' has the same name as one of ObjAttributes",
+                    toString(relationship));
         }
         else {
             NameValidationHelper helper = NameValidationHelper.getInstance();
-            String invalidChars = helper.invalidCharsInObjPathComponent(rel.getName());
+            String invalidChars = helper.invalidCharsInObjPathComponent(relationship
+                    .getName());
 
             if (invalidChars != null) {
-                validationVisitor.registerWarning("ObjRelationship "
-                        + objRelationshipIdentifier(rel)
-                        + " name contains invalid characters: "
-                        + invalidChars, object);
+                addFailure(
+                        validationResult,
+                        relationship,
+                        "ObjRelationship name '%s' contains invalid characters: %s",
+                        toString(relationship),
+                        invalidChars);
             }
-            else if (helper.invalidDataObjectProperty(rel.getName())) {
-                validationVisitor.registerWarning("ObjRelationship "
-                        + objRelationshipIdentifier(rel)
-                        + " name is invalid.", object);
+            else if (helper.invalidDataObjectProperty(relationship.getName())) {
+                addFailure(
+                        validationResult,
+                        relationship,
+                        "ObjRelationship name '%s' is a reserved word",
+                        toString(relationship));
             }
         }
 
-        if (rel.getTargetEntity() == null) {
-            validationVisitor.registerWarning("ObjRelationship "
-                    + objRelationshipIdentifier(rel)
-                    + " has no target entity.", object);
+        if (relationship.getTargetEntity() == null) {
+            addFailure(
+                    validationResult,
+                    relationship,
+                    "ObjRelationship '%s' has no target entity",
+                    toString(relationship));
         }
         else {
+
             // check for missing DbRelationship mappings
-            List<DbRelationship> dbRels = rel.getDbRelationships();
-            if (dbRels.size() == 0) {
-                validationVisitor.registerWarning("ObjRelationship "
-                        + objRelationshipIdentifier(rel)
-                        + " has no DbRelationship mapping.", object);
+            List<DbRelationship> dbRels = relationship.getDbRelationships();
+            if (dbRels.isEmpty()) {
+                addFailure(
+                        validationResult,
+                        relationship,
+                        "ObjRelationship '%s' has no DbRelationship mapping",
+                        toString(relationship));
             }
             else {
-                DbEntity expectedSrc = ((ObjEntity) rel.getSourceEntity()).getDbEntity();
-                DbEntity expectedTarget = ((ObjEntity) rel.getTargetEntity())
+                DbEntity expectedSrc = ((ObjEntity) relationship.getSourceEntity())
+                        .getDbEntity();
+                DbEntity expectedTarget = ((ObjEntity) relationship.getTargetEntity())
                         .getDbEntity();
 
                 if ((dbRels.get(0)).getSourceEntity() != expectedSrc
                         || (dbRels.get(dbRels.size() - 1)).getTargetEntity() != expectedTarget) {
-                    validationVisitor.registerWarning("ObjRelationship "
-                            + objRelationshipIdentifier(rel)
-                            + " has incomplete DbRelationship mapping.", object);
+
+                    addFailure(
+                            validationResult,
+                            relationship,
+                            "ObjRelationship '%s' has incomplete DbRelationship mapping",
+                            toString(relationship));
                 }
             }
         }
 
         // Disallow a Nullify delete rule where the relationship is toMany and the
         // foreign key attributes are mandatory.
-        if (rel.isToMany()
-                && !rel.isFlattened()
-                && (rel.getDeleteRule() == DeleteRule.NULLIFY)) {
-            ObjRelationship inverse = rel.getReverseRelationship();
+        if (relationship.isToMany()
+                && !relationship.isFlattened()
+                && (relationship.getDeleteRule() == DeleteRule.NULLIFY)) {
+            ObjRelationship inverse = relationship.getReverseRelationship();
             if (inverse != null) {
                 DbRelationship firstRel = inverse.getDbRelationships().get(0);
                 Iterator<DbJoin> attributePairIterator = firstRel.getJoins().iterator();
@@ -108,22 +125,22 @@ class ObjRelationshipValidator {
                 }
 
                 if (check) {
-                    validationVisitor
-                            .registerWarning(
-                                    "ObjRelationship "
-                                            + objRelationshipIdentifier(rel)
-                                            + " has a Nullify delete rule and a mandatory reverse relationship ",
-                                    object);
+                    addFailure(
+                            validationResult,
+                            relationship,
+                            "ObjRelationship '%s' has a Nullify delete rule and a mandatory reverse relationship",
+                            toString(relationship));
                 }
             }
         }
     }
 
-    String objRelationshipIdentifier(ObjRelationship rel) {
-        if (null == rel.getSourceEntity()) {
-            return "<[null source entity]." + rel.getName() + ">";
+    private String toString(ObjRelationship relationship) {
+        if (relationship.getSourceEntity() == null) {
+            return "[null source entity]." + relationship.getName();
         }
-        return "<" + rel.getSourceEntity().getName() + "." + rel.getName() + ">";
+
+        return relationship.getSourceEntity().getName() + "." + relationship.getName();
     }
 
 }



Mime
View raw message