KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DataLoaderTests > DataObjectTest > DataObjectTestsGenerator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * DataObjectTestsGenerator.java
22  *
23  * Created on June 26, 2001, 11:25 AM
24  */

25
26 package DataLoaderTests.DataObjectTest;
27
28 import org.openide.filesystems.Repository;
29
30
31 /**
32  *
33  * @author jzajicek
34  * @version
35  */

36 public class DataObjectTestsGenerator {
37
38     /** Creates new DataObjectTestsGenerator */
39     public DataObjectTestsGenerator() {
40     }
41
42     /**
43      * @param args the command line arguments
44      */

45     public static void main(String JavaDoc args[]) {
46         org.openide.filesystems.FileObject fo = Repository.getDefault()
47                 .findResource(PACKAGE + "/" + DATAOBJECTS + "/" + "Backup");
48         
49         org.openide.loaders.DataFolder df = null;
50         try{
51             if ( fo.isFolder() ) {
52                 df = (org.openide.loaders.DataFolder) org.openide.loaders.DataFolder.find(fo);
53                 //System.out.println(df);
54
org.openide.loaders.DataObject[] dobs = df.getChildren();
55                 
56                 //java.io.File testlist = new java.io.File(ROOT + "/DataObjectsTests.ttl");
57
//testlist.createNewFile();
58
//java.io.PrintWriter toTestlist = new java.io.PrintWriter(new java.io.FileOutputStream(testlist));
59

60                 for (int j = 0 ; j < CAT.length; j++) {
61                     for (int i = 0 ; i < dobs.length ; i++) {
62                         //System.out.println(dobs[i]);
63
String JavaDoc name = dobs[i].getPrimaryFile().getName();
64                         String JavaDoc ext = dobs[i].getPrimaryFile().getExt();
65                         
66                         java.io.File JavaDoc d = new java.io.File JavaDoc(ROOT + "/" + CAT[j] + "/" + name + "/");
67                         d.mkdirs();
68                         
69                         java.io.File JavaDoc f = new java.io.File JavaDoc(ROOT + "/" + CAT[j] + "/" + name + "/" + name + "_" + CAT[j] + ".java");
70                         f.createNewFile();
71                         
72                         //java.io.File cfg = new java.io.File(ROOT + "/" + CAT[j] + "/" + name + "/" + name /*+ "_" + CAT[j]*/ + ".cfg");
73
//cfg.createNewFile();
74

75                         String JavaDoc clazz =
76                         s1 + CAT[j] + "." +name + ";\n" +
77                         s2 + name + "_" + CAT[j] +
78                         s3 + CAT[j] + "{\n" +
79                         s4 + name + "_" + CAT[j] + s4_1 +
80                         s5 + name + "." + ext +
81                         s6 + name + "_" + CAT[j] +
82                         s7;
83                         
84                         java.io.PrintWriter JavaDoc pv = new java.io.PrintWriter JavaDoc(new java.io.FileOutputStream JavaDoc(f));
85                         pv.print(clazz);
86                         pv.flush();
87                         pv.close();
88                         
89                         //java.io.PrintWriter toCfg = new java.io.PrintWriter(new java.io.FileOutputStream(cfg));
90
//toCfg.print("EXECUTE_CLASS=" + PACKAGE.replace('/','.') + "." + CAT[j] + "." + name + "." + name + "_" + CAT[j]);
91
//toCfg.flush();
92
//toCfg.close();
93

94                         //toTestlist.print(PACKAGE + "/" + CAT[j] + "/" + name + " execute_positive\n");
95
}
96                 }
97                 //toTestlist.flush();
98
//toTestlist.close();
99
} else {
100                 System.out.println("Expecting 'DataObjects' folder in this package!");
101             }
102         }catch(Exception JavaDoc ex){
103             ex.printStackTrace();
104         }
105     }
106     
107     final static String JavaDoc PACKAGE = new DataObjectTestsGenerator().getClass().getPackage().getName().replace('.','/');
108     
109     final static String JavaDoc ROOT = org.openide.filesystems.FileUtil.toFile(
110         Repository.getDefault().findResource(PACKAGE)).getAbsolutePath();
111     
112     final static String JavaDoc DATAOBJECTS = "data";
113     final static String JavaDoc MANIPULATION = "manipulation";
114     final static String JavaDoc MODIFY = "modify";
115     final static String JavaDoc VALIDITY = "validity";
116     final static String JavaDoc DELEGATE = "delegate";
117     final static String JavaDoc OTHERS = "others";
118     
119     final static String JavaDoc[] CAT = new String JavaDoc[]{MANIPULATION,MODIFY,VALIDITY,DELEGATE,OTHERS};
120     
121     final static String JavaDoc s1 = "package DataLoaderTests.DataObjectTest.";
122     final static String JavaDoc s2 = "import junit.framework.*;\nimport org.netbeans.junit.*;\npublic class ";
123     final static String JavaDoc s3 = " extends DataLoaderTests.DataObjectTest.DataObjectTest_";
124     final static String JavaDoc s4 = " public ";
125     final static String JavaDoc s4_1 = "(java.lang.String testName){\n super(testName);\n";
126     final static String JavaDoc s5 = " NAME = \"/" + DATAOBJECTS + "/";
127     final static String JavaDoc s6 = "\";\n }\npublic static Test suite() {\n NbTestSuite suite = new NbTestSuite(";
128     final static String JavaDoc s7 = ".class);\n return suite;\n }\n}";
129     
130 }
131
Popular Tags