src/share/jaxws_classes/com/sun/xml/internal/ws/util/exception/JAXWSExceptionBase.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
child 1407
730acb5d508e
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.xml.internal.ws.util.exception;
ohair@286 27
alanb@368 28 import com.sun.istack.internal.localization.Localizable;
alanb@368 29 import com.sun.istack.internal.localization.LocalizableMessage;
alanb@368 30 import com.sun.istack.internal.localization.LocalizableMessageFactory;
alanb@368 31 import com.sun.istack.internal.localization.Localizer;
alanb@368 32 import com.sun.istack.internal.localization.NullLocalizable;
ohair@286 33 import java.io.IOException;
ohair@286 34 import java.io.ObjectInputStream;
ohair@286 35 import java.io.ObjectOutputStream;
ohair@286 36 import java.io.Serializable;
alanb@368 37 import javax.xml.ws.WebServiceException;
ohair@286 38
ohair@286 39 /**
ohair@286 40 * Represents a {@link WebServiceException} with
ohair@286 41 * localizable message.
ohair@286 42 *
ohair@286 43 * @author WS Development Team
ohair@286 44 */
ohair@286 45 public abstract class JAXWSExceptionBase
ohair@286 46 extends WebServiceException implements Localizable {
ohair@286 47
ohair@286 48 //Don't worry about previous serialVersionUID = 4818235090198755494L;, this class was not serializable before.
ohair@286 49 private static final long serialVersionUID = 1L;
ohair@286 50
ohair@286 51 private transient Localizable msg;
ohair@286 52
ohair@286 53 /**
ohair@286 54 * @deprecated
ohair@286 55 * Should use the localizable constructor instead.
ohair@286 56 */
ohair@286 57 protected JAXWSExceptionBase(String key, Object... args) {
ohair@286 58 super(findNestedException(args));
alanb@368 59 this.msg = new LocalizableMessage(getDefaultResourceBundleName(), key, args);
ohair@286 60 }
ohair@286 61
ohair@286 62
ohair@286 63 protected JAXWSExceptionBase(String message) {
ohair@286 64 this(new NullLocalizable(message));
ohair@286 65 }
ohair@286 66
ohair@286 67 /**
ohair@286 68 * Creates a new exception that wraps the specified exception.
ohair@286 69 */
ohair@286 70 protected JAXWSExceptionBase(Throwable throwable) {
ohair@286 71 this(new NullLocalizable(throwable.toString()),throwable);
ohair@286 72 }
ohair@286 73
ohair@286 74 protected JAXWSExceptionBase(Localizable msg) {
ohair@286 75 this.msg = msg;
ohair@286 76 }
ohair@286 77
ohair@286 78 protected JAXWSExceptionBase(Localizable msg, Throwable cause) {
ohair@286 79 super(cause);
ohair@286 80 this.msg = msg;
ohair@286 81 }
ohair@286 82
ohair@286 83 /**
ohair@286 84 * @serialData Default fields, followed by information in Localizable which comprises of.
ohair@286 85 * ResourceBundle name, then key and followed by arguments array.
ohair@286 86 * If there is no arguments array, then -1 is written. If there is a argument array (possible of zero
ohair@286 87 * length) then the array length is written as an integer, followed by each argument (Object).
ohair@286 88 * If the Object is serializable, the argument is written. Otherwise the output of Object.toString()
ohair@286 89 * is written.
ohair@286 90 */
ohair@286 91 private void writeObject(ObjectOutputStream out) throws IOException {
ohair@286 92 // We have to call defaultWriteObject first.
ohair@286 93 out.defaultWriteObject();
ohair@286 94
ohair@286 95 out.writeObject(msg.getResourceBundleName());
ohair@286 96 out.writeObject(msg.getKey());
ohair@286 97 Object[] args = msg.getArguments();
ohair@286 98 if (args == null) {
ohair@286 99 out.writeInt(-1);
ohair@286 100 return;
ohair@286 101 }
ohair@286 102 out.writeInt(args.length);
ohair@286 103 // Write Object values for the parameters, if it is serializable otherwise write String form of it..
ohair@286 104 for (int i = 0; i < args.length; i++) {
ohair@286 105 if (args[i] == null || args[i] instanceof Serializable) {
ohair@286 106 out.writeObject(args[i]);
ohair@286 107 } else {
ohair@286 108 out.writeObject(args[i].toString());
ohair@286 109 }
ohair@286 110 }
ohair@286 111 }
ohair@286 112
ohair@286 113 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
ohair@286 114 // We have to call defaultReadObject first.
ohair@286 115 in.defaultReadObject();
ohair@286 116 Object[] args;
ohair@286 117 String resourceBundleName = (String) in.readObject();
ohair@286 118 String key = (String) in.readObject();
ohair@286 119 int len = in.readInt();
ohair@286 120 if (len == -1) {
ohair@286 121 args = null;
ohair@286 122 } else {
ohair@286 123 args = new Object[len];
ohair@286 124 for (int i = 0; i < args.length; i++) {
ohair@286 125 args[i] = in.readObject();
ohair@286 126 }
ohair@286 127 }
ohair@286 128 msg = new LocalizableMessageFactory(resourceBundleName).getMessage(key,args);
ohair@286 129 }
ohair@286 130
ohair@286 131 private static Throwable findNestedException(Object[] args) {
ohair@286 132 if (args == null)
ohair@286 133 return null;
ohair@286 134
ohair@286 135 for( Object o : args )
ohair@286 136 if(o instanceof Throwable)
ohair@286 137 return (Throwable)o;
ohair@286 138 return null;
ohair@286 139 }
ohair@286 140
ohair@286 141 public String getMessage() {
ohair@286 142 Localizer localizer = new Localizer();
ohair@286 143 return localizer.localize(this);
ohair@286 144 }
ohair@286 145
ohair@286 146 /**
ohair@286 147 * Gets the default resource bundle name for this kind of exception.
ohair@286 148 * Used for {@link #JAXWSExceptionBase(String, Object[])}.
ohair@286 149 */
ohair@286 150 protected abstract String getDefaultResourceBundleName();
ohair@286 151
ohair@286 152 //
ohair@286 153 // Localizable delegation
ohair@286 154 //
ohair@286 155 public final String getKey() {
ohair@286 156 return msg.getKey();
ohair@286 157 }
ohair@286 158
ohair@286 159 public final Object[] getArguments() {
ohair@286 160 return msg.getArguments();
ohair@286 161 }
ohair@286 162
ohair@286 163 public final String getResourceBundleName() {
ohair@286 164 return msg.getResourceBundleName();
ohair@286 165 }
ohair@286 166 }

mercurial