use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.
the class LiteralsTest method testCreateLiteralObjectXMLGregorianCalendar.
/**
* Test method for
* {@link org.eclipse.rdf4j.model.util.Literals#createLiteral(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
* .
*/
@Test
public void testCreateLiteralObjectXMLGregorianCalendar() throws Exception {
GregorianCalendar c = new GregorianCalendar();
c.setTime(new Date());
try {
Object obj = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
Literal l = Literals.createLiteral(SimpleValueFactory.getInstance(), obj);
assertNotNull(l);
assertEquals(l.getDatatype(), XMLSchema.DATETIME);
// TODO check lexical value?
} catch (DatatypeConfigurationException e) {
e.printStackTrace();
fail("Could not instantiate javax.xml.datatype.DatatypeFactory");
}
}
use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.
the class DAWGTestResultSetParser method getBinding.
private Binding getBinding(Resource bindingNode) throws GraphUtilException {
Literal name = GraphUtil.getUniqueObjectLiteral(graph, bindingNode, VARIABLE);
Value value = GraphUtil.getUniqueObject(graph, bindingNode, VALUE);
return new SimpleBinding(name.getLabel(), value);
}
use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.
the class ContextAwareConfig method export.
@Override
public Resource export(Model model) {
Resource repImplNode = super.export(model);
ValueFactory vf = SimpleValueFactory.getInstance();
if (includeInferred != null) {
Literal bool = vf.createLiteral(includeInferred);
model.add(repImplNode, INCLUDE_INFERRED, bool);
}
if (maxQueryTime > 0) {
model.add(repImplNode, MAX_QUERY_TIME, vf.createLiteral(maxQueryTime));
}
if (queryLanguage != null) {
model.add(repImplNode, QUERY_LANGUAGE, vf.createLiteral(queryLanguage.getName()));
}
if (baseURI != null) {
model.add(repImplNode, BASE_URI, vf.createIRI(baseURI));
}
for (IRI uri : readContexts) {
model.add(repImplNode, READ_CONTEXT, uri);
}
for (IRI resource : addContexts) {
model.add(repImplNode, ADD_CONTEXT, resource);
}
for (IRI resource : removeContexts) {
model.add(repImplNode, REMOVE_CONTEXT, resource);
}
for (IRI resource : archiveContexts) {
model.add(repImplNode, ARCHIVE_CONTEXT, resource);
}
if (insertContext != null) {
model.add(repImplNode, INSERT_CONTEXT, insertContext);
}
return repImplNode;
}
use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.
the class AbstractSPARQLJSONWriter method writeValue.
protected void writeValue(Value value) throws IOException, QueryResultHandlerException {
jg.writeStartObject();
if (value instanceof IRI) {
jg.writeStringField("type", "uri");
jg.writeStringField("value", ((IRI) value).toString());
} else if (value instanceof BNode) {
jg.writeStringField("type", "bnode");
jg.writeStringField("value", ((BNode) value).getID());
} else if (value instanceof Literal) {
Literal lit = (Literal) value;
if (Literals.isLanguageLiteral(lit)) {
jg.writeObjectField("xml:lang", lit.getLanguage().orElse(null));
} else {
IRI datatype = lit.getDatatype();
boolean ignoreDatatype = datatype.equals(XMLSchema.STRING) && xsdStringToPlainLiteral();
if (!ignoreDatatype) {
jg.writeObjectField("datatype", lit.getDatatype().stringValue());
}
}
jg.writeObjectField("type", "literal");
jg.writeObjectField("value", lit.getLabel());
} else {
throw new TupleQueryResultHandlerException("Unknown Value object type: " + value.getClass());
}
jg.writeEndObject();
}
use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.
the class AbstractRepositoryImplConfig method create.
/**
* Utility method to create a new {@link RepositoryImplConfig} by reading data from the supplied
* {@link Model}.
*
* @param model
* the {@link Model} to read configuration data from.
* @param implNode
* the subject {@link Resource} identifying the configuration data in the Model.
* @return a new {@link RepositoryImplConfig} initialized with the configuration from the input Model, or
* {@code null} if no {@link RepositoryConfigSchema#REPOSITORYTYPE} property was found in the
* configuration data..
* @throws RepositoryConfigException
* if an error occurred reading the configuration data from the model.
*/
public static RepositoryImplConfig create(Model model, Resource resource) throws RepositoryConfigException {
try {
// Literal typeLit = GraphUtil.getOptionalObjectLiteral(graph,
// implNode, REPOSITORYTYPE);
final Literal typeLit = Models.objectLiteral(model.filter(resource, REPOSITORYTYPE, null)).orElse(null);
if (typeLit != null) {
RepositoryFactory factory = RepositoryRegistry.getInstance().get(typeLit.getLabel()).orElseThrow(() -> new RepositoryConfigException("Unsupported repository type: " + typeLit.getLabel()));
RepositoryImplConfig implConfig = factory.getConfig();
implConfig.parse(model, resource);
return implConfig;
}
return null;
} catch (ModelException e) {
throw new RepositoryConfigException(e.getMessage(), e);
}
}
Aggregations