• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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???
 
Sheriff
Posts: 67671
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
tarun sapra
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67671
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
     
    Rancher
    Posts: 43028
    76
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic