How to check if an IDocument instance conforms to a model?

I have an IDocument instance at hand and would like to check if it conforms to the model it is says it refers to. What I mean with conforms to is that every entity instance has a path that exists in the document model and has a repetition array length equal to the length of its path.

How can I do that?

Some background:
I have two IEntityInstance at hand and need to compare the repetition arrays of them. I would like to avoid writing exception handling code like this:

		int[] o1Rep = o1.getRepetitions();
		int[] o2Rep = o2.getRepetitions();
		if (o1Rep.length != o2Rep.length) {
			// IDocument doesn't enforce validity of entity instances when they are being added
			throw new IllegalArgumentException("This shouldn't actually happen but it did somehow.");
		}
		for (int i = 0; i < o1Rep.length; i++) {
		// ...
		}

As far as I have seen IDocument doesn’t document any restrictions when adding IEntityInstance and the standard DocumentImpl also didn’t implement any.

Moin,
in order to check a document against its document model you could use the following.

Use DocumentServiceFactory to create an IDocumentService-instance.

public class DocumentServiceFactory {
    private final IDocumentModelResolver documentModelResolver;

    public DocumentServiceFactory(IDocumentModelResolver documentModelResolver) {
        Validate.notNull(documentModelResolver);
        this.documentModelResolver = documentModelResolver;
    }

    public IDocumentSerializer createDocumentSerializer() {
        return new DocumentSerializerImpl(this.documentModelResolver);
    }

    public IDocumentService createDocumentService(IDocument document) {
        Validate.notNull(document);
        return new DocumentServiceImpl(document, this.documentModelResolver);
    }

    public IDocumentSearchService createDocumentSearchService(IDocument document) {
        Validate.notNull(document);
        return new DocumentSearchServiceImpl(document, this.documentModelResolver);
    }

    public IDocumentFactory createDocumentFactory() {
        return new DocumentFactoryImpl();
    }
}

And then you can use the checkEntities-method.

public interface IDocumentService {
    Object convertToJavaType(IFieldInstance var1, String var2, IProblemReporter var3);

    boolean checkEntities(IProblemReporter var1);

    boolean checkPresenceOfFieldInstancesInNonRepeatableGroups(IProblemReporter var1);

    boolean removeEntityTree(IGroupInstance var1);
}