KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > annotation > impl > WarScanner


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.deployment.annotation.impl;
24
25 import java.io.File JavaDoc;
26 import java.io.FileFilter JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.net.URL JavaDoc;
29 import java.net.URLClassLoader JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.Set JavaDoc;
32 import java.util.Vector JavaDoc;
33 import java.util.logging.Level JavaDoc;
34
35 import com.sun.enterprise.deployment.WebBundleDescriptor;
36 import com.sun.enterprise.deployment.WebComponentDescriptor;
37 import com.sun.enterprise.deployment.web.ServletFilter;
38 import com.sun.enterprise.deployment.web.AppListenerDescriptor;
39
40 /**
41  * Implementation of the Scanner interface for war.
42  *
43  * @author Shing Wai Chan
44  */

45 public class WarScanner extends ModuleScanner {
46     public WarScanner(File JavaDoc archiveFile, WebBundleDescriptor webBundleDesc)
47             throws IOException JavaDoc {
48         this(archiveFile, webBundleDesc, null);
49     }
50
51     /**
52      * This scanner will scan the archiveFile for annotation processing.
53      * @param archiveFile
54      * @param webBundleDesc
55      * @param classLoader
56      */

57     public WarScanner(File JavaDoc archiveFile, WebBundleDescriptor webBundleDesc,
58             ClassLoader JavaDoc classLoader) throws IOException JavaDoc {
59         if (AnnotationUtils.getLogger().isLoggable(Level.FINE)) {
60             AnnotationUtils.getLogger().fine("archiveFile is " + archiveFile);
61             AnnotationUtils.getLogger().fine("webBundle is " + webBundleDesc);
62             AnnotationUtils.getLogger().fine("classLoader is " + classLoader);
63         }
64         this.archiveFile = archiveFile;
65         this.classLoader = classLoader;
66
67         if (!archiveFile.isDirectory()) {
68             // on client side
69
return;
70         }
71
72         File JavaDoc webinf = new File JavaDoc(archiveFile, "WEB-INF");
73         File JavaDoc classes = new File JavaDoc(webinf, "classes");
74         if (classes.exists()) {
75             addScanDirectory(classes);
76         }
77         File JavaDoc lib = new File JavaDoc(webinf, "lib");
78         if (lib.exists()) {
79             File JavaDoc[] jarFiles = lib.listFiles(new FileFilter JavaDoc() {
80                  public boolean accept(File JavaDoc pathname) {
81                      return (pathname.isFile() &&
82                             pathname.getAbsolutePath().endsWith(".jar"));
83                  }
84             });
85
86             if (jarFiles != null && jarFiles.length > 0) {
87                 for (File JavaDoc jarFile : jarFiles) {
88                     addScanJar(jarFile);
89                 }
90             }
91         }
92
93         // always add servlet, filter, listener that are defined in web.xml
94
// regardless of they have annotation or not
95

96         for (Iterator JavaDoc webComponents =
97             webBundleDesc.getWebComponentDescriptorsSet().iterator();
98             webComponents.hasNext();) {
99             WebComponentDescriptor webCompDesc =
100                 (WebComponentDescriptor)webComponents.next();
101             if (webCompDesc.isServlet()) {
102                 addScanClassName(webCompDesc.getWebComponentImplementation());
103             }
104         }
105
106         Vector JavaDoc servletFilters = webBundleDesc.getServletFilters();
107         for (int i = 0; i < servletFilters.size(); i++) {
108             ServletFilter filter = (ServletFilter)servletFilters.elementAt(i);
109             addScanClassName(filter.getClassName());
110         }
111
112         Vector JavaDoc listeners = webBundleDesc.getAppListenerDescriptors();
113         for (int j = 0; j < listeners.size(); j++) {
114             AppListenerDescriptor listenerDesc =
115                 (AppListenerDescriptor) listeners.elementAt(j);
116             addScanClassName(listenerDesc.getListener());
117         }
118     }
119 }
120  
121
Popular Tags