File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes MVC question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "MVC question" Watch "MVC question" New topic
Author

MVC question

Iven Breeze
Greenhorn

Joined: Jan 11, 2004
Posts: 6
Is there an existing Model class that I should extend when I'm building the Model portion of an MVC app for the xml data?
I'm using JAXB to to marshal and unmarshal the xml data. That'll be in the Controller portion. I don't know if I should just create a brand new Model class to hold all the xml fields, or if I should extend an existing one.
[ January 11, 2004: Message edited by: Iven Breeze ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Consider leaving your XML data as a DOM and creating a class/classes to give efficient access to it. Advantages:
1. avoids "brittle" code. - ie it won't break if you add some new attributes or elements to the XML as long as the basic structure does not change.
2. allows "lazy" initialization - if you wait until data is needed, you don't have to create a bunch of Java objects that may never be used.
I am working on an exam servlet application (about the 4th re-do of the architecture - one every 2 years ) in the first 3 I created data objects for each question. Now I take the DOM for the entire question set (possibly 500 questions) and locate all the question Elements when it is read in, but thats all. When question data is needed, the lookup for the n't question Element is very fast - it gets passed to a temporary "model" object that "knows how" to get the data out of the Element as needed for display.
With this architecture, adding new question types doesn't break anything.
Bill
 
Don't get me started about those stupid light bulbs.
 
subject: MVC question