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.DELEGATE;
09:
10: import org.openrdf.model.Graph;
11: import org.openrdf.model.Resource;
12: import org.openrdf.model.util.GraphUtil;
13: import org.openrdf.model.util.GraphUtilException;
14:
15: /**
16: * @author Herko ter Horst
17: */
18: public class DelegatingSailImplConfigBase extends SailImplConfigBase
19: implements DelegatingSailImplConfig {
20:
21: private SailImplConfig delegate;
22:
23: /**
24: * Create a new RepositoryConfigImpl.
25: */
26: public DelegatingSailImplConfigBase() {
27: super ();
28: }
29:
30: /**
31: * Create a new RepositoryConfigImpl.
32: */
33: public DelegatingSailImplConfigBase(String type) {
34: super (type);
35: }
36:
37: /**
38: * Create a new RepositoryConfigImpl.
39: */
40: public DelegatingSailImplConfigBase(String type,
41: SailImplConfig delegate) {
42: this (type);
43: setDelegate(delegate);
44: }
45:
46: public SailImplConfig getDelegate() {
47: return delegate;
48: }
49:
50: public void setDelegate(SailImplConfig delegate) {
51: this .delegate = delegate;
52: }
53:
54: @Override
55: public void validate() throws SailConfigException {
56: super .validate();
57: if (delegate == null) {
58: throw new SailConfigException("No delegate specified for "
59: + getType() + " Sail");
60: }
61: delegate.validate();
62: }
63:
64: @Override
65: public Resource export(Graph graph) {
66: Resource implNode = super .export(graph);
67:
68: if (delegate != null) {
69: Resource delegateNode = delegate.export(graph);
70: graph.add(implNode, DELEGATE, delegateNode);
71: }
72:
73: return implNode;
74: }
75:
76: @Override
77: public void parse(Graph graph, Resource implNode)
78: throws SailConfigException {
79: super .parse(graph, implNode);
80:
81: try {
82: Resource delegateNode = GraphUtil
83: .getOptionalObjectResource(graph, implNode,
84: DELEGATE);
85: if (delegateNode != null) {
86: setDelegate(SailConfigUtil.parseRepositoryImpl(graph,
87: delegateNode));
88: }
89: } catch (GraphUtilException e) {
90: throw new SailConfigException(e.getMessage(), e);
91: }
92: }
93: }
|