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.sail.config;
007:
008: import static org.openrdf.repository.sail.config.SailRepositorySchema.SAILIMPL;
009: import static org.openrdf.sail.config.SailConfigSchema.SAILTYPE;
010:
011: import org.openrdf.model.Graph;
012: import org.openrdf.model.Literal;
013: import org.openrdf.model.Resource;
014: import org.openrdf.model.util.GraphUtil;
015: import org.openrdf.model.util.GraphUtilException;
016: import org.openrdf.repository.config.RepositoryConfigException;
017: import org.openrdf.repository.config.RepositoryImplConfigBase;
018: import org.openrdf.sail.config.SailConfigException;
019: import org.openrdf.sail.config.SailFactory;
020: import org.openrdf.sail.config.SailImplConfig;
021: import org.openrdf.sail.config.SailRegistry;
022:
023: /**
024: * @author Arjohn Kampman
025: */
026: public class SailRepositoryConfig extends RepositoryImplConfigBase {
027:
028: private SailImplConfig sailImplConfig;
029:
030: public SailRepositoryConfig() {
031: super (SailRepositoryFactory.REPOSITORY_TYPE);
032: }
033:
034: public SailRepositoryConfig(SailImplConfig sailImplConfig) {
035: this ();
036: setSailImplConfig(sailImplConfig);
037: }
038:
039: public SailImplConfig getSailImplConfig() {
040: return sailImplConfig;
041: }
042:
043: public void setSailImplConfig(SailImplConfig sailImplConfig) {
044: this .sailImplConfig = sailImplConfig;
045: }
046:
047: @Override
048: public void validate() throws RepositoryConfigException {
049: super .validate();
050: if (sailImplConfig == null) {
051: throw new RepositoryConfigException(
052: "No Sail implementation specified for Sail repository");
053: }
054:
055: try {
056: sailImplConfig.validate();
057: } catch (SailConfigException e) {
058: throw new RepositoryConfigException(e.getMessage(), e);
059: }
060: }
061:
062: @Override
063: public Resource export(Graph graph) {
064: Resource repImplNode = super .export(graph);
065:
066: if (sailImplConfig != null) {
067: Resource sailImplNode = sailImplConfig.export(graph);
068: graph.add(repImplNode, SAILIMPL, sailImplNode);
069: }
070:
071: return repImplNode;
072: }
073:
074: @Override
075: public void parse(Graph graph, Resource repImplNode)
076: throws RepositoryConfigException {
077: try {
078: Resource sailImplNode = GraphUtil
079: .getOptionalObjectResource(graph, repImplNode,
080: SAILIMPL);
081:
082: if (sailImplNode != null) {
083: Literal typeLit = GraphUtil.getOptionalObjectLiteral(
084: graph, sailImplNode, SAILTYPE);
085:
086: if (typeLit != null) {
087: SailFactory factory = SailRegistry.getInstance()
088: .get(typeLit.getLabel());
089:
090: if (factory == null) {
091: throw new RepositoryConfigException(
092: "Unsupported Sail type: "
093: + typeLit.getLabel());
094: }
095:
096: sailImplConfig = factory.getConfig();
097: sailImplConfig.parse(graph, sailImplNode);
098: }
099: }
100: } catch (GraphUtilException e) {
101: throw new RepositoryConfigException(e.getMessage(), e);
102: } catch (SailConfigException e) {
103: throw new RepositoryConfigException(e.getMessage(), e);
104: }
105: }
106: }
|