001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.exception;
016    
017    import com.liferay.portal.kernel.util.ClassUtil;
018    import com.liferay.portal.kernel.util.StackTraceUtil;
019    
020    import java.util.Collection;
021    
022    /**
023     * @author Michael C. Han
024     */
025    public class BulkException extends Exception {
026    
027            public BulkException(String message, Collection<Throwable> causes) {
028                    super(message);
029    
030                    _causes = causes;
031            }
032    
033            public Collection<Throwable> getCauses() {
034                    return _causes;
035            }
036    
037            @Override
038            public String getMessage() {
039                    StringBuilder sb = new StringBuilder(7 * _causes.size() + 4);
040    
041                    sb.append("{message = ");
042                    sb.append(super.getMessage());
043                    sb.append("\n");
044    
045                    for (Throwable cause : _causes) {
046                            sb.append("{");
047                            sb.append(ClassUtil.getClassName(cause));
048                            sb.append(":");
049                            sb.append(cause.getMessage());
050                            sb.append(", ");
051                            sb.append(StackTraceUtil.getStackTrace(cause));
052                            sb.append("}\n");
053                    }
054    
055                    sb.append("}");
056    
057                    return sb.toString();
058            }
059    
060            private final Collection<Throwable> _causes;
061    
062    }