001// Licensed under the Apache License, Version 2.0 (the "License"); 002// you may not use this file except in compliance with the License. 003// You may obtain a copy of the License at 004// 005// http://www.apache.org/licenses/LICENSE-2.0 006// 007// Unless required by applicable law or agreed to in writing, software 008// distributed under the License is distributed on an "AS IS" BASIS, 009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 010// See the License for the specific language governing permissions and 011// limitations under the License. 012 013package org.apache.tapestry5.internal.bindings; 014 015import org.apache.tapestry5.Asset; 016import org.apache.tapestry5.Binding; 017import org.apache.tapestry5.ComponentResources; 018import org.apache.tapestry5.commons.Location; 019import org.apache.tapestry5.services.AssetSource; 020import org.apache.tapestry5.services.BindingFactory; 021 022/** 023 * Binding factory where the expression is a reference to an asset. 024 * 025 * @see org.apache.tapestry5.services.AssetSource 026 * @see org.apache.tapestry5.internal.bindings.ContextBindingFactory 027 */ 028public class AssetBindingFactory implements BindingFactory 029{ 030 private final AssetSource source; 031 032 public AssetBindingFactory(AssetSource source) 033 { 034 this.source = source; 035 } 036 037 public Binding newBinding(String description, ComponentResources container, ComponentResources component, 038 String expression, Location location) 039 { 040 // There's some possibility this isn't quite right when it appears in a base class and a 041 // sub-class gets instantiated, because relative path for the asset should be relative to the 042 // base class, but will instead by relative to the subclass. 043 044 Asset asset = source.getComponentAsset(container, expression, container.getComponentModel().getLibraryName()); 045 046 return new AssetBinding(location, description, asset); 047 } 048}