KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > masterfs > filebasedfs > fileobjects > ReplaceForSerialization


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
20 package org.netbeans.modules.masterfs.filebasedfs.fileobjects;
21
22 import java.io.File JavaDoc;
23 import java.io.FileNotFoundException JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.io.OutputStream JavaDoc;
27 import java.util.Date JavaDoc;
28 import org.netbeans.modules.masterfs.filebasedfs.FileBasedFileSystem;
29 import org.netbeans.modules.masterfs.providers.ProvidedExtensions;
30 import org.openide.filesystems.FileLock;
31 import org.openide.filesystems.FileObject;
32
33 /**
34  * @author Radek Matous
35  */

36 public class ReplaceForSerialization extends Object JavaDoc implements java.io.Serializable JavaDoc {
37     /**
38      * generated Serialized Version UID
39      */

40     static final long serialVersionUID = -7451332135435542113L;
41     private final String JavaDoc absolutePath;
42
43     public ReplaceForSerialization(final File JavaDoc file) {
44         absolutePath = file.getAbsolutePath();
45     }
46
47     public final Object JavaDoc readResolve() {
48         final File JavaDoc file = new File JavaDoc(absolutePath);
49         final FileBasedFileSystem fs = FileBasedFileSystem.getInstance(file);
50         final FileObject retVal = (fs != null) ? fs.findFileObject(file) : null;
51         
52         
53         return (retVal != null) ? retVal : new Invalid (file);
54     }
55
56     private static class Invalid extends BaseFileObj {
57         protected Invalid(File JavaDoc file) {
58             super(file);
59         }
60
61         public void delete(FileLock lock, ProvidedExtensions.IOHandler io) throws IOException JavaDoc {
62             throw new IOException JavaDoc(getPath());
63         }
64         
65         boolean checkLock(FileLock lock) throws IOException JavaDoc {
66             return false;
67         }
68
69         protected void setValid(boolean valid) {}
70
71         public boolean isFolder() {
72             return false;
73         }
74
75         public Date JavaDoc lastModified() {
76             return new Date JavaDoc(0L);
77         }
78
79         /* Test whether the file is valid. The file can be invalid if it has been deserialized
80         * and the file no longer exists on disk; or if the file has been deleted.
81         *
82         * @return true if the file object is valid
83         */

84         public boolean isValid() {
85             return false;
86         }
87
88         public InputStream JavaDoc getInputStream() throws FileNotFoundException JavaDoc {
89             throw new FileNotFoundException JavaDoc (getPath());
90         }
91
92         public OutputStream JavaDoc getOutputStream(FileLock lock) throws IOException JavaDoc {
93             throw new IOException JavaDoc (getPath());
94         }
95
96         public FileLock lock() throws IOException JavaDoc {
97             throw new IOException JavaDoc (getPath());
98         }
99
100         public FileObject[] getChildren() {
101             return new FileObject[] {};
102         }
103
104         public FileObject getFileObject(String JavaDoc name, String JavaDoc ext) {
105             return null;
106         }
107
108         public FileObject createFolder(String JavaDoc name) throws IOException JavaDoc {
109             throw new IOException JavaDoc (getPath());
110         }
111
112         public FileObject createData(String JavaDoc name, String JavaDoc ext) throws IOException JavaDoc {
113             throw new IOException JavaDoc (getPath());
114         }
115
116         public void refresh(final boolean expected, boolean fire) {
117     }
118 }
119 }
120
Popular Tags