/** * Creates a typed {@link Literal} out of the supplied object, mapping the runtime type of the object to * the appropriate XML Schema type. If no mapping is available, the method throws a * {@link LiteralUtilException}. Recognized types are {@link Boolean}, {@link Byte}, {@link Double}, * {@link Float}, {@link Integer}, {@link Long}, {@link Short}, {@link XMLGregorianCalendar } , and * {@link Date}. * * @param valueFactory * @param object * an object to be converted to a typed literal. * @return a typed literal representation of the supplied object. * @throws LiteralUtilException * If the literal could not be created. * @throws NullPointerException * If the object was null. */ public static Literal createLiteralOrFail(ValueFactory valueFactory, Object object) throws LiteralUtilException { return createLiteral(valueFactory, object, true); }
/** * Creates a typed {@link Literal} out of the supplied object, mapping the runtime type of the object to * the appropriate XML Schema type. If no mapping is available, the method throws a * {@link LiteralUtilException}. Recognized types are {@link Boolean}, {@link Byte}, {@link Double}, * {@link Float}, {@link Integer}, {@link Long}, {@link Short}, {@link XMLGregorianCalendar } , and * {@link Date}. * * @param valueFactory * @param object * an object to be converted to a typed literal. * @return a typed literal representation of the supplied object. * @throws LiteralUtilException * If the literal could not be created. * @throws NullPointerException * If the object was null. */ public static Literal createLiteralOrFail(ValueFactory valueFactory, Object object) throws LiteralUtilException { return createLiteral(valueFactory, object, true); }
/** * Creates a typed {@link Literal} out of the supplied object, mapping the runtime type of the object to * the appropriate XML Schema type. If no mapping is available, the method returns a literal with the * string representation of the supplied object as the value, and {@link XMLSchema#STRING} as the * datatype. Recognized types are {@link Boolean}, {@link Byte}, {@link Double}, {@link Float}, * {@link Integer}, {@link Long}, {@link Short}, {@link XMLGregorianCalendar } , and {@link Date}. * * @param valueFactory * @param object * an object to be converted to a typed literal. * @return a typed literal representation of the supplied object. * @throws NullPointerException * If the object was null. */ public static Literal createLiteral(ValueFactory valueFactory, Object object) { try { return createLiteral(valueFactory, object, false); } catch (LiteralUtilException e) { // This should not happen by design throw new IllegalStateException(e); } }
/** * Creates a typed {@link Literal} out of the supplied object, mapping the runtime type of the object to * the appropriate XML Schema type. If no mapping is available, the method returns a literal with the * string representation of the supplied object as the value, and {@link XMLSchema#STRING} as the * datatype. Recognized types are {@link Boolean}, {@link Byte}, {@link Double}, {@link Float}, * {@link Integer}, {@link Long}, {@link Short}, {@link XMLGregorianCalendar } , and {@link Date}. * * @param valueFactory * @param object * an object to be converted to a typed literal. * @return a typed literal representation of the supplied object. * @throws NullPointerException * If the object was null. */ public static Literal createLiteral(ValueFactory valueFactory, Object object) { try { return createLiteral(valueFactory, object, false); } catch (LiteralUtilException e) { // This should not happen by design throw new IllegalStateException(e); } }
objectValue = Literals.createLiteral(SimpleValueFactory.getInstance(), object);
objectValue = Literals.createLiteral(SimpleValueFactory.getInstance(), object);
/** * Converts a data structure to {@link ModelHolder}. where value * is a root node of the data structure and model is a content of the RDF * graph. * * If requested object is simple object (i.e. is neither List or Map) than * method returns map entry of relevant instance of {@link Literal} as key * and empty model as value. * * @param namespace Namespace for predicates * @param t Object (or data structure) converting to RDF graph * @param rootNode root node of the graph. If not given then blank node is * created. * @return instance of {@link ModelHolder}, */ @SuppressWarnings("unchecked") public ModelHolder asModel(IRI namespace, final Object t, Value rootNode) { if (t instanceof List) { return processList(namespace, (List<Object>) t); } else if (t instanceof Map) { return processMap(namespace, (Map<String, Object>) t, rootNode); } else if (t instanceof String) { return asModelHolder(RDFUtils.makeIRI(t.toString()), modelFactory.createEmptyModel()); } else if (t == null) { return asModelHolder(vocab.nullValue, modelFactory.createEmptyModel()); } else { return asModelHolder(Literals.createLiteral(vf, t), modelFactory.createEmptyModel()); } }