KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > devmodules > api > JSPServletFinder


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.devmodules.api;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.io.File JavaDoc;
24 import org.netbeans.api.project.FileOwnerQuery;
25 import org.netbeans.api.project.Project;
26 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
27 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
28 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
29 import org.netbeans.modules.j2ee.deployment.impl.ServerString;
30 import org.netbeans.modules.j2ee.deployment.plugins.api.FindJSPServlet;
31 import org.netbeans.modules.j2ee.deployment.plugins.api.OldJSPDebug;
32 import org.openide.filesystems.FileObject;
33
34 /**
35  *
36  * @author Petr Jiricka
37  */

38 public final class JSPServletFinder {
39     
40     public static final String JavaDoc SERVLET_FINDER_CHANGED = "servlet-finder-changed"; // NOI18N
41

42     private Project project;
43
44     /** Returns JSPServletFinder for the project that contains given file.
45      * @return null if the file is not in any project
46      */

47     public static JSPServletFinder findJSPServletFinder(FileObject f) {
48         Project prj = FileOwnerQuery.getOwner (f);
49         return prj == null ? null : new JSPServletFinder(prj);
50     }
51     
52     /** Creates a new instance of JspServletFinderImpl */
53     private JSPServletFinder (Project project) {
54         this.project = project;
55     }
56     
57     private J2eeModuleProvider getProvider() {
58         return (J2eeModuleProvider) project.getLookup ().lookup (J2eeModuleProvider.class);
59     }
60     
61     /** Returns the server instance currently selected for the module associated with this JSPServletFinder.
62      * May return null.
63      */

64     private ServerString getServerString() {
65         J2eeModuleProvider dl = getProvider ();
66         if (dl == null)
67             return null;
68         ServerInstance instance = ServerRegistry.getInstance ().getServerInstance (dl.getServerInstanceID ());
69         return instance == null ? null : new ServerString (instance);
70     }
71     
72     
73     private String JavaDoc getWebURL() {
74         J2eeModuleProvider provider = (J2eeModuleProvider) project.getLookup ().lookup (J2eeModuleProvider.class);
75         return provider.getConfigSupport().getWebContextRoot();
76     }
77     
78     /** Returns the FindJSPServlet class associated with this JSPServletFinder.
79      * May return null.
80      */

81     private FindJSPServlet getServletFinder() {
82         ServerString serverS = getServerString();
83         if (serverS == null)
84             return null;
85         ServerInstance inst = serverS.getServerInstance();
86         if (inst == null)
87             return null;
88         return inst.getFindJSPServlet();
89     }
90     
91     public File JavaDoc getServletTempDirectory () {
92         FindJSPServlet find = getServletFinder();
93         if (find == null)
94             return null;
95         String JavaDoc webURL = getWebURL();
96         if (webURL == null)
97             return null;
98         //TargetModuleID moduleID = getTargetModuleID();
99
//if (moduleID == null)
100
// return null;
101
return find.getServletTempDirectory(webURL);
102         
103 /* try {
104             J2eeDeploymentLookup dl = getDeploymentLookup();
105             J2eeProfileSettings settings = dl.getJ2eeProfileSettings();
106             DeploymentTargetImpl target = new DeploymentTargetImpl(settings, dl);
107             ServerString serverS = target.getServer();
108             ServerInstance inst = serverS.getServerInstance();
109             DeploymentManager dm = inst.getDeploymentManager();
110 System.out.println("getting servlet temp directory - dm is " + dm);
111             TargetModuleID mod[] = dm.getAvailableModules(ModuleType.WAR, serverS.toTargets());
112             TargetModuleID mod0 = null; // PENDING - find by web URI
113             FindJSPServlet find = inst.getFindJSPServlet();
114 System.out.println("getting servlet temp directory - find is " + find);
115             return find.getServletTempDirectory(mod0);
116         }
117         catch (TargetException e) {
118             // PENDING
119             return null;
120         }*/

121     }
122  
123     public String JavaDoc getServletResourcePath(String JavaDoc jspResourcePath) {
124         FindJSPServlet find = getServletFinder();
125         if (find == null)
126             return null;
127         String JavaDoc webURL = getWebURL();
128         if (webURL == null)
129             return null;
130         return find.getServletResourcePath(webURL, jspResourcePath);
131     }
132  
133     public String JavaDoc getServletEncoding(String JavaDoc jspResourcePath) {
134         FindJSPServlet find = getServletFinder();
135         if (find == null)
136             return null;
137         String JavaDoc webURL = getWebURL();
138         if (webURL == null)
139             return null;
140         return find.getServletEncoding(webURL, jspResourcePath);
141     }
142  
143     public OldJSPDebug.JspSourceMapper getSourceMapper(String JavaDoc jspResourcePath) {
144         // PENDING
145
return null;
146     }
147  
148     public void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
149         // PENDING
150
}
151  
152     public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
153         // PENDING
154
}
155 }
156
Popular Tags