1 package fr.ove.utils;
2
3 import fr.ove.utils.ResourcesManager;
4
5 /***
6 * The resources manager caching the last resource required.
7 *
8 * @author © 1999 DIRAT Laurent
9 * @version 2.0 17/12/1999
10 */
11 public class CachingResourcesManager extends ResourcesManager {
12 /***
13 * The last resource name accessed by the instance.
14 */
15 private String cachedResource = "";
16
17 /***
18 * The list of properties associated to the last resource accessed by the instance.
19 */
20 private String[] cachedProperties = null;
21
22 /***
23 * The Constructor.
24 * @param resourcesName the name of the resources file.
25 */
26 public CachingResourcesManager(String resourcesName) {
27 super(resourcesName);
28 }
29
30 /***
31 * Returns the index-th resource of the specified property.
32 * @param propertyName the name of the property
33 * @param index the index of the resource
34 */
35 public String accessResource(String resource, int index) {
36 String property = null;
37
38 if (!cachedResource.equals(resource)) {
39 String[] properties = getResourceStrings(resource);
40 if ((index >= 0) && (index < properties.length)) {
41 property = properties[index];
42 cachedResource = resource;
43 cachedProperties = properties;
44 }
45 }
46 else if ((index >= 0) && (index < cachedProperties.length))
47 property = cachedProperties[index];
48
49 return property;
50
51 }
52 }