01: /*
02: * Copyright 2002,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
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: // TagFactory interface
42: //-------------------------------------------------------------------------
43: public Tag createTag(String name, Attributes attributes)
44: throws JellyException {
45: try {
46: return (Tag) tagClass.newInstance();
47: } catch (InstantiationException e) {
48: throw new JellyException(e.toString());
49: } catch (IllegalAccessException e) {
50: throw new JellyException(e.toString());
51: }
52: }
53:
54: // Properties
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: }
|