title: Proper pattern or methodology to traverse data and dynamically construct objects?
body: <p>I'm looking for potentially some design pattern advice regarding object traversal to dynamically construct objects based on the data being presented. </p>
  
  <p>Below, I am manually constructing this object. Initially, the root node is a <code>BinaryLogicOpType</code> but <em>could</em> be a different object based on the <code>rootNodeType</code>.</p>
  
  <p>My question is.. I need to dynamically construct these objects of differing types based on the string data in my lists. What is the best route in doing so?</p>
  
  <p>I'm willing to refine this questions if it's confusing. </p>
  
  <pre><code>String rootNodeType = fN.type;
  
  BinaryLogicOpType _blop = new BinaryLogicOpType();
  JAXBElement&lt;BinaryLogicOpType&gt; root = constructRootElement(_blop, factory, rootNodeType);
  
  /** LETS CREATE THE FIRST CHILD ELEMENT */
  BinaryComparisonOpType attrName1GTEFive = new BinaryComparisonOpType();
  _blop.getOps().add(factory.createPropertyIsEqualTo(attrName1GTEFive));
  
  JAXBElement&lt;String&gt; attr1Property = factory.createValueReference(fN.nodes.get(0).getProperty());
  LiteralType attr1ValueLiteral = new LiteralType();
  attr1ValueLiteral.getContent().add(fN.nodes.get(0).getValue());
  
  JAXBElement&lt;LiteralType&gt; attr1Value = factory.createLiteral(attr1ValueLiteral);
  
  attrName1GTEFive.getExpression().add(attr1Property);
  attrName1GTEFive.getExpression().add(attr1Value);
  </code></pre>
  
  <h1>Sample JSON</h1>
  
  <pre><code>{
    "type": "AND",
    "filters": [
      {
        "type": "=",
        "value": "exampleid",
        "property": "id"
      },
      {
        "type": "ILIKE",
        "value": "*",
        "property": "metacard-tags"
      },
      {
        "type": "OR",
        "filters": [
          {
            "type": "&gt;=",
            "value": null,
            "property": "benumber"
          },
          {
            "type": "ILIKE",
            "value": "redshirts",
            "property": "title",
            "isCaseSensitive": true
          }
        ]
      }
    ]
  }
  </code></pre>
  
  <h1>Sample XML</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;fes:Filter xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:gml="http://www.opengis.net/gml/3.2"&gt;
    &lt;fes:Or&gt;
      &lt;fes:PropertyIsLessThan matchAction="ANY" matchCase="false"&gt;
        &lt;fes:ValueReference&gt;name&lt;/fes:ValueReference&gt;
        &lt;fes:Function name="sub"&gt;
          &lt;fes:Literal&gt;my-id&lt;/fes:Literal&gt;
        &lt;/fes:Function&gt;
      &lt;/fes:PropertyIsLessThan&gt;
      &lt;fes:And&gt;
        &lt;fes:PropertyIsGreaterThanOrEqualTo matchAction="ANY" matchCase="false"&gt;
          &lt;fes:ValueReference&gt;attName&lt;/fes:ValueReference&gt;
          &lt;fes:Literal&gt;5&lt;/fes:Literal&gt;
        &lt;/fes:PropertyIsGreaterThanOrEqualTo&gt;
        &lt;fes:PropertyIsLike escapeChar="\" matchCase="false" singleChar="?" wildCard="*"&gt;
          &lt;fes:ValueReference&gt;title&lt;/fes:ValueReference&gt;
          &lt;fes:Literal&gt;greetings&lt;/fes:Literal&gt;
        &lt;/fes:PropertyIsLike&gt;
        &lt;fes:PropertyIsEqual&gt;
          &lt;fes:ValueReference&gt;be_number&lt;/fes:ValueReference&gt;
          &lt;fes:Function&gt;
              &lt;fes:Parameter&gt;null&lt;/fes:Parameter&gt;
              &lt;fes:Parameter&gt;null&lt;/fes:Parameter&gt;
          &lt;/fes:Function&gt; 
        &lt;/fes:PropertyIsEqual&gt;
      &lt;/fes:And&gt;
    &lt;/fes:Or&gt;
  &lt;/fes:Filter&gt;
  </code></pre>