in dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java [310:344]
private void updateDurationGetter(ClassOutline co, FieldOutline fo, JDefinedClass dc,
XmlString xmlDefaultValue, Outline outline) {
String fieldName = fo.getPropertyInfo().getName(false);
String getterName = "get" + fo.getPropertyInfo().getName(true);
JMethod method = dc.getMethod(getterName, new JType[0]);
JDocComment doc = method.javadoc();
int mods = method.mods().getValue();
JType mtype = method.type();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Updating getter: " + getterName);
}
// remove existing method and define new one
dc.methods().remove(method);
method = dc.method(mods, mtype, getterName);
method.javadoc().append(doc);
JFieldRef fr = JExpr.ref(fieldName);
if (xmlDefaultValue != null) {
JExpression test = JOp.eq(JExpr._null(), fr);
JConditional jc = method.body()._if(test);
JTryBlock b = jc._then()._try();
b.body()._return(outline.getCodeModel().ref(DatatypeFactory.class)
.staticInvoke("newInstance").invoke("newDuration").arg(JExpr.lit(xmlDefaultValue.value)));
b._catch(outline.getCodeModel().ref(DatatypeConfigurationException.class));
method.body()._return(fr);
} else {
method.body()._return(fr);
}
}