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 InvokeConsequenceFactory implements ConsequenceFactory { 35 public Consequence newConsequence(Rule rule, RuleBaseContext ruleBaseContext, Configuration configuration) throws FactoryException { 36 final QName operation = toQName(configuration, configuration.getAttribute("operation")); 37 final QName service = toQName(configuration, configuration.getAttribute("service")); 38 final QName interfaceName = toQName(configuration, configuration.getAttribute("interface")); 39 return new JbiConsequence() { 40 protected void invokeJbiOperation(JbiHelper helper, Tuple tuple) throws MessagingException { 41 helper.invoke(service, operation, interfaceName); 42 } 43 }; 44 } 45 46 49 protected QName toQName(Configuration configuration, String text) { 50 if (text == null) { 51 return null; 52 } 53 String [] names = configuration.getAttributeNames(); 54 String localPart = text; 55 String prefix = null; 56 int idx = text.indexOf(':'); 57 if (idx >= 0) { 58 prefix = "xmlns:" + text.substring(0, idx); 59 localPart = text.substring(idx + 1); 60 } 61 String uri = ""; 62 for (int i = 0; i < names.length; i++) { 63 String name = names[i]; 64 if (prefix == null) { 65 if ("xmlns".equals(name)) { 66 uri = configuration.getAttribute(name); 67 break; 68 } 69 } 70 else { 71 if (name.equals(prefix)) { 72 uri = configuration.getAttribute(name); 73 break; 74 } 75 } 76 } 77 System.out.println("Creating QName with uri: " + uri + " name: " + localPart); 78 return new QName (uri, localPart); 79 } 80 } 81 | Popular Tags |