|
1 /* |
|
2 * Copyright (c) 1997, 2012, 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 |
|
26 package com.sun.tools.internal.ws.processor.generator; |
|
27 |
|
28 import com.sun.codemodel.internal.JAnnotationArrayMember; |
|
29 import com.sun.codemodel.internal.JAnnotationUse; |
|
30 import com.sun.codemodel.internal.JClass; |
|
31 import com.sun.codemodel.internal.JMethod; |
|
32 import com.sun.tools.internal.ws.api.TJavaGeneratorExtension; |
|
33 import com.sun.tools.internal.ws.api.wsdl.TWSDLOperation; |
|
34 import com.sun.tools.internal.ws.wsdl.document.Fault; |
|
35 import com.sun.tools.internal.ws.wsdl.document.Operation; |
|
36 |
|
37 import javax.xml.ws.Action; |
|
38 import javax.xml.ws.FaultAction; |
|
39 import java.util.Map; |
|
40 |
|
41 /** |
|
42 * This Java Generator extension generates @Action annotation on web methods if an explicit wsam:Action value is specified |
|
43 * in the wsdl definitions. |
|
44 * |
|
45 * @author Arun Gupta |
|
46 */ |
|
47 public class W3CAddressingJavaGeneratorExtension extends TJavaGeneratorExtension { |
|
48 @Override |
|
49 public void writeMethodAnnotations(TWSDLOperation two, JMethod jMethod) { |
|
50 JAnnotationUse actionAnn = null; |
|
51 |
|
52 if (!(two instanceof Operation)) |
|
53 return; |
|
54 |
|
55 Operation o = ((Operation)two); |
|
56 |
|
57 // explicit input action |
|
58 if (o.getInput().getAction() != null && !o.getInput().getAction().equals("")) { |
|
59 // explicitly specified |
|
60 actionAnn = jMethod.annotate(Action.class); |
|
61 actionAnn.param("input", o.getInput().getAction()); |
|
62 } |
|
63 |
|
64 // explicit output action |
|
65 if (o.getOutput() != null && o.getOutput().getAction() != null && !o.getOutput().getAction().equals("")) { |
|
66 // explicitly specified |
|
67 if (actionAnn == null) |
|
68 actionAnn = jMethod.annotate(Action.class); |
|
69 |
|
70 actionAnn.param("output", o.getOutput().getAction()); |
|
71 } |
|
72 |
|
73 // explicit fault action |
|
74 if (o.getFaults() != null && o.getFaults().size() > 0) { |
|
75 Map<String, JClass> map = o.getFaults(); |
|
76 JAnnotationArrayMember jam = null; |
|
77 |
|
78 for (Fault f : o.faults()) { |
|
79 if (f.getAction() == null) |
|
80 continue; |
|
81 |
|
82 if (f.getAction().equals("")) |
|
83 continue; |
|
84 |
|
85 if (actionAnn == null) { |
|
86 actionAnn = jMethod.annotate(Action.class); |
|
87 } |
|
88 if (jam == null) { |
|
89 jam = actionAnn.paramArray("fault"); |
|
90 } |
|
91 final JAnnotationUse faAnn = jam.annotate(FaultAction.class); |
|
92 faAnn.param("className", map.get(f.getName())); |
|
93 faAnn.param("value", f.getAction()); |
|
94 } |
|
95 } |
|
96 } |
|
97 } |