// NOTE: ValidationContext is initialized in child's validator
public void validateAsParent(ValidationContext valCtx)
{
if(valCtx.isADD() || valCtx.isSET())
{
ConfigBean newChildBean = (ConfigBean)valCtx.value;
String newChildBeanName = getBeanElementName(newChildBean);
ConfigBean parentBean = (ConfigBean)valCtx.classObject;
String[] names = desc.exclusiveChildren;
//first, let's be sure that newChildBean in exclusive list
boolean bNewChildIsInList = false;
if(names!=null)
{
for(int i=0; i<names.length; i++)
{
if(newChildBeanName.equals(names[i]))
{
bNewChildIsInList = true;
break;
}
}
}
//now find out if any othjers are there too
if(bNewChildIsInList)
{
for(int i=0; i<names.length; i++)
{
String childName = names[i];
if(childName.equals(newChildBeanName))
continue;
childName = XPathHelper.convertName(childName);
ConfigBean[] beans = parentBean.getChildBeansByName(childName);
if (beans!=null && beans.length>0)
{
String printParentName = getConfigElementPrintName(
parentBean.getXPath(), false, false);
valCtx.result.failed(valCtx.smh.getLocalString(
GenericValidator.class.getName() + ".childrenCanExistTogether",
"{0} can not contain both sub-elements {1} and {2} in the same time.",
new Object[] {printParentName,
newChildBeanName, names[i]}));
}
}
}
}
else if(valCtx.isDELETE())
{
//Check for existence of required sub-elements
ConfigBean childBean = (ConfigBean)valCtx.value;
ConfigBean parentBean = (ConfigBean)valCtx.classObject;
String childBeanName = XPathHelper.convertName(getBeanElementName(childBean));
ConfigBean[] beans = parentBean.getChildBeansByName(childBeanName);
if (beans!=null && beans.length==1)
{ //LAST ELEM DELETION
ValidationDescriptor parentDescr = desc;
String[] names = null;
if(parentDescr!=null)
names = parentDescr.requiredChildren;
String compareTo = getBeanElementName(childBean);
String compareTo2 = compareTo+'*';
for(int i=0; names!=null && i<names.length; i++)
{
if(compareTo.equals(names[i]))
{
String printParentName = getConfigElementPrintName(
parentBean.getXPath(), false, false);
String printChildName = getConfigElementPrintName(
childBean.getXPath(), false, false);
valCtx.result.failed(valCtx.smh.getLocalString(
GenericValidator.class.getName() + ".requiredElemDelete",
"Required element {0} can not be deleted from {1}",
new Object[] {printChildName, printParentName}));
break;
}
else if(compareTo2.equals(names[i]))
{
String printParentName = getConfigElementPrintName(
parentBean.getXPath(), false, false);
String printChildName = getConfigElementPrintName(
childBean.getXPath(), false, false);
valCtx.result.failed(valCtx.smh.getLocalString(
GenericValidator.class.getName() + ".lastRequiredElemDelete",
"At least one required {0} should be present in {1}."+