Source Code Cross Referenced for FileAttachment.java in  » Test-Coverage » salome-tmf » org » objectweb » salome_tmf » data » 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 » Test Coverage » salome tmf » org.objectweb.salome_tmf.data 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SalomeTMF is a Test Management Framework
003:         * Copyright (C) 2005 France Telecom R&D
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2 of the License, or (at your option) any later version.
009:         *
010:         * This library 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 GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         *
019:         * @author Marche Mikael
020:         *
021:         * Contact: mikael.marche@rd.francetelecom.com
022:         */
023:
024:        package org.objectweb.salome_tmf.data;
025:
026:        import java.io.BufferedOutputStream;
027:        import java.io.File;
028:        import java.io.FileOutputStream;
029:        import java.sql.Date;
030:
031:        import org.objectweb.salome_tmf.api.Api;
032:        import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
033:        import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
034:        import org.objectweb.salome_tmf.api.sql.ISQLFileAttachment;
035:
036:        public class FileAttachment extends Attachment {
037:
038:            transient static ISQLFileAttachment pISQLFileAttachment = null;
039:
040:            private Long size;
041:            private Date date;
042:
043:            /////////////////////// Selecteur //////////////////////////
044:            public Date getDate() {
045:                return date;
046:            }
047:
048:            public Long getSize() {
049:                return size;
050:            }
051:
052:            ///////////////////// Constructeur ///////////////////////////
053:
054:            public FileAttachment(String name, String description) {
055:                super (name, description);
056:                if (pISQLFileAttachment == null) {
057:                    pISQLFileAttachment = Api.getISQLObjectFactory()
058:                            .getISQLFileAttachment();
059:                }
060:            }
061:
062:            public FileAttachment(File f, String description) {
063:                super (f.getName(), description);
064:                size = new Long(f.length());
065:                date = new Date(f.lastModified());
066:                localisation = f.getAbsolutePath();
067:                if (pISQLFileAttachment == null) {
068:                    pISQLFileAttachment = Api.getISQLObjectFactory()
069:                            .getISQLFileAttachment();
070:                }
071:            }
072:
073:            public void clearCache() {
074:                /* NOTHING */
075:            }
076:
077:            //	public FileAttachment(SalomeFileWrapper f, String description) {
078:            //		super(f.getName(), description);
079:            //		size = new Long(f.getLength());
080:            //		date =  new Date(f.getLastModified());
081:            //		localisation = f.getAbsolutePath();
082:            //		if (pISQLFileAttachment == null){
083:            //			pISQLFileAttachment = Api.getISQLObjectFactory().getISQLFileAttachment();
084:            //		}
085:            //	}
086:
087:            public FileAttachment(FileAttachementWrapper pFileAttachementWrapper) {
088:                super (pFileAttachementWrapper.getName(),
089:                        pFileAttachementWrapper.getDescription());
090:                idBdd = pFileAttachementWrapper.getIdBDD();
091:                date = pFileAttachementWrapper.getDate();
092:                size = pFileAttachementWrapper.getSize();
093:                localisation = pFileAttachementWrapper.getLocalisation();
094:                if (pISQLFileAttachment == null) {
095:                    pISQLFileAttachment = Api.getISQLObjectFactory()
096:                            .getISQLFileAttachment();
097:                }
098:            }
099:
100:            ///////////////////// Methode //////////////////////////
101:
102:            public void updateInDB(File f) throws Exception {
103:                if (!f.exists()) {
104:                    throw new Exception("[FileAttachment] File no exits");
105:                }
106:                pISQLFileAttachment.updateFile(idBdd, new SalomeFileWrapper(f));
107:            }
108:
109:            public void updateInModel(File f) {
110:                name = f.getName();
111:                size = new Long(f.length());
112:                date = new Date(f.lastModified());
113:                localisation = f.getAbsolutePath();
114:            }
115:
116:            public void updateInDBAndModel(File f) throws Exception {
117:                updateInDB(f);
118:                updateInModel(f);
119:            }
120:
121:            public File getFileFromDB() throws Exception {
122:                File f = getFileFromDB(null);
123:                localisation = f.getAbsolutePath();
124:                return f;
125:
126:                //		SalomeFileWrapper f =  pISQLFileAttachment.getFile(idBdd);
127:                //		
128:                //		String path = null;
129:                //		File file = null;
130:                //		InputStream is = null;
131:                //		String tmpDir;
132:                //		Properties sys = System.getProperties();
133:                //		String fs = sys.getProperty("file.separator");
134:                //		if (path == null || path.equals("")){
135:                //			// Repertoire temporaire système
136:                //			tmpDir = sys.getProperty("java.io.tmpdir");
137:                //			tmpDir = tmpDir + fs + ApiConstants.PATH_TO_ADD_TO_TEMP + fs;
138:                //		} else {
139:                //			tmpDir = path;
140:                //			if (!path.endsWith(fs)){
141:                //				tmpDir = tmpDir + fs;
142:                //			}
143:                //			
144:                //		}
145:                //		Util.log("[SQLFileAttachment->getFile] at path : " + tmpDir);
146:                //		file = new File(tmpDir + f.getName());
147:                //		File fPath = new File(file.getCanonicalPath().substring(0,file.getCanonicalPath().lastIndexOf(fs)+1));
148:                //		if (!fPath.exists()){
149:                //			fPath.mkdirs();
150:                //		}
151:                //		file.createNewFile();
152:                //		
153:                //		// Flux d'écriture sur le fichier
154:                //		FileOutputStream fos = new FileOutputStream(file);
155:                //		BufferedOutputStream bos = new BufferedOutputStream(fos);
156:                //		
157:                //		// Flux du fichier stocké dans la BdD 
158:                //		bos.write(f.getContent());
159:                //		
160:                //		//	Fermeture des flux de données
161:                //		bos.flush();
162:                //		bos.close();
163:                //		
164:                //		localisation = file.getAbsolutePath();
165:                //		return new SalomeFileWrapper(file);
166:            }
167:
168:            public File getFileFromDB(String filePath) throws Exception {
169:
170:                //long debut = Calendar.getInstance().getTimeInMillis();
171:                return pISQLFileAttachment.getFile(idBdd).toFile(filePath);
172:
173:                /*
174:                SalomeFileWrapper f = pISQLFileAttachment.getFile(idBdd);
175:                
176:                //String path = null;
177:                String path = filePath;
178:                File file = null;
179:                String tmpDir;
180:                Properties sys = System.getProperties();
181:                String fs = sys.getProperty("file.separator");
182:                if (path == null || path.equals("")){
183:                	// Repertoire temporaire système
184:                	tmpDir = sys.getProperty("java.io.tmpdir");
185:                	tmpDir = tmpDir + fs + ApiConstants.PATH_TO_ADD_TO_TEMP + fs;
186:                } else {
187:                	tmpDir = path;
188:                	if (!path.endsWith(fs)){
189:                		tmpDir = tmpDir + fs;
190:                	}
191:                	
192:                }
193:                Util.log("[SQLFileAttachment->getFile] at path : " + tmpDir);
194:                file = new File(tmpDir + f.getName());
195:                File fPath = new File(file.getCanonicalPath().substring(0,file.getCanonicalPath().lastIndexOf(fs)+1));
196:                if (!fPath.exists()){
197:                	fPath.mkdirs();
198:                }
199:                file.createNewFile();
200:                
201:                // Flux d'écriture sur le fichier
202:                FileOutputStream fos = new FileOutputStream(file);
203:                BufferedOutputStream bos = new BufferedOutputStream(fos);
204:                
205:                // Flux du fichier stocké dans la BdD 
206:                bos.write(f.getContent());
207:                
208:                //	Fermeture des flux de données
209:                bos.flush();
210:                bos.close();
211:                
212:                return file;*/
213:            }
214:
215:            public File getFileFromDBIn(File f) throws Exception {
216:                SalomeFileWrapper file = pISQLFileAttachment.getFileIn(idBdd,
217:                        new SalomeFileWrapper(f));
218:                //localisation = f.getAbsolutePath();
219:                f.createNewFile();
220:
221:                // Flux d'écriture sur le fichier
222:                FileOutputStream fos = new FileOutputStream(f);
223:                BufferedOutputStream bos = new BufferedOutputStream(fos);
224:
225:                // Flux du fichier stocké dans la BdD 
226:                bos.write(file.getContent());
227:
228:                //	Fermeture des flux de données
229:                bos.flush();
230:
231:                return file.toFile();
232:            }
233:
234:            public void deleteFromDisk() throws Exception {
235:                if (localisation != null && !localisation.equals("")) {
236:                    File file = new File(localisation);
237:                    if (file.exists()) {
238:                        file.delete();
239:                    }
240:                }
241:                localisation = null;
242:            }
243:
244:            public File getLocalFile() throws Exception {
245:                File file = null;
246:                if (localisation != null && !localisation.equals("")) {
247:                    file = new File(localisation);
248:                }
249:                return file;
250:            }
251:
252:            public boolean equals(Object o) {
253:                if (o instanceof  FileAttachment) {
254:                    FileAttachment toTest = (FileAttachment) o;
255:                    if (isInBase() && toTest.isInBase()) {
256:                        if (getIdBdd() == toTest.getIdBdd()) {
257:                            return true;
258:                        }
259:                    } else {
260:                        String loc2 = toTest.getLocalisation();
261:                        if (localisation != null && !localisation.equals("")
262:                                && loc2 != null && !loc2.equals("")) {
263:                            return localisation.equals(loc2);
264:                        }
265:                        return super .equals(o);
266:                    }
267:                }
268:                return false;
269:            }
270:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.