1 16 17 package org.apache.commons.jelly.tags.define; 18 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import org.apache.commons.beanutils.DynaClass; 23 import org.apache.commons.jelly.JellyTagException; 24 import org.apache.commons.jelly.MissingAttributeException; 25 import org.apache.commons.jelly.Tag; 26 import org.apache.commons.jelly.XMLOutput; 27 import org.apache.commons.jelly.impl.Attribute; 28 import org.apache.commons.jelly.impl.DynamicDynaBeanTag; 29 import org.apache.commons.jelly.impl.TagFactory; 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 import org.xml.sax.Attributes ; 33 34 41 public class DynaBeanTag extends DefineTagSupport { 42 43 44 private static final Log log = LogFactory.getLog(DynaBeanTag.class); 45 46 47 private static final Map EMPTY_MAP = new HashMap (); 48 49 50 private String name; 51 52 53 private DynaClass dynaClass; 54 55 56 private String varAttribute = "var"; 57 58 59 private Map attributes; 60 61 64 public void addAttribute(Attribute attribute) { 65 if ( attributes == null ) { 66 attributes = new HashMap (); 67 } 68 attributes.put( attribute.getName(), attribute ); 69 } 70 71 public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException { 74 invokeBody(output); 75 76 if (name == null) { 77 throw new MissingAttributeException("name"); 78 } 79 if (dynaClass == null) { 80 throw new MissingAttributeException("dynaClass"); 81 } 82 83 final DynaClass theDynaClass = dynaClass; 84 final Map beanAttributes = (attributes != null) ? attributes : EMPTY_MAP; 85 86 TagFactory factory = new TagFactory() { 87 public Tag createTag(String name, Attributes attributes) { 88 return new DynamicDynaBeanTag(theDynaClass, beanAttributes, varAttribute); 89 } 90 }; 91 getTagLibrary().registerBeanTag(name, factory); 92 93 attributes = null; 95 } 96 97 98 101 104 public void setName(String name) { 105 this.name = name; 106 } 107 108 113 public void setVarAttribute(String varAttribute) { 114 this.varAttribute = varAttribute; 115 } 116 117 121 public DynaClass getDynaClass() { 122 return dynaClass; 123 } 124 125 128 public void setDynaClass(DynaClass dynaClass) { 129 this.dynaClass = dynaClass; 130 } 131 132 } 133 | Popular Tags |