Home » geronimo-2.2-source-release » org.apache.geronimo.kernel.util » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   package org.apache.geronimo.kernel.util;
   18   
   19   import java.util.List;
   20   import java.lang.ref.WeakReference;
   21   import java.util.ArrayList;
   22   
   23   
   24   public class ClassLoaderRegistry {
   25       private final static List<WeakReference> list = new ArrayList<WeakReference>();
   26   
   27       public synchronized static List getList(){
   28           List<ClassLoader> ret = new ArrayList<ClassLoader>();
   29           for(int i=0;i<list.size();i++)
   30               if(list.get(i) != null) {
   31                   ret.add((ClassLoader)list.get(i).get());
   32               }
   33               else {
   34                   list.remove(i);
   35               }
   36           return ret;
   37       }
   38       
   39       public synchronized static boolean add(ClassLoader cloader){
   40           if(contains(cloader)) {
   41               return false;
   42           }
   43           return list.add(new WeakReference<ClassLoader>(cloader));
   44       } 
   45       
   46       public synchronized static boolean contains(ClassLoader cloader){
   47           for(int i=0;i<list.size();i++) {
   48               WeakReference wk = list.get(i);
   49               if(wk.get() == null) {
   50                   list.remove(i);
   51               }
   52               else if(wk.get().equals(cloader))
   53                   return true;            
   54           }
   55           return false;
   56       }
   57       
   58       public synchronized static boolean remove(ClassLoader cloader){
   59           boolean result = false;
   60           for(int i=0;i<list.size();i++){
   61               WeakReference wk = list.get(i);
   62               if(wk.get() == null)list.remove(i);
   63               else if(wk.get().equals(cloader)){
   64                   list.remove(i);
   65                   result = true;
   66               }
   67           }
   68           return result;
   69       } 
   70   }

Home » geronimo-2.2-source-release » org.apache.geronimo.kernel.util » [javadoc | source]