0

I am doing a Rule Based Mapping using XML.

Rules.xml

<?xml version="1.0" ?> 
  <rules> 
   <name>Rule1</name>
    <sourcefield>employeeName</sourcefield>   
    <targetfield>Name</targetfield>    
   </rules>

The Pojo's are below

public class Employee{

    String employeeName;

    public String getEmployeeName() {
    return employeeName;
    }

    public void setEmployeeName(String employeeName) {
    this.employeeName = employeeName;
    }

} 

package main;

public class Emp{

    String name;

    public String getName() {
    return name;
    }

    public void setName(String name) {
    this.name= name;
    }
}

The sourcefield and targetfield values are variables defined in the POJO's (Employee and Emp). In my controlller class, I am trying to fetch the source and target fields from the Rules.xml and try to form the JAVA code dynamically based on these source and target values.

for example:

I get the sourcefield and targetfield values after parsing the XML

String source = eElement.getElementsByTagName("sourcefield").item(0).getTextContent(); String target= eElement.getElementsByTagName("targetfield").item(0).getTextContent();

Now, if source value is 'employeeName' and target value is 'name' then I need to form the JAVA code as Employee.setEmployeeName() and Emp.setName() respectively.

Is there a way how to do this?

Selva Shanmugam
  • 53
  • 1
  • 2
  • 8
  • There are [existing tools](https://stackoverflow.com/questions/1432764/any-tool-for-java-object-to-object-mapping/1432956) - do you really want to do this yourself? – Andrew S Jan 25 '18 at 16:57
  • Hi Andrew, Yes I would do it by myself. If there are any open source tools can you please suggest me. Thank you.!! – Selva Shanmugam Jan 26 '18 at 09:30

0 Answers0