}
}
public DimensionCorrelation getDimensionCorrelation(
Model model, Resource resource) throws Exception {
DimensionCorrelation dimCor = (DimensionCorrelation)
getResourceFromCache(resource, DimensionCorrelation.class);
if(dimCor != null) {
return dimCor;
}
dimCor = new DimensionCorrelation();
dimCor.setResource(resource);
addResourceInstanceToCache(resource, dimCor);
Property sourceDimension = ResourceFactory.
createProperty(riNamespace + "sourceDimension");
// sourceDimension //
StmtIterator stmtI1 = model.listStatements(resource,
sourceDimension, (RDFNode)null);
while(stmtI1.hasNext()) {
Statement statement = stmtI1.nextStatement();
// validate sourceDimension property //
if(!statement.getObject().isResource()) {
if(!ModelException.throwException(ModelException.DIMENSIONCORRELATION,
"sourceDimension property of DimensionCorrelation resource:"+
resource.getURI()+" is not a resource")) {
return null;
}
} else {
Dimension dimension = (Dimension) getResourceFromCache(
statement.getObject().asResource(), Dimension.class);
if(dimension == null) {
dimension = getDimension(model, statement.getObject().asResource());
}
dimCor.setSourceDimension(dimension);
}
}
Property targetDimension = ResourceFactory.
createProperty(riNamespace + "targetDimension");
// targetDimension //
stmtI1 = model.listStatements(resource,
targetDimension, (RDFNode)null);
while(stmtI1.hasNext()) {
Statement statement = stmtI1.nextStatement();
// validate targetDimension property //
if(!statement.getObject().isResource()) {
if(!ModelException.throwException(ModelException.DIMENSIONCORRELATION,
"targetDimension property of DimensionCorrelation resource:"+
resource.getURI()+" is not a resource")) {
return null;
}
} else {
Dimension dimension = (Dimension) getResourceFromCache(
statement.getObject().asResource(), Dimension.class);
if(dimension == null) {
dimension = getDimension(model, statement.getObject().asResource());
}
dimCor.setTargetDimension(dimension);
}
}
Property correlationValue = ResourceFactory.
createProperty(riNamespace + "correlationValue");
// correlationValue //
stmtI1 = model.listStatements(resource,
correlationValue, (RDFNode)null);
while(stmtI1.hasNext()) {
Statement statement = stmtI1.nextStatement();
// validate correlationValue property //
if(!statement.getObject().isLiteral()) {
if(!ModelException.throwException(ModelException.DIMENSIONCORRELATION,
"correlationValue property of DimensionCorrelation resource:"+
resource.getURI()+" is not a literal")) {
return null;
}
} else {
dimCor.setCorrelationValue(
statement.getObject().asLiteral().getDouble());
}
}
return dimCor;
}