Skip to content

Instantly share code, notes, and snippets.

@lachlan
Created June 26, 2012 23:33
Show Gist options
  • Save lachlan/3000140 to your computer and use it in GitHub Desktop.
Save lachlan/3000140 to your computer and use it in GitHub Desktop.

Revisions

  1. lachlan created this gist Jun 26, 2012.
    70 changes: 70 additions & 0 deletions Pipeline.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    // Every webMethods Integration Server service has exactly one input
    // argument: the pipeline.
    //
    // The pipeline is like a java.util.Map object that gets passed to each
    // service that gets called. (It's actually a com.wm.data.IData object,
    // which unfortunately doesn't implement java.util.Map.)
    //
    // Because objects are passed by reference, every service called can alter
    // the keys and values in the pipeline.
    //
    // This is an example of how the webMethods Integration Server pipeline
    // would work if it was implemented in Java using java.util.Map objects.
    //
    // $ javac Pipeline.java
    // $ java Pipeline

    import java.util.*;

    public class Pipeline {
    public static void greet(Map<String, Object> pipeline) {
    // convert the name input argument to uppercase: this litters the
    // pipeline with "instring" and "outstring" variables
    pipeline.put("instring", pipeline.get("name"));
    upcase(pipeline);
    pipeline.put("name", pipeline.get("outstring"));

    // get honorific for the gender: this litters the pipeline with the
    // variable "honorific"
    honorific(pipeline);

    // add greeting variable to pipeline: this is an output argument for the method
    pipeline.put("greeting", "Hello " + pipeline.get("honorific") + " " + pipeline.get("name"));
    }

    public static void upcase(Map<String, Object> pipeline) {
    String instring = (String)pipeline.get("instring");
    String outstring = instring.toUpperCase();
    pipeline.put("outstring", outstring);
    }

    public static void honorific(Map<String, Object> pipeline) {
    String gender = (String)pipeline.get("gender");
    String honorific = "";

    if (gender.equals("male")) {
    honorific = "Mr";
    } else if (gender.equals("female")) {
    honorific = "Ms";
    }

    pipeline.put("honorific", honorific);
    }

    public static void main(String[] args) {
    // create a new pipeline, and populate it with some variables
    Map<String, Object> pipeline = new HashMap<String, Object>();
    pipeline.put("name", "John Doe");
    pipeline.put("gender", "male");
    pipeline.put("email", "[email protected]");
    pipeline.put("address", "123 Sycamore Street");

    // call greet service, passing the pipeline
    // greet then calls upcase and honorific, both of which
    // litter the pipeline with their arguments
    greet(pipeline);

    System.out.println("greeting = " + pipeline.get("greeting"));
    System.out.println("pipeline = " + pipeline);
    }
    }