KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > myoodb > tools > generator > Main


1 ///////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
4
//
5
// All Rights Reserved
6
//
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License and GNU Library
9
// General Public License as published by the Free Software Foundation;
10
// either version 2, or (at your option) any later version.
11
//
12
// This program 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 General Public License and GNU Library General Public License
16
// for more details.
17
//
18
// You should have received a copy of the GNU General Public License
19
// and GNU Library General Public License along with this program; if
20
// not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21
// MA 02139, USA.
22
//
23
///////////////////////////////////////////////////////////////////////////////
24
package org.myoodb.tools.generator;
25
26 import java.util.*;
27 import java.io.File JavaDoc;
28
29 import org.myoodb.core.*;
30
31 public class Main
32 {
33     public static void main(String JavaDoc[] args) throws Exception JavaDoc
34     {
35         if (args.length < 2)
36         {
37             throw new GeneratorException("invalid generator arguments { usage: main [--nobean] -s<sourcepath> [interface files]* }");
38         }
39
40         // TODO: make parameter parsing a bunch better
41
int startIndex = 1;
42         boolean javaBean = true;
43         String JavaDoc sourcePath = null;
44
45         for (int i = 0; i < 2; i++)
46         {
47             int index = args[i].indexOf("-s");
48             if ((index == 0) && (args[i].length() > 2))
49             {
50                 sourcePath = args[i].substring(index + 2, args[i].length());
51             }
52
53             index = args[i].indexOf("-nobean");
54             if (index == 0)
55             {
56                 javaBean = false;
57                 startIndex = 2;
58             }
59         }
60
61         if (sourcePath == null)
62         {
63             throw new GeneratorException("invalid generator arguments { usage: main [--nobean] -s<sourcepath> [interface files]* }");
64         }
65
66         for (int i = startIndex; i < args.length; i++)
67         {
68             System.out.println(" Processing interface: " + args[i]);
69
70             HashMap methods = new HashMap();
71             Helper.searchForMethods(sourcePath, args[i], methods);
72
73             //
74
// Proxy Generator
75
//
76
ProxyGenerator proxyGen = new ProxyGenerator();
77             proxyGen.beginClass(sourcePath, args[i]);
78
79             Iterator iter = methods.keySet().iterator();
80             while (iter.hasNext())
81             {
82                 String JavaDoc methodName = (String JavaDoc) iter.next();
83                 Integer JavaDoc accessLevel = (Integer JavaDoc) methods.get(methodName);
84                 if (accessLevel.intValue() == Lock.ACCESS_READ)
85                 {
86                     System.out.println(" - Method: (R) " + methodName);
87                     proxyGen.makeMethod(methodName, Lock.ACCESS_READ);
88                 }
89                 else
90                 {
91                     System.out.println(" - Method: (W) " + methodName);
92                     proxyGen.makeMethod(methodName, Lock.ACCESS_WRITE);
93                 }
94             }
95
96             proxyGen.endClass();
97
98             //
99
// Bean Generator
100
//
101
if (javaBean == true)
102             {
103                 BeanGenerator beanGen = new BeanGenerator();
104                 beanGen.beginClass(sourcePath, args[i]);
105
106                 iter = methods.keySet().iterator();
107                 while (iter.hasNext())
108                 {
109                     String JavaDoc methodName = (String JavaDoc) iter.next();
110                     Integer JavaDoc accessLevel = (Integer JavaDoc) methods.get(methodName);
111                     if (accessLevel.intValue() == Lock.ACCESS_READ)
112                     {
113                         System.out.println(" - Method: (R) " + methodName);
114                         beanGen.makeMethod(methodName, Lock.ACCESS_READ);
115                     }
116                     else
117                     {
118                         System.out.println(" - Method: (W) " + methodName);
119                         beanGen.makeMethod(methodName, Lock.ACCESS_WRITE);
120                     }
121                 }
122
123                 beanGen.endClass();
124             }
125         }
126     }
127 }
128
Popular Tags