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

📄 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-2000 by SMB GmbH. All rights reserved.//// $Id: ImplManipulator.java,v 1.6 2000/10/28 16:55:20 daniela Exp $package org.ozoneDB.tools.OPP;import java.io.*;import org.ozoneDB.core.ObjectContainer;import org.ozoneDB.DxLib.*;import de.fub.bytecode.*;import de.fub.bytecode.generic.*;import de.fub.bytecode.classfile.*;/** * 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: 1.6 $Date: 2000/10/28 16:55:20 $ */class ImplManipulator {        protected PrintWriter out;        //protected Class		cl;        protected String outputDir;        protected boolean quiet;            public ImplManipulator( Class _cl, String _outputDir, boolean _quiet ) throws Exception{        //cl = _cl;        outputDir = _outputDir;        quiet = _quiet;    }            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.     */    public void changeClassFile( DxHashSet classes, String fileName, String newClassName ) throws Exception {        String newFileName = outputDir + OPPHelper.rawClassName( newClassName ) + ".class";                OPPHelper.progressMsg( "   creating " + newFileName + " from " + fileName + " ...", quiet );                ClassParser parser = new ClassParser( fileName );        JavaClass jcl = parser.parse();                String name = jcl.getClassName();        OPPHelper.progressMsg( "class name: " + name, quiet );        OPPHelper.progressMsg( "new class name: " + newClassName, quiet );                // im Constantpool den Eintrag mit dem Classennamen 黚erschreiben        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) {            if (!quiet) {                System.out.print( "   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" ).isAssignableFrom( Class.forName(                    sName ) )) {                                String newSClassName = sName + ObjectContainer.IMPLNAME_POSTFIX;                                if (!quiet) {                    System.out.println( sName + " changed to " + newSClassName );                }                                 // im Constantpool den Eintrag mit dem Superclassennamen 黚erschreiben                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 {                if (!quiet) {                    System.out.println( "nothing changed" );                }             }         }                 // System.out.println ("new File: "+newFileName);        jcl.dump( newFileName );    }     }

⌨️ 快捷键说明

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