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 package org.apache.tapestry.enhance; 015 016 import java.beans.BeanInfo; 017 import java.beans.Introspector; 018 import java.beans.PropertyDescriptor; 019 import java.lang.reflect.Method; 020 021 import org.apache.hivemind.ApplicationRuntimeException; 022 023 024 /** 025 * Implemenation of {@link ClassInspector} that is compatible with 026 * 1.4 jres. 027 */ 028 public class ClassInspectorImpl implements ClassInspector 029 { 030 031 /** 032 * {@inheritDoc} 033 */ 034 public MethodSignature getMethodSignature(Class implementing, Method m) 035 { 036 return new MethodSignatureImpl(m); 037 } 038 039 /** 040 * {@inheritDoc} 041 */ 042 public MethodSignature getPropertyAccessor(Class type, String propertyName) 043 { 044 try { 045 BeanInfo info = Introspector.getBeanInfo(type); 046 PropertyDescriptor[] props = info.getPropertyDescriptors(); 047 048 for (int i=0; i < props.length; i++) { 049 050 if (!propertyName.equals(props[i].getName())) { 051 continue; 052 } 053 054 return new MethodSignatureImpl(props[i].getReadMethod() != null ? props[i].getReadMethod() : props[i].getWriteMethod()); 055 } 056 057 } catch (Throwable t) { 058 059 throw new ApplicationRuntimeException("Error reading property " + propertyName + " from base class : " + type, t); 060 } 061 062 return null; 063 } 064 065 }