Coverage Report - org.apache.tapestry.script.InputSymbolRule
 
Classes in this File Line Coverage Branch Coverage Complexity
InputSymbolRule
0%
0/16
0%
0/2
2.667
 
 1  
 // Copyright 2004, 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 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  
 /**
 26  
  * Constructs an {@link org.apache.tapestry.script.InputSymbolToken}from an
 27  
  * <input-symbol> element.
 28  
  * 
 29  
  * @author Howard Lewis Ship
 30  
  * @since 3.0
 31  
  */
 32  
 class InputSymbolRule extends BaseRule
 33  
 {
 34  
 
 35  
     private ClassResolver _resolver;
 36  
 
 37  
     public InputSymbolRule(ClassResolver resolver)
 38  0
     {
 39  0
         _resolver = resolver;
 40  0
     }
 41  
 
 42  
     public void startElement(RuleDirectedParser parser, Attributes attributes)
 43  
     {
 44  0
         String key = getAttribute(attributes, "key");
 45  
 
 46  0
         parser.validate(key, Tapestry.SIMPLE_PROPERTY_NAME_PATTERN,
 47  
                 "ScriptParser.invalid-key");
 48  
 
 49  0
         String className = getAttribute(attributes, "class");
 50  0
         Class expectedClass = lookupClass(parser, className);
 51  
 
 52  0
         String required = getAttribute(attributes, "required");
 53  
 
 54  0
         InputSymbolToken token = new InputSymbolToken(key, expectedClass,
 55  
                 required.equals("yes"), parser.getLocation());
 56  
 
 57  0
         IScriptToken parent = (IScriptToken) parser.peek();
 58  0
         parent.addToken(token);
 59  0
     }
 60  
 
 61  
     private Class lookupClass(RuleDirectedParser parser, String className)
 62  
     {
 63  0
         if (HiveMind.isBlank(className)) return null;
 64  
 
 65  
         try
 66  
         {
 67  0
             return _resolver.findClass(className);
 68  
         }
 69  0
         catch (Exception ex)
 70  
         {
 71  0
             throw new DocumentParseException(Tapestry.format(
 72  
                     "ScriptParser.unable-to-resolve-class", className), parser
 73  
                     .getLocation(), ex);
 74  
         }
 75  
     }
 76  
 }