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

org.sakaiproject.mailsender.MailsenderException Maven / Gradle / Ivy

/**********************************************************************************
 * Copyright 2008-2009 Sakai Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ECL-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 **********************************************************************************/
package org.sakaiproject.mailsender;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * General exception for Mailsender. This exception can store messages to be sent up to the UI for
 * display to the user. This is terrible design but somewhat necessary until the updated Email API
 * is more widely in place.
 */
public class MailsenderException extends Exception
{
	private static final long serialVersionUID = 1L;
	private List> messages;

	public MailsenderException()
	{
	}

	public MailsenderException(String code, String value)
	{
		addMessage(code, value);
	}

	public MailsenderException(List> messages)
	{
		this.messages = messages;
	}

	public MailsenderException(String message, Exception cause)
	{
		super(message, cause);
	}

	public boolean hasMessages()
	{
		return (messages != null && messages.size() > 0);
	}

	public void addMessage(Map message)
	{
		if (messages == null)
		{
			messages = new ArrayList>();
		}
		messages.add(message);
	}

	public MailsenderException addMessage(String code)
	{
		addMessage(code, "");
		return this;
	}

	public MailsenderException addMessage(String code, String value)
	{
		addMessage(code, new String[] { value });
		return this;
	}

	public MailsenderException addMessage(String code, Object[] value)
	{
		HashMap hm = new HashMap();
		hm.put(code, value);
		addMessage(hm);
		return this;
	}

	public List> getMessages()
	{
		return messages;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy