📄 oig.java
字号:
// Copyright 1997-2000 by SMB GmbH. All rights reserved.// Copyright Tim Brown <Tim.Brown@incenter.org>. All rights reserved.//// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// $Id: OIG.java,v 1.9 2000/10/28 16:55:20 daniela Exp $package org.ozoneDB.tools;import java.lang.*;import java.util.*;import java.io.*;/** * Ozone Interface Generator * * <p>This class is meant to be run statically only. It will generate an * OzoneRemote interface for your OzoneObject (s) * * <p>USAGE: * * <p> java OzoneInterfaceGenerator your_OzoneObject * * <p>CONVENTIONS: * * <p> Class Names * * <p> OzoneObject classes must be named like *Impl.java. Interfaces * are generated with a _Int inserted into the name. * * <p>File Naming: * * <p>OzoneObjects must have names like: CarImpl.java The interface generated * will be: CarImpl_Int.java * * <p>You do not have to use "Impl". Any name will do. I use a standard because * it is then easy to write makefile rules like: * * <p>%.class: %.java * <br> javac $(JFLAGS) -classpath $(CPATH) $< * <p>%Impl_Proxy.class: %Impl.java * <br> /projects/ozone/bin/opp $*Impl * <p>%Impl_Int.java: %Impl.java * <br> java -Djava.compiler=tya -classpath $(CPATH) OzoneInterfaceGenerator $*Impl * <p>javasrc = $(wildcard *.java) * <br>classes = $(javasrc:.java=.class) * <br>htmlobjs = $(javasrc:.java=.html) * <br>IntSrc = $(wildcard *Impl.java) * <br>IntObjs = $(IntSrc:Impl.java=Impl_Int.java) * <br>proxies = $(IntSrc:Impl.java=Impl_Proxy.class) * <br>proxysrc = $(IntSrc:Impl.java=Impl.class) * * <p>Coding Style * * <p> Public methods must have ALL parameters on one line. Infact * everything up to and including the open curly brace must be on the first * line. * * <p>Patterns for identifying methods which should be locked are stored in * a file called int_config. This file should be in the same directory as * the .java files. You need to list one pattern per line. Like: * <br> set * <br> update * <br> reset * <br> delete * <br> modify * <br> * <br> * * <p>OzoneInterfaceGenerator looks for and reads these in. If the first line * of your public method contains any of these strings it appends //update * to the end signaling OPP to make that method a locked() method. * * <p>If you do not provide a int_config file OIG uses my favorites, listed * above. * * <p>Public Method Examples: * <p>public void setName(String _name) { this.name = _name; } * <br> in the generated interface it produces: * <br> public void setName(String _name);//update * <br> * <br> * * <p>In the following example I use a comment to identify the update method. * One of the patterns just has to be on the first line. * <br> * <br> * <br>public void killMe() { // update * <br> Produces: * <br> public void killMe();//update * <br> * <br> * <p>NOTE: * <p> OIG will handle this: * <p> public static final String x = new String("test"); * <br> * <br> * <p>BUT not this: (working on this :) It will get mistaken for a method. * <p> public String x = new String("test"); * <br> * <br> * <p> * * */public class OIG { public static void main( String[] args ) { Vector updatePatterns = null; BufferedReader in = null; PrintWriter out = null; updatePatterns = getPatterns(); try { // first try to use args in = new BufferedReader( new FileReader( args[0] + ".java" ), 1024 ); out = new PrintWriter( new FileWriter( args[0] + "_Int.java" ) ); } catch (Exception e) { System.err.println( "Using stdin" ); in = new BufferedReader( new InputStreamReader( System.in ), 1024 ); out = new PrintWriter( System.out ); } try { String buf; String tbuf; StringTokenizer tok; boolean fndOpen = false; boolean fndConst = false; String classname = null; String intname = null; while ((buf = in.readLine()) != null) { if (buf.startsWith( "{" )) { out.println( buf ); fndOpen = true; } if (!fndOpen) { if (buf.startsWith( "import" ) || buf.startsWith( "package" )) { out.println( buf ); } else { if (buf.startsWith( "public class" ) || buf.startsWith( "public abstract class" )) { int beg; int end; beg = buf.indexOf( "class" ) + 6; end = buf.indexOf( " ", beg ); classname = buf.substring( beg, end ); intname = classname + "_Int"; out.print( "import org.ozoneDB.OzoneRemote;\n" + "import org.ozoneDB.DxLib.*;\n" + "\npublic interface " + intname + " extends OzoneRemote\n" ); } } } else { if (buf.indexOf( "static" ) == -1) { buf = remove( buf, "synchronized" ); tok = new StringTokenizer( buf ); if (tok.hasMoreTokens()) { tbuf = tok.nextToken(); if (tbuf.startsWith( "public" ) && (buf.indexOf( "(" ) > 0 && buf.indexOf( "{" ) > 0 || buf.indexOf( ");" ) > 0)) { if (!fndConst) { fndConst = true; } else { tbuf = tok.nextToken(); if (!tbuf.startsWith( classname )) { out.print( buf.substring( 0, buf.indexOf( ")" ) + 1 ) + ";" ); Enumeration en = updatePatterns.elements(); while (en.hasMoreElements()) { String s = (String)en.nextElement(); if (buf.indexOf( s ) != -1) { out.println( "//update" ); break; } } out.print( "\n" ); } } } } } } } out.println( "}" ); out.close(); } catch (Exception e) { System.out.flush(); System.err.println( e ); } } private static Vector getPatterns() { BufferedReader in = null; Vector lst = new Vector(); try { in = new BufferedReader( new FileReader( "int_config" ), 1024 ); String buf = null; while ((buf = in.readLine()) != null) { lst.addElement( buf ); } in.close(); return lst; } catch (Exception e) { lst.addElement( "delete" ); lst.addElement( "set" ); lst.addElement( "update" ); lst.addElement( "modify" ); lst.addElement( "reset" ); return lst; } } private static String remove( String buf, String rem ) { try { int beg; int end; beg = buf.indexOf( rem ); if (beg == -1) { return buf; } end = buf.indexOf( " ", beg ); if (end == -1) { return buf; } return buf.substring( 0, beg - 1 ) + buf.substring( end ); } catch (Exception e) { return buf; } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -