17
|
1 /**
|
|
2 *
|
|
3 */
|
|
4 package de.mpiwg.itgroup.annotationManager.RDFHandling;
|
|
5
|
|
6 import org.apache.log4j.Logger;
|
|
7 import org.restlet.Context;
|
|
8 import org.restlet.engine.component.ChildContext;
|
|
9
|
|
10 import de.mpiwg.itgroup.annotationManager.Errors.TripleStoreStoreError;
|
|
11 import de.mpiwg.itgroup.triplestoremanager.exceptions.TripleStoreHandlerException;
|
|
12 import de.mpiwg.itgroup.triplestoremanager.owl.TripleStoreHandler;
|
|
13
|
|
14 /**
|
|
15 * @author casties
|
|
16 *
|
|
17 */
|
|
18 public class TripleStoreConnection {
|
|
19
|
|
20 protected static Logger logger = Logger.getRootLogger();
|
|
21
|
|
22 private String user;
|
|
23 private String password;
|
|
24 private String url = "jdbc:virtuoso://virtuoso.mpiwg-berlin.mpg.de:1111";
|
|
25
|
|
26 /**
|
|
27 * Creates TripleStoreConnection with parameters from web context.
|
|
28 */
|
|
29 public TripleStoreConnection() {
|
|
30 ChildContext context = (ChildContext)Context.getCurrent();
|
|
31 user = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUser", true);
|
|
32 password = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUserPassword", true);
|
|
33 url = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreConnectionURL", true, url);
|
|
34 }
|
|
35
|
|
36 /**
|
|
37 * @param user
|
|
38 * @param password
|
|
39 * @param url
|
|
40 */
|
|
41 public TripleStoreConnection(String user, String password, String url) {
|
|
42 super();
|
|
43 this.user = user;
|
|
44 this.password = password;
|
|
45 this.url = url;
|
|
46 }
|
|
47
|
|
48 /**
|
|
49 * returns TripleStoreHandler.
|
|
50 *
|
|
51 * @return
|
|
52 * @throws TripleStoreHandlerException
|
|
53 */
|
|
54 public TripleStoreHandler getTripleStoreHandler() throws TripleStoreHandlerException {
|
|
55 if (user == null || password == null || url == null) {
|
|
56 logger.error(String.format("Missing triplestore parameters! (user=%s pw=%s url=%s)", user, password, url));
|
|
57 throw new TripleStoreStoreError();
|
|
58 }
|
|
59 TripleStoreHandler th = new TripleStoreHandler(url, user, password);
|
|
60 return th;
|
|
61 }
|
|
62
|
|
63 /**
|
|
64 * returns new TripleStoreHandler.
|
|
65 *
|
|
66 * uses parameters from web context.
|
|
67 *
|
|
68 * @return
|
|
69 * @throws TripleStoreStoreError
|
|
70 * @throws TripleStoreHandlerException
|
|
71 */
|
|
72 public static TripleStoreHandler newTripleStoreHandler() throws TripleStoreStoreError, TripleStoreHandlerException {
|
|
73 ChildContext context = (ChildContext)Context.getCurrent();
|
|
74 String user = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUser");
|
|
75 String password = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUserPassword");
|
|
76 String url = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreConnectionURL");
|
|
77 if (user == null || password == null || url == null) {
|
|
78 logger.error(String.format("Missing triplestore parameters! (user=%s pw=%s url=%s)", user, password, url));
|
|
79 throw new TripleStoreStoreError();
|
|
80 }
|
|
81 TripleStoreHandler th = new TripleStoreHandler(url, user, password);
|
|
82 return th;
|
|
83 }
|
|
84
|
|
85 }
|