remove obsolete files
This commit is contained in:
parent
01281d2034
commit
5d33da415d
2 changed files with 0 additions and 325 deletions
|
@ -1,89 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelChangedListener;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeListener;
|
||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.SimpleReasonerSetup;
|
||||
|
||||
/**
|
||||
* A ChangeListener that forwards events to a Jena ModelChangedListener
|
||||
* @author bjl23
|
||||
*
|
||||
*/
|
||||
public class JenaChangeListener implements ChangeListener {
|
||||
|
||||
private static final Log log = LogFactory.getLog(JenaChangeListener.class);
|
||||
|
||||
protected HashSet<String> ignoredGraphs = new HashSet<String>();
|
||||
|
||||
private ModelChangedListener listener;
|
||||
private Model m = ModelFactory.createDefaultModel();
|
||||
|
||||
public JenaChangeListener(ModelChangedListener listener) {
|
||||
this.listener = listener;
|
||||
ignoredGraphs.add(SimpleReasonerSetup.JENA_INF_MODEL_REBUILD);
|
||||
ignoredGraphs.add(SimpleReasonerSetup.JENA_INF_MODEL_SCRATCHPAD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addedStatement(String serializedTriple, String graphURI) {
|
||||
if (isRelevantGraph(graphURI)) {
|
||||
listener.addedStatement(parseTriple(serializedTriple));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removedStatement(String serializedTriple, String graphURI) {
|
||||
if (isRelevantGraph(graphURI)) {
|
||||
listener.removedStatement(parseTriple(serializedTriple));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isRelevantGraph(String graphURI) {
|
||||
return (graphURI == null || !ignoredGraphs.contains(graphURI));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyEvent(String graphURI, Object event) {
|
||||
log.debug("event: " + event.getClass());
|
||||
listener.notifyEvent(m, event);
|
||||
}
|
||||
|
||||
// TODO avoid overhead of Model
|
||||
private Statement parseTriple(String serializedTriple) {
|
||||
try {
|
||||
Model m = ModelFactory.createDefaultModel();
|
||||
m.read(new ByteArrayInputStream(
|
||||
serializedTriple.getBytes("UTF-8")), null, "N3");
|
||||
StmtIterator sit = m.listStatements();
|
||||
if (!sit.hasNext()) {
|
||||
throw new RuntimeException("no triple parsed from change event");
|
||||
} else {
|
||||
Statement s = sit.nextStatement();
|
||||
if (sit.hasNext()) {
|
||||
log.warn("More than one triple parsed from change event");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
} catch (RuntimeException riot) {
|
||||
log.error("Unable to parse triple " + serializedTriple, riot);
|
||||
throw riot;
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
throw new RuntimeException(uee);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,236 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.graph.BulkUpdateHandler;
|
||||
import com.hp.hpl.jena.graph.Capabilities;
|
||||
import com.hp.hpl.jena.graph.Graph;
|
||||
import com.hp.hpl.jena.graph.GraphEventManager;
|
||||
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
||||
import com.hp.hpl.jena.graph.Node;
|
||||
import com.hp.hpl.jena.graph.TransactionHandler;
|
||||
import com.hp.hpl.jena.graph.Triple;
|
||||
import com.hp.hpl.jena.graph.TripleMatch;
|
||||
import com.hp.hpl.jena.graph.impl.GraphWithPerform;
|
||||
import com.hp.hpl.jena.graph.impl.SimpleBulkUpdateHandler;
|
||||
import com.hp.hpl.jena.graph.impl.SimpleEventManager;
|
||||
import com.hp.hpl.jena.shared.AddDeniedException;
|
||||
import com.hp.hpl.jena.shared.DeleteDeniedException;
|
||||
import com.hp.hpl.jena.shared.PrefixMapping;
|
||||
import com.hp.hpl.jena.shared.impl.PrefixMappingImpl;
|
||||
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
||||
import com.hp.hpl.jena.util.iterator.WrappedIterator;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
|
||||
|
||||
public class ListeningGraph implements GraphWithPerform {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ListeningGraph.class);
|
||||
|
||||
private RDFServiceImpl rdfServiceImpl;
|
||||
private String graphURI;
|
||||
|
||||
private BulkUpdateHandler bulkUpdateHandler;
|
||||
private GraphEventManager eventManager;
|
||||
private PrefixMapping prefixMapping = new PrefixMappingImpl();
|
||||
|
||||
public ListeningGraph(String graphURI, RDFServiceImpl rdfServiceImpl) {
|
||||
this.graphURI = graphURI;
|
||||
this.rdfServiceImpl = rdfServiceImpl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Triple triple) throws AddDeniedException {
|
||||
performAdd(triple);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performAdd(Triple triple) throws AddDeniedException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("adding " + triple + " to " + graphURI);
|
||||
}
|
||||
this.rdfServiceImpl.notifyListeners(triple, ModelChange.Operation.ADD, graphURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Triple triple) throws DeleteDeniedException {
|
||||
performDelete(triple);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performDelete(Triple triple) throws DeleteDeniedException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("deleting " + triple + " from " + graphURI);
|
||||
}
|
||||
this.rdfServiceImpl.notifyListeners(triple, ModelChange.Operation.REMOVE, graphURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// Nothing to close.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Triple arg0) {
|
||||
return contains(arg0.getSubject(), arg0.getPredicate(), arg0.getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Node subject, Node predicate, Node object) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dependsOn(Graph arg0) {
|
||||
return false; // who knows?
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtendedIterator<Triple> find(TripleMatch arg0) {
|
||||
Triple t = arg0.asTriple();
|
||||
return find(t.getSubject(), t.getPredicate(), t.getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtendedIterator<Triple> find(Node subject, Node predicate, Node object) {
|
||||
List<Triple> triplist = new ArrayList<Triple>();
|
||||
return WrappedIterator.create(triplist.iterator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
for (Triple t: find(null, null, null).toList()) {
|
||||
delete(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Node subject, Node predicate, Node object) {
|
||||
for (Triple t: find(subject, predicate, object).toList()) {
|
||||
delete(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public BulkUpdateHandler getBulkUpdateHandler() {
|
||||
if (this.bulkUpdateHandler == null) {
|
||||
this.bulkUpdateHandler = new SimpleBulkUpdateHandler(this);
|
||||
}
|
||||
return this.bulkUpdateHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Capabilities getCapabilities() {
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphEventManager getEventManager() {
|
||||
if (eventManager == null) {
|
||||
eventManager = new SimpleEventManager(this);
|
||||
}
|
||||
return eventManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrefixMapping getPrefixMapping() {
|
||||
return prefixMapping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphStatisticsHandler getStatisticsHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransactionHandler getTransactionHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return !contains(null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIsomorphicWith(Graph arg0) {
|
||||
throw new UnsupportedOperationException("isIsomorphicWith() not supported " +
|
||||
"by SPARQL graphs");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
int size = find(null, null, null).toList().size();
|
||||
return size;
|
||||
}
|
||||
|
||||
private final static Capabilities capabilities = new Capabilities() {
|
||||
|
||||
@Override
|
||||
public boolean addAllowed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAllowed(boolean everyTriple) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteAllowed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteAllowed(boolean everyTriple) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean findContractSafe() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlesLiteralTyping() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean iteratorRemoveAllowed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sizeAccurate() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ListeningGraph["+ToString.hashHex(this)
|
||||
+ ", " + rdfServiceImpl
|
||||
+ ", " + ToString.modelName(graphURI) + "]";
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue