Skip to content

Commit

Permalink
SAVARA-361 Add all info into swyd descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
objectiser committed Nov 8, 2012
1 parent 79f7744 commit 385242c
Show file tree
Hide file tree
Showing 3 changed files with 255 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,26 @@ public SwitchyardBPELGenerator() {
}

public org.w3c.dom.Element createSwitchyardDescriptor(String name,
org.w3c.dom.Element descriptor, java.util.Map<String,javax.wsdl.Definition> wsdls)
throws Exception {
org.w3c.dom.Element descriptor,
java.util.Map<String,javax.wsdl.Definition> wsdls)
throws Exception {
return (createSwitchyardDescriptor(name, descriptor, null, wsdls));
}

public org.w3c.dom.Element createSwitchyardDescriptor(String name,
org.w3c.dom.Element descriptor, javax.wsdl.Definition serviceWsdl,
java.util.Map<String,javax.wsdl.Definition> wsdls)
throws Exception {
org.w3c.dom.Element ret=null;
String targetNamespace=null;

if (serviceWsdl != null) {
targetNamespace = serviceWsdl.getTargetNamespace();
}

StringBuffer composite=new StringBuffer();

composite.append("<switchyard xmlns=\"urn:switchyard-config:switchyard:1.0\"\r\n");
composite.append("\t\txmlns:swyd=\"urn:switchyard-config:switchyard:1.0\"\r\n");
composite.append("\t\txmlns:trfm=\"urn:switchyard-config:transform:1.0\"\r\n");
composite.append("\t\txmlns:bean=\"urn:switchyard-component-bean:config:1.0\"\r\n");
composite.append("\t\txmlns:soap=\"urn:switchyard-component-soap:config:1.0\"\r\n");
composite.append("\t\txmlns:bpel=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\"\r\n");
composite.append("\t\txmlns:sca=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\"\r\n");

NamedNodeMap attrs=descriptor.getAttributes();

Expand All @@ -63,11 +70,20 @@ public org.w3c.dom.Element createSwitchyardDescriptor(String name,
}
}

composite.append("\t\ttargetNamespace=\""+descriptor.getAttribute("xmlns")+"\"\r\n");
composite.append("\t\tname=\""+name+"\">\r\n");
if (targetNamespace != null) {
composite.append("\t\ttargetNamespace=\""+targetNamespace+"\"\r\n");
}

composite.append("\t\tname=\""+name+"\" >\r\n");

composite.append("\t<sca:composite name=\""+name+
"\" targetNamespace=\""+descriptor.getAttribute("xmlns")+"\">\r\n");
composite.append("\t<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" name=\""+name+
"\"");

if (targetNamespace != null) {
composite.append(" targetNamespace=\""+targetNamespace+"\"");
}

composite.append(" >\r\n");

NodeList nl=descriptor.getChildNodes();

Expand All @@ -77,17 +93,19 @@ public org.w3c.dom.Element createSwitchyardDescriptor(String name,
if (n instanceof Element && XMLUtils.getLocalname(n.getNodeName()).equals("process")) {
Element process=(Element)n;

composite.append(generateServices(process, wsdls, namespaces));
composite.append(generateServices(name, process, wsdls, namespaces));

composite.append(generateReferences(name, process, wsdls, namespaces));

composite.append(generateComponent(process, wsdls, namespaces));
composite.append(generateComponent(name, process, wsdls, namespaces));

// TODO: Generate references for any 'invoke' entry that is not
// satisfied by a service (process) provided by this deployment
// descriptor
}
}

composite.append("\t</sca:composite>\r\n");
composite.append("\t</composite>\r\n");

composite.append("</switchyard>\r\n");

