1 19 20 package org.netbeans.modules.j2ee.earproject; 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import org.openide.filesystems.FileObject; 25 import org.openide.util.NbBundle; 26 27 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 description; 37 38 ModuleType(final String description) { 39 this.description = description; 40 } 41 42 public String getDescription() { 43 return description; 44 } 45 46 47 private static final Map <String , ModuleType> DEFAULT_DD = new HashMap <String , ModuleType>(); 48 49 static { 50 DEFAULT_DD.put("web/WEB-INF/web.xml", ModuleType.WEB); DEFAULT_DD.put("src/conf/ejb-jar.xml", ModuleType.EJB); DEFAULT_DD.put("src/conf/application-client.xml", ModuleType.CLIENT); } 54 55 62 public static Map <FileObject, ModuleType> detectModules(final FileObject appRoot) { 63 Map <FileObject, ModuleType> descriptors = 64 new HashMap <FileObject, ModuleType>(); 65 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 83 public static ModuleType detectModuleType(final FileObject moduleRoot) { 84 ModuleType result = null; 85 for (Map.Entry <String , ModuleType> entry : DEFAULT_DD.entrySet()) { 86 FileObject ddFO = moduleRoot.getFileObject(entry.getKey()); 87 if (ddFO != null && ddFO.isData()) { result = entry.getValue(); 89 } 90 } 91 return result; 92 } 93 94 } 95 | Popular Tags |