KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > archive > wizard > EJBAnnotationDetector


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.archive.wizard;
21
22 import java.io.IOException JavaDoc;
23 import java.nio.channels.Channels JavaDoc;
24 import java.nio.channels.ReadableByteChannel JavaDoc;
25 import java.util.Enumeration JavaDoc;
26 import java.util.jar.JarEntry JavaDoc;
27 import java.util.jar.JarFile JavaDoc;
28 import org.openide.ErrorManager;
29
30 /**
31  *
32  * @author vbk
33  */

34 public class EJBAnnotationDetector {
35     
36     private EJBAnnotationDetector() {
37     }
38     
39     
40     /**
41      * This returns true only if the jar file contains 1 or more
42      * javax/ejb/Stateless
43      * javax/ejb/Stateful
44      * javax/ejb/MessageDriven annotations
45      * Note: caller is expected to close the
46      * @param jf the jar to be checked
47      */

48     public static boolean containsSomeAnnotatedEJBs(JarFile JavaDoc jf) throws IOException JavaDoc {
49         EJBClassFile classFile = new EJBClassFile();
50         Enumeration JavaDoc<JarEntry JavaDoc> entriesEnum = jf.entries();
51         boolean retVal = false;
52         while(!retVal && entriesEnum.hasMoreElements()) {
53             JarEntry JavaDoc je = entriesEnum.nextElement();
54             if (je.getName().endsWith(".class")) {
55                 ReadableByteChannel JavaDoc channel = null;
56                 try {
57                     channel = Channels.newChannel(jf.getInputStream(je));
58                     retVal = classFile.containsAnnotation(channel, je.getSize());
59                 } finally {
60                     if (null != channel) {
61                         try {
62                             channel.close();
63                         } catch (IOException JavaDoc ioe) {
64                             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
65                                     ioe);
66                         }
67                     }
68                 }
69                 
70             }
71         }
72         return retVal;
73     }
74 }
75
Popular Tags