/** * Return the value of the literal. In the case of plain literals * this will return the literal string. In the case of typed literals * it will return a java object representing the value. In the case * of typed literals representing a java primitive then the appropriate * java wrapper class (Integer etc) will be returned. */ @Override public Object getValue() { return asNode().getLiteralValue(); }
/** * Return the datatype of the literal. This will be null in the * case of plain literals. */ @Override public RDFDatatype getDatatype() { return asNode().getLiteralDatatype(); }
/** * Return true if this is a "plain" (i.e. old style, not typed) literal. */ public boolean isPlainLiteral() { return asNode().getLiteralDatatype() == null; }
@Override public Resource asResource() { throw new ResourceRequiredException( asNode() ); }
/** * Return the uri of the datatype of the literal. This will be null in the * case of plain literals. */ @Override public String getDatatypeURI() { return asNode().getLiteralDatatypeURI(); }
/** * Return the lexical form of the literal. */ @Override public String getLexicalForm() { return asNode().getLiteralLexicalForm(); }
@Override public String getString() { return asNode().getLiteralLexicalForm(); }
@Override public String getLanguage() { return asNode().getLiteralLanguage(); }
@Override public boolean isWellFormedXML() { return asNode().getLiteralIsXML(); }
@Override public String toString() { return asNode().toString( PrefixMapping.Standard, false ); }
/** Literals are not in any particular model, and so inModel can return this. @param m a model to move the literal into @return this */ @Override public Literal inModel( Model m ) { return getModel() == m ? this : (Literal) m.getRDFNode( asNode() ) ; }
/** * Test that two literals are semantically equivalent. * In some cases this may be the sames as equals, in others * equals is stricter. For example, two xsd:int literals with * the same value but different language tag are semantically * equivalent but distinguished by the java equality function * in order to support round tripping. */ @Override public boolean sameValueAs(Literal other) { return asNode().sameValueAs(other.asNode()); }
@Override public boolean getBoolean() { Object value = asNode().getLiteralValue(); if (isPlainLiteral()) { // old style plain literal - try parsing the string if (value.equals("true")) { return true; } else if (value.equals("false")) { return false; } else { throw new BadBooleanException( value.toString() ); } } else { // typed literal if (value instanceof Boolean) { return ((Boolean)value).booleanValue(); } else { throw new DatatypeFormatException(this.toString() + " is not a Boolean"); } } }