1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.define;
17
18 import org.apache.commons.jelly.JellyTagException;
19 import org.apache.commons.jelly.Script;
20 import org.apache.commons.jelly.XMLOutput;
21 import org.apache.commons.jelly.impl.DynamicTagLibrary;
22
23 /***
24 * <extend> is used to extend a dynamic tag defined in an inherited
25 * dynamic tag library
26 * <p/>
27 *
28 * @author <a href="mailto:tima@intalio.com">Tim Anderson</a>
29 * @version $Revision: 155420 $
30 * @see SuperTag
31 */
32 public class ExtendTag extends DefineTagSupport {
33
34 private String name;
35
36 private Script superScript;
37
38 public ExtendTag() {
39 }
40
41
42
43 public void doTag(XMLOutput output) throws JellyTagException {
44 DynamicTagLibrary library = getTagLibrary();
45 DynamicTagLibrary owner = library.find(getName());
46 if (owner == null) {
47 throw new JellyTagException(
48 "Cannot extend " + getName() + ": dynamic tag not defined");
49 }
50 if (owner == library) {
51
52
53 throw new JellyTagException("Cannot extend " + getName() +
54 ": dynamic tag defined locally");
55 }
56 superScript = owner.getDynamicTag(name);
57 if (superScript == null) {
58
59 throw new JellyTagException("Cannot extend " + getName() +
60 ": tag is not a dynamic tag");
61 }
62
63 owner.registerDynamicTag(getName() , getBody());
64 }
65
66
67
68
69 /***
70 * @return the name of the tag to create
71 */
72 public String getName() {
73 return name;
74 }
75
76 /***
77 * Sets the name of the tag to create
78 */
79 public void setName(String name) {
80 this.name = name;
81 }
82
83 /***
84 * Returns the parent implementation of this tag
85 */
86 public Script getSuperScript() {
87 return superScript;
88 }
89 }
90