KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > invicta > handler > DependAppModulesHandler


1 package net.sf.invicta.handler;
2
3 import java.io.File JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.Map JavaDoc;
6
7 import java.util.List JavaDoc;
8 import net.sf.invicta.InvictaException;
9 import net.sf.invicta.api.Product;
10
11 /**
12  * Returns instructions for creating an application.xml file.
13  */

14 public class DependAppModulesHandler extends InvictaBasicHandler {
15         
16     private final static String JavaDoc MODULE_TYPE_EJB = "ejb";
17     private final static String JavaDoc MODULE_TYPE_JAVA = "java";
18     private final static String JavaDoc MODULE_TYPE_WEB = "web";
19
20     private final static String JavaDoc PRODUCT_TYPE_EJB = "ejb";
21     private final static String JavaDoc PRODUCT_TYPE_JAVA = "jar";
22     private final static String JavaDoc PRODUCT_TYPE_WEB = "war";
23
24     /**
25      *
26      */

27     public String JavaDoc getName() {
28         return "dependAppModules";
29     }
30
31     /**
32      *
33      */

34     public String JavaDoc handle(Map JavaDoc paramsMap) throws InvictaException {
35         return getDependModules();
36     }
37
38
39     /**
40      *
41      */

42     public String JavaDoc handle(List JavaDoc params) throws InvictaException {
43         return getDependModules();
44     }
45
46     /**
47      *
48      */

49     protected String JavaDoc getDependModules() {
50         String JavaDoc modulesStr = "";
51         // Add all products
52
for (Iterator JavaDoc productIter =
53              getComponent().getRecursiveProducts().iterator();
54              productIter.hasNext();) {
55                 
56             Product product = (Product)productIter.next();
57             
58             if (product.getFile() != null) {
59                 File JavaDoc file = new File JavaDoc(product.getFile());
60                 if (product.getType().equals(PRODUCT_TYPE_EJB)) {
61                     modulesStr += getEJBModule(file.getName());
62                 } else if (product.getType().equals(PRODUCT_TYPE_JAVA)) {
63                     modulesStr += getJavaModule(file.getName());
64                 } else if (product.getType().equals(PRODUCT_TYPE_WEB)) {
65                     modulesStr += getWebModule(
66                             product.getAppName(), file.getName());
67                 }
68             }
69         }
70         return modulesStr;
71     }
72
73     /**
74      *
75      */

76     private String JavaDoc getWebModule(String JavaDoc name, String JavaDoc file) {
77
78         return "<module type=\"" + MODULE_TYPE_WEB + "\" file=\"" + file +
79                 "\" name=\"" + name + "\"/>\n";
80     }
81
82     /**
83      *
84      */

85     private String JavaDoc getJavaModule(String JavaDoc file) {
86         return "<module type=\"" + MODULE_TYPE_JAVA + "\" file=\"" + file +
87                 "\"/>\n";
88     }
89     
90     /**
91      *
92      */

93     private String JavaDoc getEJBModule(String JavaDoc file) {
94         return "<module type=\"" + MODULE_TYPE_EJB + "\" file=\"" + file +
95                         "\"/>\n";
96     }
97
98 }
99
Popular Tags