KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > test > TLDTest


1 /*
2  * (c) Copyright 2001 MyCorporation.
3  * All Rights Reserved.
4  */

5 package fr.improve.struts.taglib.layout.test;
6
7 import java.beans.IntrospectionException JavaDoc;
8 import java.beans.PropertyDescriptor JavaDoc;
9 import java.io.File JavaDoc;
10 import java.io.IOException JavaDoc;
11 import java.util.HashMap JavaDoc;
12
13 import org.apache.commons.digester.Digester;
14 import org.xml.sax.SAXException JavaDoc;
15
16 /**
17  * Tld test looking for non implemented and duplicate attributes.
18  * @version 1.0
19  * @author
20  */

21 public class TLDTest {
22     private Class JavaDoc tagClass;
23     private HashMap JavaDoc attributes;
24
25     public TLDTest() {
26         attributes = new HashMap JavaDoc();
27     }
28
29     public static void main(String JavaDoc[] args) {
30         File JavaDoc lc_file = new File JavaDoc("c:\\java\\eclipse\\workspace\\Improve Struts-Layout\\src\\library\\struts-layout.tld");
31         Digester lc_digester = new Digester();
32         lc_digester.addObjectCreate("taglib/tag", "fr.improve.struts.taglib.layout.test.TLDTest");
33         lc_digester.addCallMethod("taglib/tag/tagclass", "setTagClassName", 0);
34         lc_digester.addCallMethod("taglib/tag/attribute/name","setAttribute",0);
35         try {
36             lc_digester.parse(lc_file);
37         } catch (IOException JavaDoc e) {
38             System.err.println(e);
39         } catch (SAXException JavaDoc e) {
40             System.err.println(e);
41         }
42     }
43
44     public void setTagClassName(String JavaDoc in_name) {
45         try {
46             tagClass = Class.forName(in_name);
47         } catch (ClassNotFoundException JavaDoc cnfe) {
48             System.err.println("Class not found: " + in_name);
49             System.exit(1);
50         }
51         attributes.clear();
52     }
53
54     public void setAttribute(String JavaDoc in_attribute) {
55         // check for double definition
56
String JavaDoc lc_attribute = (String JavaDoc) attributes.get(in_attribute);
57         if (lc_attribute != null) {
58             System.err.println(
59                 "The attribute "
60                     + in_attribute
61                     + " is defined more than once for the class "
62                     + tagClass.getName());
63         } else
64             try {
65                 // check for attribute setter.
66
PropertyDescriptor JavaDoc lc_propertyDescriptor =
67                     new PropertyDescriptor JavaDoc(in_attribute, tagClass);
68                 if (lc_propertyDescriptor.getWriteMethod() == null) {
69                     System.err.println(
70                         "The setter mothod of the attribute "
71                             + in_attribute
72                             + " in the class "
73                             + tagClass.getName()
74                             + " is not implemented.");
75                 }
76             } catch (IntrospectionException JavaDoc ie) {
77                 System.err.println(
78                     "Introspection exception looking for the attribute "
79                         + in_attribute
80                         + " in the class "
81                         + tagClass.getName() + ie.getMessage());
82             }
83     }
84 }
Popular Tags