Workflow Components

Workflow Components

The XSD Adapter provides the following workflow components:

The XSDMetaModel loads the specified XSD, transforms them to Ecore models and makes them available for the other MWE components. If XSDs include/import other XSDs or if XML files reference XSDs via schemaLocation, theses XSDs are also loaded (details: the section called “How to declare XML Schemas” ). The most common scenario is to declare the XSDMetaModel within an XMLReader:

<component class="org.eclipse.xtend.typesystem.xsd.XMLReader">
  <modelSlot value="model" />
  <uri value="model.xml" />
  <metaModel id="mm" class="org.eclipse.xtend.typesystem.xsd.XSDMetaModel">
    <schemaFile value="metamodel.xsd" />
    <registerPackagesGlobally value="true" />
  </metaModel>
</component>

Another option is to specify an XSDMetaModel independently of other components as a bean:

<bean id="
mymetamodel
" class="org.eclipse.xtend.typesystem.xsd.XSDMetaModel">
  <schemaFile value="metamodel.xsd" />
</bean>
<component class="org.eclipse.xtend.typesystem.xsd.XMLReader">
  <modelSlot value="model" />
  <uri value="model.xml" />
  <metaModel 
idRef="mymetamodel"
 />
</component>

Attention: It can lead to errors when XSDs are loaded multiple times, which can only happen when using multiple XSDMetaModels within one workflow. The safe way to go is to declare just one XSDMetaModel per workflow and reference it from all components that need it.

Properties:

  • schemaFile: optional, allowed multiple times: Specifies an XSD file which is being loaded. The path can be a complete URI, or relative to the project root or classpath.

  • registerPackagesGlobally: optional, default "false": If true, generated EPackages are registered to org.eclipse.emf.ecore.EPackage.Registry.INSTANCE, EMF's global package registry. Warning: when running workflows from your own java code, make sure to remove the generated packages from the registry before the next run!

The XMLReader reads one XML file which is valid according to the XSDs loaded by the XSDMetaModel. The XML file is loaded as a model and stored in the specified slot. Example:

<component class="org.eclipse.xtend.typesystem.xsd.XMLReader">
  <modelSlot value="model" />
  <uri value="model.xml" />
  <metaModel idRef="mymetamodel" />
</component>

Properties:

The XMLWriter writes the model stored in a slot to an XML file. If the slot contains a collection of models, each one is written to a separate file. The model(s) must have been instantiated using an XSD-based meta model. Example:

<component class="org.eclipse.xtend.typesystem.xsd.XMLWriter">
  <metaModel idRef="svgmm" />
  <modelSlot value="svgmodel" />
  <uri value="src-gen/mycurve.svg" />
</component>

Properties:

The XMLBeautifier uses EMF to load the XML file, formats the mixed content (elements and text contained by the same element) and writes the file back to disk applying a nice indentation for the elements. The XMLBeautifier is not intended to be used in combination with the XMLWriter, since the XMLWriter cares about indentation by itself. Instead, use it for "manually" constructed XML files using Xpand. Since the frameworks for loading/storing XML always load the whole file into a complex data structure in memory, this approach does not scale well for huge XML files. Example:

<component class="org.eclipse.xpand2.Generator">
  <metaModel idRef="mm" />
  <expand value="${src-pkg}::${file}::Root FOR '${out}'" />
  <outlet path="${src-gen-dir}" />
  <beautifier class="org.eclipse.xtend.typesystem.xsd.XMLBeautifier">
    <maxLineWidth value="60" />
    <formatComments value="true" />
    <fileExtensions value=".xml, .html" />
  </beautifier>
</component>

Properties: