1 15 package org.apache.tapestry.script; 16 17 import org.apache.hivemind.ClassResolver; 18 import org.apache.hivemind.HiveMind; 19 import org.apache.tapestry.Tapestry; 20 import org.apache.tapestry.util.xml.BaseRule; 21 import org.apache.tapestry.util.xml.DocumentParseException; 22 import org.apache.tapestry.util.xml.RuleDirectedParser; 23 import org.xml.sax.Attributes ; 24 25 32 class InputSymbolRule extends BaseRule 33 { 34 private ClassResolver _resolver; 35 36 public InputSymbolRule(ClassResolver resolver) 37 { 38 _resolver = resolver; 39 } 40 41 public void startElement(RuleDirectedParser parser, Attributes attributes) 42 { 43 String key = getAttribute(attributes, "key"); 44 45 parser.validate(key, Tapestry.SIMPLE_PROPERTY_NAME_PATTERN, "ScriptParser.invalid-key"); 46 47 String className = getAttribute(attributes, "class"); 48 Class expectedClass = lookupClass(parser, className); 49 50 String required = getAttribute(attributes, "required"); 51 52 InputSymbolToken token = new InputSymbolToken(key, expectedClass, required.equals("yes"), 53 parser.getLocation()); 54 55 IScriptToken parent = (IScriptToken) parser.peek(); 56 parent.addToken(token); 57 } 58 59 private Class lookupClass(RuleDirectedParser parser, String className) 60 { 61 if (HiveMind.isBlank(className)) 62 return null; 63 64 try 65 { 66 return _resolver.findClass(className); 67 } 68 catch (Exception ex) 69 { 70 throw new DocumentParseException(Tapestry.format( 71 "ScriptParser.unable-to-resolve-class", 72 className), parser.getLocation(), ex); 73 } 74 } 75 } | Popular Tags |