001 /* 002 * Copyright 2002-2004 The Apache Software Foundation 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.apache.commons.clazz.bean; 017 018 import org.apache.commons.clazz.Clazz; 019 import org.apache.commons.clazz.ClazzProperty; 020 import org.apache.commons.clazz.common.ClazzFeatureSupport; 021 022 /** 023 * 024 * @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a> 025 * @version $Id: BeanClazzProperty.java 155436 2005-02-26 13:17:48Z dirkv $ 026 */ 027 public class BeanClazzProperty extends ClazzFeatureSupport 028 implements ClazzProperty 029 { 030 031 private String name; 032 private String clazzName; 033 private String type; 034 private Clazz clazz; 035 036 public BeanClazzProperty(Clazz declaringClazz, String name) { 037 this(declaringClazz, name, Object.class.getName()); 038 } 039 040 public BeanClazzProperty(Clazz declaringClazz, String name, String type) { 041 super(declaringClazz); 042 this.name = name; 043 this.clazzName = type; 044 } 045 046 /** 047 * @see org.apache.commons.clazz.ClazzProperty#getName() 048 */ 049 public String getName() { 050 return name; 051 } 052 053 /** 054 * @see org.apache.commons.clazz.ClazzProperty#getClazz() 055 */ 056 public Clazz getClazz() { 057 if (clazz == null) { 058 clazz = 059 getDeclaringClazz().getClazzLoader().getClazzForName(clazzName); 060 } 061 return clazz; 062 } 063 064 /** 065 * Returns true if the property is a collection. 066 */ 067 public boolean isCollection() { 068 return false; 069 } 070 071 /** 072 * Returns true if the property is a map. 073 */ 074 public boolean isMap() { 075 return false; 076 } 077 078 /** 079 * @see org.apache.commons.clazz.ClazzProperty#getContentClazz() 080 */ 081 public Clazz getContentClazz() { 082 return null; 083 } 084 085 /** 086 * @see org.apache.commons.clazz.ClazzProperty#getKeyClazz() 087 */ 088 public Clazz getKeyClazz() { 089 return null; 090 } 091 092 /** 093 * @see org.apache.commons.clazz.ClazzProperty#isReadOnly() 094 */ 095 public boolean isReadOnly() { 096 return false; 097 } 098 099 /** 100 * @see org.apache.commons.clazz.ClazzProperty#get(java.lang.Object) 101 */ 102 public Object get(Object instance) { 103 return ((Bean) instance).get(getName()); 104 } 105 106 /** 107 * @see org.apache.commons.clazz.ClazzProperty#set(Object, Object) 108 */ 109 public void set(Object instance, Object value) { 110 ((Bean) instance).set(getName(), value); 111 } 112 113 }