KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > earproject > ModuleType


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.earproject;
21
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24 import org.openide.filesystems.FileObject;
25 import org.openide.util.NbBundle;
26
27 /**
28  * @author Martin Krauskopf
29  */

30 public enum ModuleType {
31     
32     WEB(NbBundle.getMessage(ModuleType.class, "CTL_WebModule")),
33     EJB(NbBundle.getMessage(ModuleType.class, "CTL_EjbModule")),
34     CLIENT(NbBundle.getMessage(ModuleType.class, "CTL_ClientModule"));
35     
36     private final String JavaDoc description;
37     
38     ModuleType(final String JavaDoc description) {
39         this.description = description;
40     }
41     
42     public String JavaDoc getDescription() {
43         return description;
44     }
45     
46     /** Maps relative deployment descriptor's path to {@link ModuleType}. */
47     private static final Map JavaDoc<String JavaDoc, ModuleType> DEFAULT_DD = new HashMap JavaDoc<String JavaDoc, ModuleType>();
48     
49     static {
50         DEFAULT_DD.put("web/WEB-INF/web.xml", ModuleType.WEB); // NOI18N
51
DEFAULT_DD.put("src/conf/ejb-jar.xml", ModuleType.EJB); // NOI18N
52
DEFAULT_DD.put("src/conf/application-client.xml", ModuleType.CLIENT); // NOI18N
53
}
54     
55     /**
56      * Detects Enterprise Application modules in the <code>appRoot</code>'s
57      * subfolders recursively.
58      *
59      * @param folder root folder - typically enterprise application folder
60      * @return map of FileObject to ModuleType entries
61      */

62     public static Map JavaDoc<FileObject, ModuleType> detectModules(final FileObject appRoot) {
63         Map JavaDoc<FileObject, ModuleType> descriptors =
64                 new HashMap JavaDoc<FileObject, ModuleType>();
65         // do detection for each subdirectory
66
for (FileObject subprojectRoot : appRoot.getChildren()) {
67             if (subprojectRoot.isFolder()) {
68                 ModuleType type = ModuleType.detectModuleType(subprojectRoot);
69                 if (type != null) {
70                     descriptors.put(subprojectRoot, type);
71                 }
72             }
73         }
74         return descriptors;
75     }
76     
77     /**
78      * Tries to detect Enterprise Application module's type in the given folder.
79      *
80      * @param folder folder which possibly containing module
81      * @return <code>null</code> if no module were detected; instance otherwise
82      */

83     public static ModuleType detectModuleType(final FileObject moduleRoot) {
84         ModuleType result = null;
85         for (Map.Entry JavaDoc<String JavaDoc, ModuleType> entry : DEFAULT_DD.entrySet()) {
86             FileObject ddFO = moduleRoot.getFileObject(entry.getKey());
87             if (ddFO != null && ddFO.isData()) { // deployment descriptor detected
88
result = entry.getValue();
89             }
90         }
91         return result;
92     }
93     
94 }
95
Popular Tags