Expand All @@ -99,22 +117,18 @@ public org.w3c.dom.Element createSwitchyardDescriptor(String name,
/**
* This method generates a service element.
*
* @param compositeName The composite name
* @param process The process details
* @param wsdls The set of wsdls
* @param namespaces The namespaces
* @param port The port number
* @return The service element
*/
protected String generateServices(Element process,
protected String generateServices(String compositeName, Element process,
java.util.Map<String,javax.wsdl.Definition> wsdls,
java.util.Map<String, String> namespaces) {
StringBuffer ret=new StringBuffer();

String name=getComponentName(process);

ret.append("\t\t<sca:service name=\""+name+"\" promote=\""+name+"\">\r\n");
ret.append("\t\t\t<soap:binding.soap>\r\n");

NodeList nl=process.getElementsByTagName("provide");

java.util.List<String> wsdlPaths=new java.util.Vector<String>();
Expand All @@ -128,40 +142,110 @@ protected String generateServices(Element process,
if (services.getLength() == 1 && services.item(0) instanceof Element) {
Element service=(Element)services.item(0);

String name=getComponentName(compositeName);

String servName=getServiceName(service);

ret.append("\t\t<service name=\""+servName+"\" promote=\""+name+"/"+servName+"\">\r\n");

String wsdlInterface=getInterfaceDetails(service, wsdls, namespaces);

ret.append("\t\t\t<interface.wsdl interface=\""+wsdlInterface+"\"/>\r\n");

ret.append("\t\t\t<binding.soap xmlns=\"urn:switchyard-component-soap:config:1.0\" >\r\n");

String wsdlInterfacePath=getInterfacePath(service, wsdls, namespaces);

if (!wsdlPaths.contains(wsdlInterfacePath)) {
ret.append("\t\t\t\t<soap:wsdl>"+wsdlInterfacePath+"</soap:wsdl>\r\n");
ret.append("\t\t\t\t<wsdl>"+wsdlInterfacePath+"</wsdl>\r\n");
wsdlPaths.add(wsdlInterfacePath);
}

ret.append("\t\t\t\t<socketAddr>:18001</socketAddr>\r\n");
ret.append("\t\t\t</binding.soap>\r\n");

ret.append("\t\t</service>\r\n");
}
}
}

ret.append("\t\t\t\t<soap:socketAddr>:18001</soap:socketAddr>\r\n");
ret.append("\t\t\t</soap:binding.soap>\r\n");
return(ret.toString());
}

/**
* This method generates a reference element.
*
* @param compositeName The composite name
* @param process The process details
* @param wsdls The set of wsdls
* @param namespaces The namespaces
* @param port The port number
* @return The reference element
*/
protected String generateReferences(String compositeName, Element process,
java.util.Map<String,javax.wsdl.Definition> wsdls,
java.util.Map<String, String> namespaces) {
StringBuffer ret=new StringBuffer();

org.w3c.dom.NodeList nl = process.getElementsByTagName("invoke");

ret.append("\t\t</sca:service>\r\n");
for (int i=0; i < nl.getLength(); i++) {
Node n=nl.item(i);

if (n instanceof Element) {
NodeList services=((Element)n).getElementsByTagName("service");

if (services.getLength() == 1 && services.item(0) instanceof Element) {
Element service=(Element)services.item(0);

// TODO: Need to access wsdl details for the service

String wsdlInterface=getInterfaceDetails(service, wsdls, namespaces);

String name=getComponentName(compositeName);

String servName=getServiceName(service);

ret.append("\t\t<reference name=\""+servName+"\" promote=\""+
name+"/"+servName+"\" multiplicity=\"1..1\" >\r\n");
ret.append("\t\t\t<interface.wsdl interface=\""+wsdlInterface+"\"/>\r\n");

ret.append("\t\t\t<binding.soap xmlns=\"urn:switchyard-component-soap:config:1.0\" >\r\n");

String wsdlInterfacePath=getInterfacePath(service, wsdls, namespaces);
ret.append("\t\t\t\t<wsdl>"+wsdlInterfacePath+"</wsdl>\r\n");

ret.append("\t\t\t\t<socketAddr>:18001</socketAddr>\r\n");
ret.append("\t\t\t</binding.soap>\r\n");

ret.append("\t\t</reference>\r\n");
}
}
}

return(ret.toString());
}

/**
* This method generates the component element.
*
* @param compositeName The composite name
* @param process The process details
* @param wsdls The wsdls
* @param namespaces The namespaces
* @return The component element
*/
protected String generateComponent(Element process,
protected String generateComponent(String compositeName, Element process,
java.util.Map<String,javax.wsdl.Definition> wsdls,
java.util.Map<String, String> namespaces) {
StringBuffer ret=new StringBuffer();

ret.append("\t\t<sca:component name=\""+getComponentName(process)+"\">\r\n");
String name=getComponentName(compositeName);

ret.append("\t\t<component name=\""+name+"\">\r\n");

ret.append("\t\t\t<bpel:implementation.bpel process=\""+process.getAttribute("name")+"\" />\r\n");
ret.append("\t\t\t<implementation.bpel xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\" process=\""+
process.getAttribute("name")+"\" />\r\n");

NodeList nl=process.getElementsByTagName("provide");

Expand All @@ -178,9 +262,9 @@ protected String generateComponent(Element process,

String wsdlInterface=getInterfaceDetails(service, wsdls, namespaces);

ret.append("\t\t\t<sca:service name=\""+getServiceName(service)+"\" >\r\n");
ret.append("\t\t\t\t<sca:interface.wsdl interface=\""+wsdlInterface+"\"/>\r\n");
ret.append("\t\t\t</sca:service>\r\n");
ret.append("\t\t\t<service name=\""+getServiceName(service)+"\" >\r\n");
ret.append("\t\t\t\t<interface.wsdl interface=\""+wsdlInterface+"\"/>\r\n");
ret.append("\t\t\t</service>\r\n");
}
}
}
Expand All @@ -200,14 +284,14 @@ protected String generateComponent(Element process,

String wsdlInterface=getInterfaceDetails(service, wsdls, namespaces);

ret.append("\t\t\t<sca:reference name=\""+getServiceName(service)+"\" >\r\n");
ret.append("\t\t\t\t<sca:interface.wsdl interface=\""+wsdlInterface+"\"/>\r\n");
ret.append("\t\t\t</sca:reference>\r\n");
ret.append("\t\t\t<reference name=\""+getServiceName(service)+"\" >\r\n");
ret.append("\t\t\t\t<interface.wsdl interface=\""+wsdlInterface+"\"/>\r\n");
ret.append("\t\t\t</reference>\r\n");
}
}
}

