KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > validator > config > Def


1 package org.sapia.validator.config;
2
3
4 /**
5  * Models a rule definition.
6  *
7  * @author Yanick Duchesne
8  * <dl>
9  * <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>
10  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
11  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
12  * </dl>
13  */

14 public class Def {
15   private String JavaDoc _name;
16   private String JavaDoc _class;
17
18   public void setName(String JavaDoc name) {
19     _name = name;
20   }
21
22   public String JavaDoc getName() {
23     return _name;
24   }
25
26   public void setClass(String JavaDoc clazz) {
27     _class = clazz;
28   }
29
30   public Object JavaDoc toInstance() throws ConfigException {
31     if (_name == null) {
32       throw new ConfigException("'name' attribute not specified for definition");
33     }
34
35     if (_class == null) {
36       throw new ConfigException(
37         "'class' attribute not specified for definition " + _name);
38     }
39
40     try {
41       return Class.forName(_class).newInstance();
42     } catch (Throwable JavaDoc t) {
43       throw new ConfigException("Could not instantiate definition " + _name, t);
44     }
45   }
46 }
47
Popular Tags