MX Java Rule Code Example

An example of the MX Java rule code is provided for your reference.

package com.tibco.swift2.validate.mx.rules.spec2017;
import java.util.List;
import org.dom4j.Element;
import com.tibco.swift2.msg.MXFinder;
import com.tibco.swift2.msg.SwiftMXMessage;
import com.tibco.swift2.util.SwiftException;
import com.tibco.swift2.validate.ArgResolver;
import com.tibco.swift2.validate.MXValidationRule;
import com.tibco.swift2.validate.MXValidator;
public class PhysicalDeliveryDetails1Rule extends MXValidationRule {
public PhysicalDeliveryDetails1Rule(String name,String xpath,,String overrideErrorSeverity, String
overrideErrorCode,String overrideErrorText,
String[] args, ArgResolver resolver) throws SwiftException {
super(name, xpath, overrideErrorSeverity, overrideErrorCode, overrideErrorText, args, resolver, 0, 0, new
Class[0]);
}
@Override
public boolean eval(SwiftMXMessage msg, MXValidator validator, int validationLevel) {
MXFinder finderParent=new MXFinder(getParam_Parent());
boolean isValid = true;
List<Element> elementsParent = finderParent.getElements(msg);
String physDlvryIndTag=getParam_PhysDlvryInd().replace("//", "");
String physDlvryDtlsTag=getParam_PhysDlvryDtls().replace("//", "");
for(int i=0;i<elementsParent.size();i++) {
Element elementParent=elementsParent.get(i);
Element elementPhysDlvryInd=elementParent.element(physDlvryIndTag);
Element elementPhysDlvryDtls=elementParent.element(physDlvryDtlsTag);
if(elementPhysDlvryInd!=null) {
if(elementPhysDlvryInd != null){
if(elementPhysDlvryInd.getStringValue().equals("false") || elementPhysDlvryInd.getStringValue().equals("0")){
if(elementPhysDlvryDtls!=null) {
msg.addWarning(elementParent, getName(), getOverrideErrorCode(),getOverrideErrorText());
isValid = false;
}
}
}
}
}
return isValid;
}
public String getParam_PhysDlvryInd(){
return getParam().get("PhysDlvryInd");
}
public String getParam_PhysDlvryDtls(){
return getParam().get("PhysDlvryDtls");
}
public String getParam_Parent(){
return getParam().get("Parent");