1 17 18 package org.pentaho.core.runtime; 19 20 import java.util.*; 21 22 import org.pentaho.core.connection.IPentahoResultSet; 23 24 public class ActionParameter implements IActionParameter { 25 26 private String name; 27 28 private String type; 29 30 private Object value; 32 private List variables; 33 34 private Object defaultValue; 35 36 private ParamSelections paramSelections = null; 37 38 private int promptType = IActionParameter.PROMPT_ALLOWED; 39 40 private List saveLocations = null; 41 42 45 public ActionParameter(String name, String type, Object value, List variables, Object defaultValue) { 46 this.name = name; 47 this.value = value; 48 this.type = type; 49 this.variables = variables; 50 51 this.defaultValue = null; 54 if (defaultValue != null) { 55 if ("string".equalsIgnoreCase(type)) { this.defaultValue = defaultValue.toString(); 57 } else if ("string-list".equalsIgnoreCase(type) || "property-map-list".equalsIgnoreCase(type)) { if (defaultValue instanceof List) 59 this.defaultValue = defaultValue; 60 } else if ("property-map".equalsIgnoreCase(type)) { if (defaultValue instanceof Map) 62 this.defaultValue = defaultValue; 63 } else if ("result-set".equalsIgnoreCase(type)) { if (defaultValue instanceof IPentahoResultSet) 65 this.defaultValue = defaultValue; 66 } else if ("long".equalsIgnoreCase(type)) { try { 68 this.defaultValue = Long.valueOf(defaultValue.toString()); 69 } catch (Exception e) { 70 } 72 } 73 } 74 if ((value == null) && (defaultValue != null)) { 75 promptType = PROMPT_NEEDED; 76 } 77 } 78 79 public List getSaveLocations() { 80 return (saveLocations == null) ? new ArrayList() : saveLocations; 81 } 82 83 public void addSaveLocation(String location) { 84 if (saveLocations == null) { 85 saveLocations = new ArrayList(); 86 } 87 saveLocations.add(location); 88 return; 89 } 90 91 public List getVariables() { 92 return (variables == null) ? new ArrayList() : variables; 93 } 94 95 public String getName() { 96 return name; 97 } 98 99 public String getType() { 100 return type; 101 } 102 103 public String getStringValue() { 104 return ((value != null) ? value.toString() : ((defaultValue != null) ? defaultValue.toString() : null)); 105 } 106 107 public Object getValue() { 108 return ((value != null) ? value : defaultValue); 109 } 110 111 public List getValueAsList() { 112 Object rtn = (value != null) ? value : defaultValue; 113 if (rtn == null) { 114 return (new ArrayList()); 115 } 116 117 if (rtn instanceof List) { 118 return ((List) rtn); 119 } 120 121 ArrayList al = new ArrayList(); 122 al.add(rtn); 123 return (al); 124 } 125 126 public IPentahoResultSet getValueAsResultSet() { 127 Object rtn = (value != null) ? value : defaultValue; 128 if (rtn == null) { 129 return null; 130 } 131 132 if (rtn instanceof IPentahoResultSet) { 133 return ((IPentahoResultSet) rtn); 134 } 135 136 return null; 137 } 138 139 public void setValue(Object value) { 140 setPromptStatus((value == null) ? PROMPT_NEEDED : PROMPT_ALLOWED); 142 dispose(); 143 this.value = value; 144 } 145 146 public boolean hasDefaultValue() { 147 return (defaultValue != null); 148 } 149 150 public boolean hasValue() { 151 return (value != null); 152 } 153 154 public boolean isDefaultValue() { 155 return ((value == null) && (defaultValue != null)); 156 } 157 158 public boolean isNull() { 159 return ((value == null) && (defaultValue == null)); 160 } 161 162 public void dispose() { 163 if (value != null && value instanceof IDisposable) { 164 ((IDisposable) value).dispose(); 165 } 166 } 167 168 170 public int getPromptType() { 171 return (promptType); 172 } 173 174 public boolean hasSelections() { 175 return (paramSelections != null); 176 } 177 178 public String getSelectionDisplayName() { 179 return ((hasSelections()) ? paramSelections.displayName : ""); } 181 182 public String getSelectionNameForValue(String val) { 183 Object rtn = null; 184 if (hasSelections() && paramSelections.selNames != null) { 185 rtn = paramSelections.selNames.get(val); 186 } 187 return ((rtn != null) ? rtn.toString() : val); 188 } 189 190 public List getSelectionValues() { 191 return ((hasSelections()) ? paramSelections.selValues : new ArrayList()); 192 } 193 194 198 public void setParamSelections(List selValues, Map selNames, String displayname) { 199 paramSelections = new ParamSelections(selValues, selNames, displayname); 200 } 201 202 public Map getSelectionNameMap() { 203 return ((hasSelections()) ? paramSelections.selNames : new HashMap()); 204 } 205 206 class ParamSelections { 207 Map selNames; 208 209 List selValues; 210 211 String displayName; 212 213 ParamSelections(List selValues, Map selNames, String displayname) { 214 this.displayName = (displayname != null) ? displayname : ""; this.selNames = (selNames != null) ? selNames : new HashMap(); 216 this.selValues = (selValues != null) ? selValues : new ArrayList(); 217 } 218 } 219 220 public int getPromptStatus() { 221 return (promptType); 222 } 223 224 public boolean setPromptStatus(int status) { 225 if ((promptType == PROMPT_NEVER) || (status < 0) || (status > 3)) { 226 return (false); 227 } 228 229 promptType = status; 230 return (true); 231 } 232 233 } 234 | Popular Tags |