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;
12:
13: /**
14: * This variable models wildcards in triple pattern queres. Only onw instance of
15: * this class if allows: ANY. This allows type-safe methods.
16: *
17: * @author voelkel
18: */
19: public class Variable implements ResourceOrVariable, UriOrVariable,
20: NodeOrVariable {
21:
22: private Variable() {
23: }
24:
25: public static final Variable ANY = new Variable();
26:
27: public Resource asResource() throws ClassCastException {
28: throw new ClassCastException(
29: "A Variable cannot be seen as this");
30: }
31:
32: public Literal asLiteral() throws ClassCastException {
33: throw new ClassCastException(
34: "A Variable cannot be seen as this");
35: }
36:
37: public DatatypeLiteral asDatatypeLiteral()
38: throws ClassCastException {
39: throw new ClassCastException(
40: "A Variable cannot be seen as this");
41: }
42:
43: public LanguageTagLiteral asLanguageTagLiteral()
44: throws ClassCastException {
45: throw new ClassCastException(
46: "A Variable cannot be seen as this");
47: }
48:
49: public URI asURI() throws ClassCastException {
50: throw new ClassCastException(
51: "A Variable cannot be seen as this");
52: }
53:
54: public BlankNode asBlankNode() throws ClassCastException {
55: throw new ClassCastException(
56: "A Variable cannot be seen as this");
57: }
58:
59: public int hashCode() {
60: return 0;
61: }
62:
63: /**
64: * There is only one Variable, so it's equals to itself.
65: */
66: public boolean equals(Object other) {
67: if (other instanceof Variable)
68: return true;
69: else
70: return false;
71: }
72:
73: public int compareTo(Node other) {
74: if (other instanceof Variable) {
75: return this .hashCode() - ((Variable) other).hashCode();
76: } else {
77: return 1;
78: }
79: }
80:
81: public String toSPARQL() {
82: throw new RuntimeException(
83: "Variable (Singleton) can not be used for SPARQL queries");
84: }
85:
86: }
|