Coverage Report - org.kuali.rice.core.ojb.ContextClassLoaderListProxy
 
Classes in this File Line Coverage Branch Coverage Complexity
ContextClassLoaderListProxy
0%
0/22
0%
0/6
2.8
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
 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 org.kuali.rice.core.ojb;
 17  
 
 18  
 import java.util.Collection;
 19  
 
 20  
 import org.apache.ojb.broker.PBKey;
 21  
 import org.apache.ojb.broker.PersistenceBrokerException;
 22  
 import org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl;
 23  
 import org.apache.ojb.broker.query.Query;
 24  
 import org.kuali.rice.core.util.ClassLoaderUtils;
 25  
 import org.kuali.rice.core.util.ContextClassLoaderBinder;
 26  
 
 27  
 
 28  
 /**
 29  
  * Sets up the context classloader properly for OJB proxies.  The sequence of events in the super class is as
 30  
  * follows:
 31  
  * 
 32  
  * <pre>
 33  
  * public synchronized Collection getData()
 34  
  * {
 35  
  *    if (!isLoaded())
 36  
  *    {
 37  
  *      beforeLoading();
 38  
  *      setData(loadData());
 39  
  *      afterLoading();
 40  
  *    }
 41  
  *    return _data;
 42  
  * }
 43  
  * </pre>
 44  
  *
 45  
  * Therefore, since there is no try-catch-finally in conjunction with this call, we need to handle exceptions thrown
 46  
  * from loadData and unbind the classloader appropriately.
 47  
  */
 48  
 public class ContextClassLoaderListProxy extends ListProxyDefaultImpl {
 49  
 
 50  
         private static final long serialVersionUID = -6734848267763746202L;
 51  
 
 52  
         // this object is used by object that's are serialized and we don't want to take this reference
 53  
         // across the wire.  May need to acquire the CCL if this is null on beforeLoading() doing nothing for now...
 54  
         private transient ClassLoader contextClassLoader;
 55  
         
 56  
         public ContextClassLoaderListProxy(PBKey aKey, Class aCollClass, Query aQuery) {
 57  0
                 super(aKey, aCollClass, aQuery);
 58  0
                 this.contextClassLoader = ClassLoaderUtils.getDefaultClassLoader();
 59  0
         }
 60  
 
 61  
         public ContextClassLoaderListProxy(PBKey aKey, Query aQuery) {
 62  0
                 super(aKey, aQuery);
 63  0
                 this.contextClassLoader = ClassLoaderUtils.getDefaultClassLoader();        
 64  0
         }
 65  
 
 66  
         @Override
 67  
         protected void beforeLoading() {
 68  0
                 ContextClassLoaderBinder.bind(this.contextClassLoader);
 69  0
                 super.beforeLoading();
 70  0
         }
 71  
         
 72  
         @Override
 73  
         protected Collection loadData() throws PersistenceBrokerException {
 74  
                 try {
 75  0
                         return super.loadData();
 76  0
                 } catch (Throwable t) {
 77  0
                         ContextClassLoaderBinder.unbind();
 78  0
                         if (t instanceof PersistenceBrokerException) {
 79  0
                                 throw (PersistenceBrokerException)t;
 80  0
                         } else if (t instanceof Error) {
 81  0
                                 throw (Error)t;
 82  0
                         } else if (t instanceof RuntimeException) {
 83  0
                                 throw (RuntimeException)t;
 84  
                         } else {
 85  0
                                 throw new PersistenceBrokerException("Invalid exception type thrown!", t);
 86  
                         }
 87  
                 }
 88  
         }
 89  
 
 90  
         @Override
 91  
         protected void afterLoading() {
 92  0
                 super.afterLoading();
 93  0
                 ContextClassLoaderBinder.unbind();
 94  0
         }
 95  
 
 96  
 }