1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.impl;
17
18 import org.apache.commons.jelly.JellyException;
19 import org.apache.commons.jelly.Tag;
20
21 import org.xml.sax.Attributes;
22
23 /***
24 * <p><code>DefaultTagFactory</code> a default implementation of TagFactory
25 * which creates new instances of a given class.
26 *
27 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
28 * @version $Revision: 155420 $
29 */
30 public class DefaultTagFactory implements TagFactory {
31
32 private Class tagClass;
33
34 public DefaultTagFactory() {
35 }
36
37 public DefaultTagFactory(Class tagClass) {
38 this.tagClass = tagClass;
39 }
40
41
42
43 public Tag createTag(String name, Attributes attributes) throws JellyException {
44 try {
45 return (Tag) tagClass.newInstance();
46 } catch (InstantiationException e) {
47 throw new JellyException(e.toString());
48 } catch (IllegalAccessException e) {
49 throw new JellyException(e.toString());
50 }
51 }
52
53
54
55
56
57 /***
58 * Returns the tagClass.
59 * @return Class
60 */
61 public Class getTagClass() {
62 return tagClass;
63 }
64
65 /***
66 * Sets the tagClass.
67 * @param tagClass The tagClass to set
68 */
69 public void setTagClass(Class tagClass) {
70 this.tagClass = tagClass;
71 }
72
73 }