001 // Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry5.internal.bindings;
016
017 import org.apache.tapestry5.Binding;
018 import org.apache.tapestry5.ComponentResources;
019 import org.apache.tapestry5.PropertyConduit;
020 import org.apache.tapestry5.internal.services.StringInterner;
021 import org.apache.tapestry5.ioc.Location;
022 import org.apache.tapestry5.services.BindingFactory;
023 import org.apache.tapestry5.services.PropertyConduitSource;
024
025 /**
026 * Binding factory for reading and updating JavaBean properties.
027 * <p/>
028 * Expression are evaluated via a {@link PropertyConduit}, which is generated by {@link PropertyConduitSource} (which
029 * therefore defines the expression language).
030 */
031 public class PropBindingFactory implements BindingFactory
032 {
033 private final PropertyConduitSource source;
034
035 private final StringInterner interner;
036
037 public PropBindingFactory(PropertyConduitSource propertyConduitSource, StringInterner interner)
038 {
039 source = propertyConduitSource;
040 this.interner = interner;
041 }
042
043 public Binding newBinding(String description, ComponentResources container,
044 ComponentResources component, String expression, Location location)
045 {
046 Object target = container.getComponent();
047 Class targetClass = target.getClass();
048
049 PropertyConduit conduit = source.create(targetClass, expression);
050
051 String toString = interner.format("PropBinding[%s %s(%s)]", description, container
052 .getCompleteId(), expression);
053
054 return new PropBinding(location, target, conduit, toString);
055 }
056 }