package org.opengroupware.jope.rules;

public class RuleKeyAssignment extends RuleAssignment {

  public RuleKeyAssignment(String _keyPath, Object _value) {
    super(_keyPath, _value);
  }

  /* operations */
  
  public boolean isCandidateForKey(String _key) {
    if (_key == null)
      return true;
    
    // TODO: perform a real keypath check
    return _key.equals(this.keyPath);
  }
  
  public Object fireInContext(RuleContext _ctx) {
    // TODO: shouldn't we apply the value on ctx ?
    return _ctx != null ? _ctx.valueForKeyPath(this.value.toString()) : null;
  }
  
  /* representations */
  
  public String valueStringRepresentation() {
    return this.value.toString();
  }
}
