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

📄 opp.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// 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-@year@ by SMB GmbH. All rights reserved.//// $Id$package org.ozoneDB.tools.OPP;import java.io.File;import java.util.*;import org.ozoneDB.core.ObjectContainer;import org.ozoneDB.core.helper.ReflectionHelper;import org.ozoneDB.tools.OPP.compiler.JavaCompiler;import org.ozoneDB.tools.OPP.compiler.CompilerException;import org.ozoneDB.tools.OPP.message.MessageWriter;import org.ozoneDB.tools.OPP.message.SummaryMessageWriterDecorator;import org.ozoneDB.tools.OPP.message.StdOutMessageWriter;import org.ozoneDB.tools.OPP.srcgen.ClassDirector;import org.ozoneDB.tools.OPP.srcgen.ClassBuilder;/** * Command line driver of the OPP tool. * * @author <a href="http://www.softwarebuero.de/">SMB</a> * @version $Revision$Date$2 */public class OPP {    public final static String SIGNATURE_DELIMITER = ReflectionHelper.SIGNATURE_DELIMITER;    /**     * Update methods can marked with the following in the lines following the method signature:     * <pre>     *   //update     * </pre>     */    public final static String UPDATE_SIGN = "/[*]+ *update *[*]/|// *update";    /**     * All method signatures in build interfaces must look as foollows,     * otherwise OPP is unable to find them:     * <pre>     *   public package.return.Class[] methodname (     * </pre>     *     */    public final static String METHOD_PATTERN            = "^[ \\t]*public[ \\t]+[_a-zA-Z][_a-zA-Z0-9\\.\\[\\]]*[ \\t]+([_a-zA-Z][\\w]*)[ \\t]*\\(";    /**     * Update methods can marked with the following tag in its appropriate Javadoc Comment:     * <pre>     *   "@update"     * </pre>     */    public final static String JAVADOC_PATTERN            = "^[ \\t]+\\*[ \\t]*@update";    private boolean keepSource = false;    private boolean compileSource = true;    // private boolean printStackTrace = false;    private String outputDirName = "." + File.separator;    private String sourceDirName = "." + File.separator;    private StdOutMessageWriter msgOut = new StdOutMessageWriter(false, false);    private OPPBean oppBean = new OPPBean();    private boolean odmg = false;    //private Collection classes;    public OPP() {    }    public static void main(String[] args) {        Set classes = new HashSet();        if (args.length == 0) {            printUsage();            System.exit(0);        }        OPP opp = new OPP();        boolean preservePackageNames = true;        for (int argCount = 0; argCount < args.length; argCount++) {            if (args[argCount].equals("-q")) {                opp.msgOut.setQuiet(true);            } else if (args[argCount].equals("-ks")) {                opp.keepSource = true;            } else if (args[argCount].equals("-KS")) {                opp.keepSource = true;                opp.compileSource = false;            } else if (args[argCount].equals("-odmg")) {                opp.odmg = true;            } else if (args[argCount].equals("-nc")) {                opp.oppBean.setCache(false);            } else if (args[argCount].equals("-nf")) {                opp.oppBean.setGenerateFactory(false);            } else if (args[argCount].equals("-st")) {                opp.oppBean.setPrintStackTrace(true);            } else if (args[argCount].equals("-ni")) {                opp.oppBean.setUseSource(false);            } else if (args[argCount].startsWith("-p")) {                opp.oppBean.setUpdateExpression(args[argCount].substring(2));            } else if (args[argCount].equals("-version")) {                System.out.println("$Id$");                System.exit(0);            } else if (args[argCount].equals("-h")) {                opp.printUsage();                System.exit(0);            } else if (args[argCount].startsWith("-o")) {                opp.outputDirName = args[argCount].substring(2) + File.separator;            } else if (args[argCount].startsWith("-s")) {                opp.sourceDirName = args[argCount].substring(2) + File.separator;            } else if (args[argCount].equals("-ip")) {                preservePackageNames = false;            } else {                if (args[argCount].startsWith("-")) {                    System.out.println("Unknown option '" + args[argCount] + "'!\n");                    printUsage();                    System.exit(0);                } else {                    classes.add(args[argCount]);                }            }        }        opp.generate(classes, preservePackageNames);    }    private void generate(Collection classes, boolean preservePackageNames) {        MessageWriter genListener = new SummaryMessageWriterDecorator(msgOut);        oppBean.removeGenrationEventListener(msgOut);        oppBean.addGenrationEventListener(genListener);        genListener.startGeneration("OPP");        // We internally use the new directory parameter format,        // but the user has specified the directory parameters in the old format        // where packages were ignored        try {            if (!preservePackageNames) {                Iterator iter = classes.iterator();                if (iter.hasNext()) {                    String className = (String) iter.next();                    if (className != null) {                        int dotCount = 0;                        StringTokenizer st = new StringTokenizer(className, ".");                        while (st.hasMoreTokens()) {                            dotCount++;                            st.nextToken();                        }                        outputDirName = OPP.parentDirectoryName(outputDirName, dotCount);                        sourceDirName = OPP.parentDirectoryName(sourceDirName, dotCount);                    }                }            }            try {                File outputDir = new File(outputDirName);                File sourceDir = new File(sourceDirName);                makeProxiesAndFactories(classes, sourceDir, outputDir, "Factory", ObjectContainer.PROXYNAME_POSTFIX, genListener);                if (compileSource) {                    // the proxy source will be in the output dir                    compileSource(outputDir, outputDir, genListener, classes);                }                if (odmg) {                    genListener.startGeneration("ODMG");                    try {                        for (Iterator iter = classes.iterator(); iter.hasNext();) {                            String className = (String) iter.next();                            manipulateClass(className, genListener);                            manipulateClass(className + ObjectContainer.PROXYNAME_POSTFIX, genListener);                        }                    } finally {                        genListener.endGeneration();                    }                }            } catch (Exception e) {                e.printStackTrace(System.out);                System.exit(1);            }        } finally {            genListener.endGeneration();        }    }    private void manipulateClass(String className, MessageWriter genListener) throws Exception {        Class cl = Class.forName(className);        ImplManipulator manipulator = new ImplManipulator(outputDirName, genListener, cl.getClassLoader());        String newClassName = cl.getName() + ObjectContainer.IMPLNAME_POSTFIX;        manipulator.changeClassFile(null, outputDirName + OPPHelper.classFileBasename(cl) + ".class", newClassName);    }    private void compileSource(File sourceDir, File outputDir, MessageWriter genListener, Collection classes) throws CompilerException {        JavaCompiler compiler = OPPCompilerFactory.getCompilerInstance(sourceDir, outputDir);        genListener.startGeneration("Compile proxies");        try {            compiler.compile(getModifiedNames(sourceDir, classes, ObjectContainer.PROXYNAME_POSTFIX));        } finally {            genListener.endGeneration();        }        genListener.startGeneration("Compile factories");        try {            compiler.compile(getModifiedNames(sourceDir, classes, "Factory"));        } finally {            genListener.endGeneration();        }    }    private Collection getModifiedNames(File sourceDir, Collection classes, String postfix) {        Collection modified = new ArrayList(classes.size());        for (Iterator iter = classes.iterator(); iter.hasNext();) {            StringBuffer buffer = new StringBuffer(sourceDir.getPath());            buffer.append(File.separatorChar);            buffer.append((iter.next() + postfix).replace('.', File.separatorChar));            buffer.append(".java");            modified.add(buffer.toString());        }        return modified;    }    protected static String parentDirectoryName(String directoryName, int dotCount) {        StringBuffer b = new StringBuffer(directoryName);        for (int i = 0; i < dotCount; i++) {            b.append("..");            b.append(File.separatorChar);        }        return b.toString();    }    protected void makeProxiesAndFactories(Collection classes, File sourceDir, File outputDir, String factoryPost, String proxyPost, MessageWriter msgListener) throws Exception {        Iterator it = classes.iterator();        ClassDirector cd = oppBean.createDirector(sourceDir);        ClassBuilder cb = oppBean.createBuilder(outputDir, factoryPost, proxyPost);        while (it.hasNext()) {            String name = (String) it.next();            msgListener.info("Processing class: " + name);            cd.build(name, cb);        }    }    public static void printUsage() {        System.out.println("Ozone Post Processor");        System.out.println(                "usage: opp [-ks] [-st] [-p<pattern>] [-ni] [-nf] [-nc] [-q] [-h] [-o<directory>] [-odmg] [-ip] class [class]*");        System.out.println("   -ks       save the generated resolver files");        System.out.println("   -KS       save the generated resolver files; do not invoke compiler");        System.out.println("   -st       print stack trace");        System.out.println("   -p        regular expression to specify update methods");        System.out.println("   -ni       do not search interface code for update methods");        System.out.println("   -nf       do not create a Factory class");        System.out.println("   -q        supress output of any messages");        System.out.println("   -o        output directory");        System.out.println("   -s        resolver directory");        System.out.println("   -odmg     create proxies for the ozone ODMG interface");        System.out.println("   -ip       ignore package names");        System.out.println("   -nc       do not create code needed for direct invokes and ClientCacheDatabase");        System.out.println("   -version  shows version information");        System.out.println("   -h        shows this help");    }}

⌨️ 快捷键说明

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