Source Code Cross Referenced for JSmoothModelPersistency.java in  » Installer » jsmooth » net » charabia » jsmoothgen » application » 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 » jsmooth » net.charabia.jsmoothgen.application 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:          JSmooth: a VM wrapper toolkit for Windows
003:          Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
004:         
005:          This program is free software; you can redistribute it and/or modify
006:          it under the terms of the GNU General Public License as published by
007:          the Free Software Foundation; either version 2 of the License, or
008:          (at your option) any later version.
009:         
010:          This program is distributed in the hope that it will be useful,
011:          but WITHOUT ANY WARRANTY; without even the implied warranty of
012:          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:          GNU General Public License for more details.
014:         
015:          You should have received a copy of the GNU General Public License
016:          along with this program; if not, write to the Free Software
017:          Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:         
019:         */
020:
021:        /*
022:         * JSmoothModelPersistency.java
023:         *
024:         * Created on 7 août 2003, 19:42
025:         */
026:
027:        package net.charabia.jsmoothgen.application;
028:
029:        import java.io.*;
030:        import java.util.*;
031:
032:        import java.beans.XMLEncoder;
033:        import java.beans.XMLDecoder;
034:
035:        import javax.xml.transform.stream.StreamResult;
036:        import javax.xml.transform.stream.StreamSource;
037:
038:        import com.wutka.jox.*;
039:
040:        public class JSmoothModelPersistency {
041:            public static JSmoothModelBean load(File fin) throws IOException {
042:                FileReader fr = new FileReader(fin);
043:                try {
044:                    JSmoothModelBean jobj = new JSmoothModelBean();
045:                    String INVALID = "INVALID";
046:                    jobj.setSkeletonName(INVALID);
047:                    JOXBeanReader jbr = new JOXBeanReader(fr);
048:                    jbr.readObject(jobj);
049:                    jbr.close();
050:                    fr.close();
051:
052:                    if (jobj.getSkeletonName() == INVALID) {
053:                        throw new Exception("Not a JOX File");
054:                    }
055:                    //		System.out.println("Loaded jobj " + jobj + " = " + jobj.getJarLocation());
056:                    if ((jobj.getJarLocation() != null)
057:                            && (jobj.getJarLocation().length() > 0)) {
058:                        jobj.setEmbeddedJar(true);
059:                        //			System.out.println("Set embeddedjar to " + jobj.getEmbeddedJar());
060:                    }
061:
062:                    return jobj;
063:
064:                } catch (Exception exc) {
065:                    fr.close();
066:
067:                    try {
068:                        FileInputStream fis = new FileInputStream(fin);
069:                        XMLDecoder dec = new XMLDecoder(fis);
070:                        JSmoothModelBean xobj = (JSmoothModelBean) dec
071:                                .readObject();
072:                        fis.close();
073:
074:                        if ((xobj.getJarLocation() != null)
075:                                && (xobj.getJarLocation().length() > 0))
076:                            xobj.setEmbeddedJar(true);
077:
078:                        return xobj;
079:
080:                    } catch (Exception exc2) {
081:                        exc2.printStackTrace();
082:                        throw new IOException(exc2.toString());
083:                    }
084:                }
085:            }
086:
087:            public static void save(File fout, JSmoothModelBean obj)
088:                    throws IOException {
089:                //	FileOutputStream fos = new FileOutputStream(fout);
090:                try {
091:                    // 		XMLEncoder enc = new XMLEncoder(fos);
092:                    // 		enc.writeObject(obj);
093:                    // 		enc.close();
094:
095:                    String jarloc = obj.getJarLocation();
096:                    if (obj.getEmbeddedJar() == false)
097:                        obj.setJarLocation(null);
098:
099:                    FileWriter fw = new FileWriter(fout);
100:                    JOXBeanWriter jbw = new JOXBeanWriter(fw);
101:                    jbw.writeObject("jsmoothproject", obj);
102:                    jbw.close();
103:                    fw.close();
104:
105:                    obj.setJarLocation(jarloc);
106:
107:                } catch (Exception ex) {
108:                    throw new IOException(ex.toString());
109:                } finally {
110:                    //		    fos.close();
111:                }
112:            }
113:
114:            // root : z:/a/b/c/d
115:            // t1:    z:/a/b/e/f
116:            // t2:    c:/t/r
117:            // t3:    z:/a/b/c/d/i/m
118:            // t4:    z:/a/b/c/d
119:            static public File makePathRelativeIfPossible(File root, File f) {
120:                if (f.toString().indexOf("${") >= 0)
121:                    return f;
122:
123:                File orgfile = f;
124:                try {
125:                    if (f.isAbsolute() == false) {
126:                        f = new File(root, f.toString());
127:                    }
128:                    f = f.getCanonicalFile();
129:                    f = f.getAbsoluteFile();
130:                    root = root.getCanonicalFile();
131:                    root = root.getAbsoluteFile();
132:                } catch (IOException iox) {
133:                    iox.printStackTrace();
134:                    System.out.println("Failed, returning " + orgfile);
135:
136:                    return orgfile;
137:                }
138:                Vector rootvec = new Vector();
139:                Vector targetvec = new Vector();
140:                File cur;
141:                cur = root;
142:                while (cur != null) {
143:                    String n = cur.getName();
144:                    // lame hack, because getName() returns "" when the file is a drive (like c: or z:)
145:                    if (n.equals(""))
146:                        n = cur.getAbsolutePath();
147:                    rootvec.add(0, n);
148:                    cur = cur.getParentFile();
149:                }
150:
151:                cur = f;
152:                while (cur != null) {
153:                    String n = cur.getName();
154:                    if (n.equals(""))
155:                        n = cur.getAbsolutePath();
156:                    targetvec.add(0, n);
157:                    cur = cur.getParentFile();
158:                }
159:
160:                // find the lowest common path
161:                int cursor = 0;
162:                while ((cursor < rootvec.size()) && (cursor < targetvec.size())) {
163:                    if (rootvec.elementAt(cursor).equals(
164:                            targetvec.elementAt(cursor)) == false)
165:                        break;
166:                    cursor++;
167:                }
168:
169:                if (cursor == 0)
170:                    return f;
171:
172:                if ((cursor == rootvec.size()) && (cursor == targetvec.size()))
173:                    return new File(".");
174:
175:                StringBuffer buffer = new StringBuffer();
176:                for (int i = cursor; i < rootvec.size(); i++) {
177:                    buffer.append("../");
178:                }
179:
180:                for (int i = cursor; i < targetvec.size(); i++) {
181:                    buffer.append(targetvec.elementAt(i).toString());
182:                    buffer.append("/");
183:                }
184:
185:                return new File(buffer.toString());
186:            }
187:
188:            static public void main(String[] args) {
189:                File root = new File("z:/a/b/c/d");
190:                File t1 = new File("z:/a/b/e/f");
191:                File t2 = new File("c:/t/r");
192:                File t3 = new File("z:/a/b/c/d/i/m");
193:                File t4 = new File("z:/a/b/c/d");
194:
195:                System.out.println("Rel root, t1: "
196:                        + makePathRelativeIfPossible(root, t1));
197:                System.out.println("Rel root, t2: "
198:                        + makePathRelativeIfPossible(root, t2));
199:                System.out.println("Rel root, t3: "
200:                        + makePathRelativeIfPossible(root, t3));
201:                System.out.println("Rel root, t4: "
202:                        + makePathRelativeIfPossible(root, t4));
203:
204:                File f1 = new File("f:\\a\\b");
205:                File f2 = new File("f:\\a\\c");
206:                File f3 = new File(f1, f2.toString());
207:                System.out.println("f3 = " + f3.toString());
208:            }
209:
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.