1 /* 2 * Copyright 2004-2009 the Seasar Foundation and the Others. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 * either express or implied. See the License for the specific language 14 * governing permissions and limitations under the License. 15 */ 16 package org.seasar.cubby.spi.beans; 17 18 import java.lang.annotation.Annotation; 19 import java.lang.annotation.Inherited; 20 import java.lang.reflect.Method; 21 import java.lang.reflect.Proxy; 22 23 /** 24 * プロパティを扱うためのインターフェースです。 25 * 26 * @author baba 27 * @since 2.0.0 28 */ 29 public interface PropertyDesc { 30 31 /** 32 * プロパティ名を返します。 33 * 34 * @return プロパティ名 35 */ 36 String getPropertyName(); 37 38 /** 39 * プロパティの型を返します。 40 * 41 * @return プロパティの型 42 */ 43 Class<?> getPropertyType(); 44 45 /** 46 * getterメソッドを返します。 47 * 48 * @return getterメソッド 49 */ 50 Method getReadMethod(); 51 52 /** 53 * getterメソッドを持っているかどうか返します。 54 * 55 * @return getterメソッドを持っているかどうか 56 */ 57 boolean hasReadMethod(); 58 59 /** 60 * setterメソッドを返します。 61 * 62 * @return setterメソッド 63 */ 64 Method getWriteMethod(); 65 66 /** 67 * setterメソッドを持っているかどうか返します。 68 * 69 * @return setterメソッドを持っているかどうか 70 */ 71 boolean hasWriteMethod(); 72 73 /** 74 * プロパティの値が取得できるかどうかを返します。 75 * 76 * @return プロパティの値が取得できるかどうか 77 */ 78 boolean isReadable(); 79 80 /** 81 * プロパティの値が設定できるかどうかを返します。 82 * 83 * @return プロパティの値が設定できるかどうか 84 */ 85 boolean isWritable(); 86 87 /** 88 * プロパティの値を返します。 89 * 90 * @param target 91 * @return プロパティの値 92 * @throws IllegalPropertyException 93 * 値の取得に失敗した場合。 94 */ 95 Object getValue(Object target) throws IllegalPropertyException; 96 97 /** 98 * プロパティに値を設定します。 99 * 100 * @param target 101 * @param value 102 * @throws IllegalPropertyException 103 * 値の設定に失敗した場合。 104 */ 105 void setValue(Object target, Object value) throws IllegalPropertyException; 106 107 /** 108 * このプロパティがパラメタ化された型の場合に<code>true</code>を返します。 109 * 110 * @return このプロパティがパラメタ化された型の場合に<code>true</code> 111 */ 112 boolean isParameterized(); 113 114 /** 115 * このプロパティがパラメタ化された型の場合、その情報を返します。 116 * <p> 117 * このプロパティがパラメタ化された型でない場合は<code>null</code>を返します。 118 * </p> 119 * 120 * @return このプロパティがパラメタ化された型の場合、その情報 121 */ 122 ParameterizedClassDesc getParameterizedClassDesc(); 123 124 /** 125 * プロパティから指定されたアノテーションを取得します。 126 * <p> 127 * 以下の順序でプロパティのメソッドの定義を検索し、最初に見つかったアノテーションを返します。 128 * <ol> 129 * <li>プロパティ値の読み込みに使用するメソッド {@link #getReadMethod()}</li> 130 * <li>プロパティ値の書き込みに使用するメソッド {@link #getWriteMethod()}</li> 131 * </ol> 132 * </p> 133 * <p> 134 * また、クラスが {@link Proxy} になどよって動的に生成されている場合などは、メソッドからアノテーションを取得することができません。 135 * (アノテーションが {@link Inherited} で修飾されている場合でも取得できません。) 136 * そのため、読み込み/書き込みメソッドの定義を以下のように検索し、アノテーションを取得します。 137 * <ul> 138 * <li>読み込み/書き込みメソッドが定義されたクラス ({@link Method#getDeclaringClass()}) 139 * を検索対象クラスの起点とします。</li> 140 * <li>検索対象クラスと、そのインターフェイスから読み込み/書き込みメソッドの定義を検索します。 141 * <li>アノテーションが取得できなかった場合は、検索対象クラスをそのスーパークラスとし、再度検索を行います。</li> 142 * </ul> 143 * </p> 144 * 145 * @param <T> 146 * アノテーション 147 * @param annotationClass 148 * 取得するアノテーションの型 149 * @return アノテーション 150 */ 151 public <T extends Annotation> T getAnnotation(Class<T> annotationClass); 152 153 /** 154 * プロパティが指定されたアノテーションで修飾されているかを示します。 155 * 156 * @param annotationClass 157 * アノテーションの型 158 * @return プロパティが指定されたアノテーションで修飾されている場合は <code>true</code>、そうでない場合は 159 * <code>false</code> 160 */ 161 public boolean isAnnotationPresent( 162 Class<? extends Annotation> annotationClass); 163 164 }