|
|||||||||||||||||||
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 | |||||||||||||||
AbstractPropertyWorker.java | 100% | 100% | 100% | 100% |
|
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.enhance;
|
|
16 |
|
|
17 |
import java.util.Iterator;
|
|
18 |
|
|
19 |
import org.apache.hivemind.ErrorLog;
|
|
20 |
import org.apache.tapestry.IComponent;
|
|
21 |
import org.apache.tapestry.event.PageDetachListener;
|
|
22 |
import org.apache.tapestry.spec.IComponentSpecification;
|
|
23 |
|
|
24 |
/**
|
|
25 |
* No, this class isn't abstract ... this worker locates abstract properties in the base component
|
|
26 |
* class and provides a concrete implementation for them in the enhanced class.
|
|
27 |
*
|
|
28 |
* @author Howard M. Lewis Ship
|
|
29 |
* @since 4.0
|
|
30 |
*/
|
|
31 |
public class AbstractPropertyWorker implements EnhancementWorker |
|
32 |
{ |
|
33 |
private ErrorLog _errorLog;
|
|
34 |
|
|
35 | 526 |
public void performEnhancement(EnhancementOperation op, IComponentSpecification spec) |
36 |
{ |
|
37 | 526 |
Iterator i = op.findUnclaimedAbstractProperties().iterator(); |
38 |
|
|
39 | 526 |
while (i.hasNext())
|
40 |
{ |
|
41 | 417 |
String name = (String) i.next(); |
42 |
|
|
43 | 417 |
try
|
44 |
{ |
|
45 | 417 |
createProperty(op, name); |
46 |
} |
|
47 |
catch (Exception ex)
|
|
48 |
{ |
|
49 | 1 |
_errorLog.error( |
50 |
EnhanceMessages.errorAddingProperty(name, op.getBaseClass(), ex), |
|
51 |
spec.getLocation(), |
|
52 |
ex); |
|
53 |
} |
|
54 |
} |
|
55 |
} |
|
56 |
|
|
57 | 417 |
private void createProperty(EnhancementOperation op, String name) |
58 |
{ |
|
59 |
// This won't be null because its always for existing properties.
|
|
60 |
|
|
61 | 417 |
Class propertyType = op.getPropertyType(name); |
62 |
|
|
63 | 416 |
String fieldName = "_$" + name;
|
64 | 416 |
String defaultFieldName = fieldName + "$defaultValue";
|
65 |
|
|
66 | 416 |
op.addField(fieldName, propertyType); |
67 | 416 |
op.addField(defaultFieldName, propertyType); |
68 |
|
|
69 | 416 |
EnhanceUtils.createSimpleAccessor(op, fieldName, name, propertyType); |
70 | 416 |
EnhanceUtils.createSimpleMutator(op, fieldName, name, propertyType); |
71 |
|
|
72 |
// Copy the real attribute into the default attribute inside finish load
|
|
73 |
// (allowing a default value to be set inside finishLoad()).
|
|
74 |
|
|
75 | 416 |
op.extendMethodImplementation( |
76 |
IComponent.class,
|
|
77 |
EnhanceUtils.FINISH_LOAD_SIGNATURE, |
|
78 |
defaultFieldName + " = " + fieldName + ";"); |
|
79 |
|
|
80 |
// On page detach, restore the attribute to its default value.
|
|
81 |
|
|
82 | 416 |
op.extendMethodImplementation( |
83 |
PageDetachListener.class,
|
|
84 |
EnhanceUtils.PAGE_DETACHED_SIGNATURE, |
|
85 |
fieldName + " = " + defaultFieldName + ";"); |
|
86 |
|
|
87 |
// This is not all that necessary, but is proper.
|
|
88 |
|
|
89 | 416 |
op.claimProperty(name); |
90 |
} |
|
91 |
|
|
92 | 46 |
public void setErrorLog(ErrorLog errorLog) |
93 |
{ |
|
94 | 46 |
_errorLog = errorLog; |
95 |
} |
|
96 |
} |
|