Save This Page
Home » cglib-src-2.2 » net.sf.cglib.core » [javadoc | source]
    1   /*
    2    * Copyright 2003 The Apache Software Foundation
    3    *
    4    *  Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
   10    *  Unless required by applicable law or agreed to in writing, software
   11    * distributed under the License is distributed on an "AS IS" BASIS,
   12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13    * See the License for the specific language governing permissions and
   14    * limitations under the License.
   15    */
   16   package net.sf.cglib.core;
   17   
   18   import org.objectweb.asm.ClassAdapter;
   19   import org.objectweb.asm.ClassReader;
   20   import java.util;
   21   
   22   // TODO: optimize (ClassReader buffers entire class before accept)
   23   public class ClassNameReader {
   24       private ClassNameReader() {
   25       }
   26   
   27       private static final EarlyExitException EARLY_EXIT = new EarlyExitException();
   28       private static class EarlyExitException extends RuntimeException { }
   29       
   30       public static String getClassName(ClassReader r) {
   31       
   32           return getClassInfo(r)[0];
   33         
   34       }
   35       
   36       public static String[] getClassInfo(ClassReader r) {
   37           final List array = new ArrayList();
   38           try {
   39               r.accept(new ClassAdapter(null) {
   40                   public void visit(int version,
   41                                     int access,
   42                                     String name,
   43                                     String signature,
   44                                     String superName,
   45                                     String[] interfaces) {
   46                       array.add( name.replace('/', '.') );
   47                       if(superName != null){
   48                         array.add( superName.replace('/', '.') );
   49                       }
   50                       for(int i = 0; i < interfaces.length; i++  ){
   51                          array.add( interfaces[i].replace('/', '.') );
   52                       }
   53                       
   54                       throw EARLY_EXIT;
   55                   }
   56               }, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
   57           } catch (EarlyExitException e) { }
   58           
   59           return (String[])array.toArray( new String[]{} );
   60       }
   61   }

Save This Page
Home » cglib-src-2.2 » net.sf.cglib.core » [javadoc | source]