From 7931113259b207e375b26c6b3cbbd1edad90e345 Mon Sep 17 00:00:00 2001 From: bjl23 Date: Tue, 21 Sep 2010 20:40:53 +0000 Subject: [PATCH] merging IndividualJena overrides into trunk --- .../vitro/webapp/dao/jena/IndividualJena.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualJena.java index 44b4c4ea5..a9b5d16ac 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualJena.java @@ -22,6 +22,8 @@ import org.joda.time.DateTime; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntResource; import com.hp.hpl.jena.rdf.model.Literal; +import com.hp.hpl.jena.rdf.model.NodeIterator; +import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.Statement; @@ -39,6 +41,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Keyword; import edu.cornell.mannlib.vitro.webapp.beans.Link; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; +import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; @@ -645,7 +648,81 @@ public class IndividualJena extends IndividualImpl implements Individual { return this.objectPropertyStatements; } } + + @Override + public List getObjectPropertyStatements(String propertyURI) { + if (propertyURI == null) { + return null; + } + List objectPropertyStatements = new ArrayList(); + ind.getOntModel().enterCriticalSection(Lock.READ); + try { + StmtIterator sit = ind.listProperties(ind.getModel().getProperty(propertyURI)); + while (sit.hasNext()) { + Statement s = sit.nextStatement(); + if (!s.getSubject().canAs(OntResource.class) || !s.getObject().canAs(OntResource.class)) { + continue; + } + Individual subj = new IndividualJena((OntResource) s.getSubject().as(OntResource.class), webappDaoFactory); + Individual obj = new IndividualJena((OntResource) s.getObject().as(OntResource.class), webappDaoFactory); + ObjectProperty op = webappDaoFactory.getObjectPropertyDao().getObjectPropertyByURI(s.getPredicate().getURI()); + if (subj != null && obj != null && op != null) { + ObjectPropertyStatement ops = new ObjectPropertyStatementImpl(); + ops.setSubject(subj); + ops.setSubjectURI(subj.getURI()); + ops.setObject(obj); + ops.setObjectURI(obj.getURI()); + ops.setProperty(op); + ops.setPropertyURI(op.getURI()); + objectPropertyStatements.add(ops); + } + } + } finally { + ind.getOntModel().leaveCriticalSection(); + } + return objectPropertyStatements; + } + @Override + public List getRelatedIndividuals(String propertyURI) { + if (propertyURI == null) { + return null; + } + List relatedIndividuals = new ArrayList(); + ind.getOntModel().enterCriticalSection(Lock.READ); + try { + NodeIterator values = ind.listPropertyValues(ind.getModel().getProperty(propertyURI)); + while (values.hasNext()) { + RDFNode value = values.nextNode(); + if (value.canAs(OntResource.class)) { + relatedIndividuals.add( + new IndividualJena((OntResource) value.as(OntResource.class), webappDaoFactory) ); + } + } + } finally { + ind.getOntModel().leaveCriticalSection(); + } + return relatedIndividuals; + } + + @Override + public Individual getRelatedIndividual(String propertyURI) { + if (propertyURI == null) { + return null; + } + ind.getOntModel().enterCriticalSection(Lock.READ); + try { + RDFNode value = ind.getPropertyValue(ind.getModel().getProperty(propertyURI)); + if (value != null && value.canAs(OntResource.class)) { + return new IndividualJena((OntResource) value.as(OntResource.class), webappDaoFactory); + } else { + return null; + } + } finally { + ind.getOntModel().leaveCriticalSection(); + } + } + public List getObjectPropertyList() { if (this.propertyList != null) { return this.propertyList;