1 16 package org.apache.commons.jelly.tags.core; 17 18 import org.apache.commons.jelly.JellyContext; 19 import org.apache.commons.jelly.JellyTagException; 20 import org.apache.commons.jelly.MissingAttributeException; 21 import org.apache.commons.jelly.TagSupport; 22 import org.apache.commons.jelly.XMLOutput; 23 import org.apache.commons.jelly.util.ClassLoaderUtils; 24 25 26 43 44 public class GetStaticTag extends TagSupport { 45 46 47 private String var; 48 49 50 private String field; 51 52 53 private String className; 54 55 56 61 62 public void setVar(String var) { 63 this.var = var; 64 } 65 66 67 72 73 public void setField(String field) { 74 this.field = field; 75 } 76 77 78 83 84 public void setClassName(String className) { 85 this.className = className; 86 } 87 88 89 92 public void doTag(XMLOutput output) throws JellyTagException { 93 String message = null; 94 95 if(var == null) 96 message = "var"; 97 else if(field == null) 98 message = "field"; 99 else if(className == null) 100 message = "className"; 101 102 if(message != null) 103 throw new MissingAttributeException(message); 104 105 try { 106 Class type = ClassLoaderUtils.getClassLoader(getClass()).loadClass(className); 107 Object result = type.getField(field).get(null); 108 JellyContext context = getContext(); 109 110 context.setVariable(var, result); 111 112 } catch(Throwable t) { 113 throw 114 new JellyTagException("Could not access " + className + "." + 115 var + ". Original exception message: " + 116 t.getMessage(), t); 117 } 118 } 119 120 } 121 122 123 130 | Popular Tags |