14
14
15
15
package com .github .owlcs .ontapi ;
16
16
17
+ import com .github .owlcs .ontapi .jena .model .OntID ;
17
18
import org .apache .jena .graph .Node ;
18
19
import org .apache .jena .graph .NodeFactory ;
19
20
import org .semanticweb .owlapi .model .IRI ;
20
21
import org .semanticweb .owlapi .model .OWLOntologyID ;
21
- import com .github .owlcs .ontapi .jena .model .OntID ;
22
22
23
23
import java .lang .reflect .Field ;
24
24
import java .util .Objects ;
34
34
* @see OntID
35
35
* @see <a href='https://www.w3.org/TR/owl-syntax/#Ontology_IRI_and_Version_IRI'>3.1 Ontology IRI and Version IRI</a>
36
36
*/
37
- public class OntologyID extends OWLOntologyID implements AsNode {
37
+ public class ID extends OWLOntologyID implements AsNode {
38
38
39
39
protected final Node node ;
40
40
@@ -43,7 +43,7 @@ public class OntologyID extends OWLOntologyID implements AsNode {
43
43
*
44
44
* @param iri String, not {@code null}
45
45
*/
46
- public OntologyID (String iri ) {
46
+ public ID (String iri ) {
47
47
this (iri , null );
48
48
}
49
49
@@ -53,27 +53,27 @@ public OntologyID(String iri) {
53
53
* @param iri String, not {@code null}
54
54
* @param ver String, can be {@code null}
55
55
*/
56
- public OntologyID (String iri , String ver ) {
56
+ public ID (String iri , String ver ) {
57
57
this (NodeFactory .createURI (Objects .requireNonNull (iri , "Null iri" )), ver );
58
58
}
59
59
60
60
/**
61
61
* Constructs an anonymous ontology identifier
62
62
* specifying that the ontology IRI (and hence the version IRI) is not present.
63
63
*/
64
- public OntologyID () {
64
+ public ID () {
65
65
this (NodeFactory .createBlankNode (), null );
66
66
}
67
67
68
68
/**
69
69
* Constructs an ontology identifier from the given {@link OntID Ontology Graph Model ID}.
70
- * The difference between these two IDs ( {@link OntID} and {@link OntologyID this classs}) is
70
+ * The difference between these two IDs ( {@link OntID} and {@link ID this classs}) is
71
71
* that the former is used in the RDF representation (i.e. in {@link com.github.owlcs.ontapi.jena.model.OntGraphModel}),
72
72
* while the other is in the axiomatic view (i.e. in {@link org.semanticweb.owlapi.model.OWLOntology}).
73
73
*
74
74
* @param id {@link OntID}, not {@code null}
75
75
*/
76
- public OntologyID (OntID id ) {
76
+ public ID (OntID id ) {
77
77
this (id .asNode (), id .getVersionIRI ());
78
78
}
79
79
@@ -82,27 +82,31 @@ public OntologyID(OntID id) {
82
82
*
83
83
* @param id {@link Node}, not {@code null}, ether blank or uri node
84
84
* @param version {@link String}, can be {@code null}
85
- * @throws OntApiException if {@code id} is anonymous and {@code version} is not {@code null}
86
- * @throws IllegalStateException if the OWL-API guys have changed the basic implementation, and I do not know about it yet
87
- * @throws UnsupportedOperationException if {@code id} is not uri or blank node
88
- * @throws NullPointerException if {@code id} is {@code null}
85
+ * @throws OntApiException if {@code id} is not blank or URI (i.e. it is literal) or
86
+ * it is anonymous and {@code version} is not {@code null}
87
+ * @throws IllegalStateException if the OWL-API guys have changed the basic implementation,
88
+ * but we have not yet learned about it
89
+ * @throws NullPointerException if {@code id} is {@code null}
89
90
*/
90
- protected OntologyID (Node id , String version ) throws OntApiException ,
91
+ protected ID (Node id , String version ) throws OntApiException ,
91
92
IllegalStateException , UnsupportedOperationException , NullPointerException {
92
93
Optional <String > internalID ;
93
94
Optional <IRI > ontologyIRI , versionIRI ;
94
95
if (Objects .requireNonNull (id , "Null id node" ).isBlank ()) {
95
96
if (version != null ) {
96
- throw new OntApiException ("Anonymous ontology id (" + id +
97
+ throw new OntApiException . IllegalArgument ("Anonymous ontology id (" + id +
97
98
") can not be accompanied by a version (" + version + ")" );
98
99
}
99
100
internalID = Optional .of (id .getBlankNodeLabel ());
100
101
ontologyIRI = Optional .empty ();
101
102
versionIRI = Optional .empty ();
102
- } else {
103
+ } else if ( id . isURI ()) {
103
104
internalID = Optional .empty ();
104
105
ontologyIRI = Optional .of (id .getURI ()).map (IRI ::create );
105
106
versionIRI = Optional .ofNullable (version ).map (IRI ::create );
107
+ } else {
108
+ throw new OntApiException .IllegalArgument ("Illegal node is given: " +
109
+ id + " - it must be either URI or Blank resource." );
106
110
}
107
111
this .node = id ;
108
112
int hashCode = 17 ;
@@ -136,17 +140,17 @@ public Node asNode() {
136
140
}
137
141
138
142
/**
139
- * Converts any instance of {@link OWLOntologyID} to the {@link OntologyID ONT-API Ontology Identifier implementation}.
143
+ * Converts any instance of {@link OWLOntologyID} to the {@link ID ONT-API Ontology Identifier implementation}.
140
144
*
141
145
* @param id {@link OWLOntologyID}, not {@code null}
142
- * @return {@link OntologyID }, not {@code null}
146
+ * @return {@link ID }, not {@code null}
143
147
* @throws IllegalArgumentException should never happen, actually
144
148
*/
145
- public static OntologyID asONT (OWLOntologyID id ) throws IllegalArgumentException {
146
- if (id instanceof OntologyID ) {
147
- return (OntologyID ) id ;
149
+ public static ID asONT (OWLOntologyID id ) throws IllegalArgumentException {
150
+ if (id instanceof ID ) {
151
+ return (ID ) id ;
148
152
}
149
- if (id .isAnonymous ()) return new OntologyID ();
153
+ if (id .isAnonymous ()) return new ID ();
150
154
String iri = id .getOntologyIRI ().map (IRI ::getIRIString ).orElseThrow (IllegalArgumentException ::new );
151
155
String ver = id .getVersionIRI ().map (IRI ::getIRIString ).orElse (null );
152
156
return create (iri , ver );
@@ -157,9 +161,9 @@ public static OntologyID asONT(OWLOntologyID id) throws IllegalArgumentException
157
161
* Notice that the corresponding constructor does not allow {@code null}s, while this method does.
158
162
*
159
163
* @param iri {@link IRI}, can be {@code null}
160
- * @return {@link OntologyID }, not {@code null}
164
+ * @return {@link ID }, not {@code null}
161
165
*/
162
- public static OntologyID create (IRI iri ) {
166
+ public static ID create (IRI iri ) {
163
167
return create (iri == null ? null : iri .getIRIString (), null );
164
168
}
165
169
@@ -169,10 +173,9 @@ public static OntologyID create(IRI iri) {
169
173
*
170
174
* @param iri String, can be {@code null}
171
175
* @param ver String, can be {@code null}
172
- * @return {@link OntologyID }, not {@code null}
176
+ * @return {@link ID }, not {@code null}
173
177
*/
174
- public static OntologyID create (String iri , String ver ) {
175
- return iri == null ? new OntologyID () : new OntologyID (iri , ver );
178
+ public static ID create (String iri , String ver ) {
179
+ return iri == null ? new ID () : new ID (iri , ver );
176
180
}
177
-
178
181
}
0 commit comments