KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > config > ConfigFilesListener


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.deployment.config;
21
22 import java.io.File JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import org.netbeans.modules.j2ee.deployment.devmodules.spi.ConfigurationFilesListener;
28 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
29 import org.netbeans.modules.j2ee.deployment.impl.Server;
30 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
31 import org.openide.filesystems.FileObject;
32
33 /**
34  * @author nn136682
35  */

36 public class ConfigFilesListener extends AbstractFilesListener {
37     List JavaDoc consumers; //ConfigurationFileListener's
38

39     public ConfigFilesListener(J2eeModuleProvider provider, List JavaDoc consumers) {
40         super(provider);
41         this.consumers = consumers;
42     }
43     
44     protected File JavaDoc[] getTargetFiles() {
45         //locate the root to listen to
46
Collection JavaDoc servers = ServerRegistry.getInstance().getServers();
47         ArrayList JavaDoc result = new ArrayList JavaDoc();
48         for (Iterator JavaDoc i=servers.iterator(); i.hasNext();) {
49             Server s = (Server) i.next();
50             String JavaDoc[] paths = s.getDeploymentPlanFiles(provider.getJ2eeModule().getModuleType());
51             if (paths == null)
52                 continue;
53             
54             for (int j = 0; j < paths.length; j++) {
55                 File JavaDoc f = provider.getDeploymentConfigurationFile(paths[j]);
56                 if (f != null)
57                     result.add(f);
58             }
59         }
60         return (File JavaDoc[]) result.toArray(new File JavaDoc[result.size()]);
61     }
62
63     protected void targetDeleted(FileObject deleted) {
64         fireConfigurationFilesChanged(false, deleted);
65     }
66     
67     protected void targetCreated(FileObject added) {
68         fireConfigurationFilesChanged(true, added);
69     }
70     
71     protected void targetChanged(FileObject deleted) {
72     }
73     
74     private void fireConfigurationFilesChanged(boolean added, FileObject fo) {
75         for (Iterator JavaDoc i=consumers.iterator(); i.hasNext();) {
76             ConfigurationFilesListener cfl = (ConfigurationFilesListener) i.next();
77             if (added) {
78                 cfl.fileCreated(fo);
79             } else {
80                 cfl.fileDeleted(fo);
81             }
82         }
83     }
84
85     protected boolean isTarget(FileObject fo) {
86         return isTarget(fo.getNameExt());
87     }
88     protected boolean isTarget(String JavaDoc fileName) {
89         return ServerRegistry.getInstance().isConfigFileName(fileName, provider.getJ2eeModule().getModuleType());
90     }
91 }
92
Popular Tags