/* Open Source Java Caching Service
* Copyright (C) 2002 Frank Karlstr�m
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* The author can be contacted by email: fjankk@users.sourceforge.net
*/
package javax.util.jcache;
import org.fjank.jcache.AttributesImpl;
/**
* A factory for CacheAccess objects and to the Cache Administrative interface.
*
* @author Frank Karlstr�m
*/
public abstract class CacheAccessFactory {
private static CacheAccessFactory _singleton;
/**
* Creates a new CacheAccessFactory object.
*/
protected CacheAccessFactory() {
}
/**
* returns the default Attributes
*
* @return the default Attributes
* @deprecated removed with no replacement.
*/
public Attributes getDefaultAttributes() {
return new AttributesImpl();
}
/**
* Obtain a new instance of a CacheAccessFactory. This static method
* creates a new factory instance. This method uses the following ordered
* lookup procedure to determine the CacheAccessFactory implementation
* class to load:
*
* <ul>
* <li>
* Use the javax.util.jcache.CacheAccessFactory system property.
* </li>
* <li>
* FKache default CacheAccessFactory instance.
* </li>
* </ul>
*
*
* @return an instance of a CacheAccessFactory.
*
* @throws IllegalStateException if the implementation is not
* available or cannot be instantiated.
*/
public static synchronized CacheAccessFactory getInstance() {
if(_singleton!=null) {
return _singleton;
}
String clazz = System.getProperty("javax.util.jcache.CacheAccessFactory");
if (clazz == null) {
clazz = "org.fjank.jcache.CacheAccessFactoryImpl";
}
try {
_singleton = (CacheAccessFactory) Class.forName(clazz).newInstance();
return _singleton;
} catch (InstantiationException e) {
throw new IllegalStateException("CacheAccessFactory '" + clazz
+ "' could not be instantiated.");
} catch (IllegalAccessException e) {
throw new IllegalStateException("CacheAccessFactory '" + clazz
+ "' did not have a public empty args constructor.");
} catch (ClassNotFoundException e) {
throw new IllegalStateException("CacheAccessFactory '" + clazz
+ "' could not be located.");
}
}
/**
* Will create a named region within the cache. This defines a namespace
* for storing objects. Gets it default attributes from the properties
* file.
*
* @param name the name for the region. Must be globally unique.
*
* @throws ObjectExistsException if the name already exists in the cache.
* @throws NullObjectNameException if the region is attempted initialized
* with <CODE>null</CODE> as name.
* @throws CacheNotAvailableException if the cache is not available, either
* it is not initialized, or it is unavailable.
* @deprecated removed auto-generate-region replacement.
*/
public abstract void defineRegion(final String name)
throws ObjectExistsException, NullObjectNameException,
CacheNotAvailableException;
/**
* Will create a named region within the cache. This defines a namespace
* for storing objects.
*
* @param name the name for the region. Must be globally unique.
* @param attributes sets the default attributes for objects in the new
* region. If the Attributes is <code>null</code>, default
* attributes will be used.
*
* @throws ObjectExistsException if the name already exists in the cache.
* @throws NullObjectNameException if the region is attempted initialized
* with <CODE>null</CODE> as name.
* @throws CacheNotAvailableException if the cache is not available, either
* it is not initialized, or it is unavailable.
* @deprecated removed auto-generate-region replacement.
*/
public abstract void defineRegion(final String name,
final Attributes attributes)
throws ObjectExistsException, NullObjectNameException,
CacheNotAvailableException;
/**
* Gets the Cache which contains several usefull administraion methods.
*
* @return A Cache object wich is initialized.
*
* @throws CacheException if exceptions occur.
* @deprecated will be removed with no replacement.
*/
public abstract Cache getCache() throws CacheException;
/**
* Will get the Cache instance.
*
* @param b a boolean indicating wether to initialize the Cache or not. if
* already initialized, this is ignored.
*
* @return the Cache instance.
*
* @throws CacheException if fatal exceptions occur.
* @deprecated will be removed with no replacement.
*/
public abstract Cache getCache(final boolean b) throws CacheException;
public abstract CacheMap getMapAccess() throws CacheException;
public abstract CacheMap getMapAccess(final String region) throws CacheException;
}