Hello,
i would to specify interface constants with xml or property file
i think for that using api reflection but i don't see how to use
interface with api reflection ?
someone has idea ?
thanks in advance
Franck
Joshua Cranmer - 23 Nov 2007 16:25 GMT
> Hello,
>
[quoted text clipped - 6 lines]
> thanks in advance
> Franck
If I understand you correctly, what you want to do is to be able to
specify the constants of an interface using another file. If so, then
the only way to do this is to generate class files dynamically; (most)
interface constants are compile-time constant expressions that, for all
practical purposes, cease to exist in the compiled code. Therefore,
these values need to be known at compile time, so the using classes need
to have a ready class file available at compile time.
In short: Can't be done with reflection at runtime.

Signature
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
Giovanni Azua - 24 Nov 2007 12:07 GMT
Hello Frank,
If you really absolutely need to do that there are ways and you may be
interested to look at the following two Reflection APIs:
- Class.forName
- Proxy.newProxyInstance
BUT I would seriously object the need to use this mechanism at
application level outside of a framework: there are cleaner alternatives for
an application e.g. how about a map of Factory instances keyed by some
ID that is read from your XML? so your application create instances that
that specified through configuration hmmm sounds like IoC to me.
Well anyway you can find an example of the Proxy.newProxyInstance here:
http://perfectjpattern.svn.sourceforge.net/viewvc/perfectjpattern/trunk/perfectj
pattern-core/src/main/java/perfectjpattern/core/structural/composite/Composite.j
ava?view=markup
The idea is: you give me an interface Class type that you may create
from a String loaded from an XML file see Class.forName, and I
give you a dynamic instance (implementation) of such interface.
I managed to componentize (or make a component out of) the Composite
Design Pattern that way. It is almost exactly the same mechanism as the
Mock objects use for testing.
HTH,
Giovanni
> Hello,
>
[quoted text clipped - 6 lines]
> thanks in advance
> Franck