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: 134   Methods: 5
NCLOC: 85   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 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.Iterator;
 19   
 import java.util.List;
 20   
 import java.util.Map;
 21   
 
 22   
 import org.apache.commons.logging.Log;
 23   
 import org.apache.hivemind.ErrorHandler;
 24   
 import org.apache.hivemind.HiveMind;
 25   
 import org.apache.hivemind.Location;
 26   
 import org.apache.hivemind.internal.Module;
 27   
 import org.apache.hivemind.schema.Translator;
 28   
 import org.apache.hivemind.service.ObjectProvider;
 29   
 
 30   
 /**
 31   
  * Implementation of the indirect translator. This translator allows the contributor,
 32   
  * not the schema, to define where object values come from, and is fully extensible.
 33   
  * Perhaps I'll have an inspiration and find a better name than "indirect".
 34   
  *
 35   
  * @author Howard Lewis Ship
 36   
  */
 37   
 public class ObjectTranslator implements Translator
 38   
 {
 39   
     private ErrorHandler _errorHandler;
 40   
     private Log _log;
 41   
     private List _contributions;
 42   
 
 43   
     /**
 44   
      * Keyed on prefix, value is an {@link org.apache.hivemind.service.ObjectProvider}.
 45   
      */
 46   
     private Map _providers = new HashMap();
 47   
 
 48  5
     public void initializeService()
 49   
     {
 50  5
         Map locations = new HashMap();
 51  5
         Iterator i = _contributions.iterator();
 52  5
         while (i.hasNext())
 53   
         {
 54  7
             ObjectProviderContribution c = (ObjectProviderContribution) i.next();
 55   
 
 56  7
             String prefix = c.getPrefix();
 57   
 
 58  7
             Location oldLocation = (Location) locations.get(prefix);
 59   
 
 60  7
             if (oldLocation != null)
 61   
             {
 62  1
                 _errorHandler.error(
 63   
                     _log,
 64   
                     ServiceMessages.duplicateProviderPrefix(prefix, oldLocation),
 65   
                     c.getLocation(),
 66   
                     null);
 67  1
                 continue;
 68   
             }
 69   
 
 70  6
             locations.put(prefix, c.getLocation());
 71  6
             _providers.put(prefix, c.getProvider());
 72   
         }
 73   
     }
 74   
 
 75  6
     public Object translate(
 76   
         Module contributingModule,
 77   
         Class propertyType,
 78   
         String inputValue,
 79   
         Location location)
 80   
     {
 81  6
         if (HiveMind.isBlank(inputValue))
 82  1
             return null;
 83   
 
 84  5
         int colonx = inputValue.indexOf(':');
 85   
 
 86  5
         if (colonx < 1)
 87   
         {
 88  1
             _errorHandler.error(
 89   
                 _log,
 90   
                 ServiceMessages.invalidProviderSelector(inputValue),
 91   
                 null,
 92   
                 null);
 93   
 
 94  1
             return null;
 95   
         }
 96   
 
 97  4
         String prefix = inputValue.substring(0, colonx);
 98   
 
 99  4
         ObjectProvider provider = (ObjectProvider) _providers.get(prefix);
 100   
 
 101  4
         if (provider == null)
 102   
         {
 103  1
             _errorHandler.error(
 104   
                 _log,
 105   
                 ServiceMessages.unknownProviderPrefix(prefix),
 106   
                 location,
 107   
                 null);
 108   
 
 109  1
             return null;
 110   
         }
 111   
 
 112  3
         String locator = inputValue.substring(colonx + 1);
 113   
 
 114  3
         return provider.provideObject(contributingModule, propertyType, locator, location);
 115   
 
 116   
     }
 117   
 
 118  5
     public void setContributions(List list)
 119   
     {
 120  5
         _contributions = list;
 121   
     }
 122   
 
 123  4
     public void setErrorHandler(ErrorHandler handler)
 124   
     {
 125  4
         _errorHandler = handler;
 126   
     }
 127   
 
 128  4
     public void setLog(Log log)
 129   
     {
 130  4
         _log = log;
 131   
     }
 132   
 
 133   
 }
 134