⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oig.java

📁 用Java写的面相对象的数据库管理系统
💻 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>&nbsp;java OzoneInterfaceGenerator your_OzoneObject *  * <p>CONVENTIONS: *  * <p>&nbsp;Class Names *  * <p>&nbsp;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>&nbsp;&nbsp;&nbsp; javac $(JFLAGS) -classpath $(CPATH) $&lt; * <p>%Impl_Proxy.class: %Impl.java * <br>&nbsp;&nbsp;&nbsp;/projects/ozone/bin/opp $*Impl * <p>%Impl_Int.java: %Impl.java * <br>&nbsp;&nbsp;&nbsp;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>&nbsp;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>&nbsp;set * <br>&nbsp;update * <br>&nbsp;reset * <br>&nbsp;delete * <br>&nbsp;modify * <br>&nbsp; * <br>&nbsp; *  * <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>&nbsp;in the generated interface it produces: * <br>&nbsp;public void setName(String _name);//update * <br>&nbsp; * <br>&nbsp; *  * <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>&nbsp; * <br>&nbsp; * <br>public void killMe() { // update * <br>&nbsp;Produces: * <br>&nbsp;public void killMe();//update * <br>&nbsp; * <br>&nbsp; * <p>NOTE: * <p>&nbsp;OIG will handle this: * <p>&nbsp;public static final String x = new String("test"); * <br>&nbsp; * <br>&nbsp; * <p>BUT not this: (working on this :) It will get mistaken for a method. * <p>&nbsp;public String x = new String("test"); * <br>&nbsp; * <br>&nbsp; * <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 + -