001 /*
002 * Copyright 2010-2013 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package griffon.core.resources;
018
019 import java.util.List;
020 import java.util.Locale;
021 import java.util.Map;
022
023 /**
024 * Interface for resolving resources, with support for the parameterization and internationalization of such resources.
025 *
026 * @author Andres Almiray
027 * @author Alexander Klein
028 * @since 1.1.0
029 */
030 public interface ResourceResolver {
031 /**
032 * Try to resolve the resource.
033 *
034 * @param key Key to lookup, such as 'sample.SampleModel.icon'
035 * @return The resolved resource at the given key for the default locale
036 * @throws NoSuchResourceException if no resource is found
037 */
038 Object resolveResource(String key) throws NoSuchResourceException;
039
040 /**
041 * Try to resolve the resource.
042 *
043 * @param key Key to lookup, such as 'sample.SampleModel.icon'
044 * @param locale Locale in which to lookup
045 * @return The resolved resource at the given key for the given locale
046 * @throws NoSuchResourceException if no resource is found
047 */
048 Object resolveResource(String key, Locale locale) throws NoSuchResourceException;
049
050 /**
051 * Try to resolve the resource.
052 *
053 * @param key Key to lookup, such as 'sample.SampleModel.icon'
054 * @param args Arguments that will be filled in for params within the resource (params look like "{0}" within a
055 * resource, but this might differ between implementations), or null if none.
056 * @return The resolved resource at the given key for the default locale
057 * @throws NoSuchResourceException if no resource is found
058 */
059 Object resolveResource(String key, Object[] args) throws NoSuchResourceException;
060
061 /**
062 * Try to resolve the resource.
063 *
064 * @param key Key to lookup, such as 'sample.SampleModel.icon'
065 * @param args Arguments that will be filled in for params within the resource (params look like "{0}" within a
066 * resource, but this might differ between implementations), or null if none.
067 * @param locale Locale in which to lookup
068 * @return The resolved resource at the given key for the given locale
069 * @throws NoSuchResourceException if no resource is found
070 */
071 Object resolveResource(String key, Object[] args, Locale locale) throws NoSuchResourceException;
072
073 /**
074 * Try to resolve the resource.
075 *
076 * @param key Key to lookup, such as 'sample.SampleModel.icon'
077 * @param args Arguments that will be filled in for params within the resource (params look like "{0}" within a
078 * resource, but this might differ between implementations), or null if none.
079 * @return The resolved resource at the given key for the default locale
080 * @throws NoSuchResourceException if no resource is found
081 */
082 Object resolveResource(String key, List args) throws NoSuchResourceException;
083
084 /**
085 * Try to resolve the resource.
086 *
087 * @param key Key to lookup, such as 'sample.SampleModel.icon'
088 * @param args Arguments that will be filled in for params within the resource (params look like "{0}" within a
089 * resource, but this might differ between implementations), or null if none.
090 * @param locale Locale in which to lookup
091 * @return The resolved resource at the given key for the given locale
092 * @throws NoSuchResourceException if no resource is found
093 */
094 Object resolveResource(String key, List args, Locale locale) throws NoSuchResourceException;
095
096 /**
097 * Try to resolve the resource. Return default resource if no resource was found.
098 *
099 * @param key Key to lookup, such as 'sample.SampleModel.icon'
100 * @param defaultValue Message to return if the lookup fails
101 * @return The resolved resource at the given key for the default locale
102 */
103 Object resolveResource(String key, Object defaultValue);
104
105 /**
106 * Try to resolve the resource. Return default resource if no resource was found.
107 *
108 * @param key Key to lookup, such as 'sample.SampleModel.icon'
109 * @param defaultValue Message to return if the lookup fails
110 * @param locale Locale in which to lookup
111 * @return The resolved resource at the given key for the given locale
112 */
113 Object resolveResource(String key, Object defaultValue, Locale locale);
114
115 /**
116 * Try to resolve the resource. Return default resource if no resource was found.
117 *
118 * @param key Key to lookup, such as 'sample.SampleModel.icon'
119 * @param args Arguments that will be filled in for params within the resource (params look like "{0}"
120 * within a resource, but this might differ between implementations), or null if none.
121 * @param defaultValue Message to return if the lookup fails
122 * @return The resolved resource at the given key for the default locale
123 */
124 Object resolveResource(String key, Object[] args, Object defaultValue);
125
126 /**
127 * Try to resolve the resource. Return default resource if no resource was found.
128 *
129 * @param key Key to lookup, such as 'sample.SampleModel.icon'
130 * @param args Arguments that will be filled in for params within the resource (params look like "{0}"
131 * within a resource, but this might differ between implementations), or null if none.
132 * @param defaultValue Message to return if the lookup fails
133 * @param locale Locale in which to lookup
134 * @return The resolved resource at the given key for the given locale
135 */
136 Object resolveResource(String key, Object[] args, Object defaultValue, Locale locale);
137
138 /**
139 * Try to resolve the resource. Return default resource if no resource was found.
140 *
141 * @param key Key to lookup, such as 'sample.SampleModel.icon'
142 * @param args Arguments that will be filled in for params within the resource (params look like "{0}"
143 * within a resource, but this might differ between implementations), or null if none.
144 * @param defaultValue Message to return if the lookup fails
145 * @return The resolved resource at the given key for the default locale
146 */
147 Object resolveResource(String key, List args, Object defaultValue);
148
149 /**
150 * Try to resolve the resource. Return default resource if no resource was found.
151 *
152 * @param key Key to lookup, such as 'sample.SampleModel.icon'
153 * @param args Arguments that will be filled in for params within the resource (params look like "{0}"
154 * within a resource, but this might differ between implementations), or null if none.
155 * @param defaultValue Message to return if the lookup fails
156 * @param locale Locale in which to lookup
157 * @return The resolved resource at the given key for the given locale
158 */
159 Object resolveResource(String key, List args, Object defaultValue, Locale locale);
160
161 /**
162 * Try to resolve the resource.
163 *
164 * @param key Key to lookup, such as 'sample.SampleModel.icon'
165 * @param args Arguments that will be filled in for params within the resource (params look like "{:key}"
166 * within a resource, but this might differ between implementations), or null if none.
167 * @return The resolved resource at the given key for the default locale
168 * @throws NoSuchResourceException if no resource is found
169 */
170 Object resolveResource(String key, Map<String, Object> args) throws NoSuchResourceException;
171
172 /**
173 * Try to resolve the resource.
174 *
175 * @param key Key to lookup, such as 'sample.SampleModel.icon'
176 * @param args Arguments that will be filled in for params within the resource (params look like "{:key}"
177 * within a resource, but this might differ between implementations), or null if none.
178 * @param locale Locale in which to lookup
179 * @return The resolved resource at the given key for the given locale
180 * @throws NoSuchResourceException if no resource is found
181 */
182 Object resolveResource(String key, Map<String, Object> args, Locale locale) throws NoSuchResourceException;
183
184 /**
185 * Try to resolve the resource. Return default resource if no resource was found.
186 *
187 * @param key Key to lookup, such as 'sample.SampleModel.icon'
188 * @param args Arguments that will be filled in for params within the resource (params look like "{:key}"
189 * within a resource, but this might differ between implementations), or null if none.
190 * @param defaultValue Message to return if the lookup fails
191 * @return The resolved resource at the given key for the default locale
192 */
193 Object resolveResource(String key, Map<String, Object> args, Object defaultValue);
194
195 /**
196 * Try to resolve the resource. Return default resource if no resource was found.
197 *
198 * @param key Key to lookup, such as 'sample.SampleModel.icon'
199 * @param args Arguments that will be filled in for params within the resource (params look like "{:key}"
200 * within a resource, but this might differ between implementations), or null if none.
201 * @param defaultValue Message to return if the lookup fails
202 * @param locale Locale in which to lookup
203 * @return The resolved resource at the given key for the given locale
204 */
205 Object resolveResource(String key, Map<String, Object> args, Object defaultValue, Locale locale);
206 }
|