KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > config > DDFilesListener


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.j2ee.sun.share.config;
21
22 import java.io.File JavaDoc;
23
24 import org.openide.filesystems.FileObject;
25 import org.openide.filesystems.FileUtil;
26
27 import org.netbeans.modules.j2ee.deployment.common.api.SourceFileMap;
28 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
29 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
30 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider.ConfigSupport;
31
32 import org.netbeans.modules.j2ee.sun.share.configbean.SunONEDeploymentConfiguration;
33
34
35 /**
36  * Listen on Deployment Descriptor files, mainly to detect the
37  * need to save configuration.
38  *
39  * @author nn136682
40  */

41 public class DDFilesListener extends AbstractFilesListener {
42     
43     private SunONEDeploymentConfiguration config;
44     private File JavaDoc[] ddFiles = null;
45     
46     public DDFilesListener(SunONEDeploymentConfiguration config, J2eeModuleProvider provider) {
47         super(provider);
48         this.config = config;
49     }
50     
51     public static final File JavaDoc[] EMPTY_FILE_ARRAY = new File JavaDoc[0];
52     
53     protected File JavaDoc[] getTargetFiles() {
54         if (ddFiles != null) {
55             return ddFiles;
56         }
57
58         SourceFileMap sfm = provider.getSourceFileMap();
59         FileObject[] roots = sfm.getSourceRoots();
60         if (roots == null || roots.length < 1) {
61             ddFiles = EMPTY_FILE_ARRAY;
62             return ddFiles;
63         }
64         
65         if(roots[0] == null) {
66             ddFiles = EMPTY_FILE_ARRAY;
67             return ddFiles;
68         }
69
70         File JavaDoc configFolder = FileUtil.toFile(roots[0]);
71         String JavaDoc[] pathNames = ModuleDDSupport.getDDPaths(provider.getJ2eeModule().getModuleType());
72         ddFiles = new File JavaDoc[pathNames.length];
73         for (int i=0; i<pathNames.length; i++) {
74             String JavaDoc fileName = pathNames[i];
75             if (J2eeModule.WAR != provider.getJ2eeModule().getModuleType()) {
76                 fileName = fileName.substring(pathNames[i].lastIndexOf('/')+1); //always forward
77
}
78             ddFiles[i] = new File JavaDoc(configFolder, fileName);
79         }
80         return ddFiles;
81     }
82     
83     protected boolean isTarget(FileObject fo) {
84         if (fo == null) {
85             return false;
86         }
87         
88         getTargetFiles();
89         for (int i=0; i<ddFiles.length; i++) {
90             if (fo.getNameExt().equalsIgnoreCase(ddFiles[i].getName())) {
91                 return true;
92             }
93         }
94         return false;
95     }
96     
97     protected boolean isTarget(String JavaDoc fileName) {
98         if (fileName == null) {
99             return false;
100         }
101         
102         getTargetFiles();
103         for (int i=0; i<ddFiles.length; i++) {
104             if (fileName.equalsIgnoreCase(ddFiles[i].getName())) {
105                 return true;
106             }
107         }
108         return true;
109     }
110     
111     protected void targetCreated(FileObject fo) {
112         ConfigurationStorage cs = config.getStorage();
113         if (cs != null) {
114             cs.updateDDRoot(fo);
115 // cs.autoSave();
116
}
117     }
118     
119     protected void targetDeleted(FileObject fo) {
120     }
121     
122     protected void targetChanged(FileObject fo) {
123 // ConfigurationStorage cs = config.getStorage();
124
// if (cs != null) {
125
// cs.autoSave();
126
// }
127
}
128 }
129
Popular Tags