ret.append("\t\t</sca:component>\r\n");
ret.append("\t\t</component>\r\n");

return(ret.toString());
}
Expand Down Expand Up @@ -298,19 +382,13 @@ protected String getInterfacePath(Element service,

/**
* This method returns the name of the component associated with the
* BPEL process.
* composite.
*
* @param process The BPEL process
* @param name The composite name
* @return The component name
*/
protected String getComponentName(Element process) {
String ret=process.getAttribute("name");
int index=ret.indexOf(':');

if (index != -1) {
ret = ret.substring(index+1);
}
return (ret);
protected String getComponentName(String name) {
return (name+"Component");
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
<switchyard xmlns="urn:switchyard-config:switchyard:1.0" xmlns:bean="urn:switchyard-component-bean:config:1.0" xmlns:bpel="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:examples="http://www.jboss.org/bpel/examples" xmlns:ls="http://example.com/loan-approval/loanService/" xmlns:ra="http://example.com/loan-approval/riskAssessment/" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" xmlns:soap="urn:switchyard-component-soap:config:1.0" xmlns:swyd="urn:switchyard-config:switchyard:1.0" xmlns:trfm="urn:switchyard-config:transform:1.0" name="loanapproval" targetNamespace="http://www.apache.org/ode/schemas/dd/2007/03">
<sca:composite name="loanapproval" targetNamespace="http://www.apache.org/ode/schemas/dd/2007/03">
<sca:service name="loanApprovalProcess" promote="loanApprovalProcess">
<soap:binding.soap>
<soap:wsdl>
<switchyard xmlns="urn:switchyard-config:switchyard:1.0" xmlns:examples="http://www.jboss.org/bpel/examples" xmlns:ls="http://example.com/loan-approval/loanService/" xmlns:ra="http://example.com/loan-approval/riskAssessment/" name="loanapproval">
<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" name="loanapproval">
<service name="loanService" promote="loanapprovalComponent/loanService">
<interface.wsdl interface="loanServicePT.wsdl#wsdl.porttype(loanServicePT)"/>
<binding.soap xmlns="urn:switchyard-component-soap:config:1.0">
<wsdl>
loanServicePT.wsdl
</soap:wsdl>
<soap:socketAddr>
</wsdl>
<socketAddr>
:18001
</soap:socketAddr>
</soap:binding.soap>
</sca:service>
<sca:component name="loanApprovalProcess">
<bpel:implementation.bpel process="ls:loanApprovalProcess"/>
<sca:service name="loanService">
<sca:interface.wsdl interface="loanServicePT.wsdl#wsdl.porttype(loanServicePT)"/>
</sca:service>
<sca:reference name="riskAssessor">
<sca:interface.wsdl interface="riskAssessmentPT.wsdl#wsdl.porttype(riskAssessmentPT)"/>
</sca:reference>
</sca:component>
<sca:service name="riskAssessmentProcess" promote="riskAssessmentProcess">
<soap:binding.soap>
<soap:wsdl>
</socketAddr>
</binding.soap>
</service>
<reference multiplicity="1..1" name="riskAssessor" promote="loanapprovalComponent/riskAssessor">
<interface.wsdl interface="riskAssessmentPT.wsdl#wsdl.porttype(riskAssessmentPT)"/>
<binding.soap xmlns="urn:switchyard-component-soap:config:1.0">
<wsdl>
riskAssessmentPT.wsdl
</soap:wsdl>
<soap:socketAddr>
</wsdl>
<socketAddr>
:18001
</soap:socketAddr>
</soap:binding.soap>
</sca:service>
<sca:component name="riskAssessmentProcess">
<bpel:implementation.bpel process="ra:riskAssessmentProcess"/>
<sca:service name="riskAssessor">
<sca:interface.wsdl interface="riskAssessmentPT.wsdl#wsdl.porttype(riskAssessmentPT)"/>
</sca:service>
</sca:component>
</sca:composite>
</socketAddr>
</binding.soap>
</reference>
<component name="loanapprovalComponent">
<implementation.bpel xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" process="ls:loanApprovalProcess"/>
<service name="loanService">
<interface.wsdl interface="loanServicePT.wsdl#wsdl.porttype(loanServicePT)"/>
</service>
<reference name="riskAssessor">
<interface.wsdl interface="riskAssessmentPT.wsdl#wsdl.porttype(riskAssessmentPT)"/>
</reference>
</component>
<service name="riskAssessor" promote="loanapprovalComponent/riskAssessor">
<interface.wsdl interface="riskAssessmentPT.wsdl#wsdl.porttype(riskAssessmentPT)"/>
<binding.soap xmlns="urn:switchyard-component-soap:config:1.0">
<wsdl>
riskAssessmentPT.wsdl
</wsdl>
<socketAddr>
:18001
</socketAddr>
</binding.soap>
</service>
<component name="loanapprovalComponent">
<implementation.bpel xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" process="ra:riskAssessmentProcess"/>
<service name="riskAssessor">
<interface.wsdl interface="riskAssessmentPT.wsdl#wsdl.porttype(riskAssessmentPT)"/>
</service>
</component>
</composite>
</switchyard>
Loading

0 comments on commit 385242c

Please sign in to comment.