/
Properties.java
72 lines (66 loc) · 1.8 KB
/
Properties.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package org.jboss.weld.extensions.properties;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
/**
* Utility class for working with JavaBean style properties
*
* @author Pete Muir
* @author Shane Bryzak
*
* @see Property
*/
public class Properties
{
private Properties() {}
/**
* Create a JavaBean style property from the field
*
* @param <V>
* @param field
* @return
*/
public static <V> FieldProperty<V> createProperty(Field field)
{
return new FieldPropertyImpl<V>(field);
}
/**
* Create a JavaBean style property from the specified method
*
* @param <V>
* @param method
* @return
* @throws IllegalArgumentException if the method does not match JavaBean conventions
*
* @see http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html
*/
public static <V> MethodProperty<V> createProperty(Method method)
{
return new MethodPropertyImpl<V>(method);
}
/**
* Create a JavaBean style property from the specified member
*
* @param <V>
* @param member
* @return
* @throws IllegalArgumentException if the method does not match JavaBean conventions
*
* @see http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html
*/
public static <V> Property<V> createProperty(Member member)
{
if (member instanceof Method)
{
return new MethodPropertyImpl<V>(Method.class.cast(member));
}
else if (member instanceof Field)
{
return new FieldPropertyImpl<V>(Field.class.cast(member));
}
else
{
throw new IllegalArgumentException("Cannot make a property of " + member + " - it is neither a method or a field");
}
}
}