1 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 35 public class ObjectTranslator implements Translator 36 { 37 38 private ErrorLog _errorLog; 39 40 43 private Map _providers = new HashMap (); 44 45 public Object translate(Module contributingModule, Class propertyType, String inputValue, 46 Location location) 47 { 48 if (HiveMind.isBlank(inputValue)) 49 return null; 50 51 int colonx = inputValue.indexOf(':'); 52 53 if (colonx < 1) 54 { 55 _errorLog.error(ServiceMessages.invalidProviderSelector(inputValue), null, null); 56 57 return null; 58 } 59 60 String prefix = inputValue.substring(0, colonx); 61 62 ObjectProvider provider = (ObjectProvider) _providers.get(prefix); 63 64 if (provider == null) 65 { 66 _errorLog.error(ServiceMessages.unknownProviderPrefix(prefix), location, null); 67 68 return null; 69 } 70 71 String locator = inputValue.substring(colonx + 1); 72 73 try 74 { 75 return provider.provideObject(contributingModule, propertyType, locator, location); 76 } 77 catch (Exception ex) 78 { 79 throw new ApplicationRuntimeException(ex.getMessage(), location, ex); 80 } 81 82 } 83 84 public void setContributions(Map map) 85 { 86 _providers = map; 87 } 88 89 90 public void setErrorLog(ErrorLog errorLog) 91 { 92 _errorLog = errorLog; 93 } 94 } | Popular Tags |