1 package org.sapia.soto.state.util; 2 3 import org.apache.commons.lang.StringUtils; 4 5 import org.sapia.soto.state.Result; 6 import org.sapia.soto.state.helpers.StepSupport; 7 8 9 17 public class Assert extends StepSupport { 18 private static final String DEFAULT_MSG = "Value not found for: "; 19 private String _key; 20 private String [] _scopes; 21 private String _msg; 22 23 public Assert() { 24 } 25 26 29 public void execute(Result res) { 30 Object val = null; 31 32 if (_scopes == null) { 33 val = res.getContext().get(_key); 34 } else { 35 val = res.getContext().get(_key, _scopes); 36 } 37 38 if (val == null) { 39 if (_msg == null) { 40 res.error(DEFAULT_MSG + _key); 41 } else { 42 res.error(_msg); 43 } 44 } 45 } 46 47 public void setKey(String key) { 48 _key = key; 49 } 50 51 public void setMsg(String msg) { 52 _msg = msg; 53 } 54 55 public void setScopes(String scopes) { 56 _scopes = StringUtils.split(scopes, ","); 57 58 for (int i = 0; i < _scopes.length; i++) { 59 _scopes[i] = _scopes[i].trim(); 60 } 61 } 62 } 63 | Popular Tags |