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