1 17 package org.apache.servicemix.components.drools.dsl; 18 19 import org.apache.servicemix.components.drools.JbiHelper; 20 import org.drools.rule.Rule; 21 import org.drools.smf.Configuration; 22 import org.drools.smf.ConsequenceFactory; 23 import org.drools.smf.FactoryException; 24 import org.drools.spi.Consequence; 25 import org.drools.spi.RuleBaseContext; 26 import org.drools.spi.Tuple; 27 28 import javax.jbi.messaging.MessagingException; 29 import javax.xml.namespace.QName ; 30 31 34 public class ForwardConsequenceFactory implements ConsequenceFactory { 35 public Consequence newConsequence(Rule rule, RuleBaseContext ruleBaseContext, final Configuration configuration) throws FactoryException { 36 final String [] services = configuration.getAttribute("service").split(","); 37 return new JbiConsequence() { 38 protected void invokeJbiOperation(JbiHelper helper, Tuple tuple) throws MessagingException { 39 for (int i = 0; i < services.length; i++) { 40 QName service = toQName(configuration, services[i]); 41 helper.forwardToService(service, null, null); 42 } 43 } 44 }; 45 } 46 47 50 protected QName toQName(Configuration configuration, String text) { 51 if (text == null) { 52 return null; 53 } 54 String [] names = configuration.getAttributeNames(); 55 String localPart = text; 56 String prefix = null; 57 int idx = text.indexOf(':'); 58 if (idx >= 0) { 59 prefix = "xmlns:" + text.substring(0, idx); 60 localPart = text.substring(idx + 1); 61 } 62 String uri = ""; 63 for (int i = 0; i < names.length; i++) { 64 String name = names[i]; 65 if (prefix == null) { 66 if ("xmlns".equals(name)) { 67 uri = configuration.getAttribute(name); 68 break; 69 } 70 } 71 else { 72 if (name.equals(prefix)) { 73 uri = configuration.getAttribute(name); 74 break; 75 } 76 } 77 } 78 System.out.println("Creating QName with uri: " + uri + " name: " + localPart); 79 return new QName (uri, localPart); 80 } 81 } 82 | Popular Tags |