KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > bpe > external > JbiExternalAction


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.bpe.external;
18
19 import java.util.Enumeration JavaDoc;
20 import java.util.Properties JavaDoc;
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 JavaDoc SM_NS = "http://servicemix.apache.org/schemas/bpe/1.0";
40     
41     public static final String JavaDoc SM_ENDPOINT = "endpoint";
42     public static final String JavaDoc SM_SERVICE = "service";
43     public static final String JavaDoc SM_MEP = "mep";
44     
45     public JbiExternalAction() {
46         super();
47     }
48     
49     public void init(Properties JavaDoc props) throws BPException {
50         if (log.isDebugEnabled()) {
51             log.debug("init");
52         }
53         extractInformations(props);
54         // Do not store informations about operation
55
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 JavaDoc properties) {
63         Properties JavaDoc extProps = (Properties JavaDoc) 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 JavaDoc en = attrs.propertyNames(); en.hasMoreElements();) {
71             String JavaDoc qn = (String JavaDoc) en.nextElement();
72             String JavaDoc uri = attrs.getURI(qn);
73             String JavaDoc 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 JavaDoc[] 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 JavaDoc[] 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 JavaDoc[] split3(String JavaDoc 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 JavaDoc epName = uri.substring(idx1 + 1);
104         String JavaDoc svcName = uri.substring(idx2 + 1, idx1);
105         String JavaDoc nsUri = uri.substring(0, idx2);
106         return new String JavaDoc[] { nsUri, svcName, epName };
107     }
108     
109     protected String JavaDoc[] split2(String JavaDoc uri) {
110         char sep;
111         if (uri.indexOf('/') > 0) {
112             sep = '/';
113         } else {
114             sep = ':';
115         }
116         int idx1 = uri.lastIndexOf(sep);
117         String JavaDoc svcName = uri.substring(idx1 + 1);
118         String JavaDoc nsUri = uri.substring(0, idx1);
119         return new String JavaDoc[] { 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