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

📄 proxygenerator.java

📁 用Java写的面相对象的数据库管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-2000 by SMB GmbH. All rights reserved.//// $Id: ProxyGenerator.java,v 1.23 2000/11/07 14:50:22 daniela Exp $package org.ozoneDB.tools.OPP;import java.io.*;import java.lang.reflect.*;//import org.apache.regexp.*;import org.ozoneDB.DxLib.*;import org.ozoneDB.OzoneCompatible;import org.ozoneDB.OzoneObject;import org.ozoneDB.OzoneRemote;import org.ozoneDB.core.ObjectID;import org.ozoneDB.core.ObjectContainer;/** * @author <a href="http://www.softwarebuero.de/">SMB</a> * @version $Revision: 1.23 $Date: 2000/11/07 14:50:22 $ */class ProxyGenerator {        protected PrintWriter out;        protected Class cl;        protected Method[] methods;        protected String outputDir;        protected String proxyFileName;        protected String proxyClassName;        protected boolean quiet;        protected boolean cache;        protected Object re;        /**     * Names of update methods as Strings.     */    protected DxHashMap updateMethodsIf = new DxHashMap();        /**     * Complete signatur of methods already proceeded .     */    protected DxHashMap doneMethodsIf = new DxHashMap();            public ProxyGenerator( Class _cl, String _methodPattern, String _outputDir, boolean _quiet, boolean _cache )             throws Exception{        cl = _cl;        methods = OPPHelper.methodsOfClass( cl );        outputDir = _outputDir;        quiet = _quiet;        cache = _cache;        re = OPPHelper.newRE( _methodPattern, false );        proxyFileName = outputDir + OPPHelper.rawClassName( cl ) + ObjectContainer.PROXYNAME_POSTFIX + ".java";        proxyClassName = cl.getName() + ObjectContainer.PROXYNAME_POSTFIX;                if (!quiet) {            System.out.println( "   creating " + proxyFileName + " ..." );            System.out.println( "   update methods:" );        }                 if (!(cl instanceof Serializable)) {            System.out.println( cl.getName() + " does not implement Serializable." );            System.exit( 1 );        }                 if (!OzoneRemote.class.isAssignableFrom( cl )) {            OPPHelper.error( cl, " does not implement OzoneRemote." );        }     }            public void compileSource() throws Exception {        String[] args = new String[4];                OPPHelper.progressMsg( "   compiling " + proxyFileName + " ...", quiet );                String compilerCommand = System.getProperty( "ozone.javac", "javac" );        if (!quiet) {            OPPHelper.progressMsg( "compiler: " + compilerCommand, quiet );        }                 // get the classpath of this virtual machine        String jvmClassPath = System.getProperty( "java.class.path", "" );                // build the new argument array        args[0] = compilerCommand;        args[1] = "-classpath";        args[2] = jvmClassPath;        args[3] = proxyFileName;        Process process = Runtime.getRuntime().exec( args );        process.waitFor();        if (process.exitValue() != 0) {            OPPHelper.warnMsg( proxyFileName, 0, "Unable to compile the generated source code!" );            OPPHelper.warnMsg( proxyFileName, 0,                    "    command line: '" + args[0] + " " + args[1] + " " + args[2] + " " + args[3] + "'" );        }     }             public void generateSource() {        try {            out = new PrintWriter( new FileOutputStream( proxyFileName ) );            makeHeader();            makeCtors();            makeMethods();            out.print( "   }\n" );        } catch (Exception e) {            System.out.println( OPPHelper.rawClassName( cl ) + ".java:0: " + e.getMessage() );            e.printStackTrace();            System.exit( 1 );        } finally {            out.close();        }     }             public void deleteSource() throws Exception {        File file = new File( proxyFileName );        if (!file.delete()) {            System.out.println( "Unable to delete the source file." );        }     }             public void makeHeader() throws Exception {        out.print( "// Proxy class generated by ozone's OPP ($Revision: 1.23 $).\n" );        out.print( "// DO NOT EDIT!\n" );        out.print( "\n" );        if (!OPPHelper.packageName( cl ).equals( "" )) {            out.print( "package " + OPPHelper.packageName( cl ) + ";\n" );            out.print( "\n" );        }         out.print( "import org.ozoneDB.*;\n" );        out.print( "import org.ozoneDB.core.ObjectID;\n" );        out.print( "import org.ozoneDB.core.Lock;\n" );        out.print( "import org.ozoneDB.core.ResultConverter;\n" );                out.print( "\n" );        out.print( "/**\n" );        out.print( " * This class was automatically generated by ozone's OPP.\n" );        out.print( " * Do not instantiate or use this class directly.\n" );        out.print( " */\n" );        out.print( "public final class " + OPPHelper.rawClassName( proxyClassName ) + " \n" );        out.print( "       extends OzoneProxy\n" );                Class[] ifs = cl.getInterfaces();        for (int i = 0, c = 0; i < ifs.length; i++) {            // filter methods that are not inherited from a OzoneRemote            // interface            if (OzoneRemote.class.isAssignableFrom( ifs[i] )) {                if (c++ == 0) {                    out.print( "       implements " );                } else {                    out.print( ", " );                }                                 out.print( ifs[i].getName() );            }         }         out.print( " {\n" );                out.print( "\n   static final long	serialVersionUID = 1L;\n" );    }             /**     * Employ IfHelper and CDHelper to find the methods that need to     * acquire WRITE lock.     */    public void searchUpdateMethods( boolean searchInterfaceSource ) throws Exception {        IfHelper ifHelper = new IfHelper( cl, outputDir, quiet );        ifHelper.searchUpdateMethods( updateMethodsIf );                CDHelper cdHelper = new CDHelper( cl, outputDir, quiet );        cdHelper.searchUpdateMethods( updateMethodsIf );    }             public void makeCtors() throws Exception {        out.print( "\n" );        out.print( "   public " + OPPHelper.rawClassName( proxyClassName ) + "() {\n" );        out.print( "      super();\n" );        //       out.print ("      System.out.println (\"Ctor...\");\n");        //       out.print ("      new Exception().fillInStackTrace().printStackTrace();\n");        out.print( "      }\n" );        out.print( "\n\n" );                // create default ctor that is responsible to create a pure proxy        // without interacting with any database        out.print( "   public " + OPPHelper.rawClassName( proxyClassName )                 + " (ObjectID oid, OzoneInterface link) {\n" );        out.print( "      super (oid, link);\n" );        out.print( "      }\n" );                java.lang.reflect.Constructor[] ctors = cl.getDeclaredConstructors();        for (int i = 0; i < ctors.length; i++) {            makeCtor( ctors[i] );        }     }             public void makeCtor( Constructor ctor ) throws Exception {        // string buffer to build the signatur of this method        StringBuffer signaturBuf = new StringBuffer( "" );                signaturBuf.append( "   public " + OPPHelper.rawClassName( proxyClassName ) + " (" );                // argumente in declaration schreiben        Class[] args = ctor.getParameterTypes();                // skip default ctor        if (args.length == 0) {            return;        }                 for (int i = 0; i < args.length; i++) {            if (i != 0) {                signaturBuf.append( ", " );            }             signaturBuf.append( typecodeForClass( args[i] ) + " arg" + i );        }         signaturBuf.append( ")" );                out.print( "\n\n" );        out.print( signaturBuf.toString() );                //exceptions in declaration schreiben        Class[] excs = ctor.getExceptionTypes();        for (int i = 0; i < excs.length; i++) {            out.print( i == 0 ? " throws " : ", " );            out.print( excs[i].getName() );        }         out.print( " {\n" );                // the actual code of the method        out.print( "      try {\n" );        out.print( "         link = ExternalDatabase.forThread (Thread.currentThread());\n" );        out.print( "         if (link == null)\n" );        out.print( "            throw new TransactionExc (\"Thread has not yet joined a transaction.\");\n" );        out.print( "         \n" );                //array of arguments        out.print( "         Object[] args = {" );        for (int i = 0; i < args.length; i++) {            out.print( i > 0 ? ", " : "" );            if (args[i].isPrimitive()) {                out.print( "new " + OPPHelper.wrappercodeForPrimitive( args[i] ) + "(arg" + i + ")" );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -