}
}
public MetricMapping getMetricMapping(Model model,
Resource resource) throws Exception {
MetricMapping metMap = (MetricMapping) getResourceFromCache(
resource, MetricMapping.class);
if(metMap != null) {
return metMap;
}
metMap = new MetricMapping();
metMap.setResource(resource);
addResourceInstanceToCache(resource, metMap);
Property value = ResourceFactory.createProperty(
riNamespace + "value");
// value //
StmtIterator stmtI1 = model.listStatements(resource,
value, (RDFNode)null);
while(stmtI1.hasNext()) {
Statement statement = stmtI1.nextStatement();
// validate value property //
if(!statement.getObject().isLiteral()) {
if(!ModelException.throwException(ModelException.METRICMAPPING,
"value property of MetricMapping resource:"+
resource.getURI()+" is not a literal")) {
return null;
}
} else {
metMap.setValue(statement.getObject().asLiteral().getDouble());
}
}
Property importedMetric = ResourceFactory.createProperty(
riNamespace + "importedMetric");
// importedMetric //
stmtI1 = model.listStatements(resource,
importedMetric, (RDFNode)null);
while(stmtI1.hasNext()) {
Statement statement = stmtI1.nextStatement();
/* validate importedMetric property */
if(!statement.getObject().isResource()) {
if(!ModelException.throwException(ModelException.METRICMAPPING,
"importedMetric property of MetricMapping resource:"+
resource.getURI()+" is not a resource")) {
return null;
}
} else {
Metric metric = (Metric) getResourceFromCache(
statement.getObject().asResource(),Metric.class);
if(metric == null) {
metric = getMetric(model,statement.getObject().asResource());
}
metMap.setImportedMetric(metric);
}
}
Property resultMetric = ResourceFactory.createProperty(
riNamespace + "resultMetric");
// resultMetric //
stmtI1 = model.listStatements(resource,
resultMetric, (RDFNode)null);
while(stmtI1.hasNext()) {
Statement statement = stmtI1.nextStatement();
// validate resultMetric property //
if(!statement.getObject().isResource()) {
if(!ModelException.throwException(ModelException.METRICMAPPING,
"resultMetric property of MetricMapping resource:"+
resource.getURI()+" is not a resource")) {
return null;
}
} else {
Metric metric = (Metric) getResourceFromCache(
statement.getObject().asResource(),Metric.class);
if(metric == null) {
metric = getMetric(model,statement.getObject().asResource());
}
metMap.setResultMetric(metric);
}
}
return metMap;
}