Source Code Cross Referenced for Installer.java in  » Web-Framework » JAT » com » jat » core » installer » 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 » Web Framework » JAT » com.jat.core.installer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jat.core.installer;
002:
003:        import java.io.File;
004:        import java.io.IOException;
005:
006:        import java.awt.Dimension;
007:        import java.awt.Toolkit;
008:
009:        import com.jat.core.config.Config;
010:        import com.jat.core.init.Initable;
011:        import com.jat.core.installer.gui.ApplicationFrame;
012:        import com.jat.core.installer.step.JatProject;
013:        import com.jat.core.installer.step.WebApplication;
014:        import com.jat.core.log.LogManager;
015:
016:        /**
017:         * <p>Title: JAT</p>
018:         * <p>Description:</p>
019:         * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
020:         * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
021:         * @author stf
022:         * @version 1.1
023:         * @since 1.2
024:         */
025:
026:        public class Installer implements  Initable {
027:
028:            private String warFile;
029:            private String tempDir;
030:            private String configDir;
031:            private String configFileName;
032:
033:            private String projectName;
034:            private String projectDir;
035:            private String webAppDir;
036:
037:            private boolean packFrame = false;
038:
039:            public void setProjectName(String projectName) {
040:                this .projectName = projectName;
041:            }
042:
043:            public void setProjectDir(String projectDir) {
044:                this .projectDir = projectDir;
045:            }
046:
047:            public void setWebAppDir(String webAppDir) {
048:                this .webAppDir = webAppDir;
049:            }
050:
051:            protected void initFields() throws Exception {
052:                this .warFile = Config.getCurrent().getValue("static parameter",
053:                        "warFile");
054:                File file = new File(this .warFile);
055:                //if (!file.exists()) throw new IOException("File '" + this.warFile + "' does not exists");
056:                this .tempDir = Config.getCurrent().getValue("static parameter",
057:                        "tempDir");
058:                this .configDir = Config.getCurrent().getValue(
059:                        "static parameter", "configDir");
060:                file = new File(this .configDir);
061:                //if (!file.exists()) throw new IOException("Directory '" + this.configDir + "' does not exists");
062:                this .configFileName = Config.getCurrent().getValue(
063:                        "static parameter", "configFileName");
064:                file = new File(JatProject.getFilename(this .configDir,
065:                        this .configFileName));
066:                //if (!file.exists()) throw new IOException("File '" + JatProject.getFilename(this.configDir, this.configFileName) + "' does not exists");
067:                this .projectName = Config.getCurrent().getValue("parameter",
068:                        "projectName");
069:                this .projectDir = Config.getCurrent().getValue("parameter",
070:                        "projectDir");
071:                this .webAppDir = Config.getCurrent().getValue("parameter",
072:                        "webAppDir");
073:            }
074:
075:            public void init() throws Exception {
076:                //System.out.println(System.getProperty("os.name"));
077:                try {
078:                    initFields();
079:                    boolean gui = false;
080:                    try {
081:                        String gm = Config.getCurrent().getValue("general",
082:                                "graphic_mode");
083:                        gui = gm.equalsIgnoreCase("on");
084:                    } catch (Exception ignored) {
085:                    }
086:                    if (gui)
087:                        runGraphicMode();
088:                    else
089:                        this .runBatch();
090:                } catch (Exception ex) {
091:                    System.out.println("Installer error: " + ex.getMessage());
092:                    throw new Exception("Installer error: " + ex);
093:                }
094:            }
095:
096:            public String getWarFilename() {
097:                return this .warFile;
098:            }
099:
100:            public void setWarFilename(String filename) throws IOException {
101:                File file = new File(filename);
102:                if (!file.exists())
103:                    throw new IOException("File '" + filename
104:                            + "' does not exists");
105:                this .warFile = filename;
106:            }
107:
108:            public String getConfigFilename() {
109:                return JatProject.getFilename(this .configDir,
110:                        this .configFileName);
111:            }
112:
113:            public void setConfigFilename(String filename) throws IOException {
114:                File file = new File(filename);
115:                if (!file.exists())
116:                    throw new IOException("File '" + this .warFile
117:                            + "' does not exists");
118:                this .configDir = file.getAbsolutePath().substring(0,
119:                        file.getAbsolutePath().indexOf(file.getName()));
120:                this .configFileName = file.getName();
121:            }
122:
123:            protected void createWebApplication() throws Exception {
124:                WebApplication webApp = WebApplication.getWebApplication();
125:                try {
126:                    webApp.unwar(this .warFile, this .tempDir);
127:                    String projectConfigPath = JatProject.getFilename(
128:                            JatProject.getFilename(this .projectDir,
129:                                    this .projectName), "config");
130:                    webApp.modifyWebXml(this .tempDir, projectConfigPath,
131:                            this .configFileName);
132:                    String file = webApp.war(this .tempDir, this .projectName);
133:                    webApp.moveWar(this .tempDir, file, this .webAppDir);
134:                } finally {
135:                    try {
136:                        webApp.deleteTemp(this .tempDir);
137:                    } catch (Exception ex) {
138:                        LogManager
139:                                .sendError(this .getClass().getName()
140:                                        + "createWebApplication: unable to remove temp dir '"
141:                                        + tempDir + "': " + ex);
142:                    }
143:                }
144:            }
145:
146:            protected void createProject() throws Exception {
147:                JatProject project = new JatProject(this .projectDir,
148:                        this .projectName);
149:                project.copyConfigFiles(this .configDir, this .configFileName);
150:            }
151:
152:            public void runBatch() throws Exception {
153:                File f = new File(JatProject.getFilename(this .projectDir,
154:                        this .projectName));
155:                if (f.exists())
156:                    throw new Exception("Directory '" + this .projectName
157:                            + "' already exists");
158:                f = new File(this .webAppDir);
159:                if (!f.exists())
160:                    throw new Exception("Directory '" + f.getAbsolutePath()
161:                            + "' does not exists");
162:                createWebApplication();
163:                createProject();
164:                try {
165:                    String res = "Project successfully installed and configured on '"
166:                            + JatProject.getFilename(this .projectDir,
167:                                    this .projectName)
168:                            + "' (config) and '"
169:                            + f.getAbsolutePath() + "' (war archive)";
170:
171:                    LogManager.sendLog(res);
172:                    System.out.println(res);
173:                } catch (Exception ex) {
174:                    System.out.println("Project installed. Warning: " + ex);
175:                }
176:            }
177:
178:            private void runGraphicMode() {
179:                ApplicationFrame frame = new ApplicationFrame(this ,
180:                        this .projectName, this .projectDir, this .webAppDir);
181:                //Validate frames that have preset sizes
182:                //Pack frames that have useful preferred size info, e.g. from their layout
183:                if (packFrame) {
184:                    frame.pack();
185:                } else {
186:                    frame.validate();
187:                }
188:                //Center the window
189:                Dimension screenSize = Toolkit.getDefaultToolkit()
190:                        .getScreenSize();
191:                Dimension frameSize = frame.getSize();
192:                if (frameSize.height > screenSize.height) {
193:                    frameSize.height = screenSize.height;
194:                }
195:                if (frameSize.width > screenSize.width) {
196:                    frameSize.width = screenSize.width;
197:                }
198:                frame.setLocation((screenSize.width - frameSize.width) / 2,
199:                        (screenSize.height - frameSize.height) / 2);
200:                frame.setVisible(true);
201:
202:            }
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.