-
Notifications
You must be signed in to change notification settings - Fork 14
/
OntologyStorageProperties.java
169 lines (144 loc) · 5.38 KB
/
OntologyStorageProperties.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/**
* Copyright (C) 2016 Czech Technical University in Prague
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cz.cvut.kbss.ontodriver;
import java.net.URI;
import java.util.Objects;
/**
* Holds properties of an ontology storage.
* <p>
* These properties can be used to create a DataSource representing the storage.
*/
public class OntologyStorageProperties {
/**
* URI of the ontology.
* <p>
* Logical URI is not required, since for example for Sesame storages there is no logical
* URI, there is just the physical URI of the repository and multiple contexts in it.
* <p>
* However, OWLAPI based storages require logical URI.
*/
private final URI ontologyUri;
/**
* URI of the physical storage, e. g. OWLDB database, OWLIM storage, file
*/
private final URI physicalUri;
/**
* Fully qualified OntoDriver data source class name
*/
private final String driver;
/**
* User name for the storage, if necessary
*/
private final String username;
/**
* Password for the storage, if necessary
*/
private final String password;
OntologyStorageProperties(OntologyStoragePropertiesBuilder builder) {
this.physicalUri = Objects.requireNonNull(builder.physicalUri, "Ontology physical URI is required!");
this.driver = Objects.requireNonNull(builder.driverClass, "OntDriver data source class name is required!");
this.ontologyUri = builder.ontologyUri;
this.username = builder.username;
this.password = builder.password;
}
public URI getOntologyURI() {
return ontologyUri;
}
public URI getPhysicalURI() {
return physicalUri;
}
public String getDriver() {
return driver;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
@Override
public String toString() {
final StringBuilder b = new StringBuilder();
b.append("StorageProperties: logical URI = ");
b.append(ontologyUri);
b.append(", physical URI = ");
b.append(physicalUri);
b.append(", data source class = ");
b.append(driver);
if (username != null) {
b.append(", username = ");
b.append(username);
b.append(", password = ");
b.append(password);
}
return b.toString();
}
public static OntologyStoragePropertiesBuilder ontologyUri(URI ontologyUri) {
return new OntologyStoragePropertiesBuilder().ontologyUri(ontologyUri);
}
public static OntologyStoragePropertiesBuilder physicalUri(URI physicalUri) {
return new OntologyStoragePropertiesBuilder().physicalUri(physicalUri);
}
public static OntologyStoragePropertiesBuilder username(String username) {
return new OntologyStoragePropertiesBuilder().username(username);
}
public static OntologyStoragePropertiesBuilder password(String password) {
return new OntologyStoragePropertiesBuilder().password(password);
}
public static OntologyStoragePropertiesBuilder driver(String driverClass) {
return new OntologyStoragePropertiesBuilder().driver(driverClass);
}
/**
* Builder class for the {@code OntologyStorageProperties}.
*/
public static class OntologyStoragePropertiesBuilder {
protected URI ontologyUri;
protected URI physicalUri;
protected String username;
protected String password;
protected String driverClass;
public OntologyStoragePropertiesBuilder ontologyUri(URI ontologyUri) {
this.ontologyUri = ontologyUri;
return this;
}
public OntologyStoragePropertiesBuilder ontologyUri(String ontologyUri) {
this.ontologyUri = ontologyUri != null ? URI.create(ontologyUri) : null;
return this;
}
public OntologyStoragePropertiesBuilder physicalUri(URI physicalUri) {
this.physicalUri = physicalUri;
return this;
}
public OntologyStoragePropertiesBuilder physicalUri(String physicalUri) {
this.physicalUri = physicalUri != null ? URI.create(physicalUri) : null;
return this;
}
public OntologyStoragePropertiesBuilder username(String username) {
this.username = username;
return this;
}
public OntologyStoragePropertiesBuilder password(String password) {
this.password = password;
return this;
}
public OntologyStoragePropertiesBuilder driver(String driverClass) {
this.driverClass = driverClass;
return this;
}
public OntologyStorageProperties build() {
return new OntologyStorageProperties(this);
}
}
}