KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mchange > v2 > sql > filter > RecreatePackage


1 /*
2  * Distributed as part of c3p0 v.0.9.1
3  *
4  * Copyright (C) 2005 Machinery For Change, Inc.
5  *
6  * Author: Steve Waldman <swaldman@mchange.com>
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License version 2.1, as
10  * published by the Free Software Foundation.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this software; see the file LICENSE. If not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */

22
23
24 package com.mchange.v2.sql.filter;
25
26 import java.io.*;
27 import java.sql.*;
28 import java.lang.reflect.*;
29 import com.mchange.v2.codegen.intfc.*;
30 import com.mchange.v1.lang.ClassUtils;
31 import javax.sql.DataSource JavaDoc;
32
33 public final class RecreatePackage
34 {
35     final static Class JavaDoc[] intfcs
36     = new Class JavaDoc[]
37     {
38         Connection.class,
39         ResultSet.class,
40         DatabaseMetaData.class,
41         Statement.class,
42         PreparedStatement.class,
43         CallableStatement.class,
44         DataSource JavaDoc.class
45     };
46
47     public static void main( String JavaDoc[] argv )
48     {
49     try
50         {
51         DelegatorGenerator dg = new DelegatorGenerator();
52         String JavaDoc thisClassName = RecreatePackage.class.getName();
53         String JavaDoc pkg = thisClassName.substring(0, thisClassName.lastIndexOf('.'));
54         for (int i = 0; i < intfcs.length; ++i)
55             {
56             Class JavaDoc intfcl = intfcs[i];
57             String JavaDoc sin = ClassUtils.simpleClassName( intfcl );
58             String JavaDoc sgenclass1 = "Filter" + sin;
59             String JavaDoc sgenclass2 = "SynchronizedFilter" + sin;
60             
61             Writer w = null;
62             try
63                 {
64                 w = new BufferedWriter( new FileWriter( sgenclass1 + ".java" ) );
65                 dg.setMethodModifiers( Modifier.PUBLIC );
66                 dg.writeDelegator( intfcl, pkg + '.' + sgenclass1, w );
67                 System.err.println( sgenclass1 );
68                 }
69             finally
70                 {
71                 try { if (w != null) w.close(); }
72                 catch (Exception JavaDoc e)
73                     { e.printStackTrace(); }
74                 }
75                 
76             try
77                 {
78                 w = new BufferedWriter( new FileWriter( sgenclass2 + ".java" ) );
79                 dg.setMethodModifiers( Modifier.PUBLIC | Modifier.SYNCHRONIZED );
80                 dg.writeDelegator( intfcl, pkg + '.' + sgenclass2, w );
81                 System.err.println( sgenclass2 );
82                 }
83             finally
84                 {
85                 try { if (w != null) w.close(); }
86                 catch (Exception JavaDoc e)
87                     { e.printStackTrace(); }
88                 }
89             }
90         }
91     catch ( Exception JavaDoc e )
92         { e.printStackTrace(); }
93     }
94
95     private RecreatePackage()
96     {}
97 }
98
Popular Tags