gdaniels    02/03/07 07:45:51

  Modified:    java/src/org/apache/axis/wsdl/fromJava ClassRep.java
  Log:
  Clean up cache code a bit, pull cache up to the class level and make
  it static so that it's more useful.
  
  Might want to add some cache-cleaning code later (every call after more
  than 10 minutes have passed since the last cache-clean should scan
  through the cache and delete entries older than a time limit, etc).
  
  Revision  Changes    Path
  1.22      +29 -29    xml-axis/java/src/org/apache/axis/wsdl/fromJava/ClassRep.java
  
  Index: ClassRep.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/ClassRep.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ClassRep.java     6 Mar 2002 20:51:12 -0000       1.21
  +++ ClassRep.java     7 Mar 2002 15:45:51 -0000       1.22
  @@ -162,6 +162,13 @@
       private HashMap  _fieldNames = new HashMap();
       private Vector   _stopList    = null;
       
  +    /**
  +     * Cache of tt-bytecode BCClass objects which correspond to particular
  +     * Java classes.
  +     * 
  +     * !!! NOTE : AT PRESENT WE DO NOT CLEAN UP THIS CACHE.
  +     */ 
  +    private static HashMap ttClassCache = new HashMap();
   
       /**
        * Constructor
  @@ -289,19 +296,17 @@
        * Iterate up the inheritance chain and construct the list of methods
        * Appends to the _methods class variable.
        */ 
  -    private void walkInheritanceChain(Class cls, boolean inhMethods, Class 
implClass) {
  +    private void walkInheritanceChain(Class cls, 
  +                                      boolean inhMethods, 
  +                                      Class implClass) {
           Method[] m;
           Class currentClass = cls;
  -        HashMap ttClassCache;
  -        BCClass bclass;
           
           while (isClassOk(currentClass)) {
   
               // get the methods in this class
               m = currentClass.getDeclaredMethods();
   
  -            ttClassCache = new HashMap();
  -
               // add each method in this class to the list
               for (int i=0; i < m.length; i++) {
                   int mod = m[i].getModifiers();
  @@ -314,17 +319,7 @@
                           continue;  // skip it
                       }
                       Class[] types = getParameterTypes(m[i]);
  -                    bclass = (BCClass)ttClassCache.get(currentClass);
  -                    
  -                    if(bclass == null) {
  -                        try {
  -                            bclass = new BCClass(currentClass);
  -                            ttClassCache.put(currentClass, bclass);
  -                        } catch (IOException e) {
  -                            // what now?
  -                        }
  -                    }
  -                    String[] names = getParameterNames(m[i], implClass, bclass);
  +                    String[] names = getParameterNames(m[i], implClass);
                       ParameterMode[] modes = getParameterModes(m[i], implClass);
                       MethodRep methodRep = new MethodRep(m[i], types, modes, names);
                       getMethodMetaData(methodRep, m[i], implClass);
  @@ -443,7 +438,7 @@
        * @param types  are the parameter types after converting Holders.
        * @return array of Strings which represent the return name followed by 
parameter names
        */ 
  -    protected String[] getParameterNames(Method method, Class implClass, BCClass 
bclass) {
  +    protected String[] getParameterNames(Method method, Class implClass) {
           String[] paramNames = null;
           
           paramNames = getParameterNamesFromSkeleton(method);
  @@ -451,7 +446,7 @@
               return paramNames;
           }
           
  -        paramNames = getParameterNamesFromDebugInfo(method, bclass); 
  +        paramNames = getParameterNamesFromDebugInfo(method); 
           
           // If failed, try getting a method of the impl class.
           if (paramNames == null && implClass != null) {
  @@ -469,7 +464,7 @@
                   if (paramNames != null) {
                       return paramNames;
                   }
  -                paramNames = getParameterNamesFromDebugInfo(m, bclass); 
  +                paramNames = getParameterNamesFromDebugInfo(m); 
               }
           }            
   
  @@ -519,7 +514,8 @@
        * @param method
        * @return list of names or null
        */
  -    public String[] getParameterNamesFromDebugInfo(java.lang.reflect.Method method, 
BCClass bclass) {
  +    public String[] 
  +            getParameterNamesFromDebugInfo(java.lang.reflect.Method method) {
           Class c = method.getDeclaringClass();
           int numParams = method.getParameterTypes().length;
           Vector temp = new Vector();
  @@ -528,17 +524,21 @@
           if (numParams == 0)
               return null;
   
  -        // Try to make a tt-bytecode
  -        BCMethod bmeth = null;
  -//        BCClass bclass = null;
  -//        try {
  -//            bclass = new BCClass(c);
  -//        } catch (IOException e) {
  -//            return null;  // no dice
  -//        }
  +        // Try to obtain a tt-bytecode class object
  +        BCClass bclass = (BCClass)ttClassCache.get(c);
  +                    
  +        if(bclass == null) {
  +            try {
  +                bclass = new BCClass(c);
  +                ttClassCache.put(c, bclass);
  +            } catch (IOException e) {
  +                // what now?
  +            }
  +        }
   
           // Obtain the exact method we're interested in.
  -        bmeth = bclass.getMethod(method.getName(), method.getParameterTypes());
  +        BCMethod bmeth = bclass.getMethod(method.getName(), 
  +                                          method.getParameterTypes());
   
           if (bmeth == null)
               return null;
  
  
  


Reply via email to