Clover coverage report - Code Coverage for hivemind release 1.0-rc-2
Coverage timestamp: Sat Sep 11 2004 09:09:48 EDT
file stats: LOC: 109   Methods: 3
NCLOC: 64   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
ProxyBuilder.java 100% 100% 100% 100%
coverage
 1   
 //  Copyright 2004 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.impl;
 16   
 
 17   
 import java.lang.reflect.Modifier;
 18   
 
 19   
 import org.apache.hivemind.internal.Module;
 20   
 import org.apache.hivemind.internal.ServicePoint;
 21   
 import org.apache.hivemind.service.BodyBuilder;
 22   
 import org.apache.hivemind.service.ClassFab;
 23   
 import org.apache.hivemind.service.ClassFabUtils;
 24   
 import org.apache.hivemind.service.ClassFactory;
 25   
 import org.apache.hivemind.service.MethodIterator;
 26   
 import org.apache.hivemind.service.MethodSignature;
 27   
 
 28   
 /**
 29   
  * Class used to assist service extension points in creating proxies.
 30   
  *
 31   
  * @author Howard Lewis Ship
 32   
  */
 33   
 public final class ProxyBuilder
 34   
 {
 35   
     private ServicePoint _point;
 36   
     private Class _serviceInterface;
 37   
     private ClassFab _classFab;
 38   
     private String _type;
 39   
 
 40   
     /**
 41   
      * Constructs a new builder.  The type will be incorporated
 42   
      * into the class name and the <code>toString()</code> method.
 43   
      * The service extension point is used to identify the service interface
 44   
      * and service id.
 45   
      */
 46  1341
     public ProxyBuilder(String type, ServicePoint point)
 47   
     {
 48  1341
         _point = point;
 49  1341
         _type = type;
 50  1341
         _serviceInterface = point.getServiceInterface();
 51   
 
 52  1341
         Module module = point.getModule();
 53  1341
         ClassFactory factory =
 54   
             (ClassFactory) module.getService("hivemind.ClassFactory", ClassFactory.class);
 55   
 
 56  1341
         _classFab =
 57   
             factory.newClass(
 58   
                 ClassFabUtils.generateClassName(type),
 59   
                 Object.class,
 60   
                 module.getClassResolver().getClassLoader());
 61   
 
 62  1341
         _classFab.addInterface(_serviceInterface);
 63   
     }
 64   
 
 65  1341
     public ClassFab getClassFab()
 66   
     {
 67  1341
         return _classFab;
 68   
     }
 69   
 
 70   
     /**
 71   
      * Creates the service methods for the class.  
 72   
      * @param indirection the name of a variable, or a method invocation snippet,
 73   
      * used to redirect the invocation on the proxy to the actual service implementation.
 74   
      */
 75  1341
     public void addServiceMethods(String indirection)
 76   
     {
 77  1341
         BodyBuilder builder = new BodyBuilder();
 78   
 
 79  1341
         MethodIterator mi = new MethodIterator(_serviceInterface);
 80   
 
 81  1341
         while (mi.hasNext())
 82   
         {
 83  1556
             MethodSignature m = mi.next();
 84   
 
 85  1556
             builder.clear();
 86  1556
             builder.begin();
 87  1556
             builder.add("return ($r) ");
 88  1556
             builder.add(indirection);
 89  1556
             builder.add(".");
 90  1556
             builder.add(m.getName());
 91  1556
             builder.addln("($$);");
 92  1556
             builder.end();
 93   
 
 94  1556
             _classFab.addMethod(Modifier.PUBLIC, m, builder.toString());
 95   
         }
 96   
 
 97  1341
         if (!mi.getToString())
 98  1339
             ClassFabUtils.addToStringMethod(
 99   
                 _classFab,
 100   
                 "<"
 101   
                     + _type
 102   
                     + " for "
 103   
                     + _point.getExtensionPointId()
 104   
                     + "("
 105   
                     + _serviceInterface.getName()
 106   
                     + ")>");
 107   
     }
 108   
 }
 109