1 17 package org.apache.servicemix.jbi.nmr.flow; 18 19 import java.io.IOException ; 20 import java.net.URISyntaxException ; 21 import java.util.Map ; 22 import javax.jbi.JBIException; 23 import org.apache.activeio.util.FactoryFinder; 24 import org.apache.activemq.util.IntrospectionSupport; 25 import org.apache.activemq.util.URISupport; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 34 public class FlowProvider{ 35 private static final Log log=LogFactory.getLog(FlowProvider.class); 36 private static FactoryFinder finder=new FactoryFinder("META-INF/services/org/apache/servicemix/jbi/nmr/flow/"); 37 38 45 public static Flow getFlow(String flow) throws JBIException{ 46 Object value; 47 String flowName=getFlowName(flow); 48 try{ 49 value=finder.newInstance(flowName); 50 if(value!=null&&value instanceof Flow){ 51 String query=getQuery(flow); 52 if(query!=null){ 53 Map map=URISupport.parseQuery(query); 54 if(map!=null&&!map.isEmpty()){ 55 IntrospectionSupport.setProperties(value,map); 56 } 57 } 58 return (Flow) value; 59 } 60 throw new JBIException("No implementation found for: "+flow); 61 }catch(IllegalAccessException e){ 62 log.error("getFlow("+flow+" failed: "+e,e); 63 throw new JBIException(e); 64 }catch(InstantiationException e){ 65 log.error("getFlow("+flow+" failed: "+e,e); 66 throw new JBIException(e); 67 }catch(IOException e){ 68 log.error("getFlow("+flow+" failed: "+e,e); 69 throw new JBIException(e); 70 }catch(ClassNotFoundException e){ 71 log.error("getFlow("+flow+" failed: "+e,e); 72 throw new JBIException(e); 73 }catch(URISyntaxException e){ 74 log.error("getFlow("+flow+" failed: "+e,e); 75 throw new JBIException(e); 76 } 77 } 78 79 public static String getFlowName(String str){ 80 String result=str; 81 int index=str.indexOf('?'); 82 if(index>=0){ 83 result=str.substring(0,index); 84 } 85 return result; 86 } 87 88 protected static String getQuery(String str){ 89 String result=null; 90 int index=str.indexOf('?'); 91 if(index>=0&&(index+1)<str.length()){ 92 result=str.substring(index+1); 93 } 94 return result; 95 } 96 } | Popular Tags |