1 /*
2
3 Licensed to the Apache Software Foundation (ASF) under one or more
4 contributor license agreements. See the NOTICE file distributed with
5 this work for additional information regarding copyright ownership.
6 The ASF licenses this file to You under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with
8 the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17
18 */
19
20 package org.apache.batik.ext.awt.color;
21
22 import org.apache.batik.util.SoftReferenceCache;
23
24 import org.apache.xmlgraphics.java2d.color.ICCColorSpaceWithIntent;
25
26 /**
27 * This class manages a cache of soft references to named profiles that
28 * we have already loaded.
29 *
30 * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
31 * @version $Id: NamedProfileCache.java 1808001 2017-09-11 09:51:29Z ssteiner $
32 */
33 public class NamedProfileCache extends SoftReferenceCache {
34
35 static NamedProfileCache theCache = new NamedProfileCache();
36
37 public static NamedProfileCache getDefaultCache() { return theCache; }
38
39 /**
40 * Let people create there own caches.
41 */
42 public NamedProfileCache() {
43 super(true);
44 }
45
46 /**
47 * Check if <code>request(profileName)</code> will return with a ICCColorSpaceExt
48 * (not putting you on the hook for it). Note that it is possible
49 * that this will return true but between this call and the call
50 * to request the soft-reference will be cleared. So it
51 * is still possible for request to return NULL, just much less
52 * likely (you can always call 'clear' in that case).
53 */
54 public synchronized boolean isPresent(String profileName) {
55 return super.isPresentImpl(profileName);
56 }
57
58 /**
59 * Check if <code>request(profileName)</code> will return immediately with the
60 * ICCColorSpaceExt. Note that it is possible that this will return
61 * true but between this call and the call to request the
62 * soft-reference will be cleared.
63 */
64 public synchronized boolean isDone(String profileName) {
65 return super.isDoneImpl(profileName);
66 }
67
68 /**
69 * If this returns null then you are now 'on the hook'.
70 * to put the ICCColorSpaceExt associated with String into the
71 * cache.
72 * @param profileName the profile name
73 */
74 public synchronized ICCColorSpaceWithIntent request(String profileName) {
75 return (ICCColorSpaceWithIntent)super.requestImpl(profileName);
76 }
77
78 /**
79 * Clear the entry for String.
80 * This is the easiest way to 'get off the hook'.
81 * if you didn't indend to get on it.
82 */
83 public synchronized void clear(String profileName) {
84 super.clearImpl(profileName);
85 }
86
87 /**
88 * Associate bi with profileName. bi is only referenced through
89 * a soft reference so don't rely on the cache to keep it
90 * around. If the map no longer contains our profileName it was
91 * probably cleared or flushed since we were put on the hook
92 * for it, so in that case we will do nothing.
93 */
94 public synchronized void put(String profileName, ICCColorSpaceWithIntent bi) {
95 super.putImpl(profileName, bi);
96 }
97 }
98