}
private JavaMethod getXMLHandlersInitMethod(GroupSG pController, JavaSource pSource) throws SAXException {
JavaMethod jm = null;
DirectAccessible pData = null;
ParticleSG[] myParticles = pController.getParticles();
for (int i = 0; i < myParticles.length; i++) {
ParticleSG particle = myParticles[i];
if (particle.isElement()) {
ObjectSG objectSG = particle.getObjectSG();
TypeSG typeSG = objectSG.getTypeSG();
if (typeSG.isComplex()) {
if (jm == null) {
jm = pSource.newJavaMethod("init", JavaQNameImpl.VOID, JavaSource.PUBLIC);
pData = jm.addParam(JMHandler.Data.class, "pData");
jm.addThrows(JAXBException.class);
jm.addLine("super.init(", pData, ");");
}
String f = particle.getPropertySG().getXMLFieldName();
String handlerFieldName = "__handler_" + f;
String handlerMethodName = getXMLHandlersMethodName(particle.getPropertySG());
JavaField jf = pSource.newJavaField(handlerFieldName, JMHandler.class, JavaSource.PRIVATE);
JavaMethod jm2 = pSource.newJavaMethod(handlerMethodName, JMHandler.class, "protected");
jm2.addThrows(SAXException.class);
jm2.addIf(handlerFieldName, " == null");
ComplexTypeSG childSG = typeSG.getComplexTypeSG();
JavaQName interfaceName = childSG.getClassContext().getXMLInterfaceName();
JavaQName handlerClassName = childSG.getClassContext().getXMLHandlerName();
jm2.addTry();
if (typeSG.isGlobalClass()) {
jm2.addLine(handlerFieldName, " = getData().getFactory().getJMHandler(",
interfaceName, ".class);");
} else {
jm2.addLine(jf, " = new ", handlerClassName, "();");
}
jm2.addLine(jf, ".init(getData());");
DirectAccessible e = jm2.addCatch(JAXBException.class);
jm2.addThrowNew(SAXException.class, e);
jm2.addEndTry();
jm2.addEndIf();
jm2.addLine("return ", jf, ";");