# Stdlib workflow components

Besides the extensions described in the previous section Xpand's Stdlib provides some workflow components.

### SystemCommand

This component executes a system command.

Table 2. Workflow component org.eclipse.xtend.util.stdlib.SystemCommand

Property | Type | Mandatory | Description
--- | --- | --- | ---
command | String | yes | The command to execute.
directory | String | no | Execution directory.
arg | String | no | (multiple) command arguments
env | String | no | (multiple) additional environment entries. Format: [key],[value]

Example:

    <component class="org.eclipse.xtend.util.stdlib.SystemCommand">
      <directory value="src-gen"/>
      <command value="sh"/>
      <arg value="processdot.sh"/>
    </component>

Console output:

    1639 INFO  - Running command '[sh, processdot.sh]' in directory [absolutepath] ...
    1667 INFO  - processing shape_box.dot ...
    2597 INFO  - processing shape_polygon.dot ...
    ...
    3564 INFO  - Execution of command was successful.

Windows tip:

When executing a command on windows this is typically done with the cmd as command value. It is important that the command terminates, therefore the argument /c must be appended as arg value.[10]

### SlotCopier

This component copies an element from one slot to another. The slot content is not cloned.

Table 3. Workflow component org.eclipse.xtend.util.stdlib.SlotCopier

Property | Type | Mandatory | Description
--- | --- | --- | ---
fromSlot | String | yes | Source slot name.
toSlot | String | yes | Destination slot name.
removeTopLevelList | boolean | no | If true the source slot must contain a list and the top level list is removed (i.e. the first element from the list is copied to the destination slot), otherwise it is not removed.

Example:

    <component class="org.eclipse.xtend.util.stdlib.SlotCopier">
        <fromSlot value="model"/>
        <toSlot value="target"/>
    </component>

Console output:

    INFO SlotCopier copying org.eclipse.emf.ecore.impl.DynamicEObjectImpl@1fdbef
      (eClass: org.eclipse.emf.ecore.impl.EClassImpl@fc5b01
      (name: Model) (instanceClassName: null) (abstract: false, interface: false))
      [org.eclipse.emf.ecore.impl.DynamicEObjectImpl]

### SlotListAdder

This component copies an element from one slot to a list contained in another slot.

Table 4. Workflow component org.eclipse.xtend.util.stdlib.SlotListAdder

Property | Type | Mandatory | Description
--- | --- | --- | ---
modelSlot | String | yes | Source slot name.
listSlot | String | yes | Target slot name. This slot contains a list of elements.
uniqueNames | boolean | no | If true, names have to be unique, otherwise not. Requires that modelSlot contains an EObject.

Example:

This example adds the content of slot 'model' to the slot 'targetList'. The slot 'targetList' does not contain anything at the time of execution.

    <component class="org.eclipse.xtend.util.stdlib.SlotListAdder">
        <modelSlot value="model"/>
        <listSlot value="targetList"/>
    </component>

Console output:

    INFO CompositeComponent SlotListAdder: adding contents of slot 'model' to the list of
       stuff in 'targetList'
    ...
    ...
    INFO WorkflowRunner workflow completed in 1503ms!
    WARN WorkflowRunner 'targetList' is empty, creating a new list.
       [org.eclipse.xtend.util.stdlib.SlotListAdder@7536e7]

Note that the warn messages will appear after the workflow finished, since they are reported as a workflow warn issue.

### SlotPrinter

This component prints a workflow context slot content to the log. This can be useful for debugging purposes.

Table 5. Workflow component org.eclipse.xtend.util.stdlib.SlotPrinter

Property | Type | Mandatory | Description
--- | --- | --- | ---
slotName | String | yes | The name of a slot whose content should be dumped.
message | String | no | An optional message that will be prefixed to the log output.
level | String | no | The log level for the message. Valid values are TRACE, DEBUG, INFO, WARN.

Example:

    <component class="org.eclipse.xtend.util.stdlib.SlotPrinter">
        <slotName value="model"/>
        <message value="DUMP"/>
        <level value="INFO"/>
    </component>

Console output:

    INFO SlotPrinter DUMP: (slot: model)org.eclipse.emf.ecore.impl.DynamicEObjectImpl@d22ddb
      (eClass: org.eclipse.emf.ecore.impl.EClassImpl@fe0ce9 (name: Model) (instanceClassName: null)
      (abstract: false, interface: false))

[10] See http://www.ss64.com/nt/cmd.html, http://www.java-forum.org/de/viewtopic.php?p=469059