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

📄 implmanipulator.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.PrintWriter;import java.util.Set;import de.fub.bytecode.classfile.*;import de.fub.bytecode.generic.ClassGen;import de.fub.bytecode.generic.ConstantPoolGen;import org.ozoneDB.core.ObjectContainer;import org.ozoneDB.tools.OPP.message.MessageWriter;/** * Helper class that is responsible for all operations that are done on the * byte code of class files. * * * @author <a href="http://www.softwarebuero.de/">SMB</a> * @version $Revision$Date$ */class ImplManipulator {    protected ClassLoader loader;    protected PrintWriter out;    protected String outputDir;    protected MessageWriter genListener;    public ImplManipulator(String _outputDir, MessageWriter _genListener, ClassLoader _loader) throws Exception {        loader = _loader;        outputDir = _outputDir;        genListener = _genListener;    }    protected String slashedClassName(String className) {        StringBuffer sb = new StringBuffer(className);        for (int i = 0; i < sb.length(); i++) {            if (sb.charAt(i) == '.') {                sb.setCharAt(i, '/');            }        }        return sb.toString();    }    /**     * Renames the class and, (if classes != null) checks if the superclass     *  needs to be renamed too.     *  @param classes     *  @param fileName     *  @param newClassName     *  @throws Exception     */    public void changeClassFile(Set classes, String fileName, String newClassName) throws Exception {        String newFileName = outputDir + OPPHelper.classFileBasename(newClassName) + ".class";        genListener.info("   creating " + newFileName + " from " + fileName + " ...");        ClassParser parser = new ClassParser(fileName);        JavaClass jcl = parser.parse();        String name = jcl.getClassName();        genListener.info("class name: " + name);        genListener.info("new class name: " + newClassName);        // im Constantpool den Eintrag mit dem Classennamen ?berschreiben        ClassGen cg = new ClassGen(jcl);        ConstantPoolGen cpg = new ConstantPoolGen(jcl.getConstantPool());        //        for (int i=0; i<cpg.getSize(); i++) {        //            System.out.println (cpg.getConstant (i));        //            }        int i = cpg.lookupClass(slashedClassName(name));        if (i == -1) {            throw new Exception("Unable to lookup class name in class.");        }        // System.out.println ("ClassIndex: "+i);        ConstantClass cc = (ConstantClass) cpg.getConstant(i);        int x = cc.getNameIndex();        // System.out.println ("ClassConstant.nameIndex: "+x);        // System.out.println ("\nAlter Klassenname: "+((ConstantUtf8)cpg.getConstant (x)).getBytes ());        ((ConstantUtf8) cpg.getConstant(x)).setBytes(slashedClassName(newClassName));        // System.out.println ("Neuer Klassenname: "+((ConstantUtf8)cpg.getConstant (x)).getBytes ()+"\n");        cc.setNameIndex(cpg.addUtf8(slashedClassName(newClassName)));        // System.out.println ("ClassConstant.nameIndex: (new) "+cc.getNameIndex ());        // check super class name and change this too, if needed        if (classes != null) {            genListener.info("   checking super class... ");            String sName = jcl.getSuperclassName();            // System.out.println ("superclassname: " + name);            // change super class name if the <code>classes</code> set contains            // the name (so the super class *will* change too) or the super            // class is an proxy already (the super class has already be            // changed)            if (classes.contains(sName) || Class.forName("org.ozoneDB.OzoneProxy", true, loader).isAssignableFrom(Class.forName(                    sName, true, loader))) {                String newSClassName = sName + ObjectContainer.IMPLNAME_POSTFIX;                genListener.info(sName + " changed to " + newSClassName);                // im Constantpool den Eintrag mit dem Superclassennamen ?berschreiben                i = cpg.lookupClass(slashedClassName(sName));                // System.out.println ("ClassIndex: "+i);                cc = (ConstantClass) cpg.getConstant(i);                x = cc.getNameIndex();                // System.out.println ("ClassConstant.nameIndex: "+x);                // System.out.println ("\nAlter Klassenname: "+((ConstantUtf8)cpg.getConstant (x)).getBytes ());                ((ConstantUtf8) cpg.getConstant(x)).setBytes(slashedClassName(newSClassName));                // System.out.println ("Neuer Klassenname: "+((ConstantUtf8)cpg.getConstant (x)).getBytes ()+"\n");                cc.setNameIndex(cpg.addUtf8(slashedClassName(newSClassName)));                // System.out.println ("ClassConstant.nameIndex: (new) "+cc.getNameIndex ());            } else {                genListener.info("nothing changed");            }        }        // System.out.println ("new File: "+newFileName);        jcl.dump(newFileName);    }}

⌨️ 快捷键说明

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