KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > state > util > Assert


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 /**
10  * @author Yanick Duchesne
11  * <dl>
12  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
13  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
14  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
15  * </dl>
16  */

17 public class Assert extends StepSupport {
18   private static final String JavaDoc DEFAULT_MSG = "Value not found for: ";
19   private String JavaDoc _key;
20   private String JavaDoc[] _scopes;
21   private String JavaDoc _msg;
22
23   public Assert() {
24   }
25
26   /**
27    * @see org.sapia.soto.state.Executable#execute(org.sapia.soto.state.Result)
28    */

29   public void execute(Result res) {
30     Object JavaDoc 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 JavaDoc key) {
48     _key = key;
49   }
50
51   public void setMsg(String JavaDoc msg) {
52     _msg = msg;
53   }
54
55   public void setScopes(String JavaDoc 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