Package org.dmd.dmv.shared.extended.rulesdmo

Source Code of org.dmd.dmv.shared.extended.rulesdmo.PatternMatchRule

package org.dmd.dmv.shared.extended.rulesdmo;

import org.dmd.dmc.DmcAttribute;
import org.dmd.dmc.DmcObject;
import org.dmd.dmc.rules.DmcRuleException;
import org.dmd.dmc.rules.DmcRuleExceptionSet;
import org.dmd.dms.generated.enums.ValueTypeEnum;
import org.dmd.dmv.shared.generated.dmo.PatternMatchRuleDataDMO;
import org.dmd.dmv.shared.generated.rulesdmo.PatternMatchRuleBaseImpl;

public class PatternMatchRule extends PatternMatchRuleBaseImpl {

  public PatternMatchRule(){
    super();
  }
 
  public PatternMatchRule(PatternMatchRuleDataDMO patternMatchRuleDataDMO) {
    super(patternMatchRuleDataDMO);
  }

  @Override
  public void execute(DmcObject obj, DmcAttribute<?> attribute) throws DmcRuleExceptionSet {
    if (attribute.getAttributeInfo().valueType == ValueTypeEnum.SINGLE){
      String value = attribute.getSV().toString();
     
      if (!value.matches(ruleDMO.getMatchesPattern())){
        DmcRuleExceptionSet ex = new DmcRuleExceptionSet();
        ex.add(new DmcRuleException(this.getRuleTitle() + "\n" + obj.toOIF(), this));
        throw(ex);
      }
    }
    else{
      for(int i=0; i<attribute.getMVSize(); i++){
        Object valobj = attribute.getMVnth(i);
        if (valobj != null){
          String value = valobj.toString();
         
          if (!value.matches(ruleDMO.getMatchesPattern())){
            DmcRuleExceptionSet ex = new DmcRuleExceptionSet();
            ex.add(new DmcRuleException(this.getRuleTitle() + "\n" + obj.toOIF(), this));
            throw(ex);
          }
        }
      }
    }

  }

}
TOP

Related Classes of org.dmd.dmv.shared.extended.rulesdmo.PatternMatchRule

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.