Xinjun,
to answer your question, Castor will still use some amount of reflection
(mainly to set values onto your domain objects) even if you are using a
mapping file (a binding file is used during code generation only).
Having said that, let me add one thought. At the time most of these
articles have been written (2001 to 2002), the use of reflection
introduced some performance penalties, noticeable to some degree.
Since then, a lot of time and effort has gone into improving the
JVMs/JDK/compilers to lessen this impact further and further. In my
personal view, with the event of JDK 1.4 (and even more so with Java 5)
this problems have been addressed sufficiently in that I would not call
the use of (moderate) reflection an issue any more. If use of reflection
would still be an issue, frameworks like Spring and some of their most
powerful features (run-time AOP through Spring interceptors) would not
have been adopted by the market as it happened in the last one or two years.
Btw, in case this is not clear enough, using a mapping file instead of
Castor's 'introspector' to establish mappings between the Java domain
classes and the XML artefacts does not really improve Castor's
performance, as both modes will cause Castor to use reflection to
establish what methods to use on your Java objects to set a value, to
get a value (from an instance variable) or to add a value to a
collection member. Bear in mind that these activities happen at start-up
time only, and thus once and once only.
At run-time, when e.g. unmarshalling an XML document to a predefined
object hierarchy, Cstor will (and has to) use reflection to ...
a) create object instances (using Class.newInstance())
b) set and get values into/from your instance variables (Method.invoke())
I hope this clarifies some of your questions.
Regards
Werner
Castor, committer
Xinjun Chen wrote:
> Hi,
>
> I am going to start testing Castor. I have some questions about Castor.
> From google, I can find that quite a few articles saying Castor is slow
> because of Java reflection.
> Here my question is, if during the marshalling and unshalling, the
> binding.xml is provided, will Castor still use Java reflection during
> marshalling and unmarshalling?
>
>
> Regards,
> Xinjun
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email