001 // Copyright 2004, 2005 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.tapestry.services.impl; 016 017 import org.apache.hivemind.ApplicationRuntimeException; 018 import org.apache.hivemind.Location; 019 import org.apache.hivemind.internal.Module; 020 import org.apache.hivemind.service.ObjectProvider; 021 import org.apache.tapestry.engine.IPropertySource; 022 023 /** 024 * An implementation of {@link org.apache.hivemind.service.ObjectProvider} 025 * that gets the actual value from the 026 * <code>tapestry.GlobalPropertySource</code> service. 027 * 028 * @author Howard Lewis Ship 029 * @since 4.0 030 */ 031 public class PropertyObjectProvider implements ObjectProvider 032 { 033 private IPropertySource _source; 034 035 /** 036 * Gets the value; the locator is the key passed to 037 * {@link IPropertySource#getPropertyValue(String)}. 038 */ 039 public Object provideObject( 040 Module contributingModule, 041 Class propertyType, 042 String locator, 043 Location location) 044 { 045 try 046 { 047 return _source.getPropertyValue(locator); 048 } 049 catch (Exception ex) 050 { 051 throw new ApplicationRuntimeException(ex.getMessage(), location, ex); 052 } 053 } 054 055 public void setSource(IPropertySource source) 056 { 057 _source = source; 058 } 059 060 }