Clover coverage report - Code Coverage for hivemind release 1.0-beta-2
Coverage timestamp: Sun Aug 1 2004 14:03:45 EDT
file stats: LOC: 107   Methods: 3
NCLOC: 62   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.Method;
 18   
 import java.lang.reflect.Modifier;
 19   
 
 20   
 import org.apache.hivemind.internal.Module;
 21   
 import org.apache.hivemind.internal.ServicePoint;
 22   
 import org.apache.hivemind.service.BodyBuilder;
 23   
 import org.apache.hivemind.service.ClassFab;
 24   
 import org.apache.hivemind.service.ClassFabUtils;
 25   
 import org.apache.hivemind.service.ClassFactory;
 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  493
     public ProxyBuilder(String type, ServicePoint point)
 47   
     {
 48  493
         _point = point;
 49  493
         _type = type;
 50  493
         _serviceInterface = point.getServiceInterface();
 51   
 
 52  493
         Module module = point.getModule();
 53  493
         ClassFactory factory =
 54   
             (ClassFactory) module.getService("hivemind.ClassFactory", ClassFactory.class);
 55   
 
 56  493
         _classFab = factory.newClass(ClassFabUtils.generateClassName(type), Object.class, module);
 57   
 
 58  493
         _classFab.addInterface(_serviceInterface);
 59   
     }
 60   
 
 61  493
     public ClassFab getClassFab()
 62   
     {
 63  493
         return _classFab;
 64   
     }
 65   
 
 66   
     /**
 67   
      * Creates the service methods for the class.  
 68   
      * @param indirection the name of a variable, or a method invocation snippet,
 69   
      * used to redirect the invocation on the proxy to the actual service implementation.
 70   
      */
 71  493
     public void addServiceMethods(String indirection)
 72   
     {
 73  493
         BodyBuilder builder = new BodyBuilder();
 74  493
         boolean toString = false;
 75   
 
 76  493
         Method[] methods = _serviceInterface.getMethods();
 77  493
         for (int i = 0; i < methods.length; i++)
 78   
         {
 79  640
             Method m = methods[i];
 80   
             
 81  640
             builder.clear();
 82  640
             builder.begin();
 83  640
             builder.add("return ($r) ");
 84  640
             builder.add(indirection);
 85  640
             builder.add(".");
 86  640
             builder.add(m.getName());
 87  640
             builder.addln("($$);");
 88  640
             builder.end();
 89   
 
 90  640
             _classFab.addMethod(Modifier.PUBLIC, new MethodSignature(m), builder.toString());
 91   
 
 92  640
             toString |= ClassFabUtils.isToString(m);
 93   
         }
 94   
 
 95  493
         if (!toString)
 96  491
             ClassFabUtils.addToStringMethod(
 97   
                 _classFab,
 98   
                 "<"
 99   
                     + _type
 100   
                     + " for "
 101   
                     + _point.getExtensionPointId()
 102   
                     + "("
 103   
                     + _serviceInterface.getName()
 104   
                     + ")>");
 105   
     }
 106   
 }
 107