keycloak
公開メンバ関数 | 静的非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.keycloak.models.utils.reflection.MethodPropertyImpl< V > クラステンプレート
org.keycloak.models.utils.reflection.MethodPropertyImpl< V > の継承関係図
Inheritance graph
org.keycloak.models.utils.reflection.MethodPropertyImpl< V > 連携図
Collaboration graph

公開メンバ関数

 MethodPropertyImpl (Method method)
 
String getName ()
 
Class< V > getJavaClass ()
 
Type getBaseType ()
 
Method getAnnotatedElement ()
 
Member getMember ()
 
getValue (Object instance)
 
void setValue (Object instance, V value)
 
Class<?> getDeclaringClass ()
 
boolean isReadOnly ()
 
void setAccessible ()
 
boolean isAnnotationPresent (final Class<? extends Annotation > annotation)
 
String toString ()
 
int hashCode ()
 
boolean equals (Object obj)
 

静的非公開メンバ関数

static Method getSetterMethod (Class<?> clazz, String name)
 
static Method getGetterMethod (Class<?> clazz, String name)
 

非公開変数類

final Method getterMethod
 
final String propertyName
 
final Method setterMethod
 

静的非公開変数類

static final String GETTER_METHOD_PREFIX = "get"
 
static final String SETTER_METHOD_PREFIX = "set"
 
static final String BOOLEAN_GETTER_METHOD_PREFIX = "is"
 
static final int GETTER_METHOD_PREFIX_LENGTH = GETTER_METHOD_PREFIX.length()
 
static final int SETTER_METHOD_PREFIX_LENGTH = SETTER_METHOD_PREFIX.length()
 
static final int BOOLEAN_GETTER_METHOD_PREFIX_LENGTH = BOOLEAN_GETTER_METHOD_PREFIX.length()
 

詳解

A bean property based on the value represented by a getter/setter method pair

構築子と解体子

◆ MethodPropertyImpl()

44  {
45  final String accessorMethodPrefix;
46  final String propertyNameInAccessorMethod;
47 
48  if (method.getName().startsWith(GETTER_METHOD_PREFIX)) {
49  if (method.getReturnType() == Void.TYPE) {
50  throw new IllegalArgumentException(
51  "Invalid accessor method, must have return value if starts with 'get'. Method: " + method);
52  } else if (method.getParameterTypes().length > 0) {
53  throw new IllegalArgumentException(
54  "Invalid accessor method, must have zero arguments if starts with 'get'. Method: " + method);
55  }
56  propertyNameInAccessorMethod = method.getName().substring(GETTER_METHOD_PREFIX_LENGTH);
57  accessorMethodPrefix = GETTER_METHOD_PREFIX;
58  } else if (method.getName().startsWith(SETTER_METHOD_PREFIX)) {
59  if (method.getReturnType() != Void.TYPE) {
60  throw new IllegalArgumentException(
61  "Invalid accessor method, must not have return value if starts with 'set'. Method: " + method);
62  } else if (method.getParameterTypes().length != 1) {
63  throw new IllegalArgumentException(
64  "Invalid accessor method, must have one argument if starts with 'set'. Method: " + method);
65  }
66  propertyNameInAccessorMethod = method.getName().substring(SETTER_METHOD_PREFIX_LENGTH);
67  accessorMethodPrefix = SETTER_METHOD_PREFIX;
68  } else if (method.getName().startsWith(BOOLEAN_GETTER_METHOD_PREFIX)) {
69  if (method.getReturnType() != Boolean.TYPE || !method.getReturnType().isPrimitive()) {
70  throw new IllegalArgumentException(
71  "Invalid accessor method, must return boolean primitive if starts with 'is'. Method: " +
72  method);
73  }
74  propertyNameInAccessorMethod = method.getName().substring(BOOLEAN_GETTER_METHOD_PREFIX_LENGTH);
75  accessorMethodPrefix = BOOLEAN_GETTER_METHOD_PREFIX;
76  } else {
77  throw new IllegalArgumentException(
78  "Invalid accessor method, must start with 'get', 'set' or 'is'. " + "Method: " + method);
79  }
80 
81  if (propertyNameInAccessorMethod.length() == 0 ||
82  !Character.isUpperCase(propertyNameInAccessorMethod.charAt(0))) {
83  throw new IllegalArgumentException("Invalid accessor method, prefix '" + accessorMethodPrefix +
84  "' must be followed a non-empty property name, capitalized. Method: " + method);
85  }
86 
87  this.propertyName = Introspector.decapitalize(propertyNameInAccessorMethod);
88  this.getterMethod = getGetterMethod(method.getDeclaringClass(), propertyName);
89  this.setterMethod = getSetterMethod(method.getDeclaringClass(), propertyName);
90  }
final String propertyName
Definition: MethodPropertyImpl.java:41
static Method getSetterMethod(Class<?> clazz, String name)
Definition: MethodPropertyImpl.java:150
static Method getGetterMethod(Class<?> clazz, String name)
Definition: MethodPropertyImpl.java:163
static final int GETTER_METHOD_PREFIX_LENGTH
Definition: MethodPropertyImpl.java:36
final Method setterMethod
Definition: MethodPropertyImpl.java:42
static final int BOOLEAN_GETTER_METHOD_PREFIX_LENGTH
Definition: MethodPropertyImpl.java:38
static final String BOOLEAN_GETTER_METHOD_PREFIX
Definition: MethodPropertyImpl.java:34
final Method getterMethod
Definition: MethodPropertyImpl.java:40
static final int SETTER_METHOD_PREFIX_LENGTH
Definition: MethodPropertyImpl.java:37
static final String SETTER_METHOD_PREFIX
Definition: MethodPropertyImpl.java:33
static final String GETTER_METHOD_PREFIX
Definition: MethodPropertyImpl.java:32

