This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes how to invoke java class name given in xml tag.? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "how to invoke java class name given in xml tag.?" Watch "how to invoke java class name given in xml tag.?" New topic
Author

how to invoke java class name given in xml tag.?

tarun sapra
Greenhorn

Joined: Sep 06, 2009
Posts: 3
Hi everyone,

i was curious to know how can we invoke a java class , whose name is given with in an xml tag
like,
<class>com.example.HelloWorld</class>
this thing is also used in web.xml by the web containers , is it implemented using JAXB???
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56199
    
  13

It's pretty easy if the class has a nullary constructor.

Check out the methods to the Class class.

For more complex objects, check out the reflection API.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
tarun sapra
Greenhorn

Joined: Sep 06, 2009
Posts: 3
hi..thanks for the reply..but can you please share some code example?..as it's still not clear to me ...how exactly like the container or other softwares are able to invoke java classes written as data inside xml tags..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56199
    
  13

You're going to have to show some effort on your own. Did you look at the javadoc for the Class class?

Hints:
  • Find a method that can create a Class instance out of the string name of the class
  • Find a method that can create instances


  • You won't get anywhere if you have to depend on others to do your work for you.
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 35247
        
        7
    Class.forName(...).newInstance() will create an object from a fully-qualified class name, provided the class has a no-argument constructor. To do much useful with it (without using reflection) you'll need to cast it to some interface that it implements, though.


    Android appsImageJ pluginsJava web charts
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: how to invoke java class name given in xml tag.?
     
    Similar Threads
    TLD files variable element
    Help with custom tags
    xml reading
    Learding annotations and XML by heart
    How to update the xml tag attributes for the given tag