001 // Copyright 2008, 2009, 2011 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.ComponentResources; 018 import org.apache.tapestry5.ioc.Location; 019 020 public class RenderVariableBinding extends AbstractBinding 021 { 022 private final String description; 023 private final ComponentResources resources; 024 private final String name; 025 026 public RenderVariableBinding(Location location, String description, ComponentResources resources, String name) 027 { 028 super(location); 029 030 this.description = description; 031 this.resources = resources; 032 this.name = name; 033 } 034 035 @Override 036 public void set(Object value) 037 { 038 resources.storeRenderVariable(name, value); 039 } 040 041 /** 042 * Returns false, render variables are always variable. 043 */ 044 @Override 045 public boolean isInvariant() 046 { 047 return false; 048 } 049 050 @Override 051 public String toString() 052 { 053 return String.format("RenderVariable[%s %s]", description, name); 054 } 055 056 public Object get() 057 { 058 return resources.getRenderVariable(name); 059 } 060 061 /** 062 * Always returns Object since we don't (statically) know the type of object. 063 */ 064 @Override 065 public Class getBindingType() 066 { 067 return Object.class; 068 } 069 }