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.repository.config;
07:
08: import static org.openrdf.repository.config.RepositoryConfigSchema.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 DelegatingRepositoryImplConfigBase extends
19: RepositoryImplConfigBase implements
20: DelegatingRepositoryImplConfig {
21:
22: private RepositoryImplConfig delegate;
23:
24: /**
25: * Create a new DelegatingRepositoryImplConfigBase.
26: */
27: public DelegatingRepositoryImplConfigBase() {
28: super ();
29: }
30:
31: /**
32: * Create a new DelegatingRepositoryImplConfigBase.
33: */
34: public DelegatingRepositoryImplConfigBase(String type) {
35: super (type);
36: }
37:
38: /**
39: * Create a new DelegatingRepositoryImplConfigBase.
40: */
41: public DelegatingRepositoryImplConfigBase(String type,
42: RepositoryImplConfig delegate) {
43: this (type);
44: setDelegate(delegate);
45: }
46:
47: public RepositoryImplConfig getDelegate() {
48: return delegate;
49: }
50:
51: public void setDelegate(RepositoryImplConfig delegate) {
52: this .delegate = delegate;
53: }
54:
55: @Override
56: public void validate() throws RepositoryConfigException {
57: super .validate();
58: if (delegate == null) {
59: throw new RepositoryConfigException(
60: "No delegate specified for " + getType()
61: + " repository");
62: }
63: delegate.validate();
64: }
65:
66: @Override
67: public Resource export(Graph graph) {
68: Resource implNode = super .export(graph);
69:
70: if (delegate != null) {
71: Resource delegateNode = delegate.export(graph);
72: graph.add(implNode, DELEGATE, delegateNode);
73: }
74:
75: return implNode;
76: }
77:
78: @Override
79: public void parse(Graph graph, Resource implNode)
80: throws RepositoryConfigException {
81: super .parse(graph, implNode);
82:
83: try {
84: Resource delegateNode = GraphUtil
85: .getOptionalObjectResource(graph, implNode,
86: DELEGATE);
87: if (delegateNode != null) {
88: setDelegate(create(graph, delegateNode));
89: }
90: } catch (GraphUtilException e) {
91: throw new RepositoryConfigException(e.getMessage(), e);
92: }
93: }
94: }
|