001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.shared.cache.impl;
034:
035: import com.flexive.shared.cache.FxBackingCache;
036: import com.flexive.shared.cache.FxCacheException;
037: import org.jboss.cache.Fqn;
038: import org.jboss.cache.CacheException;
039: import org.jboss.cache.Node;
040:
041: import java.util.Set;
042: import java.util.HashSet;
043:
044: /**
045: * Base implementation of JBoss Cache wrappers.
046: *
047: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
048: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
049: * @version $Rev$
050: */
051: public abstract class AbstractJBossTreeCacheWrapper implements
052: FxBackingCache {
053:
054: /**
055: * {@inheritDoc}
056: */
057: public Object get(String path, Object key) throws FxCacheException {
058: try {
059: return getCache().get(Fqn.fromString(path), key);
060: } catch (CacheException e) {
061: throw new FxCacheException(e);
062: }
063: }
064:
065: /**
066: * {@inheritDoc}
067: */
068: public boolean exists(String path, Object key)
069: throws FxCacheException {
070: return getCache().get(Fqn.fromString(path), key) != null;
071: }
072:
073: /**
074: * {@inheritDoc}
075: */
076: public void put(String path, Object key, Object value)
077: throws FxCacheException {
078: try {
079: getCache().put(Fqn.fromString(path), key, value);
080: } catch (CacheException e) {
081: throw new FxCacheException(e);
082: }
083: }
084:
085: /**
086: * {@inheritDoc}
087: */
088: public void remove(String path) throws FxCacheException {
089: try {
090: final Node<Object, Object> node = getNode(path);
091: if (node != null) {
092: node.clearData();
093: }
094: } catch (CacheException e) {
095: throw new FxCacheException(e);
096: }
097: }
098:
099: /**
100: * {@inheritDoc}
101: */
102: public void remove(String path, Object key) throws FxCacheException {
103: try {
104: getCache().remove(Fqn.fromString(path), key);
105: } catch (CacheException e) {
106: throw new FxCacheException(e);
107: }
108: }
109:
110: /**
111: * {@inheritDoc}
112: */
113: public Set getKeys(String path) throws FxCacheException {
114: try {
115: final Node<Object, Object> node = getNode(path);
116: return node != null ? node.getKeys() : new HashSet();
117: } catch (CacheException e) {
118: throw new FxCacheException(e);
119: }
120: }
121:
122: /**
123: * {@inheritDoc}
124: */
125: public Set getChildrenNames(String path) throws FxCacheException {
126: try {
127: final Node<Object, Object> node = getNode(path);
128: return node != null ? node.getChildrenNames()
129: : new HashSet();
130: } catch (CacheException e) {
131: throw new FxCacheException(e);
132: }
133: }
134:
135: protected Node<Object, Object> getNode(String path)
136: throws FxCacheException {
137: return getCache().getRoot().getChild(Fqn.fromString(path));
138: }
139: }
|