예제: 제한조건이 있는 구/군/시 값 검사기 구현
값 검사기 구현의 예로 제한조건을 사용하여 지정된 구/군/시를 기준으로 시/도를 검사하는 값 검사기를 작성할 수 있습니다.
이 태스크 정보
이 예제에서는 지정된 구/군/시를 기준으로 시/도를 검사하는 구/군/시 값 검사기를 구현합니다. 검사를 포함하려면 제한조건을 구현합니다.
프로시저
제한조건이 있는 구/군/시 값 검사기를 구현하려면 다음을 수행하십시오.
- IlrConstraintValueChecker 클래스를 확장하십시오.
이 클래스를 사용하여 동일한 구문 내의 다른 값에 따라
값을 검사합니다.
public class CityValueChecker extends IlrConstraintValueChecker { // Returns true if the proposed city (value) is owned by // the state given in reference (ref) protected boolean accept(Object ref, Object value) { City city = <retrieve the city by its name>(value.toString()); if (city != null) { return city.state.getName().equals(ref.toString()); } return false; } // Checks if the city exists public boolean check(Object value, IlrSyntaxTree.Node node, IlrValueError valueError) { if (super.check(value, node, valueError)) { // Checks the constraint, the city according to the state // if the city exists, the state can not be filled and in // that case the constraint is not checked boolean exists = StateCityValueProvider.getCityByName(value.toString()) != null; if (!exists) { // If the city does not exist fill the value error argument valueError.setReason("This city does not exist"); } return exists; } else { return false; } } } - StateCityValueChecker를 제공하는 값 정보를 값 검사기로 선언하십시오.
public class StateCityValueInfo implements IlrValueInfo { ... public String getValueDescriptor() { return IlrValueDescriptorConstants.STRING; } private StateCityValueChecker valueChecker; public IlrValueChecker getValueChecker() { if (valueChecker == null) valueChecker = new StateCityValueChecker(); return valueChecker; } ... } - BOM 멤버에 값 정보 특성을 포함하는 사용자 정의 특성을 선언하여
제한된 값을 해당 참조와 연관시키십시오.
예를 들어, BOM 클래스 Customer에 void setBillingAddress(java.lang.String state, java.lang.String city) 메소드가 있는 경우 다음 사용자 정의 특성을 정의해야 합니다.
constraint[1] = 0
valueInfo[1] = sample.valueInfo.StateCity
- 확장점 ilog.rules.studio.model.brl.valueInfos를 선언하여 Rule
Designer에 값 정보를 통합하십시오.
ID: sample.valueInfo.StateCity
키: sample.valueInfo.StateCity
클래스: sample.StateCityValueInfo