<commit_before>package org.pentaho.ui.xul.binding;

import org.pentaho.ui.xul.dom.Document;

public class DefaultBindingFactory implements BindingFactory {
  
  private Document document;
  
  private Binding.Type type = Binding.Type.BI_DIRECTIONAL;

  public void setDocument(Document document) {
    this.document = document;
  }
  
  public void setBindingType(Binding.Type type) {
    this.type = type;
  }
  
  private Binding applyBinding(Binding b, BindingConvertor... converters) {
    b.setBindingType(type);
    if(converters != null && converters.length > 0){
      b.setConversion(converters[0]);
    }
    b.initialize();
    document.addInitializedBinding(b);
    return b;
  }
  
  public Binding createBinding(String sourceId, String sourceAttr, String targetId, String targetAttr, BindingConvertor... converters) {
    Binding b = new Binding(document.getElementById(sourceId), sourceAttr, document.getElementById(targetId), targetAttr);
    return applyBinding(b);
  }

  public Binding createBinding(Object source, String sourceAttr, String targetId, String targetAttr, BindingConvertor... converters) {
    Binding b = new Binding(source, sourceAttr, document.getElementById(targetId), targetAttr);
    return applyBinding(b);
  }

  public Binding createBinding(String sourceId, String sourceAttr, Object target, String targetAttr, BindingConvertor... converters) {
    Binding b = new Binding(document.getElementById(sourceId), sourceAttr, target, targetAttr);
    return applyBinding(b);
  }
  
  public Binding createBinding(Object source, String sourceAttr, Object target, String targetAttr, BindingConvertor... converters) {
    Binding b = new Binding(source, sourceAttr, target, targetAttr);
    return applyBinding(b);
  }

}
<commit_msg>nice error message when document is not set on DefaultBindingFactory<commit_after>package org.pentaho.ui.xul.binding;

import org.pentaho.ui.xul.dom.Document;

public class DefaultBindingFactory implements BindingFactory {
  
  private Document document;
  
  private Binding.Type type = Binding.Type.BI_DIRECTIONAL;

  public void setDocument(Document document) {
    this.document = document;
  }
  
  public void setBindingType(Binding.Type type) {
    this.type = type;
  }
  
  private Binding applyBinding(Binding b, BindingConvertor... converters) {
    b.setBindingType(type);
    if(converters != null && converters.length > 0){
      b.setConversion(converters[0]);
    }
    b.initialize();
    document.addInitializedBinding(b);
    return b;
  }
  
  private void constraintsCheck() {
    if(document == null) {
      throw new IllegalArgumentException("document is null.  Did you forget to set the document on the DefaultBindingFactory?");
    }
  }
  
  public Binding createBinding(String sourceId, String sourceAttr, String targetId, String targetAttr, BindingConvertor... converters) {
    constraintsCheck();
    Binding b = new Binding(document.getElementById(sourceId), sourceAttr, document.getElementById(targetId), targetAttr);
    return applyBinding(b);
  }

  public Binding createBinding(Object source, String sourceAttr, String targetId, String targetAttr, BindingConvertor... converters) {
    constraintsCheck();
    Binding b = new Binding(source, sourceAttr, document.getElementById(targetId), targetAttr);
    return applyBinding(b);
  }

  public Binding createBinding(String sourceId, String sourceAttr, Object target, String targetAttr, BindingConvertor... converters) {
    constraintsCheck();
    Binding b = new Binding(document.getElementById(sourceId), sourceAttr, target, targetAttr);
    return applyBinding(b);
  }
  
  public Binding createBinding(Object source, String sourceAttr, Object target, String targetAttr, BindingConvertor... converters) {
    Binding b = new Binding(source, sourceAttr, target, targetAttr);
    return applyBinding(b);
  }

}

{'fraction_non_alphanumeric': 0.09467149508535955, 'fraction_numerical': 0.0010346611484738748, 'mean_word_length': 4.423562412342216, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5009337', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1040, 'n_words': 288}