01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.sail.config;
07:
08: import static org.openrdf.sail.config.SailConfigSchema.SAILTYPE;
09:
10: import org.openrdf.model.BNode;
11: import org.openrdf.model.Graph;
12: import org.openrdf.model.Literal;
13: import org.openrdf.model.Resource;
14: import org.openrdf.model.util.GraphUtil;
15: import org.openrdf.model.util.GraphUtilException;
16:
17: /**
18: * @author Herko ter Horst
19: */
20: public class SailImplConfigBase implements SailImplConfig {
21:
22: private String type;
23:
24: /**
25: * Create a new RepositoryConfigImpl.
26: */
27: public SailImplConfigBase() {
28: }
29:
30: /**
31: * Create a new RepositoryConfigImpl.
32: */
33: public SailImplConfigBase(String type) {
34: this ();
35: setType(type);
36: }
37:
38: public String getType() {
39: return type;
40: }
41:
42: public void setType(String type) {
43: this .type = type;
44: }
45:
46: public void validate() throws SailConfigException {
47: if (type == null) {
48: throw new SailConfigException(
49: "No type specified for repository implementation");
50: }
51: }
52:
53: public Resource export(Graph graph) {
54: BNode implNode = graph.getValueFactory().createBNode();
55:
56: if (type != null) {
57: graph.add(implNode, SAILTYPE, graph.getValueFactory()
58: .createLiteral(type));
59: }
60:
61: return implNode;
62: }
63:
64: public void parse(Graph graph, Resource implNode)
65: throws SailConfigException {
66: try {
67: Literal typeLit = GraphUtil.getOptionalObjectLiteral(graph,
68: implNode, SAILTYPE);
69: if (typeLit != null) {
70: setType(typeLit.getLabel());
71: }
72: } catch (GraphUtilException e) {
73: throw new SailConfigException(e.getMessage(), e);
74: }
75: }
76: }
|