01: // ========================================================================
02: // Copyright 1996-2005 Mort Bay Consulting Pty. Ltd.
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: // http://www.apache.org/licenses/LICENSE-2.0
08: // Unless required by applicable law or agreed to in writing, software
09: // distributed under the License is distributed on an "AS IS" BASIS,
10: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11: // See the License for the specific language governing permissions and
12: // limitations under the License.
13: // ========================================================================
14: package org.mortbay.resource;
15:
16: import java.io.File;
17: import java.io.FileNotFoundException;
18: import java.io.IOException;
19: import java.io.InputStream;
20: import java.io.OutputStream;
21: import java.net.URL;
22:
23: /* ------------------------------------------------------------ */
24: /** Bad Resource.
25: *
26: * A Resource that is returned for a bade URL. Acts as a resource
27: * that does not exist and throws appropriate exceptions.
28: *
29: * @author Greg Wilkins (gregw)
30: */
31: class BadResource extends URLResource {
32: /* ------------------------------------------------------------ */
33: private String _message = null;
34:
35: /* -------------------------------------------------------- */
36: BadResource(URL url, String message) {
37: super (url, null);
38: _message = message;
39: }
40:
41: /* -------------------------------------------------------- */
42: public boolean exists() {
43: return false;
44: }
45:
46: /* -------------------------------------------------------- */
47: public long lastModified() {
48: return -1;
49: }
50:
51: /* -------------------------------------------------------- */
52: public boolean isDirectory() {
53: return false;
54: }
55:
56: /* --------------------------------------------------------- */
57: public long length() {
58: return -1;
59: }
60:
61: /* ------------------------------------------------------------ */
62: public File getFile() {
63: return null;
64: }
65:
66: /* --------------------------------------------------------- */
67: public InputStream getInputStream() throws IOException {
68: throw new FileNotFoundException(_message);
69: }
70:
71: /* --------------------------------------------------------- */
72: public OutputStream getOutputStream() throws java.io.IOException,
73: SecurityException {
74: throw new FileNotFoundException(_message);
75: }
76:
77: /* --------------------------------------------------------- */
78: public boolean delete() throws SecurityException {
79: throw new SecurityException(_message);
80: }
81:
82: /* --------------------------------------------------------- */
83: public boolean renameTo(Resource dest) throws SecurityException {
84: throw new SecurityException(_message);
85: }
86:
87: /* --------------------------------------------------------- */
88: public String[] list() {
89: return null;
90: }
91:
92: /* ------------------------------------------------------------ */
93: public String toString() {
94: return super .toString() + "; BadResource=" + _message;
95: }
96:
97: }
|