1 package net.sf.invicta.handler; 2 3 import java.util.List ; 4 import java.util.Map ; 5 6 import net.sf.invicta.InvictaException; 7 import net.sf.invicta.api.DefinedProperty; 8 import net.sf.invicta.api.InvictaComponent; 9 10 11 14 public class PropertyHandler extends InvictaBasicHandler { 15 public final static String PROPERTY_SEPARATOR = "."; 16 17 20 public String getName() { 21 return "property"; 22 } 23 24 27 public String handle(Map paramsMap) throws InvictaException { 28 29 InvictaComponent useComponent = getComponent(); 30 String propertyName = getRequiredParameter("name"); 31 String componentName = getParameter("component"); 32 if (componentName != null) { 33 useComponent = getProject().getComponent(componentName); 34 } 35 36 return getProperty(propertyName, useComponent); 37 } 38 39 42 public String handle(List params) throws InvictaException { 43 44 InvictaComponent useComponent = getComponent(); 45 String propertyName = getRequiredParameter(0); 46 return getProperty(propertyName, useComponent); 47 } 48 49 52 protected String getProperty(String 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 |