Source Code Cross Referenced for XMLConfigFile.java in  » Development » Tracelog » net » sourceforge » tracelog » config » 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 » Development » Tracelog » net.sourceforge.tracelog.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.tracelog.config;
002:
003:        import java.io.File;
004:        import java.io.FileReader;
005:        import java.io.FileWriter;
006:        import java.io.PrintWriter;
007:        import java.util.LinkedList;
008:        import java.util.List;
009:
010:        import org.apache.log4j.Logger;
011:        import org.eclipse.swt.SWT;
012:        import org.exolab.castor.mapping.Mapping;
013:        import org.exolab.castor.xml.Marshaller;
014:        import org.exolab.castor.xml.Unmarshaller;
015:        import org.xml.sax.InputSource;
016:
017:        public class XMLConfigFile extends ConfigFile {
018:            private static Logger log = Logger.getLogger(XMLConfigFile.class);
019:
020:            private static final String SERVER_CONFIG_DELIM = "|";
021:
022:            private boolean isNewConfigFile;
023:
024:            private Mapping mapping;
025:
026:            XMLConfigFile() {
027:                super ();
028:                super .configFile = new File(System.getProperty("user.home")
029:                        + projectProperties.getXMLConfigFilePath());
030:
031:                this .mapping = new Mapping();
032:                this .isNewConfigFile = false;
033:
034:                loadXMLMapping();
035:                setupDefaultXMLFile();
036:            }
037:
038:            public List<LogBean> getConfig() {
039:                try {
040:                    throw new Exception("Deprecated");
041:                } catch (Exception e) {
042:                    log.error(e);
043:                    e.printStackTrace();
044:                }
045:                return null;
046:            }
047:
048:            public UserConfig getUserConfig() {
049:                UserConfig userConfig = null;
050:
051:                try {
052:                    Unmarshaller unmarshaller = new Unmarshaller(mapping);
053:                    userConfig = (UserConfig) unmarshaller
054:                            .unmarshal(new FileReader(configFile));
055:                } catch (Exception e) {
056:                    log.error("Cannot retrieve user config from file: " + e);
057:                    e.printStackTrace();
058:                }
059:
060:                return userConfig;
061:            }
062:
063:            public void saveConfig(List<LogBean> logBeanList) {
064:                try {
065:                    throw new Exception("Deprecated");
066:                } catch (Exception e) {
067:                    log.error(e);
068:                    e.printStackTrace();
069:                }
070:            }
071:
072:            public void saveUserConfig(UserConfig userConfig) {
073:                try {
074:                    Marshaller marshaller = new Marshaller(new FileWriter(
075:                            configFile));
076:                    marshaller.setMapping(mapping);
077:                    marshaller.marshal(userConfig);
078:                } catch (Exception e) {
079:                    log.error("Cannot save user config into file: " + e);
080:                    e.printStackTrace();
081:                }
082:
083:            }
084:
085:            private void convertFromOldConfigFile() throws Exception {
086:
087:                NewConfigFile newConfigFile = new NewConfigFile();
088:
089:                // new config file and old config file exists, then
090:                // perform conversion
091:                if (isNewConfigFile && newConfigFile.isConfigFileExists()) {
092:                    List<LogBean> oldLogBeanList = newConfigFile.getConfig();
093:
094:                    List<LogFile> logFiles = new LinkedList<LogFile>();
095:
096:                    for (LogBean logBean : oldLogBeanList) {
097:                        LogFile logFile = new LogFile(logBean.getLogOrder(),
098:                                logBean.getLogName(), logBean.getLogFilePath(),
099:                                logBean.getForegroundColor(), logBean
100:                                        .getBackgroundColor());
101:
102:                        logFiles.add(logFile);
103:                    }
104:
105:                    LogGroup logGroup = new LogGroup();
106:                    logGroup.setGroupName("default");
107:                    logGroup.setGroupOrder(1);
108:                    logGroup.setLogFiles(logFiles);
109:
110:                    List<LogGroup> logGroups = new LinkedList<LogGroup>();
111:                    logGroups.add(logGroup);
112:
113:                    UserConfig userConfig = new UserConfig();
114:                    userConfig.setTextEditorPath("notepad.exe");
115:                    userConfig.setLogGroups(logGroups);
116:
117:                    saveUserConfig(userConfig);
118:                }
119:            }
120:
121:            private void createDefaultConfigFile() throws Exception {
122:                String[] sampleServerConfigs = projectProperties
123:                        .getSampleServerConfigs();
124:
125:                List<LogFile> logFiles = new LinkedList<LogFile>();
126:
127:                for (int i = 0; i < sampleServerConfigs.length; ++i) {
128:                    String logName = sampleServerConfigs[i]
129:                            .substring(0, sampleServerConfigs[i]
130:                                    .indexOf(SERVER_CONFIG_DELIM));
131:                    String logPath = sampleServerConfigs[i]
132:                            .substring(sampleServerConfigs[i]
133:                                    .indexOf(SERVER_CONFIG_DELIM) + 1);
134:                    logFiles.add(new LogFile((i + 1), logName, logPath,
135:                            SWT.COLOR_BLACK, SWT.COLOR_WHITE));
136:                }
137:
138:                LogGroup logGroup = new LogGroup();
139:                logGroup.setGroupName("default");
140:                logGroup.setGroupOrder(1);
141:                logGroup.setLogFiles(logFiles);
142:
143:                List<LogGroup> logGroups = new LinkedList<LogGroup>();
144:                logGroups.add(logGroup);
145:
146:                UserConfig userConfig = new UserConfig();
147:                userConfig.setTextEditorPath("notepad.exe");
148:                userConfig.setLogGroups(logGroups);
149:
150:                saveUserConfig(userConfig);
151:
152:            }
153:
154:            private void loadXMLMapping() {
155:                try {
156:                    mapping.loadMapping(new InputSource(getClass()
157:                            .getResourceAsStream("mapping.xml")));
158:                } catch (Exception e) {
159:                    log.error("Cannot load mapping file: " + e);
160:                    e.printStackTrace();
161:                }
162:            }
163:
164:            private void setupDefaultXMLFile() {
165:                try {
166:                    // create directory structure and config file only if not exists
167:                    if (!configFile.exists()) {
168:                        isNewConfigFile = true;
169:
170:                        configFile.getParentFile().mkdirs();
171:
172:                        PrintWriter pw = new PrintWriter(configFile);
173:                        pw
174:                                .println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
175:                        pw.println("<user-config>");
176:                        pw.println("</user-config>");
177:                        pw.close();
178:
179:                        createDefaultConfigFile();
180:
181:                    }
182:                } catch (Exception e) {
183:                    log.error("Cannot create a new config file: " + e);
184:                    e.printStackTrace();
185:                }
186:
187:                try {
188:                    convertFromOldConfigFile();
189:                } catch (Exception e) {
190:                    log
191:                            .error("Cannot convert from old config file to new config file: "
192:                                    + e);
193:                    e.printStackTrace();
194:                }
195:            }
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.