KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > color > NamedProfileCache


1 /*
2
3    Copyright 1999-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17 */

18
19 package org.apache.batik.ext.awt.color;
20
21 import org.apache.batik.util.SoftReferenceCache;
22
23 /**
24  * This class manages a cache of soft references to named profiles that
25  * we have already loaded.
26  *
27  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
28  * @version $Id: NamedProfileCache.java,v 1.4 2004/10/30 18:38:04 deweese Exp $
29  */

30
31 public class NamedProfileCache extends SoftReferenceCache{
32
33     static NamedProfileCache theCache = new NamedProfileCache();
34
35     public static NamedProfileCache getDefaultCache() { return theCache; }
36
37     /**
38      * Let people create there own caches.
39      */

40     public NamedProfileCache() { }
41
42     /**
43      * Check if <tt>request(profileName)</tt> will return with a ICCColorSpaceExt
44      * (not putting you on the hook for it). Note that it is possible
45      * that this will return true but between this call and the call
46      * to request the soft-reference will be cleared. So it
47      * is still possible for request to return NULL, just much less
48      * likely (you can always call 'clear' in that case).
49      */

50     public synchronized boolean isPresent(String JavaDoc profileName) {
51         return super.isPresentImpl(profileName);
52     }
53
54     /**
55      * Check if <tt>request(profileName)</tt> will return immediately with the
56      * ICCColorSpaceExt. Note that it is possible that this will return
57      * true but between this call and the call to request the
58      * soft-reference will be cleared.
59      */

60     public synchronized boolean isDone(String JavaDoc profileName) {
61         return super.isDoneImpl(profileName);
62     }
63
64     /**
65      * If this returns null then you are now 'on the hook'.
66      * to put the ICCColorSpaceExt associated with String into the
67      * cache. */

68     public synchronized ICCColorSpaceExt request(String JavaDoc profileName) {
69         return (ICCColorSpaceExt)super.requestImpl(profileName);
70     }
71
72     /**
73      * Clear the entry for String.
74      * This is the easiest way to 'get off the hook'.
75      * if you didn't indend to get on it.
76      */

77     public synchronized void clear(String JavaDoc profileName) {
78         super.clearImpl(profileName);
79     }
80
81     /**
82      * Associate bi with profileName. bi is only referenced through
83      * a soft reference so don't rely on the cache to keep it
84      * around. If the map no longer contains our profileName it was
85      * probably cleared or flushed since we were put on the hook
86      * for it, so in that case we will do nothing.
87      */

88     public synchronized void put(String JavaDoc profileName, ICCColorSpaceExt bi) {
89         super.putImpl(profileName, bi);
90     }
91 }
92
Popular Tags