I have a Design pattern Question in Java/J2EEWhy do you think it's a pattern question? Does the exercise specifically recommends using a pattern? If not, you can design a solution with basic OO principles and "if" statements, it's not obvious you need a pattern at all.
Problem Statement::OK. Are these name/value pairs supposed to be the same information in two different formats, or do they represent different information? Must there be some consistency between them?
Suppose there are 2 files as below
XYZ.properties file --> name = value pair
abc.xml file --> attribute=value pair.
Both the above files have pairs.;)
The question is "Design a component/jsp page such that you can read,edit,save the name,value pairs of either a Property file or xml file.?"A JSP application to update a pair of files seems a strange architectural choice.
So which Design pattern would you suggest i should be using in Java.?I don't get a few things:
The name,values pair are then fetched and displayed in another jsp page where i should be able to read,edit,save the name,value pairs such that
1>read operation results in reading the name,value pair
2>Edit operation results in editing the name,value pair
3>Save operation results in saving the value for the corresponding name,value pair in database and consequently updates either the property/xml file.
My Initial Analysis : i would use a Factory design pattern since i have 2 files which have name,value pairs and at run time decide which one to choose* depending on the name of file invokedWhat is the type of the "one" you chose?
Once done i would pass the parameters to jsp file for Read,edit and save operationWhich parameters? Are you talking about the query parameters in the URL, or about an object that represents the key/value pairs contained in the file?
Once done i would pass the parameters to jsp file for Read,edit and save operationWarning: except for an exercise, you shouldn't have business logic such as "save" in a JSP. Instead such business logic should be implemented in a model class (EJB, or POJO), or if it's a simple exercise, in a servlet class. JSPs should only be used to build HTML display out of Java objects created/updated by the business logic components.
Save would save the name,value pair to Database but i dont know how will it update the corresponding value for that name in either the property/xml file as well.*Well, assuming you are not afraid by the concurrent multi-user update of a server-side file, you can simply regenerate the whole file each time by iterating over the appropriate key/value pairs in the DB.