KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > j2ee > lib > AbstractJ2eeFile


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  * AbstractJ2eeFile.java
21  *
22  * Created on May 24, 2005, 11:51 AM
23  *
24  * To change this template, choose Tools | Options and locate the template under
25  * the Source Creation and Management node. Right-click the template and choose
26  * Open. You can then make changes to the template in the Source Editor.
27  */

28
29 package org.netbeans.test.j2ee.lib;
30
31 import java.io.File JavaDoc;
32 import org.netbeans.api.project.Project;
33 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject;
34 import org.openide.filesystems.FileObject;
35 import org.openide.filesystems.FileUtil;
36
37 /**
38  *
39  * @author jungi
40  */

41 abstract class AbstractJ2eeFile {
42     
43     protected static final String JavaDoc MESSAGE = "$0 does not exist.";
44     protected String JavaDoc pkgName;
45     protected FileObject prjRoot;
46     protected String JavaDoc name;
47     protected boolean isEjbMod;
48     protected String JavaDoc srcRoot;
49     
50     /** Creates a new instance of AbstractJ2eeFile */
51     public AbstractJ2eeFile(String JavaDoc fqName, Project p) {
52         this(fqName, p, "src/java");
53     }
54     
55     public AbstractJ2eeFile(String JavaDoc fqName, Project p, String JavaDoc srcRoot) {
56         int i = fqName.lastIndexOf('.') + 1;
57         name = fqName.substring(i);
58         pkgName = fqName.substring(0, i);
59         prjRoot = p.getProjectDirectory();
60         isEjbMod = p instanceof EjbJarProject;
61         this.srcRoot = srcRoot;
62     }
63     
64     protected boolean confFileExist(String JavaDoc name) {
65         boolean retVal = false;
66         String JavaDoc confDir = (isEjbMod) ? "src/conf" : "web/WEB-INF";
67         File JavaDoc f = new File JavaDoc(FileUtil.toFile(prjRoot), confDir);
68         try {
69             File JavaDoc ff = new File JavaDoc(f, name);
70             //System.err.println(ff.getAbsolutePath());
71
//System.err.println("confEx: " + ff.exists());
72
retVal = ff.exists();
73         } catch (Exception JavaDoc e) {
74         }
75         return retVal;
76     }
77     
78     protected boolean srcFileExist(String JavaDoc name) {
79         boolean retVal = false;
80         File JavaDoc f = new File JavaDoc(FileUtil.toFile(prjRoot), srcRoot);
81         try {
82             File JavaDoc ff = new File JavaDoc(f, name);
83             //System.err.println(ff.getAbsolutePath());
84
//System.err.println("srcEx: " + ff.exists());
85
retVal = ff.exists();
86         } catch (Exception JavaDoc e) {
87         }
88         return retVal;
89     }
90     
91     /**
92      * empty array iff there'are no errors, otherwise array of error messages
93      *
94      *@return empty array iff there'are no errors, otherwise array of error
95      * messages
96      */

97     public abstract String JavaDoc[] checkExistingFiles();
98 }
99
Popular Tags