Ejemplo n.º 1
0
public class Log4JTest {
  // Create a category instance for this class
  static Category cat = Category.getInstance(Log4JTest.class.getName());

  public static void main(String[] args) {
    // Ensure to have all necessary drivers installed !
    try {
      Driver d = (Driver) (Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
      DriverManager.registerDriver(d);
    } catch (Exception e) {
    }

    // Set the priority which messages have to be logged
    cat.setPriority(Priority.INFO);

    // Configuration with configuration-file
    PropertyConfigurator.configure("log4jtestprops.txt");

    // These messages with Priority >= setted priority will be logged to the database.
    cat.debug("debug"); // this not, because Priority DEBUG is less than INFO
    cat.info("info");
    cat.error("error");
    cat.fatal("fatal");
  }
}
public class PublishedItemText implements Serializable, ItemTextIfc, Comparable<ItemTextIfc> {
  static Category errorLogger = Category.getInstance("errorLogger");

  private static final long serialVersionUID = 7526471155622776147L;

  private Long id;
  private ItemDataIfc item;
  private Long sequence;
  private String text;
  private Set answerSet;

  private Set itemTextAttachmentSet;
  private Integer requiredOptionsCount;

  public PublishedItemText() {}

  public PublishedItemText(PublishedItemData item, Long sequence, String text, Set answerSet) {
    this.item = item;
    this.sequence = sequence;
    this.text = text;
    this.answerSet = answerSet;
  }

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public ItemDataIfc getItem() {
    return item;
  }

  public void setItem(ItemDataIfc item) {
    this.item = item;
  }

  public Long getSequence() {
    return sequence;
  }

  public void setSequence(Long sequence) {
    this.sequence = sequence;
  }

  public String getText() {
    return text;
  }

  public void setText(String text) {
    this.text = text;
  }

  public Set getAnswerSet() {
    return answerSet;
  }

  public void setAnswerSet(Set answerSet) {
    this.answerSet = answerSet;
  }

  private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();
  }

  private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
  }

  public ArrayList getAnswerArray() {
    ArrayList list = new ArrayList();
    Iterator iter = answerSet.iterator();
    while (iter.hasNext()) {
      list.add(iter.next());
    }
    return list;
  }

  public ArrayList getAnswerArraySorted() {
    ArrayList list = getAnswerArray();
    Collections.sort(list);
    return list;
  }

  public int compareTo(ItemTextIfc o) {
    return sequence.compareTo(o.getSequence());
  }

  public Set getItemTextAttachmentSet() {
    return itemTextAttachmentSet;
  }

  public List getItemTextAttachmentList() {
    return new ArrayList(itemTextAttachmentSet);
  }

  public void setItemTextAttachmentSet(Set itemTextAttachmentSet) {
    this.itemTextAttachmentSet = itemTextAttachmentSet;
  }

  // for EMI - Attachments at Answer Level
  public boolean getHasAttachment() {
    if (itemTextAttachmentSet != null && itemTextAttachmentSet.size() > 0) return true;
    else return false;
  }

  // This is an actual EMI Question Item
  // (i.e. not Theme or Lead In Text or the complete Answer Options list)
  public boolean isEmiQuestionItemText() {
    return getSequence() > 0;
  }

  public Integer getRequiredOptionsCount() {
    if (requiredOptionsCount == null) {
      return Integer.valueOf(1);
    }
    return requiredOptionsCount;
  }

  public void setRequiredOptionsCount(Integer requiredOptionsCount) {
    this.requiredOptionsCount = requiredOptionsCount;
  }

  public String getEmiCorrectOptionLabels() {
    if (!item.getTypeId().equals(TypeD.EXTENDED_MATCHING_ITEMS)) return null;
    if (!this.isEmiQuestionItemText()) return null;
    if (answerSet == null) return null;
    String correctOptionLabels = "";
    Iterator iter = getAnswerArraySorted().iterator();
    while (iter.hasNext()) {
      AnswerIfc answer = (AnswerIfc) iter.next();
      if (answer.getIsCorrect()) {
        correctOptionLabels += answer.getLabel();
      }
    }
    return correctOptionLabels;
  }
}