KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.invicta.handler;
2
3 import java.util.Map JavaDoc;
4
5 import net.sf.invicta.InvictaException;
6 import net.sf.invicta.api.Product;
7
8
9 /**
10  * Map:
11  * appName - (boolean, optional, default=false) if true, return the appName instead of name.
12  * type - (String, optional, default=jar)
13  */

14 public class ProductNameHandler extends InvictaBasicHandler {
15     public final static boolean DEFAULT_APP_NAME = false;
16     public final static String JavaDoc DEFAULT_TYPE = "jar";
17
18     /**
19      *
20      */

21     public String JavaDoc handle(Map JavaDoc paramsMap) throws InvictaException {
22         String JavaDoc type = getParameter("type", DEFAULT_TYPE);
23         boolean appName = getBooleanParameter("appName", DEFAULT_APP_NAME);
24                 
25         Product product = getComponent().getSelfProduct(type, null);
26         if (product == null)
27             throw new InvictaHandlerException(this,
28                 "No product defined for component '" +
29                 getComponent().getName() +
30                 "' with type=" + type);
31         String JavaDoc name;
32         if (appName)
33             name = product.getAppName();
34         else
35             name = product.getName();
36         
37         if (name == null)
38             throw new InvictaHandlerException(this,
39                 "No name defined for " + type + " product of component '" +
40                 getComponent().getName() + "'");
41                                     
42         return name;
43     }
44
45
46     /**
47      *
48      */

49     public String JavaDoc getName() {
50         return "productName";
51     }
52
53 }
54
Popular Tags