View Javadoc

1   // ========================================================================
2   // Copyright 1996-2005 Mort Bay Consulting Pty. Ltd.
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   // http://www.apache.org/licenses/LICENSE-2.0
8   // Unless required by applicable law or agreed to in writing, software
9   // 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  /* ------------------------------------------------------------ */
25  /** Bad Resource.
26   *
27   * A Resource that is returned for a bade URL.  Acts as a resource
28   * that does not exist and throws appropriate exceptions.
29   *
30   * @author Greg Wilkins (gregw)
31   */
32  class BadResource extends URLResource
33  {
34      /* ------------------------------------------------------------ */
35      private String _message=null;
36          
37      /* -------------------------------------------------------- */
38      BadResource(URL url,  String message)
39      {
40          super(url,null);
41          _message=message;
42      }
43      
44  
45      /* -------------------------------------------------------- */
46      public boolean exists()
47      {
48          return false;
49      }
50          
51      /* -------------------------------------------------------- */
52      public long lastModified()
53      {
54          return -1;
55      }
56  
57      /* -------------------------------------------------------- */
58      public boolean isDirectory()
59      {
60          return false;
61      }
62  
63      /* --------------------------------------------------------- */
64      public long length()
65      {
66          return -1;
67      }
68          
69          
70      /* ------------------------------------------------------------ */
71      public File getFile()
72      {
73          return null;
74      }
75          
76      /* --------------------------------------------------------- */
77      public InputStream getInputStream() throws IOException
78      {
79          throw new FileNotFoundException(_message);
80      }
81          
82      /* --------------------------------------------------------- */
83      public OutputStream getOutputStream()
84          throws java.io.IOException, SecurityException
85      {
86          throw new FileNotFoundException(_message);
87      }
88          
89      /* --------------------------------------------------------- */
90      public boolean delete()
91          throws SecurityException
92      {
93          throw new SecurityException(_message);
94      }
95  
96      /* --------------------------------------------------------- */
97      public boolean renameTo( Resource dest)
98          throws SecurityException
99      {
100         throw new SecurityException(_message);
101     }
102 
103     /* --------------------------------------------------------- */
104     public String[] list()
105     {
106         return null;
107     }
108 
109     /* ------------------------------------------------------------ */
110     public String toString()
111     {
112         return super.toString()+"; BadResource="+_message;
113     }
114     
115 }