01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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.internal.bindings;
16:
17: import org.apache.tapestry.Binding;
18: import org.apache.tapestry.ComponentResources;
19: import org.apache.tapestry.PropertyConduit;
20: import org.apache.tapestry.ioc.Location;
21: import org.apache.tapestry.ioc.internal.util.TapestryException;
22: import org.apache.tapestry.services.BindingFactory;
23: import org.apache.tapestry.services.PropertyConduitSource;
24:
25: /**
26: * Binding factory for reading and updating JavaBean properties.
27: * <p>
28: * Expression are evaluated via a {@link PropertyConduit}, which is generated by
29: * {@link PropertyConduitSource} (which therefore defines the expression language).
30: */
31: public class PropBindingFactory implements BindingFactory {
32: private final PropertyConduitSource _source;
33:
34: public PropBindingFactory(
35: PropertyConduitSource propertyConduitSource) {
36: _source = propertyConduitSource;
37: }
38:
39: public Binding newBinding(String description,
40: ComponentResources container, ComponentResources component,
41: String expression, Location location) {
42: Object target = container.getComponent();
43: Class targetClass = target.getClass();
44:
45: try {
46: PropertyConduit conduit = _source.create(targetClass,
47: expression);
48:
49: String toString = String.format("PropBinding[%s %s(%s)]",
50: description, container.getCompleteId(), expression);
51:
52: return new PropBinding(target, conduit, toString, location);
53: } catch (Throwable ex) {
54: throw new TapestryException(ex.getMessage(), location, ex);
55: }
56: }
57: }
|