[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.webtools] Re: Serializing Documenation elements

Ravikanath, you seem to have run into a limitation of the WSDL EMF model.
I have opened https://bugs.eclipse.org/bugs/show_bug.cgi?id=277056 to track 
this.
In the mean time, try this working example, which shows you how to work 
around the limitation.

public class DocumentationSample extends TestCase
{
  private static final String WSDL_PREFIX = "wsdl"; //$NON-NLS-1$

  public void testSupportsDocumentationElements() throws Exception
  {
    ResourceSetImpl resourceSet = new ResourceSetImpl();
    WSDLResourceImpl wsdlResource = 
(WSDLResourceImpl)resourceSet.createResource(URI.createFileURI("documentationTest.wsdl"));

    WSDLFactory factory = WSDLFactory.eINSTANCE;
    Definition definition = factory.createDefinition();
    wsdlResource.getContents().add(definition);
    definition.setTargetNamespace("http://www.example.org";);
    definition.addNamespace(WSDL_PREFIX, WSDLConstants.WSDL_NAMESPACE_URI);

    definition.updateElement(true);

    Document document = definition.getDocument();

    Element documentationElement = 
document.createElementNS(WSDLConstants.WSDL_NAMESPACE_URI, WSDL_PREFIX + ":"
      + WSDLConstants.DOCUMENTATION_ELEMENT_TAG);

    // Workaround WSDL EMF model limitation.

    Element definitionElement = definition.getElement();

    // Change this line appropriately to ,ake sure you insert
    // the definition element as the first child.
    definitionElement.insertBefore(documentationElement, null);

    // End workaround

    definition.setDocumentationElement(documentationElement);

    Element docChild = document.createElement("DocumentationElement");
    docChild.setAttribute("ProcessInfo", "someValue");
    documentationElement.appendChild(docChild);

    wsdlResource.save(null);
  }
}

The above code creates a WSDL document that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"; 
targetNamespace="http://www.example.org";>
  <wsdl:documentation>
    <DocumentationElement ProcessInfo="someValue"/>
  </wsdl:documentation>
</wsdl:definitions>

"Ravikanth " <ravikanth.somayaji@xxxxxxxxx> wrote in message 
news:c92b98a5d999b68c6119fdf781322c51$1@xxxxxxxxxxxxxxxxxx
> Thanks for the reply Gabriel.
>
> That's the piece I have in my code to add a documentation element to the 
> wsdlelement.
>  public static void createDocElement(Object definitionObj,
>            Object wsdlElementObj, String elementName, String attrib, 
> String val) {
> if (definitionObj instanceof Definition) {
>            Definition definition = (Definition) definitionObj;
>            if (wsdlElementObj instanceof ExtensibleElement) {
>                WSDLElement wsdlElement = (WSDLElement) wsdlElementObj;
>                Attr attr =
> 
> definition.getDocument().createAttribute("ProcessInfo");
>                attr.setValue(elementName + ":::" + val);
>                Element documentationElement =
>                        wsdlElement.getDocumentationElement();
>                if (documentationElement == null) {
>                    documentationElement =
>                            definition.getDocument()
>                                    .createElement("DocumentationElement");
>
>                }
>                documentationElement.setAttributeNode(attr);
>                wsdlElement.setDocumentationElement(documentationElement);
>                try {
>                    definition.eResource().save(null);
>                } catch (IOException e) {
>                    // TODO Auto-generated catch block
>                    e.printStackTrace();
>                }
>                System.out.println("Document##"
>                        + wsdlElement.getDocumentationElement());
>            }
> }
>
> However, the wsdl fragment for which i run the code against still looks 
> like this
> <wsdl:portType name="RTestW">
>    <wsdl:operation name="NewOperation">
>      <wsdl:input message="tns:NewOperationRequest"/>
>      <wsdl:output message="tns:NewOperationResponse"/>
>    </wsdl:operation>
>  </wsdl:portType>
>
> and I would expect <wsdl:portType name="RTestW">
>  <wsdl:documentation>ProcessInfo=elementName:::value</wsdl:documentation>
>    <wsdl:operation name="NewOperation">
> 
> <wsdl:documentation>ProcessInfo=elementName:::value</wsdl:documentation>
>      <wsdl:input message="tns:NewOperationRequest"/>
>      <wsdl:output message="tns:NewOperationResponse"/>
>    </wsdl:operation>
>  </wsdl:portType>
>
>
>
> Gabriel Indik wrote:
>
>> Ravi,
>> To better understand the problem, could you please paste a small code 
>> fragment/snippet that shows the API calls you are making to incorporate 
>> the documentation elements as well as the document serialization?
>