Clover coverage report - Code Coverage for hivemind release 1.1-alpha-2
Coverage timestamp: Wed Feb 23 2005 09:59:04 EST
file stats: LOC: 94   Methods: 3
NCLOC: 50   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
ObjectTranslator.java 100% 94.1% 100% 96.2%
coverage coverage
 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   
 
 15   
 package org.apache.hivemind.service.impl;
 16   
 
 17   
 import java.util.HashMap;
 18   
 import java.util.Map;
 19   
 
 20   
 import org.apache.hivemind.ApplicationRuntimeException;
 21   
 import org.apache.hivemind.ErrorLog;
 22   
 import org.apache.hivemind.HiveMind;
 23   
 import org.apache.hivemind.Location;
 24   
 import org.apache.hivemind.internal.Module;
 25   
 import org.apache.hivemind.schema.Translator;
 26   
 import org.apache.hivemind.service.ObjectProvider;
 27   
 
 28   
 /**
 29   
  * Implementation of the indirect translator. This translator allows the contributor, not the
 30   
  * schema, to define where object values come from, and is fully extensible. Perhaps I'll have an
 31   
  * inspiration and find a better name than "indirect".
 32   
  * 
 33   
  * @author Howard Lewis Ship
 34   
  */
 35   
 public class ObjectTranslator implements Translator
 36   
 {
 37   
     /** @since 1.1 */
 38   
     private ErrorLog _errorLog;
 39   
 
 40   
     /**
 41   
      * Keyed on prefix, value is an {@link org.apache.hivemind.service.ObjectProvider}.
 42   
      */
 43   
     private Map _providers = new HashMap();
 44   
 
 45  117
     public Object translate(Module contributingModule, Class propertyType, String inputValue,
 46   
             Location location)
 47   
     {
 48  117
         if (HiveMind.isBlank(inputValue))
 49  3
             return null;
 50   
 
 51  114
         int colonx = inputValue.indexOf(':');
 52   
 
 53  114
         if (colonx < 1)
 54   
         {
 55  1
             _errorLog.error(ServiceMessages.invalidProviderSelector(inputValue), null, null);
 56   
 
 57  1
             return null;
 58   
         }
 59   
 
 60  113
         String prefix = inputValue.substring(0, colonx);
 61   
 
 62  113
         ObjectProvider provider = (ObjectProvider) _providers.get(prefix);
 63   
 
 64  113
         if (provider == null)
 65   
         {
 66  1
             _errorLog.error(ServiceMessages.unknownProviderPrefix(prefix), location, null);
 67   
 
 68  1
             return null;
 69   
         }
 70   
 
 71  112
         String locator = inputValue.substring(colonx + 1);
 72   
 
 73  112
         try
 74   
         {
 75  112
             return provider.provideObject(contributingModule, propertyType, locator, location);
 76   
         }
 77   
         catch (Exception ex)
 78   
         {
 79  0
             throw new ApplicationRuntimeException(ex.getMessage(), location, ex);
 80   
         }
 81   
 
 82   
     }
 83   
 
 84  111
     public void setContributions(Map map)
 85   
     {
 86  111
         _providers = map;
 87   
     }
 88   
 
 89   
     /** @since 1.1 */
 90  110
     public void setErrorLog(ErrorLog errorLog)
 91   
     {
 92  110
         _errorLog = errorLog;
 93   
     }
 94   
 }