21 |
|
|
22 |
package nongnu.cashews.rdf; |
package nongnu.cashews.rdf; |
23 |
|
|
24 |
|
import java.net.URI; |
25 |
|
import java.net.URISyntaxException; |
26 |
|
|
27 |
/** |
/** |
28 |
* <p> |
* <p> |
29 |
* This interface represents an RDF node. A node can either be a URI reference |
* This interface represents an RDF node. A node can either be a URI reference |
34 |
* @see RDFURI |
* @see RDFURI |
35 |
* @see Blank |
* @see Blank |
36 |
*/ |
*/ |
37 |
public interface Node |
public abstract class Node |
38 |
|
implements Subject, RDFObject |
39 |
{ |
{ |
40 |
|
|
41 |
|
/** |
42 |
|
* The optional type of this node. |
43 |
|
*/ |
44 |
|
private URI type; |
45 |
|
|
46 |
|
/** |
47 |
|
* Returns a deep copy of the node. |
48 |
|
* |
49 |
|
* @return a deep copy of the node. |
50 |
|
*/ |
51 |
|
public Node clone() |
52 |
|
{ |
53 |
|
try |
54 |
|
{ |
55 |
|
Object clonedObject = super.clone(); |
56 |
|
Node clone = (Node) clonedObject; |
57 |
|
clone.setType(getType()); |
58 |
|
return clone; |
59 |
|
} |
60 |
|
catch (CloneNotSupportedException e) |
61 |
|
{ |
62 |
|
throw new IllegalStateException("Unexpected exception: " + e, e); |
63 |
|
} |
64 |
|
} |
65 |
|
/** |
66 |
|
* Sets the type of this node to that supplied. |
67 |
|
* |
68 |
|
* @param type the new type of this node. |
69 |
|
*/ |
70 |
|
public void setType(URI type) |
71 |
|
{ |
72 |
|
this.type = type; |
73 |
|
} |
74 |
|
|
75 |
|
/** |
76 |
|
* Retrieves a clone of the current type of this node. |
77 |
|
* |
78 |
|
* @return a clone of the current type. |
79 |
|
*/ |
80 |
|
public URI getType() |
81 |
|
{ |
82 |
|
try |
83 |
|
{ |
84 |
|
return (type == null ? null : new URI(type.toString())); |
85 |
|
} |
86 |
|
catch (URISyntaxException e) |
87 |
|
{ |
88 |
|
throw new IllegalStateException("The URI is invalid.", e); |
89 |
|
} |
90 |
|
} |
91 |
|
|
92 |
|
/** |
93 |
|
* Returns a textual representation of the node. |
94 |
|
* |
95 |
|
* @return a textual representation. |
96 |
|
*/ |
97 |
|
public String toString() |
98 |
|
{ |
99 |
|
return getClass().getName() + |
100 |
|
"[type = " + |
101 |
|
type + |
102 |
|
"]"; |
103 |
|
} |
104 |
|
|
105 |
|
/** |
106 |
|
* Sets the type of this node to the URI represented by the supplied |
107 |
|
* <code>String</code>. |
108 |
|
* |
109 |
|
* @param type the new type of the subject, in <code>String</code> form. |
110 |
|
*/ |
111 |
|
public void setType(String type) |
112 |
|
{ |
113 |
|
try |
114 |
|
{ |
115 |
|
setType(new URI(type)); |
116 |
|
} |
117 |
|
catch (URISyntaxException e) |
118 |
|
{ |
119 |
|
throw new IllegalArgumentException("Failed to parse URI: " + e, e); |
120 |
|
} |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
} |
} |