mercredi 21 février 2018

Proper pattern or methodology to traverse data and dynamically construct objects?

I'm looking for potentially some design pattern advice regarding object traversal to dynamically construct objects based on the data being presented.

Below, I am manually constructing this object. Initially, the root node is a BinaryLogicOpType but could be a different object based on the rootNodeType.

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?

I'm willing to refine this questions if it's confusing.

String rootNodeType = fN.type;

BinaryLogicOpType _blop = new BinaryLogicOpType();
JAXBElement<BinaryLogicOpType> root = constructRootElement(_blop, factory, rootNodeType);

/** LETS CREATE THE FIRST CHILD ELEMENT */
BinaryComparisonOpType attrName1GTEFive = new BinaryComparisonOpType();
_blop.getOps().add(factory.createPropertyIsEqualTo(attrName1GTEFive));

JAXBElement<String> attr1Property = factory.createValueReference(fN.nodes.get(0).getProperty());
LiteralType attr1ValueLiteral = new LiteralType();
attr1ValueLiteral.getContent().add(fN.nodes.get(0).getValue());

JAXBElement<LiteralType> attr1Value = factory.createLiteral(attr1ValueLiteral);

attrName1GTEFive.getExpression().add(attr1Property);
attrName1GTEFive.getExpression().add(attr1Value);

Aucun commentaire:

Enregistrer un commentaire