| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| org.apache.commons.jelly.tags.dynabean.DynabeanTag |
|
|
| 1 | /* |
|
| 2 | * Copyright 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.dynabean; |
|
| 17 | ||
| 18 | import org.apache.commons.beanutils.DynaBean; |
|
| 19 | import org.apache.commons.beanutils.DynaClass; |
|
| 20 | import org.apache.commons.jelly.JellyTagException; |
|
| 21 | import org.apache.commons.jelly.MissingAttributeException; |
|
| 22 | import org.apache.commons.jelly.TagSupport; |
|
| 23 | import org.apache.commons.jelly.XMLOutput; |
|
| 24 | ||
| 25 | ||
| 26 | /** A tag which conditionally evaluates its body based on some condition |
|
| 27 | * |
|
| 28 | * @author Theo Niemeijer |
|
| 29 | * @version $Revision: 155420 $ |
|
| 30 | */ |
|
| 31 | public class DynabeanTag extends TagSupport { |
|
| 32 | ||
| 33 | private DynaClass dynaClass; |
|
| 34 | private String var; |
|
| 35 | ||
| 36 | 9 | public DynabeanTag() { |
| 37 | 9 | } |
| 38 | ||
| 39 | // Tag interface |
|
| 40 | //------------------------------------------------------------------------- |
|
| 41 | public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException { |
|
| 42 | ||
| 43 | 9 | if (dynaClass == null) { |
| 44 | 0 | throw new MissingAttributeException( "dynaclass" ); |
| 45 | } |
|
| 46 | ||
| 47 | 9 | if (var == null) { |
| 48 | 0 | throw new MissingAttributeException( "var" ); |
| 49 | } |
|
| 50 | ||
| 51 | try { |
|
| 52 | // Create dynabean instance for this dynaclass |
|
| 53 | 9 | DynaBean dynaBean = dynaClass.newInstance(); |
| 54 | ||
| 55 | // Place new dynabean in context as a variable |
|
| 56 | 9 | context.setVariable(getVar(), dynaBean); |
| 57 | 0 | } catch (IllegalAccessException e) { |
| 58 | 0 | throw new JellyTagException(e); |
| 59 | 0 | } catch (InstantiationException e) { |
| 60 | 0 | throw new JellyTagException(e); |
| 61 | 9 | } |
| 62 | 9 | } |
| 63 | ||
| 64 | // Properties |
|
| 65 | //------------------------------------------------------------------------- |
|
| 66 | ||
| 67 | /** |
|
| 68 | * Sets the DynaClass of the new instance to create |
|
| 69 | */ |
|
| 70 | public void setDynaclass(DynaClass dynaClass) { |
|
| 71 | 9 | this.dynaClass = dynaClass; |
| 72 | 9 | } |
| 73 | ||
| 74 | public String getVar() { |
|
| 75 | 9 | return var; |
| 76 | } |
|
| 77 | ||
| 78 | /** |
|
| 79 | * Sets the name of the variable to export the new DynaBean instance to |
|
| 80 | */ |
|
| 81 | public void setVar(String var) { |
|
| 82 | 9 | this.var = class="keyword">var; |
| 83 | 9 | } |
| 84 | ||
| 85 | ||
| 86 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |