KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > core > io > DescriptiveResource


1 /*
2  * Copyright 2002-2006 the original author or authors.
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
17 package org.springframework.core.io;
18
19 import java.io.FileNotFoundException JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22
23 /**
24  * Simple {@link Resource} implementation that holds a resource description
25  * but does not point to an actually readable resource.
26  *
27  * <p>To be used as placeholder if a Resource argument is demanded
28  * but not necessarily used for reading.
29  *
30  * @author Juergen Hoeller
31  * @since 1.2.6
32  */

33 public class DescriptiveResource extends AbstractResource {
34
35     private final String JavaDoc description;
36
37
38     /**
39      * Create a new DescriptiveResource.
40      * @param description the resource description
41      */

42     public DescriptiveResource(String JavaDoc description) {
43         this.description = (description != null ? description : "");
44     }
45
46
47     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
48         throw new FileNotFoundException JavaDoc(
49                 getDescription() + " cannot be opened because it does not point to a readable resource");
50     }
51
52     public String JavaDoc getDescription() {
53         return this.description;
54     }
55
56
57     /**
58      * This implementation compares the underlying description String.
59      */

60     public boolean equals(Object JavaDoc obj) {
61         return (obj == this ||
62             (obj instanceof DescriptiveResource && ((DescriptiveResource) obj).description.equals(this.description)));
63     }
64
65     /**
66      * This implementation returns the hash code of the underlying description String.
67      */

68     public int hashCode() {
69         return this.description.hashCode();
70     }
71
72 }
73
Popular Tags