return;
}
JavaQName STRING_TYPE = JavaQNameImpl.getInstance(String.class);
JavaQName ATTRIBUTES_TYPE = JavaQNameImpl.getInstance(Attributes.class);
JavaMethod jm = pSource.getMethod("startElement", new JavaQName[]{STRING_TYPE, STRING_TYPE, STRING_TYPE,
ATTRIBUTES_TYPE});
if (jm == null) {
throw new IllegalStateException("No such method: 'startElement' in '" + pSource.getQName() + "'.");
}
PlaceHolder placeHolder = jm.getPlaceHolder("GroupSG");
if (placeHolder == null) {
throw new IllegalStateException("No such placeholder: 'GroupSG' in method 'startElement'");
}
placeHolder.remove();
Parameter[] parameters = jm.getParams();
Parameter pNamespaceURI = parameters[0];
Parameter pLocalName = parameters[1];
Parameter pQName = parameters[2];
Parameter pAttr = parameters[3];
jm.addCase("1");
Set namespaces = new HashSet();
for (int i = 0; i < myParticles.length; i++) {
ParticleSG child = myParticles[i];
// Did we have the same namespace before? If so, skip
String uri = child.getObjectSG().getName().getNamespaceURI();
if (namespaces.contains(uri)) {
continue;
}
if ("".equals(uri)) {
jm.addIf(namespaces.isEmpty(), pNamespaceURI, " == null || ", pNamespaceURI, ".length() == 0");
} else {
jm.addIf(namespaces.isEmpty(), JavaSource.getQuoted(uri), ".equals(", pNamespaceURI, ")");
}
namespaces.add(uri);
// Now handle all elements with the namespace uri
for (int j = i; j < myParticles.length; j++) {
child = myParticles[j];
XsQName name = child.getObjectSG().getName();
if (!name.getNamespaceURI().equals(uri)) {
continue;
}
jm.addIf(j == i, JavaSource.getQuoted(name.getLocalName()), ".equals(", pLocalName, ")");
List validStates = new ArrayList();
if (child.isMultiple()) {
validStates.add(new Integer(j+3));
}
if (pController.isChoice()) {
validStates.add(new Integer(0));
} else if (pController.isSequence()) {
boolean stateZeroIsValid = true;
for (int k = j-1; k >= 0; k--) {
ParticleSG kChild = myParticles[k];
validStates.add(new Integer(k+3));
if (kChild.getMinOccurs() > 0) {
stateZeroIsValid = false;
break;
}
}
if (stateZeroIsValid) {
validStates.add(new Integer(0));
}
} else if (pController.isAll()) {
validStates.add(new Integer(0));
for (int k = 0; k < myParticles.length; k++) {
validStates.add(new Integer(k));
}
} else {
throw new IllegalStateException("Don't know how to handle type which is neither sequence nor choice, or all.");
}
Collections.sort(validStates);
jm.addSwitch(pStateVar);
for (int k = 0; k < validStates.size(); k++) {
jm.addCase(validStates.get(k));
}
jm.addLine(pStateVar, " = " + (j+3) + ";");
if (child.getObjectSG().getTypeSG().isComplex()) {
String handlerMethodName = getXMLHandlersMethodName(child.getPropertySG());
jm.addLine(pHandlerVar, " = ", handlerMethodName, "();");
} else {
jm.addLine(pHandlerVar, " = getData().getAtomicHandler();");
}
jm.addLine(pHandlerVar, ".startDocument();");
jm.addLine(pHandlerVar, ".startElement(pNamespaceURI, pLocalName, pQName, pAttr);");
jm.addBreak();
jm.addDefault();
jm.addLine("validationEvent(", ValidationEvent.class, ".WARNING, ",
JavaSource.getQuoted("The element "), " + ", pQName, " + ",
JavaSource.getQuoted(" was unexpected at this place."),
", ", ValidationEvents.class,
".EVENT_UNEXPECTED_CHILD_STATE);");
jm.addBreak();
jm.addEndSwitch();
}
jm.addEndIf();
}
jm.addEndIf();
jm.addBreak();
jm.addDefault();
jm.addIf(pHandlerVar, " == null");
jm.addLine("super.startElement(", pNamespaceURI, ", ", pLocalName, ", ", pQName, ", ", pAttr, ");");
jm.addElse();
jm.addLine(pHandlerVar, ".startElement(", pNamespaceURI, ", ", pLocalName, ", ", pQName, ", ", pAttr, ");");
jm.addEndIf();
}