public JavaClass build(ComponentBean componentBean, JSFGeneratorConfiguration configuration) {
String superclassname =
componentBean.getSuperclass();
JavaClass javaClass =
new JavaClass(componentBean.getSimpleClassName(),
new JavaPackage(componentBean.getPackageName()));
try {
Class<?> superClass =
Class.forName(superclassname, false, configuration.getClassLoader());
javaClass.setSuperClass(superClass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
javaClass.setSuperClass(UIComponentBase.class);
}
javaClass.addModifier(JavaModifier.PUBLIC);
javaClass.addField(getComponentFamily(componentBean));
javaClass.addField(getComponentType(componentBean));
javaClass.addMethod(getConstructor(componentBean, javaClass));
Collection<PropertyBean> properties = componentBean.getProperties();
for (PropertyBean propertyBean : properties) {
PropertyProcessor proc = null;
for (int i = 0; i < propertyProcessors.length && proc == null; i++) {
PropertyProcessor processor =
propertyProcessors[i];
if (processor.accept(propertyBean, javaClass, configuration)) {
proc = processor;
}
}
if (proc != null) {
proc.process(propertyBean, javaClass, configuration);
}
}
javaClass.addMethod(getComponentFamilyMethod(componentBean));
ComponentStateManager stateManager = new ComponentStateManager(javaClass);
JavaMethod saveState = getSaveStateTemplate();
try {
saveState.setMethodBody(stateManager.getSaveStateMethodBody(configuration));
} catch (GeneratorException e) {
e.printStackTrace();
}
javaClass.addMethod(saveState);
JavaMethod restoreState = getRestoreStateTemplate();
try {
restoreState.setMethodBody(stateManager.getRestoreStateMethodBody(configuration));
} catch (GeneratorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
javaClass.addMethod(restoreState);
return javaClass;