bacoAlunos
ENGSOFT2019
BlueGrey
calm
Elegant
Català-Valencià - Catalan
中文 - Chinese (Simplified)
中文 - Chinese (Traditional)
Česky - Czech
Dansk - Danish
Nederlands - Dutch
English - English
Suomi - Finnish
Français - French
Deutsch - German
עברית - Hebrew
हिंदी - Hindi
Magyar - Hungarian
Bahasa Indonesia - Indonesian
Italiano - Italian
日本語 - Japanese
한국어 - Korean
मराठी - Marathi
Norsk - Norwegian
Polski - Polish
Português - Portuguese
Português - Portuguese (Brazil)
Русский - Russian
Slovenčina - Slovak
Slovenščina - Slovenian
Español - Spanish
Svenska - Swedish
Türkçe - Turkish
Oëzbekcha - Uzbek
Subversion Repositories
bacoAlunos
(root)
/
impl
/
src
/
java
/
pt
/
estgp
/
estgweb
/
utils
/
ReflectionBean.java
@ 1
- Rev
Rev
Blame
|
Compare with Previous
|
Last modification
|
View Log
|
RSS feed
package
pt.estgp.estgweb.utils
;
import
pt.estgp.estgweb.domain.Announcement
;
import
pt.estgp.estgweb.domain.DomainObjectFactory
;
import
pt.estgp.estgweb.domain.UserImpl
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.Date
;
import
java.util.StringTokenizer
;
/**
* @author Jorge Machado
* @date 3/Mar/2008
* @time 11:41:51
* @see pt.estgp.estgweb.utils
*/
public
class
ReflectionBean
{
private
1.
5
.0/docs/api/java/lang/String.html">
String
path
;
private
1.
5
.0/docs/api/java/lang/String.html">
String
name
;
private
1.
5
.0/docs/api/java/lang/String.html">
String
[
]
methods
;
public
ReflectionBean
(
1.
5
.0/docs/api/java/lang/String.html">
String
path
)
{
this
.
path
= path
;
parse
(
)
;
}
private
void
parse
(
)
{
1.
5
.0/docs/api/java/util/StringTokenizer.html">
StringTokenizer
ts =
new
1.
5
.0/docs/api/java/util/StringTokenizer.html">
StringTokenizer
(
path,
"."
)
;
methods =
new
1.
5
.0/docs/api/java/lang/String.html">
String
[
ts.
countTokens
(
)
- 1
]
;
name = ts.
nextToken
(
)
;
int
i =
0
;
while
(
ts.
hasMoreTokens
(
)
)
{
methods
[
i
]
= ts.
nextToken
(
)
;
i++
;
}
for
(
i =
0
;
i
<
methods.
length
;
i++
)
{
int
dif =
(
int
)
methods
[
i
]
.
charAt
(
0
)
-
'a'
;
char
firstChar =
(
char
)
(
(
(
int
)
'A'
)
+ dif
)
;
methods
[
i
]
=
"get"
+ firstChar + methods
[
i
]
.
substring
(
1
)
;
}
}
public
1.
5
.0/docs/api/java/lang/String.html">
String
getName
(
)
{
return
name
;
}
public
5+
0
%
2Fdocs
%
2Fapi+Object">
Object
invoke
(
5+
0
%
2Fdocs
%
2Fapi+Object">
Object
obj
)
throws
1.
5
.0/docs/api/java/lang/NoSuchMethodException.html">
NoSuchMethodException
,
1.
5
.0/docs/api/java/lang/IllegalAccessException.html">
IllegalAccessException
,
1.
5
.0/docs/api/java/lang/reflect/InvocationTargetException.html">
InvocationTargetException
{
5+
0
%
2Fdocs
%
2Fapi+Object">
Object
returnObj = obj
;
for
(
int
i =
0
;
i
<
methods.
length
;
i++
)
{
1.
5
.0/docs/api/java/lang/reflect/Method.html">
Method
m = returnObj.
getClass
(
)
.
getMethod
(
methods
[
i
]
,
null
)
;
returnObj = m.
invoke
(
returnObj,
null
)
;
}
return
returnObj
;
}
public
static
void
main
(
1.
5
.0/docs/api/java/lang/String.html">
String
[
]
args
)
throws
1.
5
.0/docs/api/java/lang/IllegalAccessException.html">
IllegalAccessException
,
1.
5
.0/docs/api/java/lang/NoSuchMethodException.html">
NoSuchMethodException
,
1.
5
.0/docs/api/java/lang/reflect/InvocationTargetException.html">
InvocationTargetException
{
Announcement a = DomainObjectFactory.
createAnnouncementImpl
(
)
;
a.
setOwner
(
new
UserImpl
(
)
)
;
a.
getOwner
(
)
.
setSaveDate
(
new
5+
0
%
2Fdocs
%
2Fapi+Date">
Date
(
)
)
;
a.
setStartDate
(
new
5+
0
%
2Fdocs
%
2Fapi+Date">
Date
(
)
)
;
ReflectionBean r =
new
ReflectionBean
(
"objectView"
)
;
1.
5
.0/docs/api/java/lang/System.html">
System
.
out
.
println
(
r.
invoke
(
a
)
)
;
r =
new
ReflectionBean
(
"objectView.owner.saveDate"
)
;
1.
5
.0/docs/api/java/lang/System.html">
System
.
out
.
println
(
r.
invoke
(
a
)
)
;
}
}