Clover coverage report - Code Coverage for tapestry release 4.0-rc-2
Coverage timestamp: Sat Dec 17 2005 09:39:46 PST
file stats: LOC: 75   Methods: 3
NCLOC: 42   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
InputSymbolRule.java 100% 92.9% 100% 94.7%
coverage coverage
 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 <input-symbol>
 27    * element.
 28    *
 29    * @author Howard Lewis Ship
 30    * @since 3.0
 31    */
 32    class InputSymbolRule extends BaseRule
 33    {
 34    private ClassResolver _resolver;
 35   
 36  16 public InputSymbolRule(ClassResolver resolver)
 37    {
 38  16 _resolver = resolver;
 39    }
 40   
 41  4 public void startElement(RuleDirectedParser parser, Attributes attributes)
 42    {
 43  4 String key = getAttribute(attributes, "key");
 44   
 45  4 parser.validate(key, Tapestry.SIMPLE_PROPERTY_NAME_PATTERN, "ScriptParser.invalid-key");
 46   
 47  4 String className = getAttribute(attributes, "class");
 48  4 Class expectedClass = lookupClass(parser, className);
 49   
 50  4 String required = getAttribute(attributes, "required");
 51   
 52  4 InputSymbolToken token = new InputSymbolToken(key, expectedClass, required.equals("yes"),
 53    parser.getLocation());
 54   
 55  4 IScriptToken parent = (IScriptToken) parser.peek();
 56  4 parent.addToken(token);
 57    }
 58   
 59  4 private Class lookupClass(RuleDirectedParser parser, String className)
 60    {
 61  4 if (HiveMind.isBlank(className))
 62  1 return null;
 63   
 64  3 try
 65    {
 66  3 return _resolver.findClass(className);
 67    }
 68    catch (Exception ex)
 69    {
 70  0 throw new DocumentParseException(Tapestry.format(
 71    "ScriptParser.unable-to-resolve-class",
 72    className), parser.getLocation(), ex);
 73    }
 74    }
 75    }