• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Substitute a HashMap with a XML

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

My first post here! ;-)

I am making a simple Information System where you can browse different products stored in the shop. I have a FrontController which intercepts many Actions you do (like entering the supplier, entering new customers) and stuff like that.
Now this thing is done with a HashMap that associates every command to their respective action to be done. It's quite long though, and I've been told by my colleagues that I can simply create a separate XML file with all the associations, and then invoke this XML file from the Front Controller.

how is this feasable?

thanks a lot for your answers! ;-)
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to Javaranch!

What you're describing sounds very similar to what Struts framework does. It has a struts-config xml file where you describe the command name and the associated action class. The action classes are application provided. The struts front controller intercepts the request, extracts the command name from the URL, looks it up in the xml file, gets the correspoding Action class name, instantiates it using reflection API, and calls a method in it. Struts-config XML has more than just these mappings.

So one option is you can use the Struts framework. It's quite easy to integrate into an existing app if it already has a FrontController + Commands + dispatcher-to-views architecture.

If for some reason you want to rollout your own implementation, then a simple properties file with 'command -> command-classname' key value mappings should be sufficient isn't it? Lookup the command, get corresponding action classname, use reflection to instantiate and call a method on the instance. I can't think of any added value in using XML format file over a plain properties file, in this case.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also... this sounds like a question about this unspecified Front Controller, rather than a question about XML. So I would prefer to move it to a forum which is about that Front Controller, except I don't know what forum that would be. Could you provide more details about that?
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Also... this sounds like a question about this unspecified Front Controller, rather than a question about XML. So I would prefer to move it to a forum which is about that Front Controller, except I don't know what forum that would be. Could you provide more details about that?



Ah! true. I jumped the gun and assumed it was a web app. Nao, please note - Struts is used for web apps. If your app isn't a web app, then you can't use struts.
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Karthik Shiraly wrote:

Paul Clapham wrote:Also... this sounds like a question about this unspecified Front Controller, rather than a question about XML. So I would prefer to move it to a forum which is about that Front Controller, except I don't know what forum that would be. Could you provide more details about that?



Ah! true. I jumped the gun and assumed it was a web app. Nao, please note - Struts is used for web apps. If your app isn't a web app, then you can't use struts.



It sounds like a web app to me too. It might even already be Struts, but I can't tell. It's just that "front controller" is a generic architectural term and could refer to anything.
 
Nao Andrea
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your quick answer! ;-) Sorry for my incompetence, but I'm very new to Web Applications. I'm actually trying to do something like a form where you enter data and they get stored in a db.

Now, utilizing the MVC pattern, I need to use a Front Controller which intercepts every command (and links it to an action with a map). Now, I was wondering (and here comes the XML technology) whether there was a way to AVOID the use of the maps in this FC, but rather using an XML file that gets invoked by the FC.

Maybe if it's still not clear enough then it's me doing some mistake or thinking a little too much...

Thanks guys! ;-)
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't "invoke" an XML file. It's not a program, it's data. You would have to parse the file into some internal data structure (perhaps even a Map if that was appropriate) and then use that data structure.
reply
    Bookmark Topic Watch Topic
  • New Topic