Coverage Report - org.apache.tapestry.enhance.InterfaceFabImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
InterfaceFabImpl
0%
0/35
0%
0/6
2.5
 
 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 java.lang.reflect.Modifier;
 17  
 import java.util.ArrayList;
 18  
 import java.util.Iterator;
 19  
 import java.util.List;
 20  
 
 21  
 import javassist.CtClass;
 22  
 import javassist.CtMethod;
 23  
 
 24  
 import org.apache.hivemind.ApplicationRuntimeException;
 25  
 import org.apache.hivemind.service.InterfaceFab;
 26  
 import org.apache.hivemind.service.MethodSignature;
 27  
 
 28  
 /**
 29  
  * @author Howard M. Lewis Ship
 30  
  */
 31  
 public class InterfaceFabImpl extends AbstractFab implements InterfaceFab
 32  
 {
 33  0
     private List _methods = new ArrayList();
 34  
 
 35  
     public InterfaceFabImpl(CtClassSource source, CtClass ctClass)
 36  
     {
 37  0
         super(source, ctClass);
 38  0
     }
 39  
 
 40  
     public String toString()
 41  
     {
 42  0
         StringBuffer buffer = new StringBuffer("InterfaceFabImpl[\npublic interface ");
 43  
 
 44  0
         CtClass ctClass = getCtClass();
 45  
 
 46  0
         buffer.append(ctClass.getName());
 47  
 
 48  
         try
 49  
         {
 50  0
             CtClass[] interfaces = ctClass.getInterfaces();
 51  
 
 52  0
             for (int i = 0; i < interfaces.length; i++)
 53  
             {
 54  0
                 buffer.append(i == 0 ? " extends " : ", ");
 55  0
                 buffer.append(interfaces[i].getName());
 56  
             }
 57  
 
 58  
         }
 59  0
         catch (Exception ex)
 60  
         {
 61  0
             buffer.append("<Exception: " + ex + ">");
 62  0
         }
 63  
 
 64  0
         Iterator i = _methods.iterator();
 65  
 
 66  0
         while (i.hasNext())
 67  
         {
 68  0
             MethodSignature sig = (MethodSignature) i.next();
 69  
 
 70  0
             buffer.append("\n\npublic ");
 71  0
             buffer.append(sig);
 72  0
             buffer.append(";");
 73  0
         }
 74  
 
 75  0
         buffer.append("\n]");
 76  
 
 77  0
         return buffer.toString();
 78  
     }
 79  
 
 80  
     public void addMethod(MethodSignature ms)
 81  
     {
 82  0
         CtClass ctReturnType = convertClass(ms.getReturnType());
 83  0
         CtClass[] ctParameters = convertClasses(ms.getParameterTypes());
 84  0
         CtClass[] ctExceptions = convertClasses(ms.getExceptionTypes());
 85  
 
 86  0
         CtMethod method = new CtMethod(ctReturnType, ms.getName(), ctParameters, getCtClass());
 87  
 
 88  
         try
 89  
         {
 90  0
             method.setModifiers(Modifier.PUBLIC | Modifier.ABSTRACT);
 91  0
             method.setExceptionTypes(ctExceptions);
 92  
 
 93  0
             getCtClass().addMethod(method);
 94  
         }
 95  0
         catch (Exception ex)
 96  
         {
 97  0
             throw new ApplicationRuntimeException(EnhanceMessages.unableToAddMethod(
 98  
                     ms,
 99  
                     getCtClass(),
 100  
                     ex), ex);
 101  0
         }
 102  
 
 103  0
         _methods.add(ms);
 104  0
     }
 105  
 
 106  
     public Class createInterface()
 107  
     {
 108  0
         return createClass();
 109  
     }
 110  
 
 111  
 }