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.Node;
15: import org.ontoware.rdf2go.model.node.URI;
16: import org.ontoware.rdf2go.model.node.Variable;
17: import org.slf4j.Logger;
18: import org.slf4j.LoggerFactory;
19:
20: import sun.reflect.generics.reflectiveObjects.NotImplementedException;
21:
22: public abstract class AbstractBlankNodeImpl extends ResourceImpl
23: implements BlankNode {
24:
25: private static final Logger log = LoggerFactory
26: .getLogger(Variable.class);
27:
28: private Object underlyingBlankNode;
29:
30: /** This method should only be called by RDF2Go implmentations */
31: public AbstractBlankNodeImpl(Object underlyingBlankNode) {
32: this .underlyingBlankNode = underlyingBlankNode;
33: }
34:
35: /** This method should only be called by RDF2Go implmentations */
36: public Object getUnderlyingBlankNode() {
37: return this .underlyingBlankNode;
38: }
39:
40: @Override
41: public boolean equals(Object other) {
42: return other instanceof AbstractBlankNodeImpl
43: && this .getUnderlyingBlankNode().equals(
44: ((AbstractBlankNodeImpl) other)
45: .getUnderlyingBlankNode());
46: }
47:
48: @Override
49: public String toString() {
50: return this .underlyingBlankNode.toString();
51: }
52:
53: public URI asURI() throws ClassCastException {
54: throw new ClassCastException("Cannot cast a BlankNode to a URI");
55:
56: }
57:
58: public BlankNode asBlankNode() throws ClassCastException {
59: return this ;
60: }
61:
62: @Override
63: public int hashCode() {
64: return this .underlyingBlankNode.hashCode();
65: }
66:
67: public int compareTo(Node other) {
68: if (other instanceof BlankNode) {
69: if (this .equals(other))
70: return 0;
71: // else somehow define a sorting order on blank nodes
72: return this .hashCode() - other.hashCode();
73:
74: }
75: // else sort by type
76: return NodeUtils.compareByType(this , other);
77: }
78:
79: public String toSPARQL() throws UnsupportedOperationException {
80: log
81: .warn("Variable (Singleton) should not be used for SPARQL queries");
82: throw new NotImplementedException();
83: }
84:
85: public abstract String getInternalID();
86: }
|