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