SchemaValidator implements SchemaValidatorIF { @Override public void validate(TopicIF topic) throws SchemaViolationException { TopicClass klass = (TopicClass) findClass(topic, schema.getTopicClasses()); if (klass == null) { if (schema.isStrict()) handler.violation("No matching rule for topic", topic.getTopicMap(), topic, null); return; } Collection basenamecs = klass.getAllTopicNameConstraints(); Collection occurrencecs = klass.getAllOccurrenceConstraints(); Collection rolecs = klass.getAllRoleConstraints(); Collection others = klass.getOtherClasses(); Iterator it = topic.getTypes().iterator(); while (it.hasNext()) { TopicIF tclass = (TopicIF) it.next(); if (klass.getTypeSpecification().matchType(tclass)) continue; boolean found = false; Iterator it2 = others.iterator(); while (it2.hasNext()) { TypeSpecification typespec = (TypeSpecification) it2.next(); if (typespec.matchType(tclass)) { found = true; TopicClass otherclass = (TopicClass) findClassFor(tclass, schema.getTopicClasses()); if (otherclass != null) { basenamecs.addAll(otherclass.getAllTopicNameConstraints()); occurrencecs.addAll(otherclass.getAllOccurrenceConstraints()); rolecs.addAll(otherclass.getAllRoleConstraints()); } break; } } if (!found) handler.violation("Topic instance of illegal other class", topic, tclass, null); } validate(topic, basenamecs, topic.getTopicNames(), klass.isStrict()); validate(topic, occurrencecs, topic.getOccurrences(), klass.isStrict()); validate(topic, rolecs, topic.getRoles(), klass.isStrict()); } SchemaValidator(OSLSchema schema); @Override void validate(TopicIF topic); @Override void validate(TopicMapIF topicmap); @Override void validate(AssociationIF association); @Override void setValidationHandler(ValidationHandlerIF handler); @Override ValidationHandlerIF getValidationHandler();  }
@Test public void testMinimumTopicNamesValid() throws IOException, SchemaSyntaxException{ OSLSchema schema = (OSLSchema) readSchema("in", "basename.xml"); TopicIF type = makeType("#something"); TopicIF theme = makeType("#something-else"); TopicIF instance = builder.makeTopic(); instance.addType(type); TopicNameIF basename = builder.makeTopicName(instance, ""); basename.addTheme(theme); validate(schema); }
@Test public void testMinimumTopicNamesUnconstrained() throws IOException, SchemaSyntaxException{ OSLSchema schema = (OSLSchema) readSchema("in", "basename-unc.xml"); TopicIF type = makeType("#something"); TopicIF instance = builder.makeTopic(); instance.addType(type); validate(schema, instance, null); }
@Test public void testMinimumTopicNamesValidUnconstrained() throws IOException, SchemaSyntaxException{ OSLSchema schema = (OSLSchema) readSchema("in", "basename-unc.xml"); TopicIF type = makeType("#something"); TopicIF theme = makeType("#something-else"); TopicIF instance = builder.makeTopic(); instance.addType(type); builder.makeTopicName(instance, ""); TopicNameIF basename = builder.makeTopicName(instance, ""); basename.addTheme(theme); validate(schema); }
@Test public void testMinimumOccurrences() throws IOException, SchemaSyntaxException { OSLSchema schema = (OSLSchema) readSchema("in", "occurrence.xml"); TopicIF type = makeType("#something"); TopicIF instance = builder.makeTopic(); instance.addType(type); validate(schema, instance, null); }
@Test public void testMinimumTopicRoles() throws IOException, SchemaSyntaxException { OSLSchema schema = (OSLSchema) readSchema("in", "trole.xml"); TopicIF type = makeType("#type"); TopicIF instance = builder.makeTopic(); instance.addType(type); validate(schema, instance, null); }
@Test public void testMinimumAssociationRoles() throws IOException, SchemaSyntaxException { OSLSchema schema = (OSLSchema) readSchema("in", "arole.xml"); AssociationIF instance = builder.makeAssociation(makeType("#type")); validate(schema, instance, null); }
@Test public void testExternalOccurrence() throws IOException, SchemaSyntaxException { OSLSchema schema = (OSLSchema) readSchema("in", "extocc.xml"); TopicIF type = makeType("#something"); TopicIF instance = builder.makeTopic(); instance.addType(type); TopicIF occtype = makeType("#occtype"); OccurrenceIF occ = builder.makeOccurrence(instance, occtype, "Hubba bubba"); validate(schema, instance, occ); }
@Test public void testInternalOccurrence() throws IOException, SchemaSyntaxException { OSLSchema schema = (OSLSchema) readSchema("in", "intocc.xml"); TopicIF type = makeType("#something"); TopicIF instance = builder.makeTopic(); instance.addType(type); TopicIF occtype = makeType("#occtype"); OccurrenceIF occ = builder.makeOccurrence(instance, occtype, getRelative("http: validate(schema, instance, occ); }
@Test public void testIllegalOccurrence() throws IOException, SchemaSyntaxException { OSLSchema schema = (OSLSchema) readSchema("in", "intocc.xml"); TopicIF type = makeType("#something"); TopicIF instance = builder.makeTopic(); instance.addType(type); TopicIF occtype = makeType("#illegalocctype"); OccurrenceIF occ = builder.makeOccurrence(instance, occtype, "This occurrence is internal, but of the wrong type."); validate(schema); }
@Test public void testIllegalOccurrenceStrict() throws IOException, SchemaSyntaxException { OSLSchema schema = (OSLSchema) readSchema("in", "intocc-strict.xml"); TopicIF type = makeType("#something"); TopicIF instance = builder.makeTopic(); instance.addType(type); TopicIF occtype = makeType("#illegalocctype"); OccurrenceIF occ = builder.makeOccurrence(instance, occtype, "This occurrence is internal, but of the wrong type."); validate(schema, instance, occ); }
@Test public void testNothingOccurrence() throws IOException, SchemaSyntaxException { OSLSchema schema = (OSLSchema) readSchema("in", "intocc.xml"); TopicIF type = makeType("#something"); TopicIF instance = builder.makeTopic(); instance.addType(type); TopicIF occtype = makeType("#occtype"); OccurrenceIF occ = builder.makeOccurrence(instance, occtype, ""); validate(schema); }
@Test public void testLevelOfScopeMatchingExact() throws IOException, SchemaSyntaxException { OSLSchema schema = (OSLSchema) readSchema("in", "scopelevel-exact.xml"); TopicIF type = makeType("#something"); TopicIF instance = builder.makeTopic(); instance.addType(type); TopicIF occscope = makeType("#occ_scope"); TopicIF occtype = makeType("#occtype"); OccurrenceIF occ = builder.makeOccurrence(instance, occtype, ""); occ.addTheme(occscope); validate(schema); }
@Test public void testLevelOfScopeMatchingSuperset() throws IOException, SchemaSyntaxException { OSLSchema schema = (OSLSchema) readSchema("in", "scopelevel-superset.xml"); TopicIF type = makeType("#something"); TopicIF instance = builder.makeTopic(); instance.addType(type); TopicIF occscope = makeType("#occ_scope1"); TopicIF occtype = makeType("#occtype"); OccurrenceIF occ = builder.makeOccurrence(instance, occtype, ""); occ.addTheme(occscope); validate(schema); }
@Test public void testLevelOfScopeMatchingSubset() throws IOException, SchemaSyntaxException { OSLSchema schema = (OSLSchema) readSchema("in", "scopelevel-subset.xml"); TopicIF type = makeType("#something"); TopicIF instance = builder.makeTopic(); instance.addType(type); TopicIF occscope1 = makeType("#occ_scope1"); TopicIF occscope2 = makeType("#occ_scope2"); TopicIF occscope3 = makeType("#occ_scope3"); TopicIF occtype = makeType("#occtype"); OccurrenceIF occ = builder.makeOccurrence(instance, occtype, ""); occ.addTheme(occscope1); occ.addTheme(occscope2); occ.addTheme(occscope3); validate(schema); }
@Test public void testBug430() throws IOException, SchemaSyntaxException { topicmap = ImportExportUtils.getReader(TestFileUtils.getTestInputFile(testdataDirectory, "topicmaps", "bug430.ltm")).read(); OSLSchema schema = (OSLSchema) readSchema("in", "bug430.xml"); validate(schema); }
@Test public void testVariantRequired() throws IOException, SchemaSyntaxException { OSLSchema schema = (OSLSchema) readSchema("in", "variant.xml"); TopicIF type = makeType("#type"); TopicIF instance = builder.makeTopic(); instance.addType(type); TopicNameIF bn = builder.makeTopicName(instance, "Testtopic"); validate(schema, bn, null); }
@Test public void testMinimumTopicNames() throws IOException, SchemaSyntaxException{ OSLSchema schema = (OSLSchema) readSchema("in", "basename.xml"); TopicIF type = makeType("#something"); TopicIF instance = builder.makeTopic(); instance.addType(type); validate(schema, instance, null); }