関数詳解

◆ equals()

boolean org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.equals ( Object  obj)
inline
226  {
227  if (obj instanceof MethodPropertyImpl<?>) {
228  MethodPropertyImpl<?> that = (MethodPropertyImpl<?>) obj;
229  if (this.setterMethod == null) {
230  return that.setterMethod == null && this.getterMethod.equals(that.getterMethod);
231  } else {
232  return this.setterMethod.equals(that.setterMethod) && this.getterMethod.equals(that.getterMethod);
233  }
234  } else {
235  return false;
236  }
237  }
final Method setterMethod
Definition: MethodPropertyImpl.java:42
final Method getterMethod
Definition: MethodPropertyImpl.java:40

◆ getAnnotatedElement()

Method org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.getAnnotatedElement ( )
inline

org.keycloak.models.utils.reflection.MethodProperty< V >を実装しています。

109  {
110  return getterMethod;
111  }
final Method getterMethod
Definition: MethodPropertyImpl.java:40

◆ getBaseType()

org.keycloak.models.utils.reflection.Property< V >を実装しています。

104  {
105  return getterMethod.getGenericReturnType();
106  }
final Method getterMethod
Definition: MethodPropertyImpl.java:40

◆ getDeclaringClass()

Class<?> org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.getDeclaringClass ( )
inline

org.keycloak.models.utils.reflection.Property< V >を実装しています。

183  {
184  return getterMethod.getDeclaringClass();
185  }
final Method getterMethod
Definition: MethodPropertyImpl.java:40

◆ getGetterMethod()

