|
|||||||||||||||||||
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 | |||||||||||||||
InjectScriptWorker.java | - | 100% | 100% | 100% |
|
1 |
// Copyright 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.enhance;
|
|
16 |
|
|
17 |
import java.lang.reflect.Modifier;
|
|
18 |
|
|
19 |
import org.apache.hivemind.Resource;
|
|
20 |
import org.apache.hivemind.service.MethodSignature;
|
|
21 |
import org.apache.tapestry.IScript;
|
|
22 |
import org.apache.tapestry.engine.IScriptSource;
|
|
23 |
import org.apache.tapestry.spec.InjectSpecification;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* Injects {@link org.apache.tapestry.IScript} instances directly into pages or components.
|
|
27 |
*
|
|
28 |
* @author Howard M. Lewis Ship
|
|
29 |
* @since 4.0
|
|
30 |
*/
|
|
31 |
public class InjectScriptWorker implements InjectEnhancementWorker |
|
32 |
{ |
|
33 |
private IScriptSource _source;
|
|
34 |
|
|
35 | 1 |
public void performEnhancement(EnhancementOperation op, InjectSpecification spec) |
36 |
{ |
|
37 | 1 |
String propertyName = spec.getProperty(); |
38 |
|
|
39 | 1 |
op.claimProperty(propertyName); |
40 |
|
|
41 | 1 |
Class propertyType = EnhanceUtils.verifyPropertyType(op, propertyName, IScript.class);
|
42 |
|
|
43 |
// PropertyType will likely be either java.lang.Object or IScript
|
|
44 |
|
|
45 | 1 |
String methodName = op.getAccessorMethodName(propertyName); |
46 |
|
|
47 | 1 |
Resource resource = spec.getLocation().getResource().getRelativeResource(spec.getObject()); |
48 |
|
|
49 | 1 |
DeferredScript script = new DeferredScriptImpl(resource, _source, spec.getLocation());
|
50 |
|
|
51 | 1 |
String fieldName = op.addInjectedField("_$script", script);
|
52 |
|
|
53 | 1 |
MethodSignature sig = new MethodSignature(propertyType, methodName, null, null); |
54 |
|
|
55 | 1 |
op.addMethod(Modifier.PUBLIC, sig, "return " + fieldName + ".getScript();"); |
56 |
} |
|
57 |
|
|
58 | 1 |
public void setSource(IScriptSource source) |
59 |
{ |
|
60 | 1 |
_source = source; |
61 |
} |
|
62 |
} |
|
63 |
|
|