KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > webmodule > CustomProvider


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.webmodule;
21
22 import java.util.HashMap JavaDoc;
23 import org.netbeans.modules.web.api.webmodule.*;
24 import org.netbeans.modules.web.spi.webmodule.*;
25 import org.openide.filesystems.FileObject;
26
27 /** A dummy provider that things that any *.foo file belongs to its web module.
28  *
29  * @author Pavel Buzek
30  */

31 public class CustomProvider implements WebModuleProvider {
32
33     private HashMap JavaDoc cache = new HashMap JavaDoc ();
34
35     public CustomProvider () {
36     }
37
38     public WebModule findWebModule (FileObject file) {
39         if (file.getExt ().equals ("foo")) {
40             WebModule wm = (WebModule) cache.get (file.getParent ());
41             if (wm == null) {
42                 wm = WebModuleFactory.createWebModule (new WM (file.getParent (), "/"+file.getParent ().getName (), WebModule.J2EE_14_LEVEL));
43                 cache.put (file.getParent (), wm);
44             }
45             return wm;
46         }
47         return null;
48     }
49     
50     private class WM implements WebModuleImplementation {
51         FileObject db;
52         String JavaDoc cp;
53         String JavaDoc ver;
54         
55         public WM (FileObject db, String JavaDoc cp, String JavaDoc ver) {
56             this.db = db;
57             this.cp = cp;
58             this.ver = ver;
59         }
60         
61         public String JavaDoc getContextPath () {
62             return cp;
63         }
64         
65         public FileObject getDocumentBase () {
66             return db;
67         }
68         
69         public String JavaDoc getJ2eePlatformVersion () {
70             return ver;
71         }
72         
73         public FileObject getDeploymentDescriptor () {
74             return getWebInf ().getFileObject ("web.xml");
75         }
76         
77         public FileObject getWebInf () {
78             return getDocumentBase ().getFileObject ("WEB-INF");
79         }
80         
81         public FileObject[] getJavaSources() {
82             return null;
83         }
84         
85     }
86 }
87
Popular Tags