001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.sail.helpers;
007:
008: import java.io.File;
009:
010: import org.openrdf.model.ValueFactory;
011: import org.openrdf.sail.Sail;
012: import org.openrdf.sail.SailChangedListener;
013: import org.openrdf.sail.SailConnection;
014: import org.openrdf.sail.SailException;
015: import org.openrdf.sail.StackableSail;
016:
017: /**
018: * An implementation of the StackableSail interface that wraps another Sail
019: * object and forwards any relevant calls to the wrapped Sail.
020: *
021: * @author Arjohn Kampman
022: */
023: public class SailWrapper implements StackableSail {
024:
025: /*-----------*
026: * Variables *
027: *-----------*/
028:
029: /**
030: * The base Sail for this SailWrapper.
031: */
032: private Sail baseSail;
033:
034: /*--------------*
035: * Constructors *
036: *--------------*/
037:
038: /**
039: * Creates a new SailWrapper. The base Sail for the created SailWrapper can
040: * be set later using {@link #setBaseSail}.
041: */
042: public SailWrapper() {
043: }
044:
045: /**
046: * Creates a new SailWrapper that wraps the supplied Sail.
047: */
048: public SailWrapper(Sail baseSail) {
049: setBaseSail(baseSail);
050: }
051:
052: /*---------*
053: * Methods *
054: *---------*/
055:
056: public void setBaseSail(Sail baseSail) {
057: this .baseSail = baseSail;
058: }
059:
060: public Sail getBaseSail() {
061: return baseSail;
062: }
063:
064: private void verifyBaseSailSet() {
065: if (baseSail == null) {
066: throw new IllegalStateException("No base Sail has been set");
067: }
068: }
069:
070: public File getDataDir() {
071: return baseSail.getDataDir();
072: }
073:
074: public void setDataDir(File dataDir) {
075: baseSail.setDataDir(dataDir);
076: }
077:
078: public void initialize() throws SailException {
079: verifyBaseSailSet();
080: baseSail.initialize();
081: }
082:
083: public void shutDown() throws SailException {
084: verifyBaseSailSet();
085: baseSail.shutDown();
086: }
087:
088: public boolean isWritable() throws SailException {
089: verifyBaseSailSet();
090: return baseSail.isWritable();
091: }
092:
093: public SailConnection getConnection() throws SailException {
094: verifyBaseSailSet();
095: return baseSail.getConnection();
096: }
097:
098: public ValueFactory getValueFactory() {
099: verifyBaseSailSet();
100: return baseSail.getValueFactory();
101: }
102:
103: public void addSailChangedListener(SailChangedListener listener) {
104: verifyBaseSailSet();
105: baseSail.addSailChangedListener(listener);
106: }
107:
108: public void removeSailChangedListener(SailChangedListener listener) {
109: verifyBaseSailSet();
110: baseSail.removeSailChangedListener(listener);
111: }
112: }
|