1 /* (c) Copyright 2003 Caleigo AB, All rights reserved.
2 *
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 */
18
19 package org.caleigo.toolkit.util;
20
21 import java.util.*;
22
23 /*** <Description for ResourceProvider>
24 *
25 * @author Dennis Zikovic
26 * @version 1.00
27 *
28 *//*
29 *
30 * WHEN WHO WHY & WHAT
31 * -----------------------------------------------------------------------------
32 * 2001-12-11 Dennis Zikovic Creation
33 */
34 public abstract class ResourceProvider
35 {
36 // Constants ---------------------------------------------------------------
37
38 // Static Data members -----------------------------------------------------
39 private static final List sProviderList = new ArrayList(10);
40
41 // Static methods ----------------------------------------------------------
42 public static Object getObject(String group, String name, Object def)
43 {
44 Object resource = null;
45
46 // Scan all providers for resource.
47 for(int j=0; j<sProviderList.size() && resource==null; j++)
48 if(((ResourceProvider)sProviderList.get(j)).isProvidingGroup(group))
49 resource = ((ResourceProvider)sProviderList.get(j)).getResource(group, name);
50
51 // Return found resource or the default value.
52 if(resource!=null)
53 return resource;
54 else
55 return def;
56 }
57
58 public static String getString(String group, String name, String def)
59 {
60 return (String)getObject(group, name, def);
61 }
62
63 public static void setObject(String group, String name, Object obj)
64 {
65 ResourceProvider provider = null;
66
67 // Scan all providers for group acceptance.
68 for(int j=0; j<sProviderList.size() && provider==null; j++)
69 if(((ResourceProvider)sProviderList.get(j)).isProvidingGroup(group))
70 provider = (ResourceProvider)sProviderList.get(j);
71
72 // Store resource if any provider accepts it.
73 if(provider!=null)
74 provider.setResource(group, name, obj);
75 }
76
77 public static void setString(String group, String name, String str)
78 {
79 setObject(group, name, str);
80 }
81
82 public static void addResourceProvider(ResourceProvider provider)
83 {
84 sProviderList.add(provider);
85 }
86
87 public static void removeResourceProvider(ResourceProvider provider)
88 {
89 sProviderList.remove(provider);
90 }
91
92 // Abstract methods --------------------------------------------------------
93
94 protected abstract Object getResource(String group, String name);
95 protected abstract boolean setResource(String group, String name, Object value);
96
97 protected abstract boolean isProvidingGroup(String group);
98 protected abstract boolean isReadOnly();
99
100 // Action methods ----------------------------------------------------------
101
102 // Access methods ----------------------------------------------------------
103
104 // Help methods ------------------------------------------------------------
105
106 // Nested classes ----------------------------------------------------------
107 }