Hello all.
I'm looking for a LiteralFactory.createLiteral(String v, String
language) equivalent. I know Model has a createLiteral(String v, String
language) but I don't have a Model at the point I need to create the
Literal. I've followed the Model createLiteral but either got lost or
confused or both!
In context I have the following method which creates a Statement based
on some parameters and uses ResourceFactory to create?.
public Statement getStatement(VelocityContext context) {
Resource subject =
ResourceFactory.createResource(evaluate(context, getSubjectURI()));
Property property =
ResourceFactory.createProperty(evaluate(context, getPropertyURI()));
Resource objectType =
ResourceFactory.createResource(evaluate(context, getObjectType()));
if (objectType.equals(RDFS.Resource)) {
return ResourceFactory.createStatement(subject, property,
ResourceFactory.createResource(evaluate(context, getObjectValue())));
}
if (objectType.equals(RDFS.Literal)) {
if (hasObjectDatatype()) {
return ResourceFactory.createStatement(subject,
property, ResourceFactory.createTypedLiteral(evaluate(context,
getObjectValue()),
TypeMapper.getInstance().getTypeByName(evaluate(context,
getObjectDatatype()))));
} else {
if (hasLanguage()) {
return ResourceFactory.createStatement(subject,
property, NEED_TO_CREATE_A_LITERAL_WITH_LANGUAGE);
} else {
return ResourceFactory.createStatement(subject,
property, ResourceFactory.createPlainLiteral(evaluate(context,
getObjectValue())));
}
}
}
throw new Exception(String.format("Unknown objectType [%s].",
objectType));
}