KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > wizards > Evaluator


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.web.wizards;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 import org.openide.filesystems.FileObject;
28 import org.openide.loaders.DataFolder;
29 import org.openide.util.NbBundle;
30 import org.netbeans.api.project.Project;
31
32 /**
33 * Generic methods for evaluating the input into the wizards.
34 *
35 * @author Ana von Klopp
36 */

37
38 abstract class Evaluator {
39
40     private FileType fileType = null;
41     private static final boolean debug=false;
42
43     Evaluator(FileType fileType) {
44     this.fileType = fileType;
45     }
46
47     abstract boolean isValid();
48     abstract String JavaDoc getTargetPath();
49     abstract String JavaDoc getErrorMessage();
50     abstract Iterator JavaDoc getPathItems();
51     abstract void setInitialFolder(DataFolder df, Project project);
52     
53     FileType getFileType() {
54     return fileType;
55     }
56
57     /**
58      * Returns the absolute path to the target class. Used by the
59      * wizards to display the result of the selections.
60      */

61
62     String JavaDoc getTargetPath(Iterator JavaDoc pathItems) {
63         
64         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
65     while(pathItems.hasNext()) {
66         buffer.append((String JavaDoc)(pathItems.next()));
67         if(pathItems.hasNext())
68         buffer.append(File.separator);
69     }
70     buffer.append("."); //NOI18N
71
buffer.append(fileType.getSuffix());
72     return buffer.toString();
73     }
74
75     void checkFile(Iterator JavaDoc pathItems, FileObject root) throws IOException JavaDoc {
76     if(debug) log("::checkFile() "+root); //NOI18N
77

78     String JavaDoc pathItem;
79         FileObject fo = root;
80         
81     while(pathItems.hasNext()) {
82
83         // We're good!
84

85         pathItem = (String JavaDoc)(pathItems.next());
86         if(debug) log("\tpath item is " + pathItem); //NOI18N
87

88         // Path item is a directory, check that we can get it
89
if(pathItems.hasNext()) {
90         if(debug) log("\tNot the last one"); //NOI18N
91
try {
92             fo = fo.getFileObject(pathItem, null);
93         }
94         catch(IllegalArgumentException JavaDoc iaex) {
95             throw new IOException JavaDoc(NbBundle.getMessage(Evaluator.class,
96                                   "MSG_clash_path",
97                                   pathItem));
98         }
99                 if(debug) log("\tfo="+fo); //NOI18N
100
// We're good!
101
if(fo == null) return;
102
103         if(debug)
104             log("\tgot next file object " + fo.getPath()); //NOI18N
105

106         if(!fo.isFolder()) {
107             if(debug) log("\tNot a folder"); //NOI18N
108
throw new IOException JavaDoc(NbBundle.getMessage(Evaluator.class,
109                                   "MSG_clash_path",
110                                   pathItem));
111                      
112         }
113         }
114         else {
115         if(debug) log("\tThis is the last one"); //NOI18N
116
try {
117             fo = fo.getFileObject(pathItem, fileType.getSuffix());
118         }
119         catch(IllegalArgumentException JavaDoc iaex) {
120             throw new IOException JavaDoc(NbBundle.getMessage(Evaluator.class,
121                                   "MSG_clash_path",
122                                   pathItem));
123         }
124         if(fo == null) return;
125         if(fo.isData())
126             throw new IOException JavaDoc(NbBundle.getMessage(Evaluator.class,
127                                   "MSG_file_exists",
128                                   pathItem));
129         }
130     }
131     if(debug) log("\tAt end of checkFile()"); //NOI18N
132
}
133     
134     private static void log(String JavaDoc s) {
135     System.out.println("Evaluator" + s);
136     }
137
138 }
139
140
Popular Tags