|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
InputSymbolRule.java | 100% | 92.9% | 100% | 94.7% |
|
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 | 18 |
public InputSymbolRule(ClassResolver resolver)
|
37 |
{ |
|
38 | 18 |
_resolver = resolver; |
39 |
} |
|
40 |
|
|
41 | 15 |
public void startElement(RuleDirectedParser parser, Attributes attributes) |
42 |
{ |
|
43 | 15 |
String key = getAttribute(attributes, "key");
|
44 |
|
|
45 | 15 |
parser.validate(key, Tapestry.SIMPLE_PROPERTY_NAME_PATTERN, "ScriptParser.invalid-key");
|
46 |
|
|
47 | 15 |
String className = getAttribute(attributes, "class");
|
48 | 15 |
Class expectedClass = lookupClass(parser, className); |
49 |
|
|
50 | 15 |
String required = getAttribute(attributes, "required");
|
51 |
|
|
52 | 15 |
InputSymbolToken token = new InputSymbolToken(key, expectedClass, required.equals("yes"), |
53 |
parser.getLocation()); |
|
54 |
|
|
55 | 15 |
IScriptToken parent = (IScriptToken) parser.peek(); |
56 | 15 |
parent.addToken(token); |
57 |
} |
|
58 |
|
|
59 | 15 |
private Class lookupClass(RuleDirectedParser parser, String className)
|
60 |
{ |
|
61 | 15 |
if (HiveMind.isBlank(className))
|
62 | 1 |
return null; |
63 |
|
|
64 | 14 |
try
|
65 |
{ |
|
66 | 14 |
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 |
} |
|