Clover coverage report - Code Coverage for hivemind release 1.0-rc-1
Coverage timestamp: Wed Aug 25 2004 13:06:02 EDT
file stats: LOC: 155   Methods: 9
NCLOC: 90   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
InvokeFactoryServiceConstructor.java 100% 96.2% 100% 97.4%
coverage 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.util.List;
 18   
 
 19   
 import org.apache.commons.logging.Log;
 20   
 import org.apache.hivemind.ApplicationRuntimeException;
 21   
 import org.apache.hivemind.ErrorHandler;
 22   
 import org.apache.hivemind.Occurances;
 23   
 import org.apache.hivemind.ServiceImplementationFactory;
 24   
 import org.apache.hivemind.internal.Module;
 25   
 import org.apache.hivemind.internal.ServiceImplementationConstructor;
 26   
 import org.apache.hivemind.internal.ServicePoint;
 27   
 import org.apache.hivemind.schema.Schema;
 28   
 
 29   
 /**
 30   
  * Constructs a new service by invoking methods on
 31   
  * another service (which implements the
 32   
  * {@link org.apache.hivemind.ServiceImplementationFactory} interface.
 33   
  *
 34   
  * @author Howard Lewis Ship
 35   
  */
 36   
 public final class InvokeFactoryServiceConstructor
 37   
     extends BaseLocatable
 38   
     implements ServiceImplementationConstructor
 39   
 {
 40   
     private String _factoryServiceId;
 41   
     private ServicePoint _serviceExtensionPoint;
 42   
     private Module _contributingModule;
 43   
 
 44   
     /** List of {@link org.apache.hivemind.Element}, the raw XML parameters. */
 45   
     private List _parameters;
 46   
 
 47   
     /** The factory service to be invoked. */
 48   
     private ServiceImplementationFactory _factory;
 49   
 
 50   
     /** The parameters converted to objects as per the factory's parameter schema. */
 51   
     private List _convertedParameters;
 52   
 
 53   
     // TODO: Should this method be synchronized?
 54   
 
 55  407
     public Object constructCoreServiceImplementation()
 56   
     {
 57  407
         Log serviceLog = _serviceExtensionPoint.getServiceLog();
 58   
 
 59  407
         if (_factory == null)
 60   
         {
 61  367
             ServicePoint factoryPoint = _contributingModule.getServicePoint(_factoryServiceId);
 62   
 
 63  367
             Occurances expected = factoryPoint.getParametersCount();
 64   
 
 65  367
             _factory =
 66   
                 (ServiceImplementationFactory) factoryPoint.getService(
 67   
                     ServiceImplementationFactory.class);
 68   
 
 69  367
             Schema schema = factoryPoint.getParametersSchema();
 70   
 
 71   
             // Note: it's kind of a toss up whether logging should occur using the
 72   
             // id of the service being constructed, or of the factory being invoked.
 73   
             // Here, we're using the constructed service ... with the intent being that
 74   
             // users will enable debugging for the service (or search the logs for the service)
 75   
             // if it fails to build properly.
 76   
 
 77  367
             ErrorHandler errorHandler = _contributingModule.getErrorHandler();
 78   
             
 79  367
             SchemaProcessorImpl processor =
 80   
                 new SchemaProcessorImpl(errorHandler, serviceLog, schema);
 81   
 
 82  367
             processor.process(_parameters, _contributingModule);
 83   
 
 84  367
             _convertedParameters = processor.getElements();
 85   
 
 86  367
             checkParameterCounts(errorHandler, serviceLog, expected);
 87   
         }
 88   
 
 89  407
         try
 90   
         {
 91  407
             return _factory.createCoreServiceImplementation(
 92   
                 _serviceExtensionPoint.getExtensionPointId(),
 93   
                 _serviceExtensionPoint.getServiceInterface(),
 94   
                 serviceLog,
 95   
                 _contributingModule,
 96   
                 _convertedParameters);
 97   
         }
 98   
         catch (Exception ex)
 99   
         {
 100  0
             throw new ApplicationRuntimeException(ex.getMessage(), getLocation(), ex);
 101   
         }
 102   
     }
 103   
 
 104   
     /**
 105   
      * Checks that the number of parameter elements matches the expected count.
 106   
      */
 107  367
     private void checkParameterCounts(ErrorHandler handler, Log log, Occurances expected)
 108   
     {
 109  367
         int actual = _convertedParameters.size();
 110   
 
 111  367
         if (expected.inRange(actual))
 112  366
             return;
 113   
 
 114  1
         String message = ImplMessages.wrongNumberOfParameters(_factoryServiceId, actual, expected);
 115   
 
 116  1
         handler.error(log, message, getLocation(), null);
 117   
     }
 118   
 
 119  1
     public Module getContributingModule()
 120   
     {
 121  1
         return _contributingModule;
 122   
     }
 123   
 
 124  830
     public void setContributingModule(Module module)
 125   
     {
 126  830
         _contributingModule = module;
 127   
     }
 128   
 
 129  1
     public List getParameters()
 130   
     {
 131  1
         return _parameters;
 132   
     }
 133   
 
 134  1
     public ServicePoint getServiceExtensionPoint()
 135   
     {
 136  1
         return _serviceExtensionPoint;
 137   
     }
 138   
 
 139  830
     public void setParameters(List list)
 140   
     {
 141  830
         _parameters = list;
 142   
     }
 143   
 
 144  829
     public void setFactoryServiceId(String string)
 145   
     {
 146  829
         _factoryServiceId = string;
 147   
     }
 148   
 
 149  830
     public void setServiceExtensionPoint(ServicePoint point)
 150   
     {
 151  830
         _serviceExtensionPoint = point;
 152   
     }
 153   
 
 154   
 }
 155