KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > history > FileEnvironment


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.versioning.system.cvss.ui.history;
20
21 import java.io.*;
22 import java.net.*;
23 import java.util.*;
24
25 import org.openide.text.*;
26 import org.openide.ErrorManager;
27 import org.netbeans.modules.versioning.system.cvss.VersionsCache;
28 import org.netbeans.modules.versioning.system.cvss.IllegalCommandException;
29 import org.netbeans.modules.versioning.system.cvss.NotVersionedException;
30 import org.netbeans.lib.cvsclient.command.CommandException;
31 import org.netbeans.lib.cvsclient.connection.AuthenticationException;
32
33
34 /**
35  * Defines numb read-only File environment.
36  *
37  * @author Petr Kuzel
38  */

39 public abstract class FileEnvironment implements CloneableEditorSupport.Env {
40
41     /** Serial Version UID */
42     private static final long serialVersionUID = 1L;
43     
44     private String JavaDoc mime = "text/plain"; // NOI18N
45

46     private final File peer;
47
48     private final String JavaDoc revision;
49
50     private transient Date modified;
51         
52     /** Creates new StreamEnvironment */
53     public FileEnvironment(File baseFile, String JavaDoc revision, String JavaDoc mime) {
54         if (baseFile == null) throw new NullPointerException JavaDoc();
55         peer = baseFile;
56         modified = new Date();
57         this.revision = revision;
58         if (mime != null) {
59             this.mime = mime;
60         }
61     }
62         
63     public void markModified() throws java.io.IOException JavaDoc {
64         throw new IOException("r/o"); // NOI18N
65
}
66     
67     public void unmarkModified() {
68     }
69
70     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc propertyChangeListener) {
71     }
72     
73     public boolean isModified() {
74         return false;
75     }
76     
77     public java.util.Date JavaDoc getTime() {
78         return modified;
79     }
80     
81     public void removeVetoableChangeListener(java.beans.VetoableChangeListener JavaDoc vetoableChangeListener) {
82     }
83     
84     public boolean isValid() {
85         return true;
86     }
87     
88     public java.io.OutputStream JavaDoc outputStream() throws java.io.IOException JavaDoc {
89         throw new IOException("r/o"); // NOI18N
90
}
91
92     public java.lang.String JavaDoc getMimeType() {
93         return mime;
94     }
95
96     /**
97      * Always return fresh stream.
98      */

99     public java.io.InputStream JavaDoc inputStream() throws java.io.IOException JavaDoc {
100         return new LazyInputStream();
101     }
102
103     private class LazyInputStream extends InputStream {
104
105         private InputStream in;
106
107         public LazyInputStream() {
108         }
109
110         private InputStream peer() throws IOException {
111             try {
112                 if (in == null) {
113                     File remoteFile = VersionsCache.getInstance().getRemoteFile(peer, revision, null);
114                     in = new FileInputStream(remoteFile);
115                 }
116                 return in;
117             } catch (MalformedURLException ex) {
118                 ErrorManager err = ErrorManager.getDefault();
119                 IOException ioex = new IOException();
120                 err.annotate(ioex, ex);
121                 err.annotate(ioex, ErrorManager.USER, null, null, null, null);
122                 throw ioex;
123             } catch (IOException ex) {
124                 ErrorManager err = ErrorManager.getDefault();
125                 IOException ioex = new IOException();
126                 err.annotate(ioex, ex);
127                 err.annotate(ioex, ErrorManager.USER, null, null, null, null);
128                 throw ioex;
129             } catch (CommandException ex) {
130                 ErrorManager err = ErrorManager.getDefault();
131                 IOException ioex = new IOException();
132                 err.annotate(ioex, ex);
133                 err.annotate(ioex, ErrorManager.USER, null, null, null, null);
134                 throw ioex;
135             } catch (IllegalCommandException ex) {
136                 ErrorManager err = ErrorManager.getDefault();
137                 IOException ioex = new IOException();
138                 err.annotate(ioex, ex);
139                 err.annotate(ioex, ErrorManager.USER, null, null, null, null);
140                 throw ioex;
141             } catch (AuthenticationException ex) {
142                 ErrorManager err = ErrorManager.getDefault();
143                 IOException ioex = new IOException();
144                 err.annotate(ioex, ex);
145                 err.annotate(ioex, ErrorManager.USER, null, null, null, null);
146                 throw ioex;
147             } catch (NotVersionedException ex) {
148                 ErrorManager err = ErrorManager.getDefault();
149                 IOException ioex = new IOException();
150                 err.annotate(ioex, ex);
151                 err.annotate(ioex, ErrorManager.USER, null, null, null, null);
152                 throw ioex;
153             }
154         }
155
156         public int available() throws IOException {
157             return peer().available();
158         }
159
160         public void close() throws IOException {
161             peer().close();
162         }
163
164         public void mark(int readlimit) {
165         }
166
167         public boolean markSupported() {
168             return false;
169         }
170
171         public int read() throws IOException {
172             return peer().read();
173         }
174
175         public int read(byte b[]) throws IOException {
176             return peer().read(b);
177         }
178
179         public int read(byte b[], int off, int len) throws IOException {
180             return peer().read(b, off, len);
181         }
182
183         public void reset() throws IOException {
184             peer().reset();
185         }
186
187         public long skip(long n) throws IOException {
188             return peer().skip(n);
189         }
190
191     }
192
193     public void addVetoableChangeListener(java.beans.VetoableChangeListener JavaDoc vetoableChangeListener) {
194     }
195     
196     public void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc propertyChangeListener) {
197     }
198             
199 }
200
Popular Tags