Source Code Cross Referenced for Family.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.File;
027:        import java.util.ArrayList;
028:        import java.util.Collections;
029:        import java.util.Comparator;
030:        import java.util.Vector;
031:
032:        import org.objectweb.salome_tmf.api.Api;
033:        import org.objectweb.salome_tmf.api.ApiConstants;
034:        import org.objectweb.salome_tmf.api.data.FamilyWrapper;
035:        import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
036:        import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
037:        import org.objectweb.salome_tmf.api.data.SuiteWrapper;
038:        import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
039:        import org.objectweb.salome_tmf.api.sql.ISQLFamily;
040:
041:        public class Family extends WithAttachment {
042:            transient static ISQLFamily pISQLFamily = null;
043:
044:            protected Project pProject = null;
045:            protected ArrayList suiteList;
046:            protected int order = -1;
047:
048:            public Family(String name, String description) {
049:                super (name, description);
050:                suiteList = new ArrayList();
051:                if (pISQLFamily == null) {
052:                    pISQLFamily = Api.getISQLObjectFactory().getISQLFamily();
053:                }
054:            }
055:
056:            public Family(FamilyWrapper pFamily) {
057:                super (pFamily.getName(), pFamily.getDescription());
058:                idBdd = pFamily.getIdBDD();
059:                suiteList = new ArrayList();
060:                order = pFamily.getOrder();
061:                if (pISQLFamily == null) {
062:                    pISQLFamily = Api.getISQLObjectFactory().getISQLFamily();
063:                }
064:            }
065:
066:            public Family(Project pProject, FamilyWrapper pFamily) {
067:                this (pFamily);
068:                this .pProject = pProject;
069:            }
070:
071:            public void reloadBaseFromDB() throws Exception {
072:                if (!isInBase()) {
073:                    throw new Exception("Family " + name + " is not in BDD");
074:                }
075:                FamilyWrapper pFamilyWrapper = pISQLFamily.getFamily(idBdd);
076:                name = pFamilyWrapper.getName();
077:                description = pFamilyWrapper.getDescription();
078:                order = pFamilyWrapper.getOrder();
079:            }
080:
081:            public void reloadFromDB() throws Exception {
082:                reloadBaseFromDB();
083:                reloadAttachmentDataFromDB(false);
084:                reloadTestListFromDB();
085:            }
086:
087:            /******************************************************************************/
088:            /** 							ACCESSEURS ET MUTATEURS						***/
089:            /******************************************************************************/
090:
091:            public ArrayList getSuiteListFromModel() {
092:                return suiteList;
093:            }
094:
095:            /***************************** Basic Operation *********************************/
096:
097:            /* Used By Project */
098:            void addInDB(int idProject) throws Exception {
099:                if (isInBase()) {
100:                    throw new Exception("Family " + name + " is already in BDD");
101:                }
102:                idBdd = pISQLFamily.insert(idProject, name, description);
103:                order = pISQLFamily.getFamily(idBdd).getOrder();
104:                Project.pCurrentProject.notifyChanged(
105:                        ApiConstants.INSERT_FAMILY, this );
106:            }
107:
108:            /* Used By Project */
109:            void addInModel(Project pProject) {
110:                this .pProject = pProject;
111:            }
112:
113:            /* Used By Project */
114:            void addInDBAndModel(Project pProject) throws Exception {
115:                addInDB(pProject.getIdBdd());
116:                addInModel(pProject);
117:            }
118:
119:            public void updateInDB(String newName, String newDesc)
120:                    throws Exception {
121:                if (!isInBase()) {
122:                    throw new Exception("Family " + name + " is not in BDD");
123:                }
124:                pISQLFamily.update(idBdd, newName, newDesc);
125:                Project.pCurrentProject.notifyChanged(
126:                        ApiConstants.UPDATE_FAMILY, this , new String(name),
127:                        newName);
128:            }
129:
130:            public void updateInModel(String newName, String newDesc) {
131:                name = newName;
132:                description = newDesc;
133:            }
134:
135:            public void updateInDBAndModel(String newName, String newDesc)
136:                    throws Exception {
137:                updateInDB(newName, newDesc);
138:                updateInModel(newName, newDesc);
139:            }
140:
141:            public void updateOrderInBddAndModel(boolean inc) throws Exception {
142:                if (!isInBase()) {
143:                    throw new Exception("Family " + name + " is not in BDD");
144:                }
145:                order = pISQLFamily.updateOrder(idBdd, inc);
146:            }
147:
148:            /* Used By Project */
149:            void deleteInDB() throws Exception {
150:                if (!isInBase()) {
151:                    throw new Exception("Family " + name + " is not in BDD");
152:                }
153:                pISQLFamily.delete(idBdd);
154:                Project.pCurrentProject.notifyChanged(
155:                        ApiConstants.DELETE_FAMILY, this );
156:            }
157:
158:            /* Used By Project */
159:            void deleteInModel() {
160:                pProject = null;
161:                for (int i = 0; i < suiteList.size(); i++) {
162:                    TestList pTestList = (TestList) suiteList.get(i);
163:                    pTestList.deleteInModel();
164:                    Project.pCurrentProject.notifyChanged(
165:                            ApiConstants.DELETE_SUITE, pTestList);
166:                }
167:                suiteList.clear();
168:            }
169:
170:            void deleteInDBModel() throws Exception {
171:                deleteInDB();
172:                deleteInModel();
173:            }
174:
175:            /************************** Suite/TestList **********************************/
176:
177:            public void addTestListInModel(TestList list) {
178:                list.addInModel(this );
179:                suiteList.add(list);
180:            }
181:
182:            public void addTestListInDB(TestList list) throws Exception {
183:                list.addInDB(idBdd);
184:            }
185:
186:            public void addTestListInDBAndModel(TestList list) throws Exception {
187:                addTestListInDB(list);
188:                addTestListInModel(list);
189:            }
190:
191:            public void deleteTestListInModel(TestList list) {
192:                list.deleteInModel();
193:                suiteList.remove(list);
194:            }
195:
196:            public void deleteTestListInDB(TestList list) throws Exception {
197:                list.deleteInDB();
198:            }
199:
200:            public void deleteTestListInDBAndModel(TestList list)
201:                    throws Exception {
202:                deleteTestListInDB(list);
203:                deleteTestListInModel(list);
204:            }
205:
206:            public TestList getTestListInModel(String testListName) {
207:                for (int i = 0; i < suiteList.size(); i++) {
208:                    if (((TestList) suiteList.get(i)).getNameFromModel()
209:                            .equals(testListName)) {
210:                        return (TestList) suiteList.get(i);
211:                    }
212:                }
213:                return null;
214:            } // Fin de la méthode getTestList/1
215:
216:            public TestList getTestListFromModel(int id) {
217:                for (int i = 0; i < suiteList.size(); i++) {
218:                    if (((TestList) suiteList.get(i)).getIdBdd() == id) {
219:                        return (TestList) suiteList.get(i);
220:                    }
221:                }
222:                return null;
223:            }
224:
225:            public boolean isContainTestFromModel(int id) {
226:                boolean res = false;
227:                for (int i = 0; i < suiteList.size(); i++) {
228:                    TestList pTestList = (TestList) suiteList.get(i);
229:                    if (pTestList.getTestFromModel(id) != null) {
230:                        return true;
231:                    }
232:                }
233:                return res;
234:            }
235:
236:            public boolean isContainTestInModel(Test pTest) {
237:                return isContainTestFromModel(pTest.getIdBdd());
238:            }
239:
240:            public void reloadTestListFromDB() throws Exception {
241:                for (int i = 0; i < suiteList.size(); i++) {
242:                    ((TestList) suiteList.get(i)).deleteInModel();
243:                }
244:                suiteList.clear();
245:                Vector testListVector = getSuitesWrapperFromDB();
246:                for (int j = 0; j < testListVector.size(); j++) {
247:                    SuiteWrapper testListBdd = (SuiteWrapper) testListVector
248:                            .get(j);
249:                    TestList testList = new TestList(this , testListBdd);
250:                    testList.reloadFromDB();
251:                    addTestListInModel(testList);
252:                }
253:            }
254:
255:            public Vector getSuitesWrapperFromDB() throws Exception {
256:                if (!isInBase()) {
257:                    throw new Exception("Family " + name + " is not in BDD");
258:                }
259:                SuiteWrapper[] tmpArray = pISQLFamily.getTestList(idBdd);
260:                Vector tmpVector = new Vector();
261:                for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
262:                    tmpVector.add(tmpArray[tmpI]);
263:                }
264:                return tmpVector;
265:            }
266:
267:            /************************** ATTACHEMENTS **********************/
268:            public void addAttachementInDB(Attachment attach) throws Exception {
269:                if (attach instanceof  FileAttachment) {
270:                    addAttachFileInDB((FileAttachment) attach);
271:                } else {
272:                    addAttachUrlInDB((UrlAttachment) attach);
273:                }
274:            }
275:
276:            void addAttachFileInDB(FileAttachment file) throws Exception {
277:                if (!isInBase()) {
278:                    throw new Exception("TestList " + name + " is not in BDD");
279:                }
280:                File f = file.getLocalFile();
281:                int id = pISQLFamily.addAttachFile(idBdd,
282:                        new SalomeFileWrapper(f), file
283:                                .getDescriptionFromModel());
284:                file.setIdBdd(id);
285:            }
286:
287:            void addAttachUrlInDB(UrlAttachment url) throws Exception {
288:                if (!isInBase()) {
289:                    throw new Exception("TestList " + name + " is not in BDD");
290:                }
291:                int id = pISQLFamily.addAttachUrl(idBdd,
292:                        url.getNameFromModel(), url.getDescriptionFromModel());
293:                url.setIdBdd(id);
294:            }
295:
296:            protected void deleteAttachementInDB(int attachId) throws Exception {
297:                if (!isInBase()) {
298:                    throw new Exception("TestList " + name + " is not in BDD");
299:                }
300:                pISQLFamily.deleteAttach(idBdd, attachId);
301:            }
302:
303:            public void deleteAttachementInDBAndModel(Attachment attach)
304:                    throws Exception {
305:                deleteAttachementInDB(attach.getIdBdd());
306:                deleteAttachmentInModel(attach);
307:            }
308:
309:            public Vector getAttachFilesFromDB() throws Exception {
310:                if (!isInBase()) {
311:                    throw new Exception("TestList " + name + " is not in BDD");
312:                }
313:                FileAttachementWrapper[] tmpArray = pISQLFamily
314:                        .getAllAttachFiles(idBdd);
315:                Vector tmpVector = new Vector();
316:                for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
317:                    tmpVector.add(tmpArray[tmpI]);
318:                }
319:                return tmpVector;
320:            }
321:
322:            public Vector getAttachUrlsFromDB() throws Exception {
323:                if (!isInBase()) {
324:                    throw new Exception("TestList " + name + " is not in BDD");
325:                }
326:                UrlAttachementWrapper[] tmpArray = pISQLFamily
327:                        .getAllAttachUrls(idBdd);
328:                Vector tmpVector = new Vector();
329:                for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
330:                    tmpVector.add(tmpArray[tmpI]);
331:                }
332:                return tmpVector;
333:            }
334:
335:            ////////////////////////////////////////////////////////////////////////////////
336:            public static boolean isInBase(Project pProject, Family family) {
337:                return isInBase(pProject, family.getNameFromModel());
338:            } // Fin de la méthode isInBase/1
339:
340:            public static boolean isInBase(Project pProject, String familyName) {
341:                try {
342:                    int id = pISQLFamily.getID(pProject.getIdBdd(), familyName);
343:                    if (id > 0) {
344:                        return true;
345:                    }
346:                    return false;
347:                } catch (Exception e) {
348:
349:                }
350:                return false;
351:            } // Fin de la méthode isInBase/1
352:
353:            public boolean existeInBase() throws Exception {
354:                if (!isInBase()) {
355:                    return false;
356:                }
357:                return pISQLFamily.getID(pProject.getIdBdd(), name) == idBdd;
358:            }
359:
360:            /**** COPIER/COLER ************/
361:            public static Family getCopie(Family toCopie) throws Exception {
362:                Family pCopie = new Family(toCopie.getNameFromModel(), toCopie
363:                        .getDescriptionFromModel());
364:                SuiteWrapper[] allTestList = pISQLFamily.getTestList(toCopie
365:                        .getIdBdd());
366:                int size = allTestList.length;
367:                for (int i = 0; i < size; i++) {
368:                    SuiteWrapper pSuiteWrapper = allTestList[i];
369:                    TestList copie = TestList.getCopie(new TestList(
370:                            pSuiteWrapper));
371:                    pCopie.addTestListInModel(copie);
372:                }
373:                return pCopie;
374:            }
375:
376:            public static Family copieIn(Family toCopie) throws Exception {
377:                Family pCopie = new Family(toCopie.getNameFromModel(), toCopie
378:                        .getDescriptionFromModel());
379:                String familyName = toCopie.getNameFromModel();
380:                int i = 0;
381:                while (pCopie.isInBase(DataLoader.getCurrentProject(),
382:                        familyName)) {
383:                    familyName = toCopie.getNameFromModel() + "_" + i;
384:                    i++;
385:                }
386:                pCopie.updateInModel(familyName, toCopie
387:                        .getDescriptionFromModel());
388:                DataLoader.getCurrentProject().addFamilyInDBAndModel(pCopie);
389:
390:                SuiteWrapper[] allTestList = pISQLFamily.getTestList(toCopie
391:                        .getIdBdd());
392:                int size = allTestList.length;
393:                for (i = 0; i < size; i++) {
394:                    SuiteWrapper pSuiteWrapper = allTestList[i];
395:                    TestList copie = TestList.copieIn(new TestList(
396:                            pSuiteWrapper), pCopie);
397:                    //pCopie.addTestListInModel(copie);
398:                }
399:
400:                return pCopie;
401:            }
402:
403:            /*************************************************************************/
404:
405:            public void triTestListInModel() {
406:                Collections.sort(suiteList, new ComparateurTestList());
407:            }
408:
409:            class ComparateurTestList implements  Comparator {
410:                public int compare(Object poTest1, Object poTest2) {
411:                    TestList pTest1 = (TestList) poTest1;
412:                    TestList pTest2 = (TestList) poTest2;
413:                    /*
414:                    System.out.println(" ORDER1 = " + pTest1.getNameFromModel() + " " + pTest1.order);
415:                    System.out.println(" ORDER2 = " + pTest2.getNameFromModel() + " " + pTest2.order);
416:                     */
417:                    if (pTest1.order > pTest2.order) {
418:                        return 1;
419:                    } else {
420:                        return -1;
421:                    }
422:                }
423:            }
424:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.