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.reflect.common; 017 018 import java.lang.reflect.Method; 019 020 import org.apache.commons.clazz.Clazz; 021 022 /** 023 * 024 * @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a> 025 * @version $Id: ReflectedListProperty.java 155436 2005-02-26 13:17:48Z dirkv $ 026 */ 027 public class ReflectedListProperty extends ReflectedAccessorPairProperty { 028 029 private Class contentType; 030 private Method sizeMethod; 031 private Method getMethod; 032 private Method addMethod; 033 private Method addIndexedMethod; 034 private Method setMethod; 035 private Method removeMethod; 036 private Method removeIndexedMethod; 037 038 /** 039 * Constructor for ReflectedListProperty. 040 * @param declaringClazz 041 * @param name 042 */ 043 public ReflectedListProperty(Clazz declaringClazz, String name) { 044 super(declaringClazz, name); 045 } 046 047 /** 048 * @see org.apache.commons.clazz.ClazzProperty#isCollection() 049 */ 050 public boolean isCollection() { 051 return true; 052 } 053 054 /** 055 * Returns the contentType. 056 * @return Class 057 */ 058 public Class getContentType() { 059 return contentType; 060 } 061 062 /** 063 * Sets the contentType. 064 * @param contentType The contentType to set 065 */ 066 public void setContentType(Class valueType) { 067 this.contentType = valueType; 068 } 069 070 /** 071 * Returns the getMethod. 072 * @return Method 073 */ 074 public Method getGetMethod() { 075 return getMethod; 076 } 077 078 /** 079 * Sets the getMethod. 080 * @param getMethod The getMethod to set 081 */ 082 public void setGetMethod(Method getMethod) { 083 this.getMethod = getMethod; 084 } 085 086 /** 087 * Returns the setMethod. 088 * @return Method 089 */ 090 public Method getSetMethod() { 091 return setMethod; 092 } 093 094 /** 095 * Sets the setMethod. 096 * @param setMethod The setMethod to set 097 */ 098 public void setSetMethod(Method setMethod) { 099 this.setMethod = setMethod; 100 } 101 102 /** 103 * Returns the addMethod. 104 * @return Method 105 */ 106 public Method getAddMethod() { 107 return addMethod; 108 } 109 110 /** 111 * Sets the addMethod. 112 * @param addMethod The addMethod to set 113 */ 114 public void setAddMethod(Method addMethod) { 115 this.addMethod = addMethod; 116 } 117 118 /** 119 * Returns the addIndexedMethod. 120 * @return Method 121 */ 122 public Method getAddIndexedMethod() { 123 return addIndexedMethod; 124 } 125 126 /** 127 * Sets the addIndexedMethod. 128 * @param addIndexedMethod The addIndexedMethod to set 129 */ 130 public void setAddIndexedMethod(Method addIndexedMethod) { 131 this.addIndexedMethod = addIndexedMethod; 132 } 133 134 /** 135 * Returns the removeMethod. 136 * @return Method 137 */ 138 public Method getRemoveMethod() { 139 return removeMethod; 140 } 141 142 /** 143 * Sets the removeMethod. 144 * @param removeMethod The removeMethod to set 145 */ 146 public void setRemoveMethod(Method removeMethod) { 147 this.removeMethod = removeMethod; 148 } 149 150 /** 151 * Returns the removeIndexedMethod. 152 * @return Method 153 */ 154 public Method getRemoveIndexedMethod() { 155 return removeIndexedMethod; 156 } 157 158 /** 159 * Sets the removeIndexedMethod. 160 * @param removeIndexedMethod The removeIndexedMethod to set 161 */ 162 public void setRemoveIndexedMethod(Method removeIndexedMethod) { 163 this.removeIndexedMethod = removeIndexedMethod; 164 } 165 166 /** 167 * Returns the sizeMethod. 168 * @return Method 169 */ 170 public Method getSizeMethod() { 171 return sizeMethod; 172 } 173 174 /** 175 * Sets the sizeMethod. 176 * @param sizeMethod The sizeMethod to set 177 */ 178 public void setSizeMethod(Method sizeMethod) { 179 this.sizeMethod = sizeMethod; 180 } 181 182 public String toString() { 183 StringBuffer buffer = new StringBuffer("[ReflectedListProperty "); 184 if (getType() != null) { 185 buffer.append(getType().getName()); 186 buffer.append(" "); 187 } 188 if (getContentType() != null) { 189 buffer.append("[content: "); 190 buffer.append(getContentType().getName()); 191 buffer.append("] "); 192 } 193 buffer.append(getName()); 194 if (getReadMethod() != null) { 195 buffer.append("\n [read method] "); 196 buffer.append(getReadMethod()); 197 } 198 if (getWriteMethod() != null) { 199 buffer.append("\n [write method] "); 200 buffer.append(getWriteMethod()); 201 } 202 if (getGetMethod() != null) { 203 buffer.append("\n [get method] "); 204 buffer.append(getGetMethod()); 205 } 206 if (getSetMethod() != null) { 207 buffer.append("\n [set method] "); 208 buffer.append(getSetMethod()); 209 } 210 if (getAddMethod() != null) { 211 buffer.append("\n [add method] "); 212 buffer.append(getAddMethod()); 213 } 214 if (getAddIndexedMethod() != null) { 215 buffer.append("\n [add(i) method] "); 216 buffer.append(getAddIndexedMethod()); 217 } 218 if (getRemoveMethod() != null) { 219 buffer.append("\n [remove method] "); 220 buffer.append(getRemoveMethod()); 221 } 222 if (getRemoveIndexedMethod() != null) { 223 buffer.append("\n [remove(i) method] "); 224 buffer.append(getRemoveIndexedMethod()); 225 } 226 if (getSizeMethod() != null) { 227 buffer.append("\n [size method] "); 228 buffer.append(getSizeMethod()); 229 } 230 buffer.append("]"); 231 return buffer.toString(); 232 } 233 /** 234 * @see org.apache.commons.clazz.ClazzProperty#get(java.lang.Object) 235 */ 236 public Object get(Object instance) { 237 return new ReflectedList(instance, this); 238 } 239 240 public Object getList(Object instance) { 241 return super.get(instance); 242 } 243 244 /** 245 * @see org.apache.commons.clazz.ClazzProperty#set(Object, Object) 246 */ 247 public void set(Object instance, Object value) { 248 super.set(instance, value); 249 } 250 }