View Javadoc

1   /*
2    * Copyright 1999-2002,2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
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.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      // Tag interface
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              // disallow extension of tags defined within the same tag
52              // library
53              throw new JellyTagException("Cannot extend " + getName() +
54                                       ": dynamic tag defined locally");
55          }
56          superScript = owner.getDynamicTag(name);
57          if (superScript == null) {
58              // tag doesn't define a script - disallow this for the moment.
59              throw new JellyTagException("Cannot extend " + getName() +
60                                       ": tag is not a dynamic tag");
61          }
62  
63          owner.registerDynamicTag(getName() , getBody());
64      }
65  
66      // Properties
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