Featured Post

Applying Email Validation to a JavaFX TextField Using Binding

This example uses the same controller as in a previous post but adds a use case to support email validation.  A Commons Validator object is ...

Saturday, June 2, 2012

Fixing Element Names in EA-Generated WSDL Docs

You can quickly generate WSDL documents from Sparx Systems EA.  There are a few adjustments you will need to make to adapt the generated product into one usable in your organization.  One of these adjustments is to rename the toplevel element in the <types> section.

In Sparx Systems EA, a simple drag-and-drop operation will generate a WSDL.  You can then edit the generated artifacts -- Service, Binding, PortType, etc. -- to adapt them to your organization's naming convention and to add to the bindings and operations.  This blog post describes how to rename the toplevel element in the <types> section which is, by default, the same as the type name. 

Nobody wants an element name "OrderRequestType".

This screenshot shows a WSDL generated by EA.  Some renaming has taken place for the Service, Binding, PortType, Operation, and Messages sections.  The Types section is left with the original values.
WSDL Generated by EA with Some Mods
Drilling into the Types section, there are two types defined, OutputParameters and InputParameters.
Types Diagram with Generated Types
When the WSDL document is generated (Tools > Web Services > Generate WSDL) the result will be two complexType XML elements with a pair of xsd:element elements.  This is the Garden of Eden authoring style which exposes all types and elements globally.

The resulting WSDL section follows.
WSDL Generated by EA
Editing Type Name

To adapt the WSDL to your organization's naming conventions, begin by renaming the complexTypes.  Select one of the objects and hit Alt-Enter to bring up the Properties dialog. Rename the object.

Renamed complexTypes
This results in the following <types> section.  Note the globally-defined elements are named OrderRequestType which isn't an acceptable element name.
OrderResponseType used for complexType (good); for element (bad)
Adding New Toplevel Elements

To have properly named elements, add your own to the types section by dragging-and-dropping.  From the tools, drag an element object.  Use the ... button to link up the element -- named orderRequest -- with the type "OrderRequestType".

A New Toplevel Element
The resulting WSDL now has an element that will adhere to the naming convention.

New Toplevel Elements Available to Remaining WSDL
Garden of Eden Authoring

It's possible to turn off Garden of Eden authoring in EA, but not in the context of generating WSDL.  The setting is only available when generating XSDs, so if you want to continue using the WSDL generation capability without separating the types into their own XSDs, you'll have to live with the extra elements.  (The settings does not "cascade" from the WSDL generation to the <types> section.)

For XSD Generation Only
You can quickly produce a WSDL with EA by simply dragging-and-dropping a WSDL Namespace on a toplevel Class Diagram.  Drilling into the sections and renaming the generated objects will bring the WSDL into compliance with your organization's naming conventions.  If you want to keep the <types> definition in the WSDL, you'll need to add a special toplevel element to avoid element names like "OrderRequestType".
  

No comments:

Post a Comment