@Nullable private static Literal toLiteral(@Nullable final Object old, @Nullable final String label) { if (label == null) { return null; } String lang = null; URI dt = null; if (old instanceof Literal) { final Literal l = (Literal) old; lang = l.getLanguage(); dt = l.getDatatype(); } return lang != null ? new GroovyLiteral(label, lang) : dt != null ? new GroovyLiteral( label, dt) : new GroovyLiteral(label); }
return (Value) object; } else if (object instanceof Long) { return new GroovyLiteral(object.toString(), XMLSchema.LONG); } else if (object instanceof Integer) { return new GroovyLiteral(object.toString(), XMLSchema.INT); } else if (object instanceof Short) { return new GroovyLiteral(object.toString(), XMLSchema.SHORT); } else if (object instanceof Byte) { return new GroovyLiteral(object.toString(), XMLSchema.BYTE); } else if (object instanceof Double) { return new GroovyLiteral(object.toString(), XMLSchema.DOUBLE); } else if (object instanceof Float) { return new GroovyLiteral(object.toString(), XMLSchema.FLOAT); } else if (object instanceof Boolean) { return new GroovyLiteral(object.toString(), XMLSchema.BOOLEAN); } else if (object instanceof XMLGregorianCalendar) { final XMLGregorianCalendar c = (XMLGregorianCalendar) object; return new GroovyLiteral(c.toXMLFormat(), XMLDatatypeUtil.qnameToURI(c .getXMLSchemaType())); } else if (object instanceof Date) { c.setTime((Date) object); final XMLGregorianCalendar xc = DATATYPE_FACTORY.newXMLGregorianCalendar(c); return new GroovyLiteral(xc.toXMLFormat(), XMLDatatypeUtil.qnameToURI(xc .getXMLSchemaType())); } else if (object instanceof CharSequence) { return new GroovyLiteral(object.toString(), XMLSchema.STRING); } else if (object != null) { return new GroovyLiteral(object.toString());
return new GroovyLiteral(object.toString(), XMLSchema.LONG); } else if (object instanceof Integer) { return new GroovyLiteral(object.toString(), XMLSchema.INT); } else if (object instanceof Short) { return new GroovyLiteral(object.toString(), XMLSchema.SHORT); } else if (object instanceof Byte) { return new GroovyLiteral(object.toString(), XMLSchema.BYTE); } else if (object instanceof Double) { return new GroovyLiteral(object.toString(), XMLSchema.DOUBLE); } else if (object instanceof Float) { return new GroovyLiteral(object.toString(), XMLSchema.FLOAT); } else if (object instanceof Boolean) { return new GroovyLiteral(object.toString(), XMLSchema.BOOLEAN); } else if (object instanceof XMLGregorianCalendar) { final XMLGregorianCalendar c = (XMLGregorianCalendar) object; return new GroovyLiteral(c.toXMLFormat(), XMLDatatypeUtil.qnameToURI(c .getXMLSchemaType())); } else if (object instanceof Date) { c.setTime((Date) object); final XMLGregorianCalendar xc = DATATYPE_FACTORY.newXMLGregorianCalendar(c); return new GroovyLiteral(xc.toXMLFormat(), XMLDatatypeUtil.qnameToURI(xc .getXMLSchemaType())); } else if (object instanceof CharSequence) { return new GroovyLiteral(object.toString(), XMLSchema.STRING); } else { return new GroovyLiteral(object.toString());
@Nullable private static Value normalize(@Nullable final Value v) { if (v instanceof URI) { return v instanceof GroovyURI ? v : new GroovyURI(v.stringValue()); } else if (v instanceof BNode) { return v instanceof GroovyBNode ? v : new GroovyBNode(v.stringValue()); } else if (v instanceof Literal) { if (v instanceof GroovyLiteral) { return v; } final Literal l = (Literal) v; if (l.getLanguage() != null) { return new GroovyLiteral(l.getLabel(), l.getLanguage()); } else if (l.getDatatype() != null) { return new GroovyLiteral(l.getLabel(), l.getDatatype()); } else { return new GroovyLiteral(l.getLabel()); } } return null; }