01: /*
02: * LICENSE INFORMATION
03: * Copyright 2005-2007 by FZI (http://www.fzi.de).
04: * Licensed under a BSD license (http://www.opensource.org/licenses/bsd-license.php)
05: * <OWNER> = Max Völkel
06: * <ORGANIZATION> = FZI Forschungszentrum Informatik Karlsruhe, Karlsruhe, Germany
07: * <YEAR> = 2007
08: *
09: * Project information at http://semweb4j.org/rdf2go
10: */
11: package org.ontoware.rdf2go.model.node.impl;
12:
13: import org.ontoware.rdf2go.model.node.BlankNode;
14: import org.ontoware.rdf2go.model.node.Literal;
15: import org.ontoware.rdf2go.model.node.Resource;
16: import org.ontoware.rdf2go.model.node.URI;
17:
18: /**
19: * Subclasses must have valid equals() and hashCode() implementations.
20: * @author voelkel
21: *
22: */
23: public abstract class LiteralImpl implements Literal {
24:
25: public abstract String getValue();
26:
27: public Resource asResource() throws ClassCastException {
28: throw new ClassCastException("Literals are no resources");
29: }
30:
31: public Literal asLiteral() throws ClassCastException {
32: return this ;
33: }
34:
35: public URI asURI() throws ClassCastException {
36: throw new ClassCastException("Literals are no URIs");
37: }
38:
39: public BlankNode asBlankNode() throws ClassCastException {
40: throw new ClassCastException("Literals are no BlankNodes");
41: }
42:
43: protected static String sparqlEncode(String raw) {
44: String result = raw;
45: result = result.replace("\\", "\\\\");
46: result = result.replace("'", "\\'");
47: result = result.replace("\"", "\\\"");
48: return result;
49: }
50:
51: }
|