|
Last change
on this file was
2,
checked in by dsowen, 21 years ago
|
|
Initial commit.
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | /* |
|---|
| 2 | * Created on Mar 15, 2005 |
|---|
| 3 | * |
|---|
| 4 | * $Log$ |
|---|
| 5 | * Revision 1.1 2005/08/03 00:35:29 dsowen |
|---|
| 6 | * Initial commit. |
|---|
| 7 | * |
|---|
| 8 | * Revision 1.2 2005/04/10 19:48:29 dowen |
|---|
| 9 | * Renamed package. |
|---|
| 10 | * |
|---|
| 11 | * Revision 1.1 2005/03/19 16:49:20 dowen |
|---|
| 12 | * Initial commit. |
|---|
| 13 | * |
|---|
| 14 | */ |
|---|
| 15 | package ws.fugue88.jpath; |
|---|
| 16 | |
|---|
| 17 | import java.lang.reflect.InvocationTargetException; |
|---|
| 18 | import java.lang.reflect.Method; |
|---|
| 19 | |
|---|
| 20 | /** |
|---|
| 21 | * @author dsowen |
|---|
| 22 | */ |
|---|
| 23 | class ImmutableMethodProperty implements Property { |
|---|
| 24 | |
|---|
| 25 | ImmutableMethodProperty(String name, Class clas, String get_method) |
|---|
| 26 | throws NoSuchMethodException |
|---|
| 27 | { |
|---|
| 28 | _name = name; |
|---|
| 29 | |
|---|
| 30 | _get = clas.getDeclaredMethod(get_method, null); |
|---|
| 31 | _get.setAccessible(true); |
|---|
| 32 | |
|---|
| 33 | _type = _get.getReturnType(); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | public Class getType() |
|---|
| 37 | { |
|---|
| 38 | return _type; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | public String getName() |
|---|
| 42 | { |
|---|
| 43 | return _name; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | public Object getValue(Object that) throws InvocationTargetException |
|---|
| 47 | { |
|---|
| 48 | try { |
|---|
| 49 | return _get.invoke(that, null); |
|---|
| 50 | } catch(IllegalAccessException e) { |
|---|
| 51 | throw new Error(e); |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | public void setValue(Object that, Object value) |
|---|
| 56 | throws InvocationTargetException |
|---|
| 57 | { |
|---|
| 58 | throw new UnsupportedOperationException("Property '" + _name |
|---|
| 59 | + "' of class " + _type + "is read-only."); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | private String _name; |
|---|
| 63 | private Class _type; |
|---|
| 64 | private Method _get; |
|---|
| 65 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.