ALF-10771: schema validation and differences rules

Laying some groundwork for the main code.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31921 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2011-11-14 10:16:59 +00:00
parent 60688d34b9
commit 4c863f5e0a
16 changed files with 165 additions and 84 deletions

View File

@@ -21,10 +21,12 @@ package org.alfresco.util.schemacomp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.alfresco.util.schemacomp.Result.Strength;
import org.alfresco.util.schemacomp.Difference.Where;
import org.alfresco.util.schemacomp.Result.Strength;
import org.alfresco.util.schemacomp.model.DbObject;
import org.alfresco.util.schemacomp.model.Schema;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
@@ -54,6 +56,18 @@ public class DefaultComparisonUtils implements ComparisonUtils
}
@Override
public List<DbObject> findEquivalentObjects(Schema schema, DbObject objToMatch)
{
EquivalentObjectSeeker objectSeeker = new EquivalentObjectSeeker(objToMatch);
schema.accept(objectSeeker);
return objectSeeker.getMatches();
}
@Override
public void compareSimpleCollections(DbProperty leftProp,
DbProperty rightProp, DiffContext ctx, Strength strength)
@@ -235,4 +249,33 @@ public class DefaultComparisonUtils implements ComparisonUtils
"Property value is a DbObject - this method shouldn't be used to compare this type: " + obj);
}
}
private static class EquivalentObjectSeeker implements DbObjectVisitor
{
private final List<DbObject> matches = new ArrayList<DbObject>();
private final DbObject objToMatch;
public EquivalentObjectSeeker(DbObject objToMatch)
{
this.objToMatch = objToMatch;
}
@Override
public void visit(DbObject dbObject)
{
if (objToMatch.sameAs(dbObject))
{
matches.add(dbObject);
}
}
/**
* @return the matches
*/
public List<DbObject> getMatches()
{
return this.matches;
}
}
}