Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcsalter2005-05-11 23:08:05 +0000
committercsalter2005-05-11 23:08:05 +0000
commit0f45332c891c593b8b9a546eebd76a8e85b42b2d (patch)
tree405c4823fac3d2531e4b73b2cbfd1c1114f23989 /bundles/org.eclipse.wst.wsdl
parent76b2a82c90117c670147cbce1423400c50e6eebd (diff)
downloadwebtools.webservices-0f45332c891c593b8b9a546eebd76a8e85b42b2d.tar.gz
webtools.webservices-0f45332c891c593b8b9a546eebd76a8e85b42b2d.tar.xz
webtools.webservices-0f45332c891c593b8b9a546eebd76a8e85b42b2d.zip
[94864] move wsdl content generators into the wsdl model
Diffstat (limited to 'bundles/org.eclipse.wst.wsdl')
-rw-r--r--bundles/org.eclipse.wst.wsdl/src-http/org/eclipse/wst/wsdl/binding/http/internal/generator/HTTPContentGenerator.java267
-rw-r--r--bundles/org.eclipse.wst.wsdl/src-soap/org/eclipse/wst/wsdl/binding/soap/internal/generator/SOAPContentGenerator.java371
-rw-r--r--bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/BaseGenerator.java56
-rw-r--r--bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/BindingGenerator.java529
-rw-r--r--bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/ContentGenerator.java32
-rw-r--r--bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/PortGenerator.java78
6 files changed, 1333 insertions, 0 deletions
diff --git a/bundles/org.eclipse.wst.wsdl/src-http/org/eclipse/wst/wsdl/binding/http/internal/generator/HTTPContentGenerator.java b/bundles/org.eclipse.wst.wsdl/src-http/org/eclipse/wst/wsdl/binding/http/internal/generator/HTTPContentGenerator.java
new file mode 100644
index 000000000..5435b8bc7
--- /dev/null
+++ b/bundles/org.eclipse.wst.wsdl/src-http/org/eclipse/wst/wsdl/binding/http/internal/generator/HTTPContentGenerator.java
@@ -0,0 +1,267 @@
+package org.eclipse.wst.wsdl.binding.http.internal.generator;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.wst.wsdl.Binding;
+import org.eclipse.wst.wsdl.BindingFault;
+import org.eclipse.wst.wsdl.BindingInput;
+import org.eclipse.wst.wsdl.BindingOperation;
+import org.eclipse.wst.wsdl.BindingOutput;
+import org.eclipse.wst.wsdl.ExtensibilityElement;
+import org.eclipse.wst.wsdl.Fault;
+import org.eclipse.wst.wsdl.Input;
+import org.eclipse.wst.wsdl.Operation;
+import org.eclipse.wst.wsdl.Output;
+import org.eclipse.wst.wsdl.Port;
+import org.eclipse.wst.wsdl.PortType;
+import org.eclipse.wst.wsdl.binding.http.HTTPAddress;
+import org.eclipse.wst.wsdl.binding.http.HTTPBinding;
+import org.eclipse.wst.wsdl.binding.http.HTTPFactory;
+import org.eclipse.wst.wsdl.binding.http.HTTPOperation;
+import org.eclipse.wst.wsdl.binding.http.HTTPUrlEncoded;
+import org.eclipse.wst.wsdl.internal.generator.ContentGenerator;
+import org.w3c.dom.Element;
+
+public class HTTPContentGenerator implements ContentGenerator
+{
+ public static final int VERB_POST = 0;
+ public static final int VERB_GET = 1;
+ public static final int VERB_NOT_SET = -1;
+
+ private int verbOption = VERB_NOT_SET;
+ protected String addressLocation = ContentGenerator.ADDRESS_LOCATION;
+
+ protected final static String[] requiredNamespaces = { "http://schemas.xmlsoap.org/wsdl/mime/", "http://schemas.xmlsoap.org/wsdl/http/" };
+
+ public void setVerb(int verb) {
+ verbOption = verb;
+ }
+
+ public void setAddressLocation(String addressLocation) {
+ this.addressLocation = addressLocation;
+ }
+
+ public String[] getRequiredNamespaces()
+ {
+ return requiredNamespaces;
+ }
+
+ public String getPreferredNamespacePrefix(String namespace)
+ {
+ if (namespace.equals("http://schemas.xmlsoap.org/wsdl/mime/")) {
+ return "mime";
+ }
+ else if (namespace.equals("http://schemas.xmlsoap.org/wsdl/http/")) {
+ return "http";
+ }
+
+ return "";
+ }
+
+ public void generatePortContent(Port port)
+ {
+ // We blow away any existing ExtensibilityElements/content before we generate it
+ // Is it worth being smarter? Look for matching content first and create those which aren't found????
+ List removeList = new ArrayList(port.getEExtensibilityElements());
+ removeExtensebilityElements(port.getEExtensibilityElements(), removeList);
+
+ HTTPAddress httpAddress= HTTPFactory.eINSTANCE.createHTTPAddress();
+ httpAddress.setLocationURI(addressLocation);
+ port.addExtensibilityElement(httpAddress);
+ }
+
+ public void generateBindingContent(Binding binding, PortType portType)
+ {
+ // We blow away any existing ExtensibilityElements/content before we generate it
+ // Is it worth being smarter? Look for matching content first and create those which aren't found????
+ List removeList = new ArrayList(binding.getEExtensibilityElements());
+ removeExtensebilityElements(binding.getEExtensibilityElements(), removeList);
+
+ HTTPBinding httpBinding = HTTPFactory.eINSTANCE.createHTTPBinding();
+ httpBinding.setVerb(getVerbOption(binding) == VERB_POST ? "POST" : "GET");
+
+ binding.addExtensibilityElement(httpBinding);
+ }
+
+ public void generateBindingOperationContent(BindingOperation bindingOperation, Operation operation)
+ {
+ // We blow away any existing ExtensibilityElements/content before we generate it
+ // Is it worth being smarter? Look for matching content first and create those which aren't found????
+ List removeList = new ArrayList(bindingOperation.getEExtensibilityElements());
+ removeExtensebilityElements(bindingOperation.getEExtensibilityElements(), removeList);
+
+ HTTPOperation httpOperation = HTTPFactory.eINSTANCE.createHTTPOperation();
+ httpOperation.setLocationURI("/" + operation.getName());
+ bindingOperation.addExtensibilityElement(httpOperation);
+ }
+
+ public void generateBindingInputContent(BindingInput bindingInput, Input input)
+ {
+ // We blow away any existing ExtensibilityElements/content before we generate it
+ // Is it worth being smarter? Look for matching content first and create those which aren't found????
+ List removeList = new ArrayList(bindingInput.getEExtensibilityElements());
+
+ // hack: we're being sneaky here. Set the 'verb' options now.
+ int option = getVerbOption(bindingInput);
+ removeExtensebilityElements(bindingInput.getEExtensibilityElements(), removeList);
+
+ if (option == VERB_POST)
+ {
+ // TODO: Is there an equivalent HTTP Model Object for this?....
+ Element element = createElement(bindingInput.getElement(), "mime", "content");
+ element.setAttribute("type", "application/x-www-form-urlencoded");
+ }
+ else
+ {
+ HTTPUrlEncoded urlEncoded= HTTPFactory.eINSTANCE.createHTTPUrlEncoded();
+ bindingInput.addExtensibilityElement(urlEncoded);
+ }
+ }
+
+ public void generateBindingOutputContent(BindingOutput bindingOutput, Output output)
+ {
+ // We blow away any existing ExtensibilityElements/content before we generate it
+ // Is it worth being smarter? Look for matching content first and create those which aren't found????
+ List removeList = new ArrayList(bindingOutput.getEExtensibilityElements());
+
+ // hack: we're being sneaky here. Set the 'verb' options now.
+ getVerbOption(bindingOutput);
+ removeExtensebilityElements(bindingOutput.getEExtensibilityElements(), removeList);
+
+ // TODO: Is there an equivalent HTTP Model Object for this?....
+ Element bindingOutputElement = bindingOutput.getElement();
+ Element element = createElement(bindingOutputElement, "mime", "content");
+ element.setAttribute("type", "text/xml");
+ }
+
+ public void generateBindingFaultContent(BindingFault bindingFault, Fault fault)
+ {
+ //TODO!!
+ }
+
+ protected Element createElement(Element parentElement, String prefix, String elementName)
+ {
+ String name = prefix != null ? (prefix + ":" + elementName) : elementName;
+ Element result = parentElement.getOwnerDocument().createElement(name);
+ parentElement.insertBefore(result, parentElement.getFirstChild());
+// parentElement.appendChild(result);
+ return result;
+ }
+
+ /////////////////////
+ private int getVerbOption(Object genericBindingObject) {
+ if (verbOption == VERB_NOT_SET && genericBindingObject != null) {
+ // init() was never called, try to determine the 'verb' based on what we have/know
+ Binding binding = getBindingObject(genericBindingObject);
+
+ // Try to determine the verb from the Binding Object
+ if (binding != null) {
+ List list = binding.getEExtensibilityElements();
+ Iterator valuesIt = getExtensibilityElementAttributeValue(list, "verb").iterator();
+
+ while (valuesIt.hasNext()) {
+ String verb = (String) valuesIt.next();
+
+ if (verb.equals("POST")) {
+ verbOption = VERB_POST;
+ }
+ else if (verb.equals("GET")) {
+ verbOption = VERB_GET;
+ }
+
+ if (verbOption != VERB_NOT_SET) {
+ break;
+ }
+ }
+ }
+ }
+
+ if (verbOption == VERB_NOT_SET) {
+ verbOption = VERB_GET;
+ }
+
+ return verbOption;
+ }
+
+ private List getExtensibilityElementAttributeValue(List eeList, String attributeKey) {
+ List values = new ArrayList();
+ Iterator eeElementsIt = eeList.iterator();
+
+ while (eeElementsIt.hasNext()) {
+ ExtensibilityElement eeElement = (ExtensibilityElement) eeElementsIt.next();
+ String attributeValue = eeElement.getElement().getAttribute(attributeKey);
+ if (attributeValue != null && !attributeValue.equals("")) {
+ values.add(attributeValue);
+ }
+ }
+
+ return values;
+ }
+
+ private Binding getBindingObject(Object genericBindingObject) {
+ Object parent = genericBindingObject;
+
+ int index = 0;
+ while (parent != null && index < 5) {
+ parent = getGenericBindingObjectParent(parent);
+ if (parent instanceof Binding) {
+ break;
+ }
+ index++;
+ }
+
+ return (parent instanceof Binding)? (Binding) parent : null;
+ }
+
+ private List getMessageReferenceBindingObjects(Object genericBindingObject) {
+ List list = new ArrayList();
+ Binding binding = getBindingObject(genericBindingObject);
+
+ if (binding != null) {
+ Iterator operationsIt = binding.getEBindingOperations().iterator();
+
+ while (operationsIt.hasNext()) {
+ BindingOperation op = (BindingOperation) operationsIt.next();
+ list.add(op.getEBindingInput());
+ list.add(op.getEBindingOutput());
+ list.addAll(op.getEBindingFaults());
+ }
+ }
+
+ return list;
+ }
+
+ private Object getGenericBindingObjectParent(Object genericBindingObject) {
+ Object parent = null;
+
+ if (genericBindingObject != null) {
+ if (genericBindingObject instanceof BindingOperation) {
+ parent = ((BindingOperation) genericBindingObject).getContainer();
+ }
+ else if (genericBindingObject instanceof BindingInput) {
+ parent = ((BindingInput) genericBindingObject).getContainer();
+ }
+ else if (genericBindingObject instanceof BindingOutput) {
+ parent = ((BindingOutput) genericBindingObject).getContainer();
+ }
+ else if (genericBindingObject instanceof BindingFault) {
+ parent = ((BindingFault) genericBindingObject).getContainer();
+ }
+ }
+
+ return parent;
+ }
+
+ private void removeExtensebilityElements(List originalList, List removeList) {
+ Iterator removeIt = removeList.iterator();
+ while (removeIt.hasNext()) {
+ originalList.remove(removeIt.next());
+ }
+ }
+
+ public String getProtocol() {
+ return "HTTP";
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.wst.wsdl/src-soap/org/eclipse/wst/wsdl/binding/soap/internal/generator/SOAPContentGenerator.java b/bundles/org.eclipse.wst.wsdl/src-soap/org/eclipse/wst/wsdl/binding/soap/internal/generator/SOAPContentGenerator.java
new file mode 100644
index 000000000..5d6e3d8be
--- /dev/null
+++ b/bundles/org.eclipse.wst.wsdl/src-soap/org/eclipse/wst/wsdl/binding/soap/internal/generator/SOAPContentGenerator.java
@@ -0,0 +1,371 @@
+package org.eclipse.wst.wsdl.binding.soap.internal.generator;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.wst.wsdl.Binding;
+import org.eclipse.wst.wsdl.BindingFault;
+import org.eclipse.wst.wsdl.BindingInput;
+import org.eclipse.wst.wsdl.BindingOperation;
+import org.eclipse.wst.wsdl.BindingOutput;
+import org.eclipse.wst.wsdl.ExtensibilityElement;
+import org.eclipse.wst.wsdl.Fault;
+import org.eclipse.wst.wsdl.Input;
+import org.eclipse.wst.wsdl.Operation;
+import org.eclipse.wst.wsdl.Output;
+import org.eclipse.wst.wsdl.Port;
+import org.eclipse.wst.wsdl.PortType;
+import org.eclipse.wst.wsdl.WSDLElement;
+import org.eclipse.wst.wsdl.binding.soap.SOAPAddress;
+import org.eclipse.wst.wsdl.binding.soap.SOAPBinding;
+import org.eclipse.wst.wsdl.binding.soap.SOAPBody;
+import org.eclipse.wst.wsdl.binding.soap.SOAPFactory;
+import org.eclipse.wst.wsdl.binding.soap.SOAPFault;
+import org.eclipse.wst.wsdl.binding.soap.SOAPOperation;
+import org.eclipse.wst.wsdl.binding.soap.internal.impl.SOAPFactoryImpl;
+import org.w3c.dom.Element;
+
+import org.eclipse.wst.wsdl.internal.generator.ContentGenerator;
+
+public class SOAPContentGenerator implements ContentGenerator
+{
+ public static final int OPTION_NOT_SET = -1;
+
+ public static final int STYLE_DOCUMENT = 1;
+ public static final int STYLE_RPC = 2;
+
+ public static final int USE_LITERAL = 1;
+ public static final int USE_ENCODED = 2;
+
+ private int styleOption = OPTION_NOT_SET;
+ private int useOption = OPTION_NOT_SET;
+
+ protected String namespaceValue = "";
+ protected String addressLocation = ContentGenerator.ADDRESS_LOCATION;
+
+ protected final static String[] requiredNamespaces = {"http://schemas.xmlsoap.org/wsdl/soap/"};
+ protected final static String[] preferredNamespacePrefixes = {"soap"};
+
+
+ public String[] getRequiredNamespaces()
+ {
+ return requiredNamespaces;
+ }
+
+ public String getPreferredNamespacePrefix(String namespace)
+ {
+ if (namespace.equals("http://schemas.xmlsoap.org/wsdl/soap/")) {
+ return "soap";
+ }
+
+ return "";
+ }
+
+ public void setStyle(int style) {
+ styleOption = style;
+ }
+
+ public void setUse(int use) {
+ useOption = use;
+ }
+
+ public void setAddressLocation(String addressLocation) {
+ this.addressLocation = addressLocation;
+ }
+
+ public void generatePortContent(Port port)
+ {
+ // We blow away any existing ExtensibilityElements/content before we generate it
+ // Is it worth being smarter? Look for matching content first and create those which aren't found????
+ List removeList = new ArrayList(port.getEExtensibilityElements());
+ removeExtensebilityElements(port.getEExtensibilityElements(), removeList);
+
+ SOAPAddress soapAddress= SOAPFactory.eINSTANCE.createSOAPAddress();
+ soapAddress.setLocationURI(addressLocation);
+ port.addExtensibilityElement(soapAddress);
+ }
+
+ public void generateBindingContent(Binding binding, PortType portType)
+ {
+ // We blow away any existing ExtensibilityElements/content before we generate it
+ // Is it worth being smarter? Look for matching content first and create those which aren't found????
+ List removeList = new ArrayList(binding.getEExtensibilityElements());
+ removeExtensebilityElements(binding.getEExtensibilityElements(), removeList);
+
+ SOAPFactory soapFactory = SOAPFactory.eINSTANCE;
+ SOAPBinding soapBinding = soapFactory.createSOAPBinding();
+ soapBinding.setStyle((getStyleOption(binding) == STYLE_DOCUMENT) ? "document" : "rpc");
+ soapBinding.setTransportURI("http://schemas.xmlsoap.org/soap/http");
+
+ binding.addExtensibilityElement(soapBinding);
+ }
+
+ public void generateBindingOperationContent(BindingOperation bindingOperation, Operation operation)
+ {
+ // We blow away any existing ExtensibilityElements/content before we generate it
+ // Is it worth being smarter? Look for matching content first and create those which aren't found????
+ List removeList = new ArrayList(bindingOperation.getEExtensibilityElements());
+ Element bindingOperationElement = bindingOperation.getElement();
+ removeExtensebilityElements(bindingOperation.getEExtensibilityElements(), removeList);
+
+ SOAPOperation soapOperation = SOAPFactory.eINSTANCE.createSOAPOperation();
+
+
+ String soapActionValue = getNamespace(bindingOperation);
+ if (!soapActionValue.endsWith("/"))
+ {
+ soapActionValue += "/";
+ }
+ soapActionValue += operation.getName();
+
+ soapOperation.setSoapActionURI(soapActionValue);
+
+ bindingOperation.addExtensibilityElement(soapOperation);
+ }
+
+ public void generateBindingInputContent(BindingInput bindingInput, Input input)
+ {
+ // We blow away any existing ExtensibilityElements/content before we generate it
+ // Is it worth being smarter? Look for matching content first and create those which aren't found????
+ List removeList = new ArrayList(bindingInput.getEExtensibilityElements());
+ Element bindingInputElement = bindingInput.getElement();
+ removeExtensebilityElements(bindingInput.getEExtensibilityElements(), removeList);
+
+ SOAPFactory soapFactory = SOAPFactory.eINSTANCE;
+ SOAPBody soapBody = soapFactory.createSOAPBody();
+ soapBody.setUse((getUseOption(null) == USE_ENCODED) ? "encoded" : "literal");
+ if (getUseOption(bindingInput) == USE_ENCODED && getStyleOption(bindingInput) == STYLE_RPC)
+ {
+ List encodingList = new BasicEList();
+ encodingList.add("http://schemas.xmlsoap.org/soap/encoding/");
+ soapBody.setEncodingStyles(encodingList);
+ soapBody.setNamespaceURI(getNamespace(bindingInput));
+ }
+ else if (getUseOption(bindingInput) == USE_LITERAL && getStyleOption(bindingInput) == STYLE_RPC) {
+ soapBody.setNamespaceURI(getNamespace(bindingInput));
+ }
+
+ bindingInput.addExtensibilityElement(soapBody);
+ }
+
+ public void generateBindingOutputContent(BindingOutput bindingOutput, Output output)
+ {
+ // We blow away any existing ExtensibilityElements/content before we generate it
+ // Is it worth being smarter? Look for matching content first and create those which aren't found????
+ List removeList = new ArrayList(bindingOutput.getEExtensibilityElements());
+ Element bindingOutputElement = bindingOutput.getElement();
+ removeExtensebilityElements(bindingOutput.getEExtensibilityElements(), removeList);
+
+ SOAPFactory soapFactory = SOAPFactory.eINSTANCE;
+ SOAPBody soapBody = soapFactory.createSOAPBody();
+ soapBody.setUse((getUseOption(bindingOutput) == USE_ENCODED) ? "encoded" : "literal");
+ if (getUseOption(bindingOutput) == USE_ENCODED && getStyleOption(bindingOutput) == STYLE_RPC)
+ {
+ List encodingList = new BasicEList();
+ encodingList.add("http://schemas.xmlsoap.org/soap/encoding/");
+ soapBody.setEncodingStyles(encodingList);
+ soapBody.setNamespaceURI(getNamespace(bindingOutput));
+ }
+ else if (getUseOption(bindingOutput) == USE_LITERAL && getStyleOption(bindingOutput) == STYLE_RPC) {
+ soapBody.setNamespaceURI(getNamespace(bindingOutput));
+ }
+
+ bindingOutput.addExtensibilityElement(soapBody);
+ }
+
+ public void generateBindingFaultContent(BindingFault bindingFault, Fault fault)
+ {
+ // We blow away any existing ExtensibilityElements/content before we generate it
+ // Is it worth being smarter? Look for matching content first and create those which aren't found????
+ List removeList = new ArrayList(bindingFault.getEExtensibilityElements());
+ Element bindingFaultElement = bindingFault.getElement();
+ removeExtensebilityElements(bindingFault.getEExtensibilityElements(), removeList);
+
+ SOAPFactory soapFactory = SOAPFactory.eINSTANCE;
+ SOAPFault soapFault = soapFactory.createSOAPFault();
+ soapFault.setUse((getUseOption(bindingFault) == USE_ENCODED) ? "encoded" : "literal");
+ soapFault.setName(fault.getName());
+ soapFault.setNamespaceURI(getNamespace(bindingFault));
+
+ if (getUseOption(bindingFault) == USE_ENCODED && getStyleOption(bindingFault) == STYLE_RPC)
+ {
+ List encodingList = new BasicEList();
+ encodingList.add("http://schemas.xmlsoap.org/soap/encoding/");
+ soapFault.setEncodingStyles(encodingList);
+ }
+
+ bindingFault.addExtensibilityElement(soapFault);
+ }
+
+ private String getNamespace(WSDLElement wsdlElement) {
+ if (namespaceValue.equals("") && wsdlElement != null) {
+ namespaceValue = wsdlElement.getEnclosingDefinition().getTargetNamespace();
+ }
+
+ return namespaceValue;
+ }
+
+ private void removeExtensebilityElements(List originalList, List removeList) {
+ Iterator removeIt = removeList.iterator();
+ while (removeIt.hasNext()) {
+ originalList.remove(removeIt.next());
+ }
+ }
+
+ private Binding getBindingObject(Object genericBindingObject) {
+ Object parent = genericBindingObject;
+
+ int index = 0;
+ while (parent != null && index < 5) {
+ parent = getGenericBindingObjectParent(parent);
+ if (parent instanceof Binding) {
+ break;
+ }
+ index++;
+ }
+
+ return (parent instanceof Binding)? (Binding) parent : null;
+ }
+
+ private Object getGenericBindingObjectParent(Object genericBindingObject) {
+ Object parent = null;
+
+ if (genericBindingObject != null) {
+ if (genericBindingObject instanceof BindingOperation) {
+ parent = ((BindingOperation) genericBindingObject).getContainer();
+ }
+ else if (genericBindingObject instanceof BindingInput) {
+ parent = ((BindingInput) genericBindingObject).getContainer();
+ }
+ else if (genericBindingObject instanceof BindingOutput) {
+ parent = ((BindingOutput) genericBindingObject).getContainer();
+ }
+ else if (genericBindingObject instanceof BindingFault) {
+ parent = ((BindingFault) genericBindingObject).getContainer();
+ }
+ }
+
+ return parent;
+ }
+
+ private int getStyleOption(Object genericBindingObject) {
+ if (styleOption == OPTION_NOT_SET && genericBindingObject != null) {
+ // init() was never called, try to determine the 'style' based on what we have/know
+ Binding binding = getBindingObject(genericBindingObject);
+
+ // Try to determine the style from the Binding Object
+ if (binding != null) {
+ List list = binding.getEExtensibilityElements();
+ Iterator valuesIt = getExtensibilityElementAttributeValue(list, "style").iterator();
+
+ while (valuesIt.hasNext()) {
+ String style = (String) valuesIt.next();
+
+ if (style.equals("document")) {
+ styleOption = STYLE_DOCUMENT;
+ }
+ else if (style.equals("rpc")) {
+ styleOption = STYLE_RPC;
+ }
+
+ if (styleOption != OPTION_NOT_SET) {
+ break;
+ }
+ }
+ }
+ }
+
+ if (styleOption == OPTION_NOT_SET) {
+ styleOption = STYLE_DOCUMENT;
+ }
+
+ return styleOption;
+ }
+
+ private int getUseOption(Object genericBindingObject) {
+ if (useOption == OPTION_NOT_SET) {
+ // init() was never called, try to determine the 'use' based on what we have/know
+ Iterator messageRefIt = getMessageReferenceBindingObjects(genericBindingObject).iterator();
+
+ // Try to determine the use from the list of BindingInputs, BindingOutputs, and BindingFaults
+ while (messageRefIt.hasNext()) {
+ Object messageRef = messageRefIt.next();
+ List values = new ArrayList();
+
+ if (messageRef instanceof BindingInput) {
+ List list = ((BindingInput) messageRef).getEExtensibilityElements();
+ values = getExtensibilityElementAttributeValue(list, "use");
+ }
+ else if (messageRef instanceof BindingOutput) {
+ List list = ((BindingOutput) messageRef).getEExtensibilityElements();
+ values = getExtensibilityElementAttributeValue(list, "use");
+ }
+ else if (messageRef instanceof BindingFault) {
+ List list = ((BindingFault) messageRef).getEExtensibilityElements();
+ values = getExtensibilityElementAttributeValue(list, "use");
+ }
+
+ Iterator valuesIt = values.iterator();
+ while (valuesIt.hasNext()) {
+ String use = (String) valuesIt.next();
+
+ if (use.equals("literal")) {
+ useOption = USE_LITERAL;
+ }
+ else if (use.equals("encoded")) {
+ useOption = USE_ENCODED;
+ }
+ }
+
+ if (useOption != OPTION_NOT_SET) {
+ break;
+ }
+ }
+ }
+
+ if (useOption == OPTION_NOT_SET) {
+ useOption = USE_LITERAL;
+ }
+
+ return useOption;
+ }
+
+ private List getMessageReferenceBindingObjects(Object genericBindingObject) {
+ List list = new ArrayList();
+ Binding binding = getBindingObject(genericBindingObject);
+
+ if (binding != null) {
+ Iterator operationsIt = binding.getEBindingOperations().iterator();
+
+ while (operationsIt.hasNext()) {
+ BindingOperation op = (BindingOperation) operationsIt.next();
+ list.add(op.getEBindingInput());
+ list.add(op.getEBindingOutput());
+ list.addAll(op.getEBindingFaults());
+ }
+ }
+
+ return list;
+ }
+
+ private List getExtensibilityElementAttributeValue(List eeList, String attributeKey) {
+ List values = new ArrayList();
+ Iterator eeElementsIt = eeList.iterator();
+
+ while (eeElementsIt.hasNext()) {
+ ExtensibilityElement eeElement = (ExtensibilityElement) eeElementsIt.next();
+ String attributeValue = eeElement.getElement().getAttribute(attributeKey);
+ if (attributeValue != null && !attributeValue.equals("")) {
+ values.add(attributeValue);
+ }
+ }
+
+ return values;
+ }
+
+ public String getProtocol() {
+ return "SOAP";
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/BaseGenerator.java b/bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/BaseGenerator.java
new file mode 100644
index 000000000..3b477ec2f
--- /dev/null
+++ b/bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/BaseGenerator.java
@@ -0,0 +1,56 @@
+package org.eclipse.wst.wsdl.internal.generator;
+
+import org.eclipse.wst.wsdl.Definition;
+
+public abstract class BaseGenerator {
+ private String name;
+ private String refName;
+ private boolean overwrite;
+ protected Definition definition;
+ protected ContentGenerator contentGenerator;
+
+
+ public void setContentGenerator(ContentGenerator generator) {
+ contentGenerator = generator;
+ }
+
+ public ContentGenerator getContentGenerator() {
+ return contentGenerator;
+ }
+
+ public void setOverwrite(boolean overwrite) {
+ this.overwrite = overwrite;
+ }
+
+ public boolean getOverwrite() {
+ return overwrite;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setRefName(String refName) {
+ this.refName = refName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getRefName() {
+ return refName;
+ }
+
+ public Definition getDefinition() {
+ return definition;
+ }
+
+ public String getProtocol() {
+ if (contentGenerator != null) {
+ return contentGenerator.getProtocol();
+ }
+
+ return null;
+ }
+}
diff --git a/bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/BindingGenerator.java b/bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/BindingGenerator.java
new file mode 100644
index 000000000..a4fd79513
--- /dev/null
+++ b/bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/BindingGenerator.java
@@ -0,0 +1,529 @@
+package org.eclipse.wst.wsdl.internal.generator;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.eclipse.wst.wsdl.Binding;
+import org.eclipse.wst.wsdl.BindingFault;
+import org.eclipse.wst.wsdl.BindingInput;
+import org.eclipse.wst.wsdl.BindingOperation;
+import org.eclipse.wst.wsdl.BindingOutput;
+import org.eclipse.wst.wsdl.Definition;
+import org.eclipse.wst.wsdl.ExtensibilityElement;
+import org.eclipse.wst.wsdl.ExtensibleElement;
+import org.eclipse.wst.wsdl.Fault;
+import org.eclipse.wst.wsdl.Input;
+import org.eclipse.wst.wsdl.Operation;
+import org.eclipse.wst.wsdl.Output;
+import org.eclipse.wst.wsdl.Port;
+import org.eclipse.wst.wsdl.PortType;
+import org.eclipse.wst.wsdl.Service;
+import org.eclipse.wst.wsdl.WSDLFactory;
+import org.eclipse.wst.wsdl.internal.impl.WSDLFactoryImpl;
+
+import org.eclipse.wst.wsdl.internal.generator.extension.ContentGeneratorExtensionFactoryRegistry;
+
+/*
+ * Class used to generate the Binding and it's content. We look in the registry for
+ * appropriate ContentGenerator classes based on the existing Binding Content's namespace.
+ * Alternatively, users can pass in a namespace through the constructor to specify which
+ * namespace to use when searching the registry.
+ *
+ * The ContentGenerator may also be set manually by calling
+ * setContentGenerator(ContentGenerator).
+ */
+public class BindingGenerator extends BaseGenerator {
+ private WSDLFactory factory = WSDLFactory.eINSTANCE;
+ private Binding binding;
+
+ /*
+ * When the constructor is used, automatically attempt to retrieve a proper
+ * ContentGenerator based on the Binding given. The ContentGenerator may
+ * be replaced by calling setContentGenerator(ContentGenerator).
+ */
+ public BindingGenerator(Definition definition, Binding binding) {
+ this.definition = definition;
+ this.binding = binding;
+ contentGenerator = getContentGenerator(binding);
+ }
+
+ /*
+ * When the constructor is used, automatically attempt to retrieve a proper
+ * ContentGenerator based on the namespace given. The ContentGenerator may
+ * be replaced by calling setContentGenerator(ContentGenerator).
+ */
+ public BindingGenerator(Definition definition, Binding binding, String namespace) {
+ this.definition = definition;
+ this.binding = binding;
+ contentGenerator = getContentGenerator(namespace);
+ }
+
+ public static ContentGenerator getContentGenerator(Binding binding) {
+ if (binding == null) {
+ return null;
+ }
+ /******************************************************
+ * Find the regeistered Content Generator for the Binding
+ ******************************************************/
+ // Get BindingContent namespace
+ String namespace = null;
+ List eeList = binding.getEExtensibilityElements();
+ if (eeList.size() > 0) {
+ ExtensibilityElement ee = (ExtensibilityElement) eeList.get(0);
+ // TODO: QName qName = ee.getElementType(); go get the namespace instead?
+ namespace = ee.getElement().getNamespaceURI();
+ return getContentGenerator(namespace);
+ }
+
+ return null;
+ }
+
+ public static ContentGenerator getContentGenerator(String namespace) {
+ ContentGenerator contentGen = null;
+ if (namespace != null) {
+ ContentGeneratorExtensionFactoryRegistry factoryRegistry = ContentGeneratorExtensionFactoryRegistry.getInstance();
+ contentGen = factoryRegistry.getGeneratorClassFromNamespace(namespace);
+ }
+
+ return contentGen;
+ }
+
+ private Binding createEmptyBinding(String localName) {
+ String name = localName;
+ if (localName == null) {
+ name = "";
+ }
+ Binding newBinding = WSDLFactory.eINSTANCE.createBinding();
+ newBinding.setQName(new QName(definition.getTargetNamespace(),localName));
+ newBinding.setEnclosingDefinition(definition);
+ definition.addBinding(newBinding);
+
+ return newBinding;
+ }
+
+ public Binding generateBinding() {
+ try {
+ // If Binding is null (No Binding was passed into the constructor), we create an empty Binding first.
+ if (binding == null) {
+ binding = createEmptyBinding(getName());
+ }
+ if (getName() != null) {
+ binding.setQName(new QName(binding.getQName().getNamespaceURI(), getName()));
+ }
+ if (getRefName() != null) {
+ PortType portType = getPortType();
+ binding.setEPortType(portType);
+ if (portType == null) {
+ //The model doesn't reconile with it's Element properly when we're setting a null for it's PortType
+ binding.getElement().setAttribute("type", "");
+ }
+ }
+
+ List bindingOperations = binding.getEBindingOperations();
+ PortType portType = binding.getEPortType();
+ if (portType == null) {
+ // We need to blow away everything under the Binding. No PortType associated with this Binding
+ bindingOperations.clear();
+ return binding;
+ }
+
+ addRequiredNamespaces(binding);
+
+ List operations = portType.getOperations();
+
+ /******************************************************
+ * Compare the Operations
+ ******************************************************/
+ // Remove any BindingOperations which are no longer used
+ for (int index = 0; index < bindingOperations.size(); index++) {
+ BindingOperation bindingOperation = (BindingOperation) bindingOperations.get(index);
+
+ boolean foundMatch = false;
+ Iterator operationsIt = operations.iterator();
+ while (operationsIt.hasNext()) {
+ Operation operation = (Operation) operationsIt.next();
+
+ if (namesEqual(bindingOperation.getName(), operation.getName())) {
+ foundMatch = true;
+ break;
+ }
+ }
+
+ if (!foundMatch){
+ // We need to remove this BindingFault from the bindingFaults List
+ bindingOperations.remove(index);
+ index--;
+ }
+ }
+
+ // Remove any Operations which already exists in bindingOperations. What we
+ // have left are the Operations which needs newly created BindingOperations
+ List bindingOperationsNeeded = new ArrayList();
+ for (int index = 0; index < operations.size(); index++) {
+ Operation operation = (Operation) operations.get(index);
+
+ boolean foundMatch = false;
+ Iterator bindingOperationsIt = bindingOperations.iterator();
+ while (bindingOperationsIt.hasNext()) {
+ BindingOperation bindingOperation = (BindingOperation) bindingOperationsIt.next();
+
+ if (namesEqual(bindingOperation.getName(), operation.getName())) {
+ foundMatch = true;
+ break;
+ }
+ }
+
+ if (!foundMatch){
+ // We need to remove this BindingFault from the bindingFaults List
+ bindingOperationsNeeded.add(operation); // Store the actual Operation
+ }
+ }
+
+ // bindingFaultsNeeded contains the needed BindingFault's we need to create
+ Iterator neededBindingOperationsIt = bindingOperationsNeeded.iterator();
+ while (neededBindingOperationsIt.hasNext()) {
+ Operation operation = (Operation) neededBindingOperationsIt.next();
+ BindingOperation newBindingOperation = factory.createBindingOperation();
+ newBindingOperation.setEOperation(operation);
+ newBindingOperation.setName(operation.getName());
+ binding.addBindingOperation(newBindingOperation);
+ }
+
+ /******************************************************
+ * Process the contents of the Operations
+ ******************************************************/
+ Iterator bindingOperationsIt = binding.getEBindingOperations().iterator();
+ while (bindingOperationsIt.hasNext()) {
+ generateBindingOperation((BindingOperation) bindingOperationsIt.next());
+ }
+
+ generateBindingContent(binding);
+
+ return binding;
+ }
+ catch (Exception e) {
+
+ }
+ return null;
+ }
+
+ private void generateBindingOperation(BindingOperation bindingOperation) {
+ BindingInput bindingInput = bindingOperation.getEBindingInput();
+ BindingOutput bindingOutput = bindingOperation.getEBindingOutput();
+ List bindingFaults = bindingOperation.getEBindingFaults();
+
+ Operation operation = bindingOperation.getEOperation();
+ Input input = operation.getEInput();
+ Output output = operation.getEOutput();
+ List faults = operation.getEFaults();
+
+ /******************************************************
+ * Compare the Operation names
+ ******************************************************/
+ if (!namesEqual(bindingOperation.getName(), operation.getName())) {
+ bindingOperation.setName(operation.getName());
+ }
+
+
+ /******************************************************
+ * Compare the Output
+ ******************************************************/
+ if (output == null) {
+ bindingOperation.setBindingOutput(null);
+ }
+ else {
+ // Create BindingOutput if necessary
+ if (bindingOutput == null) {
+ BindingOutput newBindingOutput = factory.createBindingOutput();
+ newBindingOutput.setEOutput(output);
+ newBindingOutput.setName(output.getName());
+ bindingOperation.setBindingOutput(newBindingOutput);
+ }
+ else {
+ // Compare the Output names
+ if (!namesEqual(bindingOutput.getName(), output.getName())) {
+ bindingOutput.setName(output.getName());
+ }
+ }
+ }
+ generateBindingOutputContent(bindingOperation.getEBindingOutput());
+
+
+ /******************************************************
+ * Compare the Input
+ ******************************************************/
+ if (input == null) {
+ bindingOperation.setBindingInput(null);
+ }
+ else {
+ // Create BindingInput if necessary
+ if (bindingInput == null) {
+ BindingInput newBindingInput = factory.createBindingInput();
+ newBindingInput.setEInput(input);
+ newBindingInput.setName(input.getName());
+ bindingOperation.setBindingInput(newBindingInput);
+ }
+ else {
+ // Compare the Input names
+ if (!namesEqual(bindingInput.getName(), input.getName())) {
+ bindingInput.setName(input.getName());
+ }
+ }
+ }
+ generateBindingInputContent(bindingOperation.getEBindingInput());
+
+
+ /******************************************************
+ * Compare the Faults
+ ******************************************************/
+ // Remove any BindingFaults which are no longer used
+ for (int index = 0; index < bindingFaults.size(); index++) {
+ BindingFault bindingFault = (BindingFault) bindingFaults.get(index);
+
+ boolean foundMatch = false;
+ Iterator faultsIt = faults.iterator();
+ while (faultsIt.hasNext()) {
+ Fault fault = (Fault) faultsIt.next();
+ if (namesEqual(bindingFault.getName(), fault.getName())) {
+ foundMatch = true;
+ break;
+ }
+ }
+
+ if (!foundMatch){
+ // We need to remove this BindingFault from the bindingFaults List
+ bindingFaults.remove(index);
+ index--;
+ }
+ }
+
+ // Remove any Faults which already exists in bindingFaults. What we
+ // have left are the Faults which needs newly created BindingFaults
+ List bindingFaultsNeeded = new ArrayList();
+ for (int index = 0; index < faults.size(); index++) {
+ Fault fault = (Fault) faults.get(index);
+
+ boolean foundMatch = false;
+ Iterator bindingFaultsIt = bindingFaults.iterator();
+ while (bindingFaultsIt.hasNext()) {
+ BindingFault bindingFault = (BindingFault) bindingFaultsIt.next();
+ if (namesEqual(bindingFault.getName(), fault.getName())) {
+ foundMatch = true;
+ break;
+ }
+ }
+
+ if (!foundMatch){
+ // We need to remove this BindingFault from the bindingFaults List
+ bindingFaultsNeeded.add(fault);
+ }
+ }
+
+ // bindingFaultsNeeded contains the needed BindingFault's we need to create
+ Iterator neededBindingFaultsIt = bindingFaultsNeeded.iterator();
+ while (neededBindingFaultsIt.hasNext()) {
+ Fault fault = (Fault) neededBindingFaultsIt.next();
+ BindingFault newBindingFault = factory.createBindingFault();
+ newBindingFault.setEFault(fault);
+ newBindingFault.setName(fault.getName());
+ bindingOperation.addBindingFault(newBindingFault);
+ }
+
+ // Create the contents for each BindingFault
+ Iterator faultContentIt = bindingOperation.getEBindingFaults().iterator();
+ while (faultContentIt.hasNext()) {
+ BindingFault bindingFault = (BindingFault) faultContentIt.next();
+ generateBindingFaultContent(bindingFault);
+ }
+
+ generateBindingOperationContent(bindingOperation);
+ }
+
+ private boolean namesEqual(String name1, String name2) {
+ boolean match = false;
+
+ if (name1 != null ^ name2 != null) {
+ // one is null
+ match = false;
+ }
+ else if (name1 != null && name2 != null) {
+ // neither is null
+ match = name1.equals(name2);
+ }
+ else {
+ // both are null
+ match = true;
+ }
+
+ return match;
+ }
+
+ protected void generateBindingContent(Binding binding) {
+ if (contentGenerator != null) {
+ contentGenerator.generateBindingContent(binding, (PortType) binding.getEPortType());
+ }
+ else {
+ removeExtensibilityElements(binding);
+ }
+ }
+
+ protected void generateBindingOperationContent(BindingOperation bindingOperation) {
+ if (bindingOperation != null && contentGenerator != null) {
+ contentGenerator.generateBindingOperationContent(bindingOperation, bindingOperation.getEOperation());
+ }
+ else {
+ removeExtensibilityElements(bindingOperation);
+ }
+ }
+
+ protected void generateBindingInputContent(BindingInput bindingInput) {
+ if (bindingInput != null && contentGenerator != null) {
+ contentGenerator.generateBindingInputContent(bindingInput, bindingInput.getEInput());
+ }
+ else {
+ removeExtensibilityElements(bindingInput);
+ }
+ }
+
+ protected void generateBindingOutputContent(BindingOutput bindingOutput) {
+ if (bindingOutput != null && contentGenerator != null) {
+ contentGenerator.generateBindingOutputContent(bindingOutput, bindingOutput.getEOutput());
+ }
+ else {
+ removeExtensibilityElements(bindingOutput);
+ }
+ }
+
+ protected void generateBindingFaultContent(BindingFault bindingFault) {
+ if (bindingFault != null && contentGenerator != null) {
+ contentGenerator.generateBindingFaultContent(bindingFault, bindingFault.getEFault());
+ }
+ else {
+ removeExtensibilityElements(bindingFault);
+ }
+ }
+
+ private void removeExtensibilityElements(ExtensibleElement ee) {
+ ee.getEExtensibilityElements().clear();
+ }
+
+ /*
+ * Generate Port Content for all Ports with a reference to the Binding
+ * which was passed in through the constructor (or a reference to the
+ * newly created Binding).
+ */
+ public void generatePortContent() {
+ if (binding != null && contentGenerator != null) {
+ List portsToUpdate = new ArrayList();
+
+ Iterator servicesIt = binding.getEnclosingDefinition().getEServices().iterator();
+ while (servicesIt.hasNext()) {
+ Service service = (Service) servicesIt.next();
+ Iterator portsIt = service.getEPorts().iterator();
+ while (portsIt.hasNext()) {
+ Port port = (Port) portsIt.next();
+ if (binding.equals(port.getEBinding())) {
+ // Found a match
+ portsToUpdate.add(port);
+ }
+ }
+ }
+
+ Iterator portsToUpdateIt = portsToUpdate.iterator();
+ while (portsToUpdateIt.hasNext()) {
+ contentGenerator.generatePortContent((Port) portsToUpdateIt.next());
+ }
+ }
+ }
+
+ /*
+ * methods addRequiredNamespaces() and computeUniquePrefix() are used to add necessary
+ * namespaces
+ *
+ * TODO:
+ * Does this belong here? This is copied from wsdl.ui. Can we sync up in some way?
+ */
+ protected void addRequiredNamespaces(Binding binding) {
+ if (contentGenerator != null) {
+ String[] namespaceNames = contentGenerator.getRequiredNamespaces();
+ String[] preferredPrefixes = new String[namespaceNames.length];
+ for (int index = 0; index < namespaceNames.length; index++) {
+ preferredPrefixes[index] = contentGenerator.getPreferredNamespacePrefix(namespaceNames[index]);
+ }
+
+ Map map = binding.getEnclosingDefinition().getNamespaces();
+
+ for (int i = 0; i < namespaceNames.length; i++) {
+ String namespace = namespaceNames[i];
+ if (!map.containsValue(namespace)) {
+ String prefix = (i < preferredPrefixes.length) ? preferredPrefixes[i] : "p0";
+ if (map.containsKey(prefix)) {
+ prefix = computeUniquePrefix("p", map);
+ }
+ binding.getEnclosingDefinition().addNamespace(prefix, namespace);
+ }
+ }
+ }
+ }
+
+ private String computeUniquePrefix(String base, Map table){
+ int i = 0;
+ String prefix = base;
+ while (true) {
+ if (!table.containsKey(prefix)) {
+ break;
+ }
+ else {
+ prefix = base + i;
+ i++;
+ }
+ }
+ return prefix;
+ }
+
+ private PortType getPortType() {
+ if (getRefName().equals("")) {
+ // Means we should set the PortType to Unspecified
+ return null;
+ }
+
+ if (getRefName() != null) {
+ Iterator portTypeIt = definition.getEPortTypes().iterator();
+
+ while (portTypeIt.hasNext()) {
+ PortType pt = (PortType) portTypeIt.next();
+ List prefixedNames = getPrefixedNames(pt);
+ if (prefixedNames.contains(getRefName())) {
+ return pt;
+ }
+ }
+ }
+
+ return binding.getEPortType();
+ }
+
+ private List getPrefixedNames(PortType portType) {
+ List prefixedNames = new ArrayList();
+ String currentPortTypeName = portType.getQName().getLocalPart();
+ String currentNamespace = portType.getQName().getNamespaceURI();
+
+ Map namespaceMap = definition.getNamespaces();
+ Iterator keys = namespaceMap.keySet().iterator();
+ while (keys.hasNext()) {
+ Object key = keys.next();
+ Object value = namespaceMap.get(key);
+
+ if (currentNamespace.equals(value)) {
+ // Found a match. Add to our list
+ prefixedNames.add(key + ":" + currentPortTypeName);
+ }
+ }
+
+ return prefixedNames;
+
+ }
+}
diff --git a/bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/ContentGenerator.java b/bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/ContentGenerator.java
new file mode 100644
index 000000000..62ede6730
--- /dev/null
+++ b/bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/ContentGenerator.java
@@ -0,0 +1,32 @@
+package org.eclipse.wst.wsdl.internal.generator;
+
+import org.eclipse.wst.wsdl.Binding;
+import org.eclipse.wst.wsdl.BindingFault;
+import org.eclipse.wst.wsdl.BindingInput;
+import org.eclipse.wst.wsdl.BindingOperation;
+import org.eclipse.wst.wsdl.BindingOutput;
+import org.eclipse.wst.wsdl.Fault;
+import org.eclipse.wst.wsdl.Input;
+import org.eclipse.wst.wsdl.Operation;
+import org.eclipse.wst.wsdl.Output;
+import org.eclipse.wst.wsdl.Port;
+import org.eclipse.wst.wsdl.PortType;
+
+public interface ContentGenerator
+{
+ public static String ADDRESS_LOCATION = "http://www.example.org/";
+
+ public String[] getRequiredNamespaces();
+ public String getPreferredNamespacePrefix(String namespace);
+
+ // generates the 'address' extensiblity element for a port
+ public void generatePortContent(Port port);
+
+ public void generateBindingContent(Binding binding, PortType portType);
+ public void generateBindingOperationContent(BindingOperation bindingOperation, Operation operation);
+ public void generateBindingInputContent(BindingInput bindingInput, Input input);
+ public void generateBindingOutputContent(BindingOutput bindingOutput, Output output);
+ public void generateBindingFaultContent(BindingFault bindingFault, Fault fault);
+
+ public String getProtocol();
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/PortGenerator.java b/bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/PortGenerator.java
new file mode 100644
index 000000000..40f62d618
--- /dev/null
+++ b/bundles/org.eclipse.wst.wsdl/src-wsdl/org/eclipse/wst/wsdl/internal/generator/PortGenerator.java
@@ -0,0 +1,78 @@
+package org.eclipse.wst.wsdl.internal.generator;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.wst.wsdl.Binding;
+import org.eclipse.wst.wsdl.Port;
+import org.eclipse.wst.wsdl.Service;
+import org.eclipse.wst.wsdl.WSDLFactory;
+
+public class PortGenerator extends BaseGenerator {
+ private Service service;
+
+ public PortGenerator(Service service) {
+ this.service = service;
+ definition = service.getEnclosingDefinition();
+ }
+
+ public Port generatePort() {
+ String name = getName();
+ String bindingName = getRefName();
+
+ Port port = WSDLFactory.eINSTANCE.createPort();
+ port.setName(getName());
+ port.setEnclosingDefinition(service.getEnclosingDefinition());
+ port.setBinding(getBinding(getRefName()));
+ service.addPort(port);
+
+ if (this.getContentGenerator() != null) {
+ this.getContentGenerator().generatePortContent(port);
+ }
+
+ return port;
+ }
+
+ private Binding getBinding(String bindingName) {
+ Iterator bindingIt = definition.getEBindings().iterator();
+ while (bindingIt.hasNext()) {
+ Binding binding = (Binding) bindingIt.next();
+ String currentBindingName = binding.getQName().getLocalPart();
+ String currentNamespace = binding.getQName().getNamespaceURI();
+
+ List prefixedNames = getPrefixedNames(binding);
+
+ if (prefixedNames.contains(bindingName)) {
+ return binding;
+ }
+ }
+
+ return null;
+ }
+
+ private List getPrefixedNames(Binding binding) {
+ List prefixedNames = new ArrayList();
+ String currentBindingName = binding.getQName().getLocalPart();
+ String currentNamespace = binding.getQName().getNamespaceURI();
+
+ Map namespaceMap = definition.getNamespaces();
+ Iterator keys = namespaceMap.keySet().iterator();
+ while (keys.hasNext()) {
+ Object key = keys.next();
+ Object value = namespaceMap.get(key);
+
+ if (currentNamespace.equals(value)) {
+ // Found a match. Add to our list
+ prefixedNames.add(key + ":" + currentBindingName);
+ }
+ }
+
+ return prefixedNames;
+ }
+
+ public Service getService() {
+ return service;
+ }
+}

Back to the top