One approach to achieve this would be to introduce these auxiliary methods through aspects. AspectJ will be a potential candidate for this, or if you use Spring, then Spring AOP can also do the job.
Thus, using AspectJ, you would use the "inter-type declaration" function, which allows you to introduce new functions into existing classes. If your generated JAXWS class is called MyTypeGen
, you must introduce new methods using the aspect (optionally named MyTypeAspect
) as follows:
class MyTypeGen {
int x, y;
public void setX(int x) { this.x = x; }
public void setY(int y) { this.y = y; }
}
aspect MyTypeAspect {
public int MyTypeGen.multiply() {
return x * y;
}
public int MyTypeGen.sum() {
return x + y;
}
}
At run time, you can invoke these two new methods that were woven at MyTypeGen
build time. No casting required.
MyTypeGen mytype = new MyTypeGen();
mytype.setX(3);
mytype.setY(4);
int product = mytype.multiply();
Spring AOP , Java- @Aspect
, introductions.