static Method org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.getGetterMethod ( Class<?>  clazz,
String  name 
)
inlinestaticprivate
163  {
164  for (Method method : clazz.getDeclaredMethods()) {
165  String methodName = method.getName();
166  if (method.getParameterTypes().length == 0) {
167  if (methodName.startsWith(GETTER_METHOD_PREFIX)) {
168  if (Introspector.decapitalize(methodName.substring(GETTER_METHOD_PREFIX_LENGTH)).equals(name)) {
169  return method;
170  }
171  } else if (methodName.startsWith(BOOLEAN_GETTER_METHOD_PREFIX)) {
172  if (Introspector.decapitalize(
173  methodName.substring(BOOLEAN_GETTER_METHOD_PREFIX_LENGTH)).equals(name)) {
174  return method;
175  }
176  }
177  }
178  }
179  throw new IllegalArgumentException("no such getter method: " + clazz.getName() + '.' + name);
180  }
static final int GETTER_METHOD_PREFIX_LENGTH
Definition: MethodPropertyImpl.java:36
static final int BOOLEAN_GETTER_METHOD_PREFIX_LENGTH
Definition: MethodPropertyImpl.java:38
boolean equals(Object obj)
Definition: MethodPropertyImpl.java:226
static final String BOOLEAN_GETTER_METHOD_PREFIX
Definition: MethodPropertyImpl.java:34
static final String GETTER_METHOD_PREFIX
Definition: MethodPropertyImpl.java:32

◆ getJavaClass()

Class<V> org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.getJavaClass ( )
inline

org.keycloak.models.utils.reflection.Property< V >を実装しています。

99  {
100  return (Class<V>) getterMethod.getReturnType();
101  }
final Method getterMethod
Definition: MethodPropertyImpl.java:40

◆ getMember()

org.keycloak.models.utils.reflection.Property< V >を実装しています。

114  {
115  return getterMethod;
116  }
final Method getterMethod
Definition: MethodPropertyImpl.java:40

◆ getName()

org.keycloak.models.utils.reflection.Property< V >を実装しています。

93  {
94  return propertyName;
95  }
final String propertyName
Definition: MethodPropertyImpl.java:41

◆ getSetterMethod()

static Method org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.getSetterMethod ( Class<?>  clazz,
String  name 
)
inlinestaticprivate
150  {
151  Method[] methods = clazz.getMethods();
152  for (Method method : methods) {
153  String methodName = method.getName();
154  if (methodName.startsWith(SETTER_METHOD_PREFIX) && method.getParameterTypes().length == 1) {
155  if (Introspector.decapitalize(methodName.substring(SETTER_METHOD_PREFIX_LENGTH)).equals(name)) {
156  return method;
157  }
158  }
159  }
160  return null;
161  }
boolean equals(Object obj)
Definition: MethodPropertyImpl.java:226
static final int SETTER_METHOD_PREFIX_LENGTH
Definition: MethodPropertyImpl.java:37
static final String SETTER_METHOD_PREFIX
Definition: MethodPropertyImpl.java:33

◆ getValue()

V org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.getValue ( Object  instance)
inline

org.keycloak.models.utils.reflection.Property< V >を実装しています。

119  {
120  if (getterMethod == null) {
121  throw new UnsupportedOperationException("Property " +
122  this.setterMethod.getDeclaringClass() + "." + propertyName +
123  " cannot be read, as there is no getter method.");
124  }
125  return Reflections.cast(Reflections.invokeMethod(getterMethod, instance));
126  }
final String propertyName
Definition: MethodPropertyImpl.java:41
final Method setterMethod
Definition: MethodPropertyImpl.java:42
final Method getterMethod
Definition: MethodPropertyImpl.java:40

◆ hashCode()

218  {
219  int hash = 1;
220  hash = hash * 31 + (setterMethod == null ? 0 : setterMethod.hashCode());
221  hash = hash * 31 + getterMethod.hashCode();
222  return hash;
223  }
final Method setterMethod
Definition: MethodPropertyImpl.java:42
final Method getterMethod
Definition: MethodPropertyImpl.java:40

◆ isAnnotationPresent()

boolean org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.isAnnotationPresent ( final Class<? extends Annotation >  annotation)
inline

org.keycloak.models.utils.reflection.Property< V >を実装しています。

203  {
204  return getAnnotatedElement() != null && getAnnotatedElement().isAnnotationPresent(annotation);
205  }
Method getAnnotatedElement()
Definition: MethodPropertyImpl.java:109

◆ isReadOnly()

boolean org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.isReadOnly ( )
inline

org.keycloak.models.utils.reflection.Property< V >を実装しています。

188  {
189  return setterMethod == null;
190  }
final Method setterMethod
Definition: MethodPropertyImpl.java:42

◆ setAccessible()

void org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.setAccessible ( )
inline

org.keycloak.models.utils.reflection.Property< V >を実装しています。

193  {
194  if (setterMethod != null) {
195  Reflections.setAccessible(setterMethod);
196  }
197  if (getterMethod != null) {
198  Reflections.setAccessible(getterMethod);
199  }
200  }
final Method setterMethod
Definition: MethodPropertyImpl.java:42
final Method getterMethod
Definition: MethodPropertyImpl.java:40

◆ setValue()

void org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.setValue ( Object  instance,
value 
)
inline

org.keycloak.models.utils.reflection.Property< V >を実装しています。

129  {
130  if (setterMethod == null) {
131  // if the setter method is null may be because the declaring type is an interface which does not declare
132  // a setter method. We just check if the instance is assignable from the property declaring class and
133  // try to find a overridden method.
134  if (getDeclaringClass().isAssignableFrom(instance.getClass())) {
135  Method instanceSetterMethod = getSetterMethod(instance.getClass(), getName());
136 
137  if (instanceSetterMethod != null) {
138  Reflections.invokeMethod(instanceSetterMethod, instance, value);
139  return;
140  }
141  }
142 
143  throw new UnsupportedOperationException("Property " +
144  this.getterMethod.getDeclaringClass() + "." + propertyName +
145  " is read only, as there is no setter method.");
146  }
147  Reflections.invokeMethod(setterMethod, instance, value);
148  }
final String propertyName
Definition: MethodPropertyImpl.java:41
static Method getSetterMethod(Class<?> clazz, String name)
Definition: MethodPropertyImpl.java:150
String getName()
Definition: MethodPropertyImpl.java:93
final Method setterMethod
Definition: MethodPropertyImpl.java:42
Class<?> getDeclaringClass()
Definition: MethodPropertyImpl.java:183
final Method getterMethod
Definition: MethodPropertyImpl.java:40

◆ toString()

208  {
209  StringBuilder builder = new StringBuilder();
210  if (isReadOnly()) {
211  builder.append("read-only ").append(setterMethod.toString()).append("; ");
212  }
213  builder.append(getterMethod.toString());
214  return builder.toString();
215  }
final Method setterMethod
Definition: MethodPropertyImpl.java:42
final Method getterMethod
Definition: MethodPropertyImpl.java:40
boolean isReadOnly()
Definition: MethodPropertyImpl.java:188

メンバ詳解

◆ BOOLEAN_GETTER_METHOD_PREFIX

final String org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.BOOLEAN_GETTER_METHOD_PREFIX = "is"
staticprivate

◆ BOOLEAN_GETTER_METHOD_PREFIX_LENGTH

final int org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.BOOLEAN_GETTER_METHOD_PREFIX_LENGTH = BOOLEAN_GETTER_METHOD_PREFIX.length()
staticprivate

◆ GETTER_METHOD_PREFIX

final String org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.GETTER_METHOD_PREFIX = "get"
staticprivate

◆ GETTER_METHOD_PREFIX_LENGTH

final int org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.GETTER_METHOD_PREFIX_LENGTH = GETTER_METHOD_PREFIX.length()
staticprivate

◆ getterMethod

final Method org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.getterMethod
private

◆ propertyName

final String org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.propertyName
private

◆ SETTER_METHOD_PREFIX

final String org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.SETTER_METHOD_PREFIX = "set"
staticprivate

◆ SETTER_METHOD_PREFIX_LENGTH

final int org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.SETTER_METHOD_PREFIX_LENGTH = SETTER_METHOD_PREFIX.length()
staticprivate

◆ setterMethod

final Method org.keycloak.models.utils.reflection.MethodPropertyImpl< V >.setterMethod
private

このクラス詳解は次のファイルから抽出されました: