All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jtopenlite.com.ibm.jtopenlite.MessageException Maven / Gradle / Ivy

///////////////////////////////////////////////////////////////////////////////
//
// JTOpenLite
//
// Filename:  MessageException.java
//
// The source code contained herein is licensed under the IBM Public License
// Version 1.0, which has been approved by the Open Source Initiative.
// Copyright (C) 2011-2012 International Business Machines Corporation and
// others.  All rights reserved.
//
///////////////////////////////////////////////////////////////////////////////

package com.ibm.jtopenlite;

import java.io.*;
import java.util.LinkedList;
import java.util.List;

/**
 * Represents an IOException that includes one or more Messages as part of its exception text.
**/
public class MessageException extends IOException
{
  /**
	 * 
	 */
	private static final long serialVersionUID = 3994984723312909458L;
  private final String text_;
  private Message[] messages_;
  private List messagesList_;

  /**
   * Constructs a MessageException with the specified preamble and messages.
  **/
  public MessageException(final String preamble, final Message[] messages)
  {
    super(buildString(preamble, messages));
    text_ = preamble;
    messages_ = messages;
    messagesList_ = null; 
  }

  public MessageException(final String preamble, final List messages)
  {
    super(buildString(preamble, messages));
    text_ = preamble;
    messagesList_ = messages;
    messages_ = null; 
  }

  /**
   * Constructs a MessageException with no preamble.
  **/
  public MessageException(final Message[] messages)
  {
    super(buildString(null, messages));
    text_ = null;
    messages_ = messages;
    messagesList_ = null; 
  }

  public MessageException(final List messages)
  {
    super(buildString(null, messages));
    text_ = null;
    messages_ = null; 
    messagesList_ = messages;
  }

  private static final String buildString(final String text, final List messages)
  {
	StringBuffer s = new StringBuffer(); 
	if (text != null) {
		s.append(text);
		s.append("\n"); 
		
	}
	s.append(messages.get(0).toString()); 

    for (int i=1; i getMessagesList()
  {
	if (messagesList_ == null) {
		if (messages_ != null) { 
			messagesList_ = new LinkedList(); 
			for (int i = 0; i < messages_.length ; i++) {
				messagesList_.add(messages_[i]); 
			}
		}
	}
    return messagesList_;
  }
  
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy