1 16 package org.apache.commons.jelly.tags.core; 17 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 import java.util.Map ; 22 23 import org.apache.commons.jelly.JellyTagException; 24 import org.apache.commons.jelly.expression.Expression; 25 import org.apache.commons.jelly.impl.CollectionTag; 26 27 37 public class UseListTag extends UseBeanTag implements CollectionTag { 38 39 private Expression items; 40 41 public UseListTag(){ 42 } 43 44 public List getList() { 45 return (List ) getBean(); 46 } 47 48 49 public void addItem(Object value) { 52 getList().add(value); 53 } 54 55 public Class getAttributeType(String name) throws JellyTagException { 58 if (name.equals("items")) { 59 return Expression.class; 60 } 61 return super.getAttributeType(name); 62 } 63 64 65 68 protected void setBeanProperties(Object bean, Map attributes) throws JellyTagException { 69 items = (Expression) attributes.remove("items"); 70 super.setBeanProperties(bean, attributes); 71 } 72 73 protected void processBean(String var, Object bean) throws JellyTagException { 74 super.processBean(var, bean); 75 76 List list = getList(); 77 78 if (items != null) { 80 Iterator iter = items.evaluateAsIterator(context); 81 while (iter.hasNext()) { 82 list.add( iter.next() ); 83 } 84 } 85 } 86 87 protected Class getDefaultClass() { 88 return ArrayList .class; 89 } 90 } 91 | Popular Tags |