1 7 package org.ejtools.jmx.browser.web.taglib; 8 9 import java.util.ArrayList ; 10 import java.util.Arrays ; 11 import java.util.Collection ; 12 import java.util.List ; 13 14 import javax.servlet.jsp.JspException ; 15 import javax.servlet.jsp.tagext.TagSupport ; 16 17 import org.apache.struts.util.RequestUtils; 18 import org.ejtools.jmx.MBeanSorter; 19 20 28 public class MBeanSortTag extends TagSupport 29 { 30 31 protected String id = null; 32 33 protected String name = null; 34 35 protected String property = null; 36 37 protected String scope = null; 38 39 40 46 public int doStartTag() 47 throws JspException 48 { 49 Object object = null; 50 51 if (property != null) 53 { 54 object = RequestUtils.lookup(pageContext, name, property, scope); 55 } 56 else 57 { 58 object = RequestUtils.lookup(pageContext, name, scope); 59 } 60 61 if (object == null) 62 { 63 throw new JspException ("Unable to find bean " + name + " or its property " + property); 64 } 65 66 List content = null; 67 if (object.getClass().isArray()) 68 { 69 content = Arrays.asList((Object []) object); 70 MBeanSorter.sortByName(content); 71 } 72 else 73 { 74 if (object instanceof Collection ) 75 { 76 content = new ArrayList ((Collection ) object); 77 } 78 if (object instanceof List ) 79 { 80 content = (List ) object; 81 } 82 if (content != null) 83 { 84 MBeanSorter.sortByName(content); 85 } 86 } 87 88 if (content != null) 90 { 91 pageContext.setAttribute(id, content); 92 } 93 else 94 { 95 throw new JspException ("Cannot sort input " + object); 96 } 97 98 return (SKIP_BODY); 100 } 101 102 103 109 public String getId() 110 { 111 return (this.id); 112 } 113 114 115 121 public String getName() 122 { 123 return (this.name); 124 } 125 126 127 133 public String getProperty() 134 { 135 return (this.property); 136 } 137 138 139 145 public String getScope() 146 { 147 return (this.scope); 148 } 149 150 151 152 public void release() 153 { 154 super.release(); 155 id = null; 156 name = null; 157 property = null; 158 scope = null; 159 } 160 161 162 167 public void setId(String id) 168 { 169 this.id = id; 170 } 171 172 173 178 public void setName(String name) 179 { 180 this.name = name; 181 } 182 183 184 189 public void setProperty(String property) 190 { 191 this.property = property; 192 } 193 194 195 200 public void setScope(String scope) 201 { 202 this.scope = scope; 203 } 204 } 205 206 | Popular Tags |