KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > lf5 > util > Resource


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

16 package org.apache.log4j.lf5.util;
17
18 import java.io.InputStream JavaDoc;
19 import java.io.InputStreamReader JavaDoc;
20 import java.net.URL JavaDoc;
21
22 /**
23  * Resource encapsulates access to Resources via the Classloader.
24  *
25  * @author Michael J. Sikorsky
26  * @author Robert Shaw
27  */

28
29 // Contributed by ThoughtWorks Inc.
30

31 public class Resource {
32   //--------------------------------------------------------------------------
33
// Constants:
34
//--------------------------------------------------------------------------
35

36   //--------------------------------------------------------------------------
37
// Protected Variables:
38
//--------------------------------------------------------------------------
39
protected String JavaDoc _name;
40
41   //--------------------------------------------------------------------------
42
// Private Variables:
43
//--------------------------------------------------------------------------
44

45   //--------------------------------------------------------------------------
46
// Constructors:
47
//--------------------------------------------------------------------------
48

49   /**
50    * Default, no argument constructor.
51    */

52   public Resource() {
53     super();
54   }
55
56   /**
57    * Construct a Resource given a name.
58    *
59    * @see #setName(String)
60    */

61   public Resource(String JavaDoc name) {
62     _name = name;
63   }
64
65   //--------------------------------------------------------------------------
66
// Public Methods:
67
//--------------------------------------------------------------------------
68

69   /**
70    * Set the name of the resource.
71    * <p>
72    * A resource is some data (images, audio, text, etc) that can be accessed
73    * by class code in a way that is independent of the location of the code.
74    * </p>
75    * <p>
76    * The name of a resource is a "/"-separated path name that identifies
77    * the resource.
78    * </p>
79    *
80    * @see #getName()
81    */

82   public void setName(String JavaDoc name) {
83     _name = name;
84   }
85
86   /**
87    * Get the name of the resource. Set setName() for a description of
88    * a resource.
89    *
90    * @see #setName
91    */

92   public String JavaDoc getName() {
93     return (_name);
94   }
95
96   /**
97    * Get the InputStream for this Resource. Uses the classloader
98    * from this Resource.
99    *
100    * @see #getInputStreamReader
101    * @see ResourceUtils
102    */

103   public InputStream JavaDoc getInputStream() {
104     InputStream JavaDoc in = ResourceUtils.getResourceAsStream(this, this);
105
106     return (in);
107   }
108
109   /**
110    * Get the InputStreamReader for this Resource. Uses the classloader from
111    * this Resource.
112    *
113    * @see #getInputStream
114    * @see ResourceUtils
115    */

116   public InputStreamReader JavaDoc getInputStreamReader() {
117     InputStream JavaDoc in = ResourceUtils.getResourceAsStream(this, this);
118
119     if (in == null) {
120       return null;
121     }
122
123     InputStreamReader JavaDoc reader = new InputStreamReader JavaDoc(in);
124
125     return reader;
126   }
127
128   /**
129    * Get the URL of the Resource. Uses the classloader from this Resource.
130    *
131    * @see ResourceUtils
132    */

133   public URL JavaDoc getURL() {
134     return (ResourceUtils.getResourceAsURL(this, this));
135   }
136
137   //--------------------------------------------------------------------------
138
// Protected Methods:
139
//--------------------------------------------------------------------------
140

141   //--------------------------------------------------------------------------
142
// Private Methods:
143
//--------------------------------------------------------------------------
144

145   //--------------------------------------------------------------------------
146
// Nested Top-Level Classes or Interfaces:
147
//--------------------------------------------------------------------------
148

149 }
150
151
152
153
154
155
156
Popular Tags