Clover coverage report - Code Coverage for hivemind release 1.1-beta-1
Coverage timestamp: Thu Apr 28 2005 19:53:41 EDT
file stats: LOC: 69   Methods: 2
NCLOC: 25   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ServiceSerializationHelper.java 75% 100% 100% 93.3%
coverage coverage
 1   
 // Copyright 2005 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.hivemind.internal.ser;
 16   
 
 17   
 import java.lang.ref.WeakReference;
 18   
 
 19   
 import org.apache.commons.logging.Log;
 20   
 import org.apache.commons.logging.LogFactory;
 21   
 import org.apache.hivemind.ApplicationRuntimeException;
 22   
 
 23   
 /**
 24   
  * Class used to hold a <em>global</em> instance of
 25   
  * {@link org.apache.hivemind.internal.ser.ServiceSerializationSupport}, so that
 26   
  * {@link org.apache.hivemind.internal.ser.ServiceToken}s may locate them.
 27   
  * 
 28   
  * @author Howard M. Lewis Ship
 29   
  * @since 1.1
 30   
  */
 31   
 public class ServiceSerializationHelper
 32   
 {
 33   
     private static final Log LOG = LogFactory.getLog(ServiceSerializationHelper.class);
 34   
 
 35   
     private static final ThreadLocal _threadLocal = new ThreadLocal();
 36   
 
 37   
     /**
 38   
      * Returns the previously stored SSS.
 39   
      * 
 40   
      * @throws ApplicationRuntimeException
 41   
      *             if no SSS has been stored.
 42   
      */
 43  4
     public static ServiceSerializationSupport getServiceSerializationSupport()
 44   
     {
 45  4
         ServiceSerializationSupport result = null;
 46   
 
 47  4
         WeakReference reference = (WeakReference) _threadLocal.get();
 48  4
         if (reference != null)
 49  4
             result = (ServiceSerializationSupport) reference.get();
 50   
 
 51  4
         if (result == null)
 52  1
             throw new ApplicationRuntimeException(SerMessages.noSupportSet());
 53   
 
 54  3
         return result;
 55   
     }
 56   
 
 57   
     /**
 58   
      * Stores the SSS instance for later access; if an existing SSS is already stored, then an error
 59   
      * is logged (should be just one SSS per class loader).
 60   
      */
 61   
 
 62  743
     public static void setServiceSerializationSupport(
 63   
             ServiceSerializationSupport serviceSerializationSupport)
 64   
     {
 65  743
         WeakReference reference = new WeakReference(serviceSerializationSupport);
 66   
 
 67  743
         _threadLocal.set(reference);
 68   
     }
 69   
 }