KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > util > jcache > CacheAccessFactory


1 /* Open Source Java Caching Service
2 * Copyright (C) 2002 Frank Karlstrøm
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * The author can be contacted by email: fjankk@users.sourceforge.net
18 */

19 package javax.util.jcache;
20
21 import org.fjank.jcache.AttributesImpl;
22
23
24 /**
25  * A factory for CacheAccess objects and to the Cache Administrative interface.
26  *
27  * @author Frank Karlstrøm
28  */

29 public abstract class CacheAccessFactory {
30     private static CacheAccessFactory _singleton;
31
32     /**
33      * Creates a new CacheAccessFactory object.
34      */

35     protected CacheAccessFactory() {
36     }
37     /**
38      * returns the default Attributes
39      *
40      * @return the default Attributes
41      * @deprecated removed with no replacement.
42      */

43     public Attributes getDefaultAttributes() {
44         return new AttributesImpl();
45     }
46     /**
47      * Obtain a new instance of a CacheAccessFactory. This static method
48      * creates a new factory instance. This method uses the following ordered
49      * lookup procedure to determine the CacheAccessFactory implementation
50      * class to load:
51      *
52      * <ul>
53      * <li>
54      * Use the javax.util.jcache.CacheAccessFactory system property.
55      * </li>
56      * <li>
57      * FKache default CacheAccessFactory instance.
58      * </li>
59      * </ul>
60      *
61      *
62      * @return an instance of a CacheAccessFactory.
63      *
64      * @throws IllegalStateException if the implementation is not
65      * available or cannot be instantiated.
66      */

67     public static synchronized CacheAccessFactory getInstance() {
68         if(_singleton!=null) {
69             return _singleton;
70         }
71         String JavaDoc clazz = System.getProperty("javax.util.jcache.CacheAccessFactory");
72         if (clazz == null) {
73             clazz = "org.fjank.jcache.CacheAccessFactoryImpl";
74         }
75         try {
76             _singleton = (CacheAccessFactory) Class.forName(clazz).newInstance();
77             return _singleton;
78         } catch (InstantiationException JavaDoc e) {
79             throw new IllegalStateException JavaDoc("CacheAccessFactory '" + clazz
80                 + "' could not be instantiated.");
81         } catch (IllegalAccessException JavaDoc e) {
82             throw new IllegalStateException JavaDoc("CacheAccessFactory '" + clazz
83                 + "' did not have a public empty args constructor.");
84         } catch (ClassNotFoundException JavaDoc e) {
85             throw new IllegalStateException JavaDoc("CacheAccessFactory '" + clazz
86                 + "' could not be located.");
87         }
88     }
89
90     /**
91      * Will create a named region within the cache. This defines a namespace
92      * for storing objects. Gets it default attributes from the properties
93      * file.
94      *
95      * @param name the name for the region. Must be globally unique.
96      *
97      * @throws ObjectExistsException if the name already exists in the cache.
98      * @throws NullObjectNameException if the region is attempted initialized
99      * with <CODE>null</CODE> as name.
100      * @throws CacheNotAvailableException if the cache is not available, either
101      * it is not initialized, or it is unavailable.
102      * @deprecated removed auto-generate-region replacement.
103      */

104     public abstract void defineRegion(final String JavaDoc name)
105         throws ObjectExistsException, NullObjectNameException,
106             CacheNotAvailableException;
107
108     /**
109      * Will create a named region within the cache. This defines a namespace
110      * for storing objects.
111      *
112      * @param name the name for the region. Must be globally unique.
113      * @param attributes sets the default attributes for objects in the new
114      * region. If the Attributes is <code>null</code>, default
115      * attributes will be used.
116      *
117      * @throws ObjectExistsException if the name already exists in the cache.
118      * @throws NullObjectNameException if the region is attempted initialized
119      * with <CODE>null</CODE> as name.
120      * @throws CacheNotAvailableException if the cache is not available, either
121      * it is not initialized, or it is unavailable.
122      * @deprecated removed auto-generate-region replacement.
123      */

124     public abstract void defineRegion(final String JavaDoc name,
125         final Attributes attributes)
126         throws ObjectExistsException, NullObjectNameException,
127             CacheNotAvailableException;
128
129     /**
130      * Gets the Cache which contains several usefull administraion methods.
131      *
132      * @return A Cache object wich is initialized.
133      *
134      * @throws CacheException if exceptions occur.
135      * @deprecated will be removed with no replacement.
136      */

137     public abstract Cache getCache() throws CacheException;
138
139     /**
140      * Will get the Cache instance.
141      *
142      * @param b a boolean indicating wether to initialize the Cache or not. if
143      * already initialized, this is ignored.
144      *
145      * @return the Cache instance.
146      *
147      * @throws CacheException if fatal exceptions occur.
148      * @deprecated will be removed with no replacement.
149      */

150     public abstract Cache getCache(final boolean b) throws CacheException;
151
152     public abstract CacheMap getMapAccess() throws CacheException;
153
154     public abstract CacheMap getMapAccess(final String JavaDoc region) throws CacheException;
155 }
156
Popular Tags