, Pattern> namePatterns)
+ {
+ this.namePatterns = namePatterns;
+ }
+
+ /**
+ * If during validation, there is no specific name validation pattern for the supplied {@link Dialect}
+ * then the defaultNamePattern property will be used - if not null.
+ *
+ * If defaultNamePattern is null then a validation failure will be produced.
+ *
+ * @param defaultNamePattern
+ */
+ public void setDefaultNamePattern(Pattern defaultNamePattern)
+ {
+ this.defaultNamePattern = defaultNamePattern;
+ }
+}
diff --git a/source/java/org/alfresco/util/schemacomp/validator/NameValidatorTest.java b/source/java/org/alfresco/util/schemacomp/validator/NameValidatorTest.java
new file mode 100644
index 0000000000..a3e24c229b
--- /dev/null
+++ b/source/java/org/alfresco/util/schemacomp/validator/NameValidatorTest.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2005-2011 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ */
+package org.alfresco.util.schemacomp.validator;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.alfresco.util.schemacomp.DiffContext;
+import org.alfresco.util.schemacomp.Differences;
+import org.alfresco.util.schemacomp.ValidationResult;
+import org.alfresco.util.schemacomp.model.DbObject;
+import org.alfresco.util.schemacomp.model.Index;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.Oracle10gDialect;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for the NameValidator class.
+ *
+ * @author Matt Ward
+ */
+public class NameValidatorTest
+{
+ private NameValidator validator;
+ private DiffContext ctx;
+ private List validationResults;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ validator = new NameValidator();
+ validationResults = new ArrayList();
+ ctx = new DiffContext(new Oracle10gDialect(), new Differences(), validationResults);
+ }
+
+ @Test
+ public void canSpecifyDefaultRequiredPattern()
+ {
+ validator.setDefaultNamePattern(Pattern.compile("SYS_[A-Z_]+"));
+ validator.validate(indexForName("SYS_MYINDEX"), ctx);
+ validator.validate(indexForName("SYS_"), ctx);
+ validator.validate(indexForName("SYS_MY_INDEX"), ctx);
+ validator.validate(indexForName("MY_INDEX"), ctx);
+
+ assertEquals(2, validationResults.size());
+ assertEquals("SYS_", validationResults.get(0).getValue());
+ assertEquals("MY_INDEX", validationResults.get(1).getValue());
+ }
+
+ @Test
+ public void canValidateAgainstPatternForDialect()
+ {
+ Map, Pattern> patterns = new HashMap, Pattern>();
+ patterns.put(Oracle10gDialect.class, Pattern.compile("ORA_[A-Z_]+"));
+ validator.setNamePatterns(patterns);
+
+ validator.validate(indexForName("ORA_MYINDEX"), ctx);
+ validator.validate(indexForName("SYS_MYINDEX"), ctx);
+
+ assertEquals(1, validationResults.size());
+ assertEquals("SYS_MYINDEX", validationResults.get(0).getValue());
+ }
+
+
+ private DbObject indexForName(String name)
+ {
+ return new Index(name, new ArrayList());
+ }
+}
diff --git a/source/java/org/alfresco/util/schemacomp/validator/NullValidator.java b/source/java/org/alfresco/util/schemacomp/validator/NullValidator.java
new file mode 100644
index 0000000000..4ce49d6b53
--- /dev/null
+++ b/source/java/org/alfresco/util/schemacomp/validator/NullValidator.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2005-2011 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ */
+package org.alfresco.util.schemacomp.validator;
+
+import org.alfresco.util.schemacomp.DiffContext;
+import org.alfresco.util.schemacomp.model.DbObject;
+
+/**
+ * TODO: comment me!
+ * @author Matt Ward
+ */
+public class NullValidator implements DbValidator
+{
+ @Override
+ public void validate(DbObject dbo, DiffContext ctx)
+ {
+ // Do nothing
+ }
+}
diff --git a/source/java/org/alfresco/util/schemacomp/validator/ValidatorTestSuite.java b/source/java/org/alfresco/util/schemacomp/validator/ValidatorTestSuite.java
new file mode 100644
index 0000000000..4f54d724c7
--- /dev/null
+++ b/source/java/org/alfresco/util/schemacomp/validator/ValidatorTestSuite.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2005-2011 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ */
+package org.alfresco.util.schemacomp.validator;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses(
+{
+ NameValidatorTest.class
+})
+public class ValidatorTestSuite
+{
+}