예제: Rule Designer에서 상태 값 제공자로 구/군/시 구현

값 제공자 구현의 예로 구/군/시를 나타내는 구문이나 역할에 대한 값 제공자를 선언하고 해당 값 제공자에 대한 값 정보를 선언할 수 있습니다.

이 태스크 정보

이 예제에서는 구/군/시를 나타내는 구문이나 역할에 대한 값 제공자를 선언합니다. 사전 정의된 구/군/시는 계층 구조에 상태별로 구성되어 있습니다.

프로시저

구/군/시 값 제공자를 상태별로 구현하려면 다음을 수행하십시오.

  1. City 클래스를 정의하고 IlrAbstractValueProvider를 확장하여 StateCityValueProvider 클래스를 작성하십시오.
    public interface Named {
        String getName();
    }
    
    // Represents a city, this city is owned by a state
    public class City implements Named {
      public final State state;
      public final String name;
          
      public City(State state, String name) {
        this.state = state;
        this.name = name;
      }    
      
      public String getName() {
        return name;
      }
    }
    
    // Represents a state, a state has a list of cities
    public class State implements Named {
      private final String name;
      public City[] cities;
      
      public State(String name) {      
        this.name = name;		  
      }
      
      public String getName() {
        return name;
      }
    }
    
    // Represents a hierarchical predefined set of values for cities
    // The hierarchy has two levels, at the root level there are states, 
    // and each state has a list of cities as children 
    public class StateCityValueProvider extends IlrAbstractValueProvider {
      
      // The predefined list of states
      public static State[] STATES;
      
      // Returns the root level of the hierarchy (all the states)
      public Object[] getValues() {
        return STATES;
      }
    
      // Returns the children of a predefined value, 
      // in this case only a state can have children
      public Object[] getChildren(Object parent) {
        return parent instanceof State ? ((State) parent).cities : null;
      }
    
      // Returns the parent of a predefined value, in this case only a city 
      // can have a parent (a state)
      public Object getParent(Object element) {
        return element instanceof City ? ((City) element).state : null;
      }
    
      // Returns true, if a predefined value has children, 
      // in this case only a state can have children
      public boolean hasChildren(Object element) {
        return element instanceof State;
      }
    
      // Returns the text to be displayed 
      // in the drop-down list for that predefined value
      public String getDisplayText(Object element, Locale locale) {
        return ((Named) element).getName();
      }
      
      // Returns the text to be inserted in 
      // the text of the rule for that predefined value.
      // In this case only a city value can be inserted.
      public String getText(Object element, Locale locale) {
        return element instanceof City ? ('"' + ((City) element).name + '"') : 
    null;
      }
      
      // The predefined set of cities is not exclusive
      public boolean isExclusive() {
        return false;
      }  
    }
  2. StateCityValueProvider를 제공하는 값 정보를 값 제공자로 선언하십시오.
    public class StateCityValueInfo implements IlrValueInfo {
      ...
      public String getValueDescriptor() {
           return IlrValueDescriptorConstants.STRING;
       }
      
      private StateCityValueProvider valueProvider;
      
      public IlrValueProvider getValueProvider() {
        if (valueProvider == null)
          valueProvider = new StateCityValueProvider();
        return valueProvider;
      }
    ...
    }
  3. 값 정보를 BOM 멤버에 첨부하십시오.

    예를 들어, 이 고객 void setCity(String city)에 구/군/시를 지정하는 메소드가 포함된 Customer 클래스가 있는 경우 이 메소드에서 사용자 정의 특성 valueInfo[<arg index>]를 정의하십시오.

    valueInfo[0] = sample.valueInfo.StateCity
  4. 확장점 ilog.rules.studio.model.brl.valueInfos를 선언하여 Rule Designer에 값 정보를 통합하십시오.

    ID: sample.valueInfo.StateCity

    키: sample.valueInfo.StateCity

    클래스: sample.StateCityValueInfo