updating for NIHVIVO-3494

"Add RDF leads to null pointer exception in certain cases". Including check for null to avoid null pointer exception.
This commit is contained in:
hjkhjk54 2011-12-13 19:20:23 +00:00
parent 1a201b9037
commit 02304f6bb8

View file

@ -91,31 +91,34 @@ public class JenaModelUtils {
ontModel.enterCriticalSection(Lock.READ); ontModel.enterCriticalSection(Lock.READ);
try { try {
try { try {
for (Iterator rootClassIt = myWebappDaoFactory.getVClassDao() List<VClass> rootClasses = myWebappDaoFactory.getVClassDao()
.getRootClasses().iterator(); rootClassIt.hasNext(); ) { .getRootClasses();
VClass rootClass = (VClass) rootClassIt.next(); if(rootClasses != null) {
for (Iterator rootClassIt = rootClasses.iterator(); rootClassIt.hasNext(); ) {
Individual classGroup = modelForClassgroups.createIndividual( VClass rootClass = (VClass) rootClassIt.next();
wadf.getDefaultNamespace() + "vitroClassGroup" +
rootClass.getLocalName(), classGroupClass); Individual classGroup = modelForClassgroups.createIndividual(
classGroup.setLabel(rootClass.getName(), null); wadf.getDefaultNamespace() + "vitroClassGroup" +
rootClass.getLocalName(), classGroupClass);
Resource rootClassRes = modelForClassgroupAnnotations.getResource( classGroup.setLabel(rootClass.getName(), null);
rootClass.getURI());
modelForClassgroupAnnotations.add( Resource rootClassRes = modelForClassgroupAnnotations.getResource(
rootClassRes, inClassGroupProperty, classGroup); rootClass.getURI());
for (Iterator<String> childIt = myWebappDaoFactory.getVClassDao() modelForClassgroupAnnotations.add(
.getAllSubClassURIs(rootClass.getURI()).iterator(); rootClassRes, inClassGroupProperty, classGroup);
childIt.hasNext(); ) { for (Iterator<String> childIt = myWebappDaoFactory.getVClassDao()
String childURI = (String) childIt.next(); .getAllSubClassURIs(rootClass.getURI()).iterator();
Resource childClass = modelForClassgroupAnnotations childIt.hasNext(); ) {
.getResource(childURI); String childURI = (String) childIt.next();
if (!modelForClassgroupAnnotations.contains( Resource childClass = modelForClassgroupAnnotations
childClass, inClassGroupProperty, (RDFNode) null)) { .getResource(childURI);
childClass.addProperty(inClassGroupProperty, classGroup); if (!modelForClassgroupAnnotations.contains(
} childClass, inClassGroupProperty, (RDFNode) null)) {
} childClass.addProperty(inClassGroupProperty, classGroup);
} }
}
}
}
} catch (Exception e) { } catch (Exception e) {
String errMsg = "Unable to create class groups automatically " + String errMsg = "Unable to create class groups automatically " +
"based on class hierarchy"; "based on class hierarchy";