001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
004: //
005: // All Rights Reserved
006: //
007: // This program is free software; you can redistribute it and/or modify
008: // it under the terms of the GNU General Public License and GNU Library
009: // General Public License as published by the Free Software Foundation;
010: // either version 2, or (at your option) any later version.
011: //
012: // This program is distributed in the hope that it will be useful,
013: // but WITHOUT ANY WARRANTY; without even the implied warranty of
014: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: // GNU General Public License and GNU Library General Public License
016: // for more details.
017: //
018: // You should have received a copy of the GNU General Public License
019: // and GNU Library General Public License along with this program; if
020: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
021: // MA 02139, USA.
022: //
023: ///////////////////////////////////////////////////////////////////////////////
024: package org.myoodb.tools.generator;
025:
026: import java.util.*;
027: import java.io.File;
028:
029: import org.myoodb.core.*;
030:
031: public class Main {
032: public static void main(String[] args) throws Exception {
033: if (args.length < 2) {
034: throw new GeneratorException(
035: "usage: main [[--nobean] --noscript]] -s<sourcepath> [interface files]*");
036: }
037:
038: int startIndex = 0;
039: boolean javaBean = true;
040: boolean javaScript = true;
041: String sourcePath = null;
042:
043: for (int i = 0; i < args.length; i++) {
044: int index = args[i].indexOf("-nobean");
045: if (index != -1) {
046: javaBean = false;
047: startIndex++;
048: }
049:
050: index = args[i].indexOf("-noscript");
051: if (index != -1) {
052: javaScript = false;
053: startIndex++;
054: }
055:
056: index = args[i].indexOf("-s");
057: if ((index == 0) && (args[i].length() > 2)) {
058: sourcePath = args[i].substring(index + 2, args[i]
059: .length());
060: startIndex++;
061: break;
062: }
063: }
064:
065: if (sourcePath == null) {
066: throw new GeneratorException(
067: "usage: main [[--nobean] --noscript]] -s<sourcepath> [interface files]*");
068: }
069:
070: for (int i = startIndex; i < args.length; i++) {
071: System.out.println(" Processing interface: " + args[i]);
072:
073: HashMap methods = new HashMap();
074: Helper.searchForMethods(sourcePath, args[i], methods);
075:
076: //
077: // Proxy Generator
078: //
079: ProxyGenerator proxyGen = new ProxyGenerator();
080: proxyGen.beginClass(sourcePath, args[i]);
081:
082: Iterator iter = methods.keySet().iterator();
083: while (iter.hasNext()) {
084: String methodName = (String) iter.next();
085: Integer accessLevel = (Integer) methods.get(methodName);
086: if (accessLevel.intValue() == org.myoodb.MyOodbAccess.WRITE) {
087: System.out.println(" - Method: (Write) "
088: + methodName);
089: proxyGen.makeMethod(methodName,
090: org.myoodb.MyOodbAccess.WRITE);
091: } else if (accessLevel.intValue() == org.myoodb.MyOodbAccess.TUNNEL) {
092: System.out.println(" - Method: (Tunnel) "
093: + methodName);
094: proxyGen.makeMethod(methodName,
095: org.myoodb.MyOodbAccess.TUNNEL);
096: } else if (accessLevel.intValue() == org.myoodb.MyOodbAccess.REALTIME) {
097: System.out.println(" - Method: (Realtime) "
098: + methodName);
099: proxyGen.makeMethod(methodName,
100: org.myoodb.MyOodbAccess.REALTIME);
101: } else if (accessLevel.intValue() == org.myoodb.MyOodbAccess.ABANDON) {
102: System.out.println(" - Method: (Abandon) "
103: + methodName);
104: proxyGen.makeMethod(methodName,
105: org.myoodb.MyOodbAccess.ABANDON);
106: } else {
107: System.out.println(" - Method: (Read) "
108: + methodName);
109: proxyGen.makeMethod(methodName,
110: org.myoodb.MyOodbAccess.READ);
111: }
112: }
113:
114: proxyGen.endClass();
115:
116: //
117: // Bean Generator
118: //
119: if (javaBean == true) {
120: BeanGenerator beanGen = new BeanGenerator();
121: beanGen.beginClass(sourcePath, args[i]);
122:
123: iter = methods.keySet().iterator();
124: while (iter.hasNext()) {
125: String methodName = (String) iter.next();
126: System.out.println(" - Method: (Read/Write) "
127: + methodName);
128: beanGen.makeMethod(methodName,
129: org.myoodb.MyOodbAccess.NONE);
130: }
131:
132: beanGen.endClass();
133: }
134:
135: //
136: // Script Generator
137: //
138: if (javaScript == true) {
139: ScriptGenerator scriptGen = new ScriptGenerator();
140: scriptGen.beginClass(sourcePath, args[i]);
141:
142: iter = methods.keySet().iterator();
143: while (iter.hasNext()) {
144: String methodName = (String) iter.next();
145: Integer accessLevel = (Integer) methods
146: .get(methodName);
147: if (accessLevel.intValue() == org.myoodb.MyOodbAccess.WRITE) {
148: System.out.println(" - Method: (Write) "
149: + methodName);
150: scriptGen.makeMethod(methodName,
151: org.myoodb.MyOodbAccess.WRITE);
152: } else if (accessLevel.intValue() == org.myoodb.MyOodbAccess.TUNNEL) {
153: System.out.println(" - Method: (Tunnel) "
154: + methodName);
155: scriptGen.makeMethod(methodName,
156: org.myoodb.MyOodbAccess.TUNNEL);
157: } else if (accessLevel.intValue() == org.myoodb.MyOodbAccess.REALTIME) {
158: System.out
159: .println(" - Method: (Realtime) "
160: + methodName);
161: proxyGen.makeMethod(methodName,
162: org.myoodb.MyOodbAccess.REALTIME);
163: } else if (accessLevel.intValue() == org.myoodb.MyOodbAccess.ABANDON) {
164: System.out
165: .println(" - Method: (Abandon) "
166: + methodName);
167: proxyGen.makeMethod(methodName,
168: org.myoodb.MyOodbAccess.ABANDON);
169: } else {
170: System.out.println(" - Method: (Read) "
171: + methodName);
172: scriptGen.makeMethod(methodName,
173: org.myoodb.MyOodbAccess.READ);
174: }
175: }
176:
177: scriptGen.endClass();
178: }
179: }
180: }
181: }
|