001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.repository.http.config;
007:
008: import static org.openrdf.repository.http.config.HTTPRepositorySchema.PASSWORD;
009: import static org.openrdf.repository.http.config.HTTPRepositorySchema.REPOSITORYURL;
010: import static org.openrdf.repository.http.config.HTTPRepositorySchema.USERNAME;
011:
012: import org.openrdf.model.Graph;
013: import org.openrdf.model.Literal;
014: import org.openrdf.model.Resource;
015: import org.openrdf.model.URI;
016: import org.openrdf.model.util.GraphUtil;
017: import org.openrdf.model.util.GraphUtilException;
018: import org.openrdf.repository.config.RepositoryConfigException;
019: import org.openrdf.repository.config.RepositoryImplConfigBase;
020:
021: /**
022: * @author Arjohn Kampman
023: */
024: public class HTTPRepositoryConfig extends RepositoryImplConfigBase {
025:
026: private String url;
027:
028: private String username;
029:
030: private String password;
031:
032: public HTTPRepositoryConfig() {
033: super (HTTPRepositoryFactory.REPOSITORY_TYPE);
034: }
035:
036: public HTTPRepositoryConfig(String url) {
037: this ();
038: setURL(url);
039: }
040:
041: public String getURL() {
042: return url;
043: }
044:
045: public void setURL(String url) {
046: this .url = url;
047: }
048:
049: public String getUsername() {
050: return username;
051: }
052:
053: public void setUsername(String username) {
054: this .username = username;
055: }
056:
057: public String getPassword() {
058: return password;
059: }
060:
061: public void setPassword(String password) {
062: this .password = password;
063: }
064:
065: @Override
066: public void validate() throws RepositoryConfigException {
067: super .validate();
068: if (url == null) {
069: throw new RepositoryConfigException(
070: "No URL specified for HTTP repository");
071: }
072: }
073:
074: @Override
075: public Resource export(Graph graph) {
076: Resource implNode = super .export(graph);
077:
078: if (url != null) {
079: graph.add(implNode, REPOSITORYURL, graph.getValueFactory()
080: .createURI(url));
081: }
082: // if (username != null) {
083: // graph.add(implNode, USERNAME, graph.getValueFactory().createLiteral(username));
084: // }
085: // if (password != null) {
086: // graph.add(implNode, PASSWORD, graph.getValueFactory().createLiteral(password));
087: // }
088:
089: return implNode;
090: }
091:
092: @Override
093: public void parse(Graph graph, Resource implNode)
094: throws RepositoryConfigException {
095: super .parse(graph, implNode);
096:
097: try {
098: URI uri = GraphUtil.getOptionalObjectURI(graph, implNode,
099: REPOSITORYURL);
100: if (uri != null) {
101: setURL(uri.toString());
102: }
103: Literal username = GraphUtil.getOptionalObjectLiteral(
104: graph, implNode, USERNAME);
105: if (username != null) {
106: setUsername(username.getLabel());
107: }
108: Literal password = GraphUtil.getOptionalObjectLiteral(
109: graph, implNode, PASSWORD);
110: if (password != null) {
111: setPassword(password.getLabel());
112: }
113: } catch (GraphUtilException e) {
114: throw new RepositoryConfigException(e.getMessage(), e);
115: }
116: }
117: }
|