}
public TrustBetweenCommunities getTrustBetweenCommunities(
Model model, Resource resource,
Class<? extends TrustBetweenCommunities> type) throws Exception {
TrustBetweenCommunities truBet = (TrustBetweenCommunities)
getResourceFromCache(resource, type);
if(truBet != null) {
return truBet;
}
if(type != null) {
truBet = type.newInstance();
truBet.setResource(resource);
addResourceInstanceToCache(resource, truBet);
} else {
StmtIterator stmtI1 = model.listStatements(resource, RDF.type, (RDFNode)null);
Resource fixedCommunitiesTrust = ResourceFactory.
createResource(riNamespace + "FixedCommunitiesTrust");
Resource categoryMatching = ResourceFactory.
createResource(riNamespace + "CategoryMatching");
while(stmtI1.hasNext()) {
Statement typeStatement = stmtI1.nextStatement();
if(typeStatement.getObject().asResource().getURI().equals(
fixedCommunitiesTrust.getURI())) {
return getFixedCommunitiesTrust(model, resource);
} else if (typeStatement.getObject().asResource().getURI().equals(
categoryMatching.getURI())) {
return getCategoryMatching(model, resource);
}
}
if(truBet == null) {
truBet = new TrustBetweenCommunities();
truBet.setResource(resource);
addResourceInstanceToCache(resource, truBet);
}
}
Property trustProvidedBy = ResourceFactory.
createProperty(riNamespace + "trustProvidedBy");
// trustProvidedBy //
StmtIterator stmtI1 = model.listStatements(resource,
trustProvidedBy, (RDFNode)null);
while(stmtI1.hasNext()) {
Statement statement = stmtI1.nextStatement();
// validate trustProvidedBy property //
if(!statement.getObject().isResource()) {
if(!ModelException.throwException(ModelException.TRUSTBETWEENCOMMUNITIES,
"trustProvidedBy property of TrustBetweenCommunities resource:"+
resource.getURI()+" is not a resource")) {
return null;
}
} else {
TrustBetweenCommunities truBetInside = (TrustBetweenCommunities)
getResourceFromCache(statement.getObject().asResource(),
TrustBetweenCommunities.class);
if(truBetInside == null) {
truBetInside = getTrustBetweenCommunities(
model, statement.getObject().asResource(), null);