Skip to content

Method: username(String)

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