KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
12  *
13  */

14 public class PropertyHandler extends InvictaBasicHandler {
15     public final static String JavaDoc PROPERTY_SEPARATOR = ".";
16             
17     /**
18      *
19      */

20     public String JavaDoc getName() {
21         return "property";
22     }
23
24     /**
25      *
26      */

27     public String JavaDoc handle(Map JavaDoc paramsMap) throws InvictaException {
28         
29         InvictaComponent useComponent = getComponent();
30         String JavaDoc propertyName = getRequiredParameter("name");
31         String JavaDoc componentName = getParameter("component");
32         if (componentName != null) {
33             useComponent = getProject().getComponent(componentName);
34         }
35         
36         return getProperty(propertyName, useComponent);
37     }
38     
39     /**
40      *
41      */

42     public String JavaDoc handle(List JavaDoc params) throws InvictaException {
43         
44         InvictaComponent useComponent = getComponent();
45         String JavaDoc propertyName = getRequiredParameter(0);
46         return getProperty(propertyName, useComponent);
47     }
48     
49     /**
50      *
51      */

52     protected String JavaDoc getProperty(String JavaDoc propertyName, InvictaComponent useComponent) throws InvictaHandlerException {
53         DefinedProperty property = useComponent.getDefinedProperty(propertyName);
54         if (property == null) {
55             throw new InvictaHandlerException
56                     (this, "Property '" + propertyName +
57                      "' not defined for component '" + useComponent.getName() +
58                      "' (type '" + useComponent.getTypeName() + "')");
59         }
60                     
61         return property.getReferenceValue();
62     }
63     
64 }
65
Popular Tags