1/*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.xml.internal.ws.model;
27
28import java.lang.reflect.Method;
29
30import com.sun.xml.internal.bind.api.Bridge;
31import com.sun.xml.internal.ws.api.model.CheckedException;
32import com.sun.xml.internal.ws.api.model.ExceptionType;
33import com.sun.xml.internal.ws.api.model.JavaMethod;
34import com.sun.xml.internal.ws.addressing.WsaActionUtil;
35import com.sun.xml.internal.ws.spi.db.XMLBridge;
36import com.sun.xml.internal.ws.spi.db.TypeInfo;
37
38/**
39 * CheckedException class. Holds the exception class - class that has public
40 * constructor
41 *
42 * <code>public WrapperException()String message, FaultBean){}</code>
43 *
44 * and method
45 *
46 * <code>public FaultBean getFaultInfo();</code>
47 *
48 * @author Vivek Pandey
49 */
50public final class CheckedExceptionImpl implements CheckedException {
51    private final Class exceptionClass;
52    private final TypeInfo detail;
53    private final ExceptionType exceptionType;
54    private final JavaMethodImpl javaMethod;
55    private String messageName;
56    private String faultAction = "";
57    private Method faultInfoGetter;
58
59    /**
60     * @param jm {@link JavaMethodImpl} that throws this exception
61     * @param exceptionClass
62     *            Userdefined or WSDL exception class that extends
63     *            java.lang.Exception.
64     * @param detail
65     *            detail or exception bean's TypeReference
66     * @param exceptionType
67     *            either ExceptionType.UserDefined or
68     */
69    public CheckedExceptionImpl(JavaMethodImpl jm, Class exceptionClass, TypeInfo detail, ExceptionType exceptionType) {
70        this.detail = detail;
71        this.exceptionType = exceptionType;
72        this.exceptionClass = exceptionClass;
73        this.javaMethod = jm;
74    }
75
76    public AbstractSEIModelImpl getOwner() {
77        return javaMethod.owner;
78    }
79
80    public JavaMethod getParent() {
81        return javaMethod;
82    }
83
84    /**
85     * @return the <code>Class</clode> for this object
86     *
87     */
88    public Class getExceptionClass() {
89        return exceptionClass;
90    }
91
92    public Class getDetailBean() {
93        return (Class) detail.type;
94    }
95    /** @deprecated */
96    public Bridge getBridge() {
97//TODO        return getOwner().getBridge(detail);
98        return null;
99    }
100
101    public XMLBridge getBond() {
102        return getOwner().getXMLBridge(detail);
103    }
104
105    public TypeInfo getDetailType() {
106        return detail;
107    }
108
109    public ExceptionType getExceptionType() {
110        return exceptionType;
111    }
112
113    public String getMessageName() {
114        return messageName;
115    }
116
117    public void setMessageName(String messageName) {
118        this.messageName = messageName;
119    }
120
121    public String getFaultAction() {
122        return faultAction;
123    }
124
125    public void setFaultAction(String faultAction) {
126        this.faultAction = faultAction;
127    }
128
129    public String getDefaultFaultAction() {
130        return WsaActionUtil.getDefaultFaultAction(javaMethod,this);
131    }
132
133    public Method getFaultInfoGetter() {
134        return faultInfoGetter;
135    }
136
137    public void setFaultInfoGetter(Method faultInfoGetter) {
138        this.faultInfoGetter = faultInfoGetter;
139    }
140}
141