KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > wsgen > A_WsGen


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: A_WsGen.java,v 1.4 2004/04/16 16:42:47 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.wsgen;
27
28 import java.io.File JavaDoc;
29 import java.io.FileOutputStream JavaDoc;
30 import java.io.IOException JavaDoc;
31 import java.io.InputStream JavaDoc;
32 import java.util.Enumeration JavaDoc;
33 import java.util.jar.JarFile JavaDoc;
34 import java.util.zip.ZipEntry JavaDoc;
35
36 import org.objectweb.jonas.jtests.util.JWebServicesTestCase;
37
38 public abstract class A_WsGen extends JWebServicesTestCase {
39     private String JavaDoc jonasbase = null;
40     private String JavaDoc resources = null;
41     private String JavaDoc basedir = null;
42
43     public A_WsGen(String JavaDoc name) {
44         super(name);
45     }
46     
47     public void setUp() throws Exception JavaDoc {
48         super.setUp();
49
50         jonasbase = System.getProperty("jonasbase");
51         resources = System.getProperty("ws.resources");
52         basedir = System.getProperty("basedir");
53
54     }
55
56     public void tearDown() throws Exception JavaDoc {
57         super.tearDown();
58     }
59
60     protected String JavaDoc getJonasBaseFile(String JavaDoc path) {
61         return jonasbase + File.separator + path;
62     }
63
64     protected String JavaDoc getResourceFile(String JavaDoc path) {
65         return resources + File.separator + path;
66     }
67
68     protected String JavaDoc getTestFile(String JavaDoc path) {
69         return basedir + File.separator + path;
70     }
71
72     protected static boolean deleteDirectory(String JavaDoc dir) throws IOException JavaDoc {
73         File JavaDoc file = new File JavaDoc(dir);
74         boolean isDestroy = true;
75         if (file.isDirectory()) {
76             // destroy all childs
77
File JavaDoc[] childs = file.listFiles();
78             for (int i = 0; i < childs.length; i++) {
79                 isDestroy &= deleteDirectory(childs[i].getAbsolutePath());
80             }
81         }
82         return isDestroy && file.delete();
83
84     }
85
86     protected static String JavaDoc unpackJar(JarFile JavaDoc file) throws IOException JavaDoc {
87         String JavaDoc tmp = createTempDir();
88         
89         for (Enumeration JavaDoc e = file.entries(); e.hasMoreElements(); ) {
90             ZipEntry JavaDoc ze = (ZipEntry JavaDoc) e.nextElement();
91             String JavaDoc newFilename = tmp + File.separator
92                 + ze.getName().replace('/', File.separator.charAt(0));
93             File JavaDoc entryFile = new File JavaDoc(newFilename);
94
95             entryFile.getParentFile().mkdirs();
96             FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(entryFile);
97             InputStream JavaDoc is = file.getInputStream(ze);
98
99             int n = 0;
100             byte[] buffer = new byte[1024];
101             
102             while ((n = is.read(buffer)) > 0) {
103                 fos.write(buffer, 0, n);
104             }
105             
106             fos.close();
107             is.close();
108         }
109         
110         return tmp;
111     }
112
113     protected static String JavaDoc createTempDir() throws IOException JavaDoc {
114         File JavaDoc tmpDir = File.createTempFile("wsgen-tests", null, null);
115         tmpDir.delete();
116         tmpDir.mkdir();
117         return tmpDir.getAbsolutePath();
118     }
119
120 }
121
Popular Tags