KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.invicta.handler;
2
3 import java.util.List JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import net.sf.invicta.InvictaException;
7 import net.sf.invicta.api.DefinedProperty;
8 import net.sf.invicta.api.InvictaComponent;
9
10 /**
11  * Returns the actual value of a property of any type. <BR>
12  * Usage: <BR>
13  * - Map <BR>
14  * name - (String, required) Property name.<BR>
15  * component - (String, optional, default=none) The component to
16  * return an actual property value for.
17  * Use the Current component if not specified. <BR>
18  * - List: <BR>
19  * 0 - (String, required) Property name.
20  */

21 public class ActualPropertyValueHandler extends InvictaBasicHandler {
22
23     /**
24      *
25      */

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

33     public String JavaDoc handle(Map JavaDoc paramsMap) throws InvictaException {
34         
35         InvictaComponent useComponent = getComponent();
36         String JavaDoc propertyName = getRequiredParameter("name");
37         String JavaDoc componentName = getParameter("component");
38         
39         // Use the current component if a component name was not given.
40
if (componentName != null) {
41             useComponent = getProject().getComponent(componentName);
42         }
43         
44         return getActualPropertyValue(propertyName, useComponent);
45     }
46     
47     /**
48      *
49      */

50     public String JavaDoc handle(List JavaDoc params) throws InvictaException {
51         
52         InvictaComponent useComponent = getComponent();
53         String JavaDoc propertyName = getRequiredParameter(0);
54         return getActualPropertyValue(propertyName, useComponent);
55     }
56     
57     /**
58      *
59      */

60     protected String JavaDoc getActualPropertyValue(String JavaDoc propertyName, InvictaComponent useComponent) throws InvictaHandlerException {
61         DefinedProperty property = useComponent.getDefinedProperty(propertyName);
62         if (property == null) {
63             throw new InvictaHandlerException
64                     (this, "Property '" + propertyName +
65                      "' not defined for component '" + useComponent.getName() +
66                      "' (type '" + useComponent.getTypeName() + "')");
67         }
68         return property.getActualValue();
69     }
70
71 }
72
Popular Tags