Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

API Reflection Interface

Thread view: 
franck.dubois1970@gmail.com - 23 Nov 2007 14:32 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.