KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > Resource


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

15 package org.apache.hivemind;
16
17 import java.net.URL JavaDoc;
18 import java.util.Locale JavaDoc;
19
20 /**
21  * Describes the location of a resource, such as a module deployment
22  * descriptor, or a messages file.
23  *
24  * <p>
25  * Resources may be either base or localized. A localized
26  * version of a base resource may be obtained
27  * via {@link #getLocalization(Locale)}.
28  *
29  * <p>
30  * Resource locations are used as Map keys, they must
31  * implement {@link java.lang.Object#hashCode()} and
32  * {@link java.lang.Object#equals(java.lang.Object)}
33  * properly.
34  *
35  * <p>
36  * Resource locations are valid even if the corresponding
37  * resource <i>doesn't exist</i>. To verify if a localization
38  * actually exists, use {@link #getResourceURL()}, which returns
39  * null if the resource doesn't exist. {@link #getLocalization(Locale)}
40  * returns only real resource locations, where the resource exists.
41  *
42  * <p>
43  * Folders must be represented with a trailing slash.
44  *
45  * @author Howard Lewis Ship
46  *
47  **/

48
49 public interface Resource
50 {
51     /**
52      * Returns a URL for the resource.
53      *
54      * @return the URL for the resource if it exists, or null if it does not
55      *
56      */

57     
58     public URL JavaDoc getResourceURL();
59     
60     /**
61      * Returns the file name portion of the resource location.
62      *
63      */

64     
65     public String JavaDoc getName();
66     
67     /**
68      * Returns a localized version of this resource (or this resource, if no
69      * appropriate localization is found). Should only be invoked
70      * on a base resource.
71      *
72      * @param locale to localize for, or null for no localization.
73      * @return a localized version of this resource, of null if the resource
74      * itself does not exist.
75      *
76      */

77     
78     public Resource getLocalization(Locale JavaDoc locale);
79     
80     /**
81      * Returns at a relative location to this resource.
82      * The new resource may or may not exist; this can be determined
83      * via {@link #getResourceURL()}.
84      *
85      * @param name name of new resource, possibly as a relative path, or
86      * as an absolute path (starting with a slash).
87      *
88      */

89     
90     public Resource getRelativeResource(String JavaDoc name);
91     
92     /**
93      * Returns the path that represents the resource. This should
94      * only be used when the type of resource is known.
95      *
96      */

97     
98     public String JavaDoc getPath();
99
100     /**
101      * Returns the locale for which this resource has been localized
102      * or null if the resource has not been localized. This should
103      * only be used when the type of resource is known.
104      *
105      * This locale is the same or more general than the locale for which localization
106      * was requested. For example, if the requested locale was en_US, but only the file
107      * Home_en was found, this locale returned would be en.
108      */

109     
110     public Locale JavaDoc getLocale();
111 }
112
Popular Tags