001: /*
002: * %W% %E%
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.jump.module.contentstore;
028:
029: import java.io.IOException;
030:
031: /**
032: * <code>JUMPStoreHandle</code> is a handle to perform operations on
033: * a <code>JUMPStore</code>. Instances of handles are acquired by calling
034: * <code>JUMPContentStore.openStore()</code> method.
035: */
036: public class JUMPStoreHandle {
037: private boolean exclusive;
038: private JUMPStore store;
039:
040: /**
041: * Creates a new instance of JUMPStoreHandle
042: */
043: JUMPStoreHandle(JUMPStore store, boolean exclusive) {
044: this .exclusive = exclusive;
045: this .store = store;
046: }
047:
048: public boolean isExclusive() {
049: return this .exclusive;
050: }
051:
052: public boolean isReadOnly() {
053: return !this .exclusive;
054: }
055:
056: /**
057: * See {@link JUMPStore#createDataNode(String, JUMPData)}. This method
058: * would throw a runtime exception if it is called on a non-exclusive
059: * handle.
060: *
061: *
062: * @exception IOException if the underlying <code>JUMPStore.createDataNode(String, JUMPData)</code> causes <code>IOException</code>
063: * @exception JUMPStoreRuntimeException if the handle is in non-executive mode.
064: */
065: public void createDataNode(String uri, JUMPData data)
066: throws IOException {
067: if (isExclusive())
068: this .store.createDataNode(uri, data);
069: else
070: throw new JUMPStoreRuntimeException("Access Denied");
071: }
072:
073: /**
074: * See {@link JUMPStore#createNode(String)}. This method
075: * would throw a runtime exception if it is called on a non-exclusive
076: * handle.
077: *
078: * @exception IOException if the underlying <code>JUMPStore.createNode(String) </code>causes <code>IOException</code>
079: * @exception JUMPStoreRuntimeException if the handle is in non-executive mode.
080: */
081: public void createNode(String uri) throws IOException {
082: if (isExclusive())
083: this .store.createNode(uri);
084: else
085: throw new JUMPStoreRuntimeException("Access Denied");
086: }
087:
088: /**
089: * See {@link JUMPStore#getNode(String)}.
090: *
091: * @exception IOException if the underlying <code>JUMPStore.getNode(String)</code> causes <code>IOException</code>
092: */
093: public JUMPNode getNode(String uri) throws IOException {
094: return this .store.getNode(uri);
095: }
096:
097: /**
098: * See {@link JUMPStore#deleteNode(String)}. This method
099: * would throw a runtime exception if it is called on a non-exclusive
100: * handle.
101: *
102: * @exception IOException if the underlying <code>JUMPStore.deleteNode(String)</code> causes <code>IOException</code>
103: * @exception JUMPStoreRuntimeException if the handle is in non-executive mode.
104: */
105: public void deleteNode(String uri) throws IOException {
106: if (isExclusive())
107: this .store.deleteNode(uri);
108: else
109: throw new JUMPStoreRuntimeException("Access Denied");
110: }
111:
112: /**
113: * See {@link JUMPStore#updateDataNode(String, JUMPData)}. This method
114: * would throw a runtime exception if it is called on a non-exclusive
115: * handle.
116: *
117: * @exception IOException if the underlying <code>JUMPStore.updateDataNode(String, JUMPData)</code> causes <code>IOException</code>
118: * @exception JUMPStoreRuntimeException if the handle is in non-executive mode.
119: */
120: public void updateDataNode(String uri, JUMPData data)
121: throws IOException {
122: if (isExclusive())
123: this .store.updateDataNode(uri, data);
124: else
125: throw new JUMPStoreRuntimeException("Access Denied");
126: }
127: }
|