KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > source > impl > AbstractSource


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

17 package org.apache.excalibur.source.impl;
18
19 import java.io.IOException JavaDoc;
20 import java.io.InputStream JavaDoc;
21
22 import org.apache.excalibur.source.Source;
23 import org.apache.excalibur.source.SourceException;
24 import org.apache.excalibur.source.SourceValidity;
25
26 /**
27  * Abstract base class for a source implementation.
28  *
29  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
30  * @version CVS $Revision: 1.5 $ $Date: 2004/02/28 11:47:24 $
31  */

32
33 public abstract class AbstractSource
34     implements Source
35 {
36     private boolean m_gotInfos;
37     private long m_lastModificationDate;
38     private long m_contentLength;
39     private String JavaDoc m_systemId;
40
41     private String JavaDoc m_scheme;
42
43     /**
44      * Get the last modification date and content length of the source.
45      * Any exceptions are ignored.
46      * Override this to get the real information
47      */

48     protected void getInfos()
49     {
50         this.m_contentLength = -1;
51         this.m_lastModificationDate = 0;
52     }
53
54     protected void checkInfos()
55     {
56         if( !m_gotInfos )
57         {
58             getInfos();
59             m_gotInfos = true;
60         }
61     }
62
63     /**
64      * Return an <code>InputStream</code> object to read from the source.
65      *
66      * @throws SourceException if file not found or
67      * HTTP location does not exist.
68      * @throws IOException if I/O error occured.
69      */

70     public InputStream JavaDoc getInputStream()
71         throws IOException JavaDoc, SourceException
72     {
73         return null;
74     }
75
76     /**
77      * Return the unique identifer for this source
78      */

79     public String JavaDoc getURI()
80     {
81         return m_systemId;
82     }
83
84     /**
85      * Return the protocol identifier.
86      */

87     public String JavaDoc getScheme()
88     {
89         return this.m_scheme;
90     }
91
92     /**
93      * Get the Validity object. This can either wrap the last modification
94      * date or the expires information or...
95      * If it is currently not possible to calculate such an information
96      * <code>null</code> is returned.
97      */

98     public SourceValidity getValidity()
99     {
100         return null;
101     }
102
103     /**
104      * Refresh this object and update the last modified date
105      * and content length.
106      */

107     public void refresh()
108     {
109         m_gotInfos = false;
110     }
111
112     /**
113      * The mime-type of the content described by this object.
114      * If the source is not able to determine the mime-type by itself
115      * this can be null.
116      */

117     public String JavaDoc getMimeType()
118     {
119         return null;
120     }
121
122     /**
123      * Return the content length of the content or -1 if the length is
124      * unknown
125      */

126     public long getContentLength()
127     {
128         checkInfos();
129         return this.m_contentLength;
130     }
131
132     /**
133      * Get the last modification date of the source or 0 if it
134      * is not possible to determine the date.
135      */

136     public long getLastModified()
137     {
138         checkInfos();
139         return this.m_lastModificationDate;
140     }
141     /**
142      * Sets the contentLength.
143      * @param contentLength The contentLength to set
144      */

145     protected void setContentLength(long contentLength)
146     {
147         m_contentLength = contentLength;
148     }
149
150     /**
151      * Sets the lastModificationDate.
152      * @param lastModificationDate The lastModificationDate to set
153      */

154     protected void setLastModified(long lastModificationDate)
155     {
156         m_lastModificationDate = lastModificationDate;
157     }
158
159     /**
160      * Sets the scheme.
161      * @param scheme The scheme to set
162      */

163     protected void setScheme(String JavaDoc scheme)
164     {
165         m_scheme = scheme;
166     }
167
168     /**
169      * Sets the systemId.
170      * @param systemId The systemId to set
171      */

172     protected void setSystemId(String JavaDoc systemId)
173     {
174         m_systemId = systemId;
175     }
176
177 }
178
Popular Tags