java - Configuration mechanism to flag the attributes of an object that should be synchronized -


i'm refactoring old java application. has component responsible synchronizing complex object object of same type different source. object has lot of attributes (nearly hundred) of different types, including class types, in turn have lot of attributes.

i want have feature tell component attributes of object should synchronized or not. first idea dependency injection. should inject? don't want have interface methods public boolean shouldsynchronizeattributea(), public boolean shouldsynchronizeattributeb() etc. every attribute including attributes of compositions of objects. how solve issue in nice , maintainable way?

here example using strings , mvel. there many other libraries available (e.g, ognl). use orika (i not familiar with. used dozer many years ago)

public static void main(string[] args) {     final someclass o1 = new someclass();     o1.setaddress(new address("paris"));      final someclass o2 = new someclass();     o2.setaddress(new address("london"));      system.out.println(o2.getaddress().getcity()); // shows london     synchronise(o1,o2,"address.city");     system.out.println(o2.getaddress().getcity()); // shows paris  }  private static <t> void synchronise(final t o1, final t o2, final string path) {      final string source = "source";     final string target = "target";      final map<string,t> c = new treemap<string, t>();      c.put(source,o1);     c.put(target,o2);      final parsercontext parsercontext = new parsercontext();      final string expr = target + "." + path + "=" + source  + "." + path;      final compiledexpression compiledexpression = new expressioncompiler(expr, parsercontext).compile();       mvel.executeexpression(compiledexpression,c );   } 

the examples classes:

public class someclass {     private string name;     private address address;      public string getname() {         return name;     }      public void setname(string name) {         this.name = name;     }      public address getaddress() {         return address;     }      public void setaddress(address address) {         this.address = address;     }  }  public class address {     private string city;      public address(string city) {         this.city = city;     }      public string getcity() {         return city;     }      public void setcity(string city) {         this.city = city;     } } 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -