1 17 package org.apache.servicemix.bpe.external; 18 19 import java.util.Enumeration ; 20 import java.util.Properties ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 import org.apache.ode.bpe.action.bpel.ExternalServiceAction; 26 import org.apache.ode.bpe.context.resolver.ContextResolver; 27 import org.apache.ode.bpe.definition.IPMDProcess; 28 import org.apache.ode.bpe.deployment.bpel.BPELAttributes; 29 import org.apache.ode.bpe.deployment.bpel.WSDLOperationKey; 30 import org.apache.ode.bpe.engine.IEvaluationContext; 31 import org.apache.ode.bpe.engine.IProcessCallBack; 32 import org.apache.ode.bpe.instance.IPMIProcess; 33 import org.apache.ode.bpe.util.BPException; 34 35 public class JbiExternalAction extends ExternalServiceAction { 36 37 private static Log log = LogFactory.getLog(JbiExternalAction.class); 38 39 public static final String SM_NS = "http://servicemix.apache.org/schemas/bpe/1.0"; 40 41 public static final String SM_ENDPOINT = "endpoint"; 42 public static final String SM_SERVICE = "service"; 43 public static final String SM_MEP = "mep"; 44 45 public JbiExternalAction() { 46 super(); 47 } 48 49 public void init(Properties props) throws BPException { 50 if (log.isDebugEnabled()) { 51 log.debug("init"); 52 } 53 extractInformations(props); 54 props.remove(ExternalServiceAction.OPERATION_KEY); 56 super.init(props); 57 if (log.isDebugEnabled()) { 58 log.debug("properties: " + props); 59 } 60 } 61 62 protected void extractInformations(Properties properties) { 63 Properties extProps = (Properties ) properties.get(EXT_ACTION_PROPS); 64 BPELAttributes attrs = (BPELAttributes) properties.get(INVOKE_ATTRIBUTES); 65 WSDLOperationKey opKey = (WSDLOperationKey) properties.get(ExternalServiceAction.OPERATION_KEY); 66 extProps.setProperty(JbiInvokeAction.INTERFACE_NAMESPACE, opKey.getNameSpace()); 67 extProps.setProperty(JbiInvokeAction.INTERFACE_LOCALNAME, opKey.getPortType()); 68 extProps.setProperty(JbiInvokeAction.OPERATION_NAMESPACE, opKey.getNameSpace()); 69 extProps.setProperty(JbiInvokeAction.OPERATION_LOCALNAME, opKey.getOperationName()); 70 for (Enumeration en = attrs.propertyNames(); en.hasMoreElements();) { 71 String qn = (String ) en.nextElement(); 72 String uri = attrs.getURI(qn); 73 String val = attrs.getProperty(qn); 74 if (SM_NS.equals(uri)) { 75 if (qn.indexOf(':') > 0) { 76 qn = qn.substring(qn.indexOf(':') + 1); 77 } 78 if (SM_ENDPOINT.equals(qn)) { 79 String [] parts = split3(val); 80 extProps.setProperty(JbiInvokeAction.SERVICE_NAMESPACE, parts[0]); 81 extProps.setProperty(JbiInvokeAction.SERVICE_LOCALNAME, parts[1]); 82 extProps.setProperty(JbiInvokeAction.ENDPOINT_NAME, parts[2]); 83 } else if (SM_SERVICE.equals(qn)) { 84 String [] parts = split2(val); 85 extProps.setProperty(JbiInvokeAction.SERVICE_NAMESPACE, parts[0]); 86 extProps.setProperty(JbiInvokeAction.SERVICE_LOCALNAME, parts[1]); 87 } else if (SM_MEP.equals(qn)) { 88 extProps.setProperty(JbiInvokeAction.MEP, val); 89 } 90 } 91 } 92 } 93 94 protected String [] split3(String uri) { 95 char sep; 96 if (uri.indexOf('/') > 0) { 97 sep = '/'; 98 } else { 99 sep = ':'; 100 } 101 int idx1 = uri.lastIndexOf(sep); 102 int idx2 = uri.lastIndexOf(sep, idx1 - 1); 103 String epName = uri.substring(idx1 + 1); 104 String svcName = uri.substring(idx2 + 1, idx1); 105 String nsUri = uri.substring(0, idx2); 106 return new String [] { nsUri, svcName, epName }; 107 } 108 109 protected String [] split2(String uri) { 110 char sep; 111 if (uri.indexOf('/') > 0) { 112 sep = '/'; 113 } else { 114 sep = ':'; 115 } 116 int idx1 = uri.lastIndexOf(sep); 117 String svcName = uri.substring(idx1 + 1); 118 String nsUri = uri.substring(0, idx1); 119 return new String [] { nsUri, svcName }; 120 } 121 122 public boolean execute( 123 ContextResolver resolver, 124 IEvaluationContext ec, 125 IProcessCallBack pcb, 126 IPMIProcess processInstance, 127 IPMDProcess processDefinition) 128 throws BPException { 129 return super.execute(resolver, ec, pcb, processInstance, processDefinition); 130 } 131 } 132 | Popular Tags |