}
}
XSParticle particle = null;
if (modelGroup != null && modelGroup.getParticles() != null) {
for (int i = 0; i < modelGroup.getParticles().getLength(); i++) {
XSObject particleObject = modelGroup.getParticles().item(i);
if (particleObject instanceof XSParticle) {
XSParticle currentParticle = (XSParticle) particleObject;
if (currentParticle.getTerm() instanceof XSElementDeclaration) {
XSElementDeclaration particleElement = (XSElementDeclaration) currentParticle.getTerm();
if (particleElement.getName().equals(element.getName())) {
particle = currentParticle;
break;
}
}
}
}
}
Config config = dataProvider.getConfig();
int iterationCounter = 0;
while (tmpl.contains(Constants.TEMPLATE_DELIMITER_COMPLEX_VALIDATION)) {
iterationCounter++;
if (iterationCounter > config.getMaxTemplateResolvingIterations()) {
System.err.println("********************************************");
System.err.println("Could not resolve template:");
System.err.println(fillInTemplate(tmpl, cppElementName, null, null, null, null, null, dataProvider));
System.err.println("********************************************");
break;
}
if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_STRUCT_TYPE)) {
tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_STRUCT_TYPE, cppValidationDataStructType);
}
if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_STRUCT_NAME)) {
tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_STRUCT_NAME, config
.getComplexValidationDataStructVariableName());
}
if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_PARENT_STRUCT_NAME)) {
tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_PARENT_STRUCT_NAME, config
.getComplexValidationDataParentStructVariableName());
}
if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_STRUCT_MEMBER)) {
tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_STRUCT_MEMBER, Util
.createComplexValidationDataStructMemberName(element, config));
}
if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_CHECK_MAX_OCCURENCE)) {
String maxOccCheck = config.getTemplateComplexValidationCheckMaxOccurence();
if (particle == null || (particle != null && particle.getMaxOccursUnbounded()) || complexTypeMaxOccursUnbounded ) {
maxOccCheck = "";
}
tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_CHECK_MAX_OCCURENCE, maxOccCheck);
}
if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_GET_VALIDATION_DATA)) {
tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_GET_VALIDATION_DATA, config
.getTemplateComplexValidationGetTopValidationData());
}
if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_DELETE_VALIDATION_DATA)) {
tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_DELETE_VALIDATION_DATA, config
.getTemplateComplexValidationDeleteValidationData());
}
if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_GET_PARENT_VALIDATION_DATA)) {
tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_GET_PARENT_VALIDATION_DATA, config
.getTemplateComplexValidationGetTopParentValidationData());
}
if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_INCREMENT_OCCURENCE)) {
tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_INCREMENT_OCCURENCE, config
.getTemplateComplexValidationIncrementOccurence());
}
if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_MAX_OCCURENCE)) {
int maxOccurence = 0;
if (particle != null) {
maxOccurence = particle.getMaxOccurs();
}
tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_MAX_OCCURENCE, String.valueOf(maxOccurence));
}
if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_CHECK_MIN_OCCURENCE_OF_CHILDREN)) {
String childrenCheck = "";
if (modelGroup != null && modelGroup.getParticles() != null) {
switch (modelGroup.getCompositor()) {
case XSModelGroup.COMPOSITOR_ALL:
case XSModelGroup.COMPOSITOR_SEQUENCE:
for (int i = 0; i < modelGroup.getParticles().getLength(); i++) {
XSObject item = modelGroup.getParticles().item(i);
if (item instanceof XSParticle) {
XSParticle child = (XSParticle) item;
if (child.getMinOccurs() == 0) {
continue;
}
String particleTmpl = config.getTemplateComplexValidationCheckMinOccurencOfChildren();
childrenCheck += fillInComplexValidationParticleTemplate(particleTmpl, child, config);
}
}
break;
case XSModelGroup.COMPOSITOR_CHOICE:
boolean allChildrenHaveMinOccurs = true;
for (int i = 0; i < modelGroup.getParticles().getLength(); i++) {
XSObject item = modelGroup.getParticles().item(i);
if (item instanceof XSParticle) {
XSParticle child = (XSParticle) item;
if (child.getMinOccurs() == 0) {
allChildrenHaveMinOccurs = false;
continue;
}
String particleTmpl = config
.getTemplateComplexValidationChoiceCheckMinOccurencOfChildren();
childrenCheck += fillInComplexValidationParticleTemplate(particleTmpl, child, config);
}
}
if (allChildrenHaveMinOccurs) {
childrenCheck += config.getTemplateComplexValidationChoiceCheckOneChildPresent();
if (childrenCheck.contains(Constants.TMPL_COMPLEX_VALI_CHOICE_ONE_CHILD_PER_CHILD)) {
for (int i = 0; i < modelGroup.getParticles().getLength(); i++) {
XSObject item = modelGroup.getParticles().item(i);
if (item instanceof XSParticle) {
XSParticle child = (XSParticle) item;
String perChild = config
.getTemplateComplexValidationChoiceCheckOneChildPresentPerChild();
if (i != modelGroup.getParticles().getLength() - 1) {