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

📄 factorybuilder.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        out.println("     * logical from an object oriented point of view: you probably want a factory that");        out.println("     * creates its objects in the default database, or in the same realm as another");        out.println("     * factory you already have created...</p>");        out.println("     * @param databaseUrl url defining the remote database (something like");        out.println("     * <code>ozone:remote://localhost:3333</code>)");        out.println("     */");        out.println("    public " + simpleClassName + "(String databaseUrl) throws Exception {");        out.println("        super(databaseUrl);");        out.println("    }\n");        out.println("    /** <p>Creates a factory that creates its objects in the same database as a specific");        out.println("     * other fatory does.</p>");        out.println("     * @param factory the factory that creates its objects in the same database as the new factory");        out.println("     * should");        out.println("     */");        out.println("    public " + simpleClassName + "(AbstractFactory factory) {");        out.println("        super(factory);");        out.println("    }\n");        out.println("    /**");        out.println("     * Gets called automatically to indicate that the default database has been");        out.println("     * closed. DO NOT CALL THIS METHOD YOURSELF.");        out.println("     */");        out.println("    protected void defaultClosed() {");        out.println("        defaultInstance = null;");        out.println("    }\n");    }    private void makeObjectForHandle(String type) {        out.println("    /**");        out.println("     * <p>Retrieves an object through its handle. <emp>Do not use this function");        out.println("     * unless you are perfectly sure about what you are doing</emp>. See the");        out.println("     * examples for some hands-on information on when to use handles. Note that");        out.println("     * normally one would use names or just standard java object references.</p>");        out.println("     */");        out.println("    public " + type + " objectForHandle(String handle) throws Exception {");        out.println("        return (" + type + ") getDatabase().objectForHandle(handle);");        out.println("    }\n");    }    private void makeObjectForName(String type) {        out.println("    /**");        out.println("     * <p>Retrieves an object from the database through its name.</p>");        out.println("     */");        out.println("    public " + type + " objectForName(String name) throws Exception {");        out.println("        return (" + type + ") getDatabase().objectForName(name);");        out.println("    }\n");    }    public void init(MessageWriter msgWriter) {        this.msgWriter = msgWriter;    }    public void beginClass(int modifer, String fullName, String superClass, String interfaces[]) throws BuilderException {        msgWriter.startGeneration("Generating factory for: " + fullName);        this.interfaces = interfaces;        try {            out = new PrintWriter(outputFactory.newInstance(fullName + postfix));        } catch (IOException e) {            throw new BuilderException(e);        }        makeGlobalHeader(fullName);        makeLocalHeader(OPPHelper.simpleClassName(fullName) + postfix);        makeObjectForHandle(interfaces[0]);        makeObjectForName(interfaces[0]);        makeCreateInternal(fullName, interfaces[0]);    }    public void makeConstructor(int modifier, ClassBuilder.Parameter parameters[], String exceptions[]) throws BuilderException {        // The original factory srcgen returned instantly when the modifier was private        // or protected but generated constructors for public and "package" encapsulation        // level.        // Since "package" is actually more restrictive than is protected I reconed that        // this was simply overlooked in the original factory srcgen thus now only private        // causes make method to return instantly.        if (Modifier.isPrivate(modifier)) {            return;        }        String mod;        // This is not foolproof since the modifier can contain other keywords than        // the different protectionlevels. However in the constructor context we can assume        // that the modifier is valid can't we?        mod = Modifier.toString(modifier);        StringBuffer ctorHeader = new StringBuffer();        StringBuffer ctorArgTypes = new StringBuffer();        StringBuffer ctorArgs = new StringBuffer();        for (int i = 0; i < parameters.length; ++i) {            String paramType = parameters[i].getType();            if (ctorArgTypes.length() > 0) {                ctorArgTypes.append(", ");                ctorHeader.append(", ");                ctorArgs.append(", ");            }            ctorArgTypes.append(paramType).append(".class");            ctorHeader.append(paramType).append(" p").append(i);            if (OPPHelper.isPrimitive(paramType)) {                ctorArgs.append("new ").append(OPPHelper.wrappercodeForPrimitive(paramType)).append("(");            }            ctorArgs.append("p").append(i);            if (OPPHelper.isPrimitive(paramType)) {                ctorArgs.append(")");            }        }        out.println("    /**");        out.println("     * <p>Creates a new database object</p>");        out.println("     */");        out.println("    " + mod + " " + interfaces[0] + " create(" + ctorHeader + ") throws Exception {");        if (ctorArgTypes.length() == 0) {            out.println("        Class[] ctorArgTypes = null;");            out.println("        Object[] ctorArgs = null;");        } else {            out.println("        Class[] ctorArgTypes = new Class[] {" + ctorArgTypes + "};");            out.println("        Object[] ctorArgs = new Object[] {" + ctorArgs + "};");        }        out.println("        return createInternal(null, null, ctorArgTypes, ctorArgs);");        out.println("    }\n");        // with metadata        if (ctorHeader.length() > 0) {            ctorHeader.insert(0, ", ");        }        out.println("    /**");        out.println("     * <p>Creates a new database object with given metadata</p>");        out.println("     */");        out.println("    " + mod + " " + interfaces[0] + " create(OzonePersonalMetaData personalMeta, OzoneSharedMetaData sharedMeta" + ctorHeader + ") throws Exception {");        if (ctorArgTypes.length() == 0) {            out.println("        Class[] ctorArgTypes = null;");            out.println("        Object[] ctorArgs = null;");        } else {            out.println("        Class[] ctorArgTypes = new Class[] {" + ctorArgTypes + "};");            out.println("        Object[] ctorArgs = new Object[] {" + ctorArgs + "};");        }        out.println("        return createInternal(personalMeta, sharedMeta, ctorArgTypes, ctorArgs);");        out.println("    }\n");    }    public void makeMethod(int modifier, String name, ClassBuilder.Parameter parameters[], String returnType, String exceptions[], int lockLevel) throws BuilderException {    }    public void endClass() throws BuilderException {        out.println("}");        out.close();        msgWriter.endGeneration();    }}

⌨️ 快捷键说明

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