0

Considering the commonality and flexibility of our project, we need to add fields and related get/set methods into a basic class with a array of columns from a XML configuration file. I was thinking of Cglib and did a study about it.

I've learned that how to use Cglib to implement AOP functionality in application like this:

public static SampleManager getSelectivityAuthInstance(AuthProxy auth) {
  Enhancer enhancer = new Enhancer();
  enhancer.setSuperclass(SampleManager .class);
  enhancer.setCallbacks(new Callback[] { auth, NoOp.INSTANCE });
  enhancer.setCallbackFilter(new AuthProxyFilter());

  return (SampleManager ) enhancer.create();
} 

There is insufficient resources for learning and researching Cglib on the internet. I was wishing to get a help from here. Following is my question in detail.

1, I have a basic POJO class BasicUser which is empty primitively.

2, Application should have ability to read a list of fields that includes information like name, data type, length,etc from project.xml, and add these fields in the BasicUser class, and then application uses the new class updated by Cglib to reach business requirements.

I ever thought to use Map to implement it, but it's not technical. Can anybody professional gives me guidance.

Brady Zhu
  • 1,305
  • 5
  • 21
  • 43

1 Answers1

2

There is actually a class for this in cglib, the BeanGenerator. I wrote something about the use of this class here: http://mydailyjava.blogspot.no/2013/11/cglib-missing-manual.html

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192