Coverage Report - org.apache.tapestry.enhance.ClassFactoryImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassFactoryImpl
0%
0/21
0%
0/2
2.75
 
 1  
 // Copyright 2004, 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  
 package org.apache.tapestry.enhance;
 15  
 
 16  
 import javassist.CtClass;
 17  
 import org.apache.hivemind.ApplicationRuntimeException;
 18  
 import org.apache.hivemind.service.ClassFab;
 19  
 import org.apache.hivemind.service.ClassFactory;
 20  
 import org.apache.hivemind.service.InterfaceFab;
 21  
 import org.apache.tapestry.event.ResetEventListener;
 22  
 
 23  
 /**
 24  
  * Implementation of the hivemind core {@link ClassFactory} service to get around some incompatibilities 
 25  
  * the current 1.1.1 implementation of hivemind has with the latest (3.4) version of javassist. 
 26  
  */
 27  0
 public class ClassFactoryImpl implements ClassFactory, ResetEventListener {
 28  
     
 29  
     static final int EXPIRED_CLASS_COUNT = 120;
 30  
     
 31  
     /**
 32  
      * ClassPool shared by all modules (all CtClassSource instances).
 33  
      */
 34  0
     private HiveMindClassPool _pool = new HiveMindClassPool();
 35  
 
 36  0
     private CtClassSource _classSource = new CtClassSource(_pool);
 37  
 
 38  0
     int _classCounter = 0;
 39  
 
 40  
     public ClassFab newClass(String name, Class superClass)
 41  
     {
 42  
         try
 43  
         {
 44  0
             checkPoolExpiration();
 45  
             
 46  0
             CtClass ctNewClass = _classSource.newClass(name, superClass);
 47  
             
 48  0
             return new ClassFabImpl(_classSource, ctNewClass);
 49  
         }
 50  0
         catch (Exception ex)
 51  
         {
 52  0
             throw new ApplicationRuntimeException(EnhanceMessages.unableToCreateClass(name, superClass, ex), ex);
 53  
         }
 54  
     }
 55  
 
 56  
     /** @since 1.1 */
 57  
 
 58  
     public InterfaceFab newInterface(String name)
 59  
     {
 60  
         try
 61  
         {
 62  0
             checkPoolExpiration();
 63  
             
 64  0
             CtClass ctNewClass = _classSource.newInterface(name);
 65  
 
 66  0
             return new InterfaceFabImpl(_classSource, ctNewClass);
 67  
         }
 68  0
         catch (Exception ex)
 69  
         {
 70  0
             throw new ApplicationRuntimeException(EnhanceMessages.unableToCreateInterface(name, ex), ex);
 71  
         }
 72  
 
 73  
     }
 74  
 
 75  
     public void resetEventDidOccur()
 76  
     {
 77  0
         if (_classCounter >= EXPIRED_CLASS_COUNT)
 78  
         {
 79  0
             _classCounter = 0;
 80  
 
 81  0
             _pool = new HiveMindClassPool();
 82  0
             _classSource.setPool(_pool);
 83  
         }
 84  0
     }
 85  
 
 86  
     void checkPoolExpiration()
 87  
     {
 88  0
         _classCounter++;
 89  0
     }
 90  
 }