}
}
public ImportationUnit getImportationUnit(Model model,
Resource resource) throws Exception {
ImportationUnit impUni = (ImportationUnit) getResourceFromCache(
resource, ImportationUnit.class);
if(impUni != null) {
return impUni;
}
impUni = new ImportationUnit();
impUni.setResource(resource);
addResourceInstanceToCache(resource, impUni);
Property importedCommunity = ResourceFactory.createProperty(
riNamespace + "importedCommunity");
/* importedCommunity */
StmtIterator stmtI1 = model.listStatements(resource,
importedCommunity, (RDFNode)null);
while(stmtI1.hasNext()) {
Statement statement = stmtI1.nextStatement();
/* validate importedCommunity property */
if(!statement.getObject().isResource()) {
if(!ModelException.throwException(ModelException.IMPORTATIONUNIT,
"importedCommunity property of ImportationUnit resource:"+
resource.getURI()+" is not a resource")) {
return null;
}
} else {
Community community = (Community) getResourceFromCache(
statement.getObject().asResource(), Community.class);
if(community == null) {
community = getCommunity(model,
statement.getObject().asResource());
}
impUni.setImportedCommunity(community);
}
}
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.IMPORTATIONUNIT,
"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());
}
impUni.setImportedMetric(metric);
}
}
Property collectsReputationBy = ResourceFactory.createProperty(
riNamespace + "collectsReputationBy");
/* collectsReputationBy */
stmtI1 = model.listStatements(resource,
collectsReputationBy, (RDFNode)null);
while(stmtI1.hasNext()) {
Statement statement = stmtI1.nextStatement();
/* validate collectsReputationBy property */
if(!statement.getObject().isResource()) {
if(!ModelException.throwException(ModelException.IMPORTATIONUNIT,
"collectsReputationBy property of ImportationUnit resource:"+
resource.getURI()+" is not a resource")) {
return null;
}
} else {
ReputationAlgorithmImplementation colAlg = (
ReputationAlgorithmImplementation) getResourceFromCache(
statement.getObject().asResource(),ReputationAlgorithmImplementation.class);
if(colAlg == null) {
colAlg = getReputationAlgorithm(model,
statement.getObject().asResource(),null);
}
impUni.setCollectsReputationBy(colAlg);
}
}
Property metricTransformation = ResourceFactory.createProperty(
riNamespace + "metricTransformation");
/* metricTransformation */
stmtI1 = model.listStatements(resource,
metricTransformation, (RDFNode)null);
while(stmtI1.hasNext()) {
Statement statement = stmtI1.nextStatement();
/* validate metricTransformation property */
if(!statement.getObject().isResource()) {
if(!ModelException.throwException(ModelException.IMPORTATIONUNIT,
"metricTransformation property of ImportationUnit resource:"+
resource.getURI()+" is not a resource")) {
return null;
}
} else {
MetricTransformer metTra = (MetricTransformer)
getResourceFromCache(statement.getObject().asResource(),
MetricTransformer.class);
if(metTra == null) {
metTra = getMetricTransformer(model,
statement.getObject().asResource(),null);
}
impUni.setMetricTransformation(metTra);
}
}
Property trust = ResourceFactory.createProperty(
riNamespace + "trust");
/* trust */
stmtI1 = model.listStatements(resource,
trust, (RDFNode)null);
while(stmtI1.hasNext()) {
Statement statement = stmtI1.nextStatement();
/* validate trust property */
if(!statement.getObject().isResource()) {
if(!ModelException.throwException(ModelException.IMPORTATIONUNIT,
"trust property of importationUnit ImportationUnit resource:"+
resource.getURI()+" is not a resource")) {
return null;
}
} else {
TrustBetweenCommunities truBet = (TrustBetweenCommunities)
getResourceFromCache(statement.getObject().asResource(),
TrustBetweenCommunities.class);
if(truBet == null) {
truBet = getTrustBetweenCommunities(model,
statement.getObject().asResource(),null);
}
impUni.setTrust(truBet);
}
}
return impUni;
}