use of org.openrdf.model.Resource in project vcell by virtualcell.
the class XMLMetaDataWriter method getElement.
public static Element getElement(VCMetaData metaData, IdentifiableProvider identifiableProvider) {
Element element = new Element(XMLMetaData.VCMETADATA_TAG);
Element elementRDF = metaData.createElement();
// add RDF data
if (elementRDF != null) {
element.addContent(elementRDF);
}
Element elementNonRDFList = createNonRDFAnnotationElement(metaData, identifiableProvider);
element.addContent(elementNonRDFList);
// add resource binding table
Element bindingListElement = new Element(XMLMetaData.URI_BINDING_LIST_TAG);
Set<Registry.Entry> resources = metaData.getRegistry().getAllEntries();
for (Registry.Entry entry : resources) {
VCID vcid = identifiableProvider.getVCID(entry.getIdentifiable());
Identifiable identifiable = identifiableProvider.getIdentifiableObject(vcid);
if (identifiable != null && entry.getResource() != null) {
Element entryElement = new Element(XMLMetaData.URI_BINDING_TAG);
Resource resource = entry.getResource();
if (resource != null) {
entryElement.setAttribute(XMLMetaData.URI_ATTR_TAG, resource.stringValue());
}
entryElement.setAttribute(XMLMetaData.VCID_ATTR_TAG, vcid.toASCIIString());
bindingListElement.addContent(entryElement);
}
}
element.addContent(bindingListElement);
return element;
}
use of org.openrdf.model.Resource in project blueprints by tinkerpop.
the class SailEdge method removeProperty.
public <T> T removeProperty(final String key) {
if (key.equals(SailTokens.NAMED_GRAPH)) {
try {
Resource ng = this.rawEdge.getContext();
SailHelper.removeStatement(this.rawEdge, this.graph.getSailConnection().get());
this.rawEdge = new StatementImpl(this.rawEdge.getSubject(), this.rawEdge.getPredicate(), this.rawEdge.getObject());
SailHelper.addStatement(this.rawEdge, this.graph.getSailConnection().get());
return (T) ng;
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
} else {
throw new IllegalArgumentException(NAMED_GRAPH_PROPERTY);
}
}
use of org.openrdf.model.Resource in project blueprints by tinkerpop.
the class SailGraph method addEdge.
public Edge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex, final String label) {
if (label == null)
throw ExceptionFactory.edgeLabelCanNotBeNull();
Value outVertexValue = ((SailVertex) outVertex).getRawVertex();
Value inVertexValue = ((SailVertex) inVertex).getRawVertex();
if (!(outVertexValue instanceof Resource)) {
throw new IllegalArgumentException(outVertex.toString() + " is not a legal URI or blank node");
}
try {
URI labelURI = new URIImpl(this.expandPrefix(label));
Statement statement = new StatementImpl((Resource) outVertexValue, labelURI, inVertexValue);
SailHelper.addStatement(statement, this.sailConnection.get());
return new SailEdge(statement, this);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
use of org.openrdf.model.Resource in project blueprints by tinkerpop.
the class GraphSailConnection method clearInternal.
private void clearInternal(final boolean inferred, final Resource... contexts) throws SailException {
if (!canWrite()) {
WriteAction a = new WriteAction(ActionType.CLEAR);
a.inferred = inferred;
a.contexts = contexts;
queueUpdate(a);
return;
}
if (0 == contexts.length) {
deleteEdgesInIterator(inferred, store.matchers[0x0].match(null, null, null, null, inferred));
} else {
for (Resource context : contexts) {
// Note: order of operands to the "or" is important here
deleteEdgesInIterator(inferred, store.matchers[0x8].match(null, null, null, context, inferred));
}
}
}
use of org.openrdf.model.Resource in project blueprints by tinkerpop.
the class GraphSailConnection method getStatementsInternal.
public CloseableIteration<? extends Statement, SailException> getStatementsInternal(final Resource subject, final URI predicate, final Value object, final boolean includeInferred, final Resource... contexts) throws SailException {
int index = 0;
if (null != subject) {
index |= 0x1;
}
if (null != predicate) {
index |= 0x2;
}
if (null != object) {
index |= 0x4;
}
if (0 == contexts.length) {
return createIteration(store.matchers[index].match(subject, predicate, object, null, includeInferred));
} else {
Collection<CloseableIteration<Statement, SailException>> iterations = new LinkedList<CloseableIteration<Statement, SailException>>();
// TODO: as an optimization, filter on multiple contexts simultaneously (when context is not used in the matcher), rather than trying each context consecutively.
for (Resource context : contexts) {
index |= 0x8;
Matcher m = store.matchers[index];
iterations.add(createIteration(m.match(subject, predicate, object, context, includeInferred)));
}
return new CompoundCloseableIteration<Statement, SailException>(iterations);
}
}
Aggregations