Source Code Cross Referenced for JavaBuilderPersister.java in  » Installer » VAInstall » com » memoire » vainstall » builder » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Installer » VAInstall » com.memoire.vainstall.builder.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: JavaBuilderPersister.java,v $
003:         * @modification $Date: 2001/09/28 19:41:42 $
004:         * @version      $Id: JavaBuilderPersister.java,v 1.1 2001/09/28 19:41:42 hfalk Exp $
005:         *
006:         */
007:
008:        package com.memoire.vainstall.builder.util;
009:
010:        import com.memoire.vainstall.builder.*;
011:
012:        import java.awt.Rectangle;
013:        import java.io.File;
014:        import java.io.IOException;
015:        import java.util.*;
016:
017:        import javax.xml.parsers.*;
018:        import org.xml.sax.*;
019:        import org.xml.sax.helpers.*;
020:        import org.w3c.dom.*;
021:
022:        import javax.xml.transform.*;
023:        import javax.xml.transform.dom.*;
024:        import javax.xml.transform.stream.*;
025:
026:        /**
027:         * This class performs the persistance of the VAInstall Builder
028:         *
029:         * @see com.memoire.vainstall.VAIBuilderModel
030:         * @see com.memoire.vainstall.util.BuilderPersisterInterface
031:         *
032:         * @author Henrik Falk
033:         * @version $Id: JavaBuilderPersister.java,v 1.1 2001/09/28 19:41:42 hfalk Exp $
034:         */
035:        public class JavaBuilderPersister implements  BuilderPersisterInterface {
036:
037:            /**
038:             * The Builder data model
039:             */
040:            VAIBuilderModel model = null;
041:
042:            /**
043:             * A not so elegant way to find out where the VAInstall shared
044:             * directory is located.
045:             * Used for saving the vaibuilder.xml file which contains data
046:             * from the builder data model.
047:             */
048:            String vai_home = XmlUtil.findVAISharedDir().getAbsolutePath();
049:
050:            /**
051:             * Default constructor
052:             */
053:            public JavaBuilderPersister() {
054:                super ();
055:            }
056:
057:            /**
058:             * Initializes this class in order to know which datamodel to save
059:             * and load.
060:             * @param model The builder model
061:             */
062:            public void initialize(VAIBuilderModel model) {
063:                this .model = model;
064:            }
065:
066:            /**
067:             * Loads the data from datastore
068:             */
069:            public void load() {
070:
071:                // check if we are initialized
072:                if (model == null) {
073:                    return;
074:                }
075:
076:                // Check if vaibuilder.xml exists
077:                String vaibuilder = vai_home + java.io.File.separator
078:                        + "vaibuilder.xml";
079:                if (new File(vaibuilder).exists() == false) {
080:                    // this is the first time we run the builder
081:                    return;
082:                }
083:
084:                // Parse the XML file at the moment non-validating
085:                Document doc = null;
086:                try {
087:                    doc = XmlUtil.parse(vaibuilder, null);
088:                } catch (XmlParseException exc) {
089:                    //            System.out.println("Could not load preferences.");
090:                    return;
091:                }
092:
093:                // extract data from the Document to the data model
094:                importData(doc);
095:            }
096:
097:            /**
098:             * Saves the data in datastore
099:             */
100:            public void save() {
101:
102:                // check if we are initialized
103:                if (model == null) {
104:                    return;
105:                }
106:
107:                // create a new Document
108:                Document doc = null;
109:                try {
110:                    DocumentBuilder builder = DocumentBuilderFactory
111:                            .newInstance().newDocumentBuilder();
112:                    doc = builder.newDocument();
113:
114:                } catch (ParserConfigurationException exc) {
115:                    return;
116:                }
117:
118:                // Extract data from the model to the Document
119:                exportData(doc);
120:
121:                // Create a Transformer which enables us to export the Document
122:                Transformer transformer = null;
123:                try {
124:                    transformer = TransformerFactory.newInstance()
125:                            .newTransformer();
126:                    transformer.setOutputProperty("indent", "yes");
127:                } catch (TransformerConfigurationException exc) {
128:                    exc.printStackTrace();
129:                    return;
130:                }
131:
132:                // Export the Document
133:                String vaibuilder = vai_home + java.io.File.separator
134:                        + "vaibuilder.xml";
135:                try {
136:                    transformer.transform(new DOMSource(doc), new StreamResult(
137:                            new File(vaibuilder)));
138:                } catch (TransformerException exc) {
139:                    exc.printStackTrace();
140:                }
141:
142:            }
143:
144:            /**
145:             * Extract data from a Document and updates the data model
146:             * @param doc a Document
147:             */
148:            private void importData(Document doc) {
149:
150:                NodeList nodelist;
151:
152:                Element rootElement = doc.getDocumentElement();
153:
154:                // get saved window positions
155:                nodelist = rootElement.getElementsByTagName("window");
156:                for (int i = 0; i < nodelist.getLength(); i++) {
157:                    Node window = (Node) nodelist.item(i);
158:
159:                    NamedNodeMap map = window.getAttributes();
160:
161:                    Rectangle rect = new Rectangle(XmlUtil.getAttributeAsInt(
162:                            map, "x"), XmlUtil.getAttributeAsInt(map, "y"),
163:                            XmlUtil.getAttributeAsInt(map, "width"), XmlUtil
164:                                    .getAttributeAsInt(map, "height"));
165:                    model.getWindowList().put(
166:                            XmlUtil.getAttribute(map, "name"), rect);
167:                }
168:
169:                // get saved last opened projects
170:                nodelist = rootElement.getElementsByTagName("lastfile");
171:
172:                LinkedList tmpList = new LinkedList();
173:                for (int i = 0; i < nodelist.getLength(); i++) {
174:                    tmpList.add("");
175:                }
176:                for (int i = 0; i < nodelist.getLength(); i++) {
177:                    int number = new Integer(XmlUtil.getAttribute(nodelist
178:                            .item(i), "number")).intValue();
179:                    String lastproject = XmlUtil.getAttribute(nodelist.item(i),
180:                            "file");
181:                    tmpList.set(number, lastproject);
182:                }
183:
184:                for (int i = tmpList.size() - 1; i >= 0; i--) {
185:                    model.addLastOpenedProject((String) tmpList.get(i));
186:                }
187:
188:                // get builder properties
189:                nodelist = rootElement.getElementsByTagName("property");
190:
191:                for (int i = 0; i < nodelist.getLength(); i++) {
192:                    String name = XmlUtil
193:                            .getAttribute(nodelist.item(i), "name");
194:                    String value = XmlUtil.getAttribute(nodelist.item(i),
195:                            "value");
196:                    model.getPropertyList().put(name, value);
197:                }
198:            }
199:
200:            /**
201:             * Extract data from the data model and updates a Document
202:             * @param doc a Document
203:             */
204:            private void exportData(Document doc) {
205:
206:                // create root element
207:                Element root = doc.createElement("vaibuilder");
208:                doc.appendChild(root);
209:
210:                // create <window> elements
211:                Hashtable windowList = model.getWindowList();
212:
213:                Enumeration keys = windowList.keys();
214:                while (keys.hasMoreElements() == true) {
215:                    String key = (String) keys.nextElement();
216:                    Rectangle rect = (Rectangle) windowList.get(key);
217:
218:                    Element element = doc.createElement("window");
219:                    element.setAttribute("name", key);
220:                    element.setAttribute("x", String.valueOf(rect.x));
221:                    element.setAttribute("y", String.valueOf(rect.y));
222:                    element.setAttribute("width", String.valueOf(rect.width));
223:                    element.setAttribute("height", String.valueOf(rect.height));
224:
225:                    root.appendChild(element);
226:                }
227:
228:                // create <lastproject> elements
229:                LinkedList lastproject = model.getLastOpenedProjectList();
230:
231:                for (int i = 0; i < lastproject.size(); i++) {
232:
233:                    Element element = doc.createElement("lastfile");
234:                    element.setAttribute("number", String.valueOf(i));
235:                    element.setAttribute("file", String.valueOf(lastproject
236:                            .get(i)));
237:
238:                    root.appendChild(element);
239:                }
240:
241:                // create <property> elements
242:                Hashtable propertyList = model.getPropertyList();
243:
244:                Enumeration propertyKeys = propertyList.keys();
245:                while (propertyKeys.hasMoreElements() == true) {
246:                    String name = (String) propertyKeys.nextElement();
247:                    String value = (String) propertyList.get(name);
248:
249:                    Element element = doc.createElement("property");
250:                    element.setAttribute("name", name);
251:                    element.setAttribute("value", value);
252:
253:                    root.appendChild(element);
254:                }
255:
256:            }
257:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.