KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > masterfs > filebasedfs > naming > UNCName


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.naming;
21
22 import java.io.File JavaDoc;
23 import java.io.FileFilter JavaDoc;
24 import java.io.FilenameFilter JavaDoc;
25 import java.io.IOException JavaDoc;
26
27 /**
28  * @author Radek Matous
29  */

30 public final class UNCName extends FolderName {
31     UNCName(final FileNaming parent, final File JavaDoc f) {
32         super(parent, f);
33     }
34
35     public final File JavaDoc getFile() {
36         File JavaDoc file = super.getFile();
37         file = (file instanceof UNCFile) ? file : new UNCFile(file);
38         return file;
39     }
40
41     public final FileNaming getParent() {
42         final FileNaming parent = super.getParent();
43         return parent;
44     }
45
46     public static final class UNCFile extends File JavaDoc {
47         private UNCFile(final File JavaDoc file) {
48             super(file.getAbsolutePath());
49         }
50
51         public final boolean isDirectory() {
52             return true;
53         }
54
55         public final File JavaDoc getParentFile() {
56             return wrap(super.getParentFile());
57         }
58
59         public final File JavaDoc getAbsoluteFile() {
60             return wrap(super.getAbsoluteFile());
61         }
62
63         public final File JavaDoc getCanonicalFile() throws IOException JavaDoc {
64             return wrap(super.getCanonicalFile());
65         }
66
67
68         public final File JavaDoc[] listFiles() {
69             return wrap(super.listFiles());
70         }
71
72
73         public final File JavaDoc[] listFiles(final FilenameFilter JavaDoc filter) {
74             return wrap(super.listFiles(filter));
75         }
76
77         public final File JavaDoc[] listFiles(final FileFilter JavaDoc filter) {
78             return wrap(super.listFiles(filter));
79         }
80
81         private File JavaDoc[] wrap(final File JavaDoc[] files) {
82             if (files != null) {
83                 for (int i = 0; i < files.length; i++) {
84                     final File JavaDoc file = files[i];
85                     files[i] = (file != null) ? new UNCFile(file) : null;
86                     ;
87                 }
88             }
89             return files;
90         }
91
92         private File JavaDoc wrap(final File JavaDoc file) {
93             return (file != null) ? new UNCFile(file) : null;
94         }
95
96         public final boolean exists() {
97             return true;
98         }
99
100     }
101 }
Popular Tags