| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| org.apache.commons.jelly.tags.define.ExtendTag |
|
|
| 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 | 9 | public ExtendTag() { |
| 39 | 9 | } |
| 40 | ||
| 41 | // Tag interface |
|
| 42 | //------------------------------------------------------------------------- |
|
| 43 | public void doTag(XMLOutput output) throws JellyTagException { |
|
| 44 | 9 | DynamicTagLibrary library = getTagLibrary(); |
| 45 | 9 | DynamicTagLibrary owner = library.find(getName()); |
| 46 | 9 | if (owner == null) { |
| 47 | 0 | throw new JellyTagException( |
| 48 | "Cannot extend " + getName() + ": dynamic tag not defined"); |
|
| 49 | } |
|
| 50 | 9 | if (owner == library) { |
| 51 | // disallow extension of tags defined within the same tag |
|
| 52 | // library |
|
| 53 | 0 | throw new JellyTagException("Cannot extend " + getName() + |
| 54 | ": dynamic tag defined locally"); |
|
| 55 | } |
|
| 56 | 9 | superScript = owner.getDynamicTag(name); |
| 57 | 9 | if (superScript == null) { |
| 58 | // tag doesn't define a script - disallow this for the moment. |
|
| 59 | 0 | throw new JellyTagException("Cannot extend " + getName() + |
| 60 | ": tag is not a dynamic tag"); |
|
| 61 | } |
|
| 62 | ||
| 63 | 9 | owner.registerDynamicTag(getName() , getBody()); |
| 64 | 9 | } |
| 65 | ||
| 66 | // Properties |
|
| 67 | //------------------------------------------------------------------------- |
|
| 68 | ||
| 69 | /** |
|
| 70 | * @return the name of the tag to create |
|
| 71 | */ |
|
| 72 | public String getName() { |
|
| 73 | 18 | return name; |
| 74 | } |
|
| 75 | ||
| 76 | /** |
|
| 77 | * Sets the name of the tag to create |
|
| 78 | */ |
|
| 79 | public void setName(String name) { |
|
| 80 | 9 | this.name = name; |
| 81 | 9 | } |
| 82 | ||
| 83 | /** |
|
| 84 | * Returns the parent implementation of this tag |
|
| 85 | */ |
|
| 86 | public Script getSuperScript() { |
|
| 87 | 9 | return superScript; |
| 88 | } |
|
| 89 | } |
|
| 90 |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |