1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon;
20
21 import java.util.Iterator;
22 import java.util.Map;
23
24 import net.sf.jameleon.exception.JameleonException;
25 import net.sf.jameleon.exception.JameleonTagException;
26 import net.sf.jameleon.util.Configurator;
27 import net.sf.jameleon.util.SupportedTags;
28
29 import org.apache.commons.jelly.JellyException;
30 import org.apache.commons.jelly.Tag;
31 import org.apache.commons.jelly.TagLibrary;
32 import org.xml.sax.Attributes;
33
34 /***
35 * Registers the tag libraries based on what is set up in SupportedTags.
36 * SupportedTags by default reads its configuration from jameleon.conf' plugins
37 * directive.
38 * Even if no plug-ins are configured, then the following files should be read in:
39 * <ol>
40 * <li>jameleon-core.properties</li>
41 * <li>TestCaseTagDefs.properties</li>
42 * </ol>
43 * The format of those files is:<br>
44 * tagname=package.and.classname.of.function.point
45 */
46 public class TestCaseTagLibrary extends TagLibrary {
47
48 protected static SupportedTags st = new SupportedTags();
49 protected static boolean warnOnNoPluginsFound;
50
51 public TestCaseTagLibrary() {
52 warnOnNoPluginsFound = Boolean.valueOf(Configurator.getInstance().getValue("warnOnNoPluginsFound", "true")).booleanValue();
53 st.setWarnOnNoPluginsFile(warnOnNoPluginsFound);
54 registerTags(st.getSupportedTags());
55 }
56
57 /***
58 * Loops through all keys in a file named by the <code>name</code parameter.
59 * @param tags - a tag name - class name map of tags to register
60 */
61 protected void registerTags(Map tags){
62 Iterator keys = tags.keySet().iterator();
63 String key = null;
64 while (keys.hasNext()) {
65 key = (String)keys.next();
66 String className = (String)tags.get(key);
67 registerTag(key,getClassLoader(className));
68 }
69 }
70
71
72 private Class getClassLoader(String className){
73 ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
74 Class clzz = null;
75 if (classLoader == null) {
76 classLoader = this.getClass().getClassLoader();
77 } else {
78 if (findClass(className,classLoader) == null) {
79 classLoader = this.getClass().getClassLoader();
80 }
81 }
82 clzz = findClass(className, classLoader);
83 if (clzz == null) {
84 throw new JameleonException("Couldn't find "+className);
85 }
86 return clzz;
87 }
88
89 private Class findClass(String className, ClassLoader cl){
90 Class clzz = null;
91 try{
92 clzz = cl.loadClass(className);
93 }catch(ClassNotFoundException cnfe){
94
95 }
96 return clzz;
97 }
98
99 public static void resetTags(){
100 st = new SupportedTags();
101 st.setWarnOnNoPluginsFile(warnOnNoPluginsFound);
102 }
103
104 public static void setWarnOnNoPluginsFound(boolean warnOnNoPlugins){
105 warnOnNoPluginsFound = warnOnNoPlugins;
106 if (st != null) {
107 st.setWarnOnNoPluginsFile(warnOnNoPlugins);
108 }
109 }
110
111
112
113 /*** Creates a new Tag for the given tag name and attributes */
114 public Tag createTag(String name, Attributes attributes)
115 throws JellyException {
116 Tag tag = super.createTag(name, attributes);
117 if (tag == null) {
118 throw new JameleonTagException(name, "is not a recognized Jameleon tag. Please check the spelling and try again.");
119 }
120 return tag;
121 }
122
123 /*** Creates a new script to execute the given tag name and attributes */
124
125
126
127
128
129
130
131
132
133
134
135
136
137 }