001: package com.sun.xml.ws.wsdl.parser;
002:
003: /*
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
005: *
006: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
007: *
008: * The contents of this file are subject to the terms of either the GNU
009: * General Public License Version 2 only ("GPL") or the Common Development
010: * and Distribution License("CDDL") (collectively, the "License"). You
011: * may not use this file except in compliance with the License. You can obtain
012: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
013: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
014: * language governing permissions and limitations under the License.
015: *
016: * When distributing the software, include this License Header Notice in each
017: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
018: * Sun designates this particular file as subject to the "Classpath" exception
019: * as provided by Sun in the GPL Version 2 section of the License file that
020: * accompanied this code. If applicable, add the following below the License
021: * Header, with the fields enclosed by brackets [] replaced by your own
022: * identifying information: "Portions Copyrighted [year]
023: * [name of copyright owner]"
024: *
025: * Contributor(s):
026: *
027: * If you wish your version of this file to be governed by only the CDDL or
028: * only the GPL Version 2, indicate your decision by adding "[Contributor]
029: * elects to include this software in this distribution under the [CDDL or GPL
030: * Version 2] license." If you don't indicate a single choice of license, a
031: * recipient has the option to distribute your version of this file under
032: * either the CDDL, the GPL Version 2 or to extend the choice of license to
033: * its licensees as provided above. However, if you add GPL Version 2 code
034: * and therefore, elected the GPL Version 2 license, then the option applies
035: * only if the new code is made subject to such option by the copyright
036: * holder.
037: */
038:
039: import javax.xml.ws.WebServiceException;
040: import java.util.ArrayList;
041: import java.util.Collections;
042: import java.util.List;
043:
044: /**
045: * A list of {@link InaccessibleWSDLException} wrapped in one exception.
046: *
047: * <p>
048: * This exception is used to report all the errors during WSDL parsing from {@link RuntimeWSDLParser#parse(java.net.URL, org.xml.sax.EntityResolver, boolean, com.sun.xml.ws.api.wsdl.parser.WSDLParserExtension[])}
049: *
050: * @author Vivek Pandey
051: */
052: public class InaccessibleWSDLException extends WebServiceException {
053:
054: private final List<Throwable> errors;
055:
056: private static final long serialVersionUID = 1L;
057:
058: public InaccessibleWSDLException(List<Throwable> errors) {
059: super (errors.size() + " counts of InaccessibleWSDLException.\n");
060: assert !errors.isEmpty() : "there must be at least one error";
061: this .errors = Collections
062: .unmodifiableList(new ArrayList<Throwable>(errors));
063: }
064:
065: public String toString() {
066: StringBuilder sb = new StringBuilder(super .toString());
067: sb.append('\n');
068:
069: for (Throwable error : errors)
070: sb.append(error.toString()).append('\n');
071:
072: return sb.toString();
073: }
074:
075: /**
076: * Returns a read-only list of {@link InaccessibleWSDLException}s
077: * wrapped in this exception.
078: *
079: * @return
080: * a non-null list.
081: */
082: public List<Throwable> getErrors() {
083: return errors;
084: }
085:
086: public static class Builder implements ErrorHandler {
087: private final List<Throwable> list = new ArrayList<Throwable>();
088:
089: public void error(Throwable e) {
090: list.add(e);
091: }
092:
093: /**
094: * If an error was reported, throw the exception.
095: * Otherwise exit normally.
096: */
097: public void check() throws InaccessibleWSDLException {
098: if (list.isEmpty())
099: return;
100: throw new InaccessibleWSDLException(list);
101: }
102: }
103:
104: }
|