01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
20: import java.io.IOException;
21: import java.io.InputStream;
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 description;
36:
37: /**
38: * Create a new DescriptiveResource.
39: * @param description the resource description
40: */
41: public DescriptiveResource(String description) {
42: this .description = (description != null ? description : "");
43: }
44:
45: public InputStream getInputStream() throws IOException {
46: throw new FileNotFoundException(
47: getDescription()
48: + " cannot be opened because it does not point to a readable resource");
49: }
50:
51: public String getDescription() {
52: return this .description;
53: }
54:
55: /**
56: * This implementation compares the underlying description String.
57: */
58: public boolean equals(Object obj) {
59: return (obj == this || (obj instanceof DescriptiveResource && ((DescriptiveResource) obj).description
60: .equals(this .description)));
61: }
62:
63: /**
64: * This implementation returns the hash code of the underlying description String.
65: */
66: public int hashCode() {
67: return this.description.hashCode();
68: }
69:
70: }
|