1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/*******************************************************************************
* Copyright (c) 2009 Shane Clarke.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Shane Clarke - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.ws.internal.jaxws.ui.annotations.initialization;
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.CLASS_NAME;
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.DOT_CHARACTER;
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.JAXWS_SUBPACKAGE;
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.LOCAL_NAME;
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.OPERATION_NAME;
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.TARGET_NAMESPACE;
import java.util.ArrayList;
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebService;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.MemberValuePair;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jst.ws.annotations.core.AnnotationsCore;
import org.eclipse.jst.ws.annotations.core.initialization.AnnotationAttributeInitializer;
import org.eclipse.jst.ws.annotations.core.utils.AnnotationUtils;
import org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils;
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIPlugin;
import org.eclipse.jst.ws.jaxws.core.utils.JDTUtils;
public class RequestWrapperAttributeInitializer extends AnnotationAttributeInitializer {
@Override
public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast, IType annotationType) {
List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
if (javaElement.getElementType() == IJavaElement.METHOD) {
IMethod method = (IMethod) javaElement;
IType type = method.getCompilationUnit().findPrimaryType();
MemberValuePair classNameValuePair = AnnotationsCore.createStringMemberValuePair(ast, CLASS_NAME,
getClassName(type, method));
MemberValuePair localNameValuePair = AnnotationsCore.createStringMemberValuePair(ast, LOCAL_NAME,
getLocalName(type, method));
MemberValuePair targetNamespaceValuePair = AnnotationsCore.createStringMemberValuePair(ast,
TARGET_NAMESPACE, getTargetNamespace(type));
memberValuePairs.add(classNameValuePair);
memberValuePairs.add(localNameValuePair);
memberValuePairs.add(targetNamespaceValuePair);
}
return memberValuePairs;
}
public List<ICompletionProposal> getCompletionProposalsForMemberValuePair(IJavaElement javaElement,
MemberValuePair memberValuePair) {
List<ICompletionProposal> completionProposals = new ArrayList<ICompletionProposal>(1);
if (javaElement.getElementType() == IJavaElement.METHOD) {
IMethod method = (IMethod) javaElement;
IType type = method.getCompilationUnit().findPrimaryType();
String memberValuePairName = memberValuePair.getName().getIdentifier();
if (memberValuePairName.equals(CLASS_NAME)) {
completionProposals.add(createCompletionProposal(getClassName(type, method),
memberValuePair.getValue()));
}
if (memberValuePairName.equals(LOCAL_NAME)) {
completionProposals.add(createCompletionProposal(getLocalName(type, method),
memberValuePair.getValue()));
}
if (memberValuePairName.equals(TARGET_NAMESPACE)) {
completionProposals.add(createCompletionProposal(getTargetNamespace(type),
memberValuePair.getValue()));
}
}
return completionProposals;
}
protected String getPackageName(IType type) {
StringBuilder packageName = new StringBuilder(type.getPackageFragment().getElementName());
if (packageName.length() > 0) {
packageName.append(DOT_CHARACTER);
}
packageName.append(JAXWS_SUBPACKAGE);
packageName.append(DOT_CHARACTER);
return packageName.toString();
}
protected String getClassName(IType type, IMethod method) {
try {
String methodName = method.getElementName();
return getPackageName(type) + methodName.substring(0, 1).toUpperCase()
+ methodName.substring(1) + JAXWSUtils.accountForOverloadedMethods(method);
} catch (JavaModelException jme) {
JAXWSUIPlugin.log(jme.getStatus());
}
return ""; //$NON-NLS-1$
}
protected String getLocalName(IType type, IMethod method) {
try {
IAnnotation annotation = AnnotationUtils.getAnnotation(WebMethod.class, method);
if (annotation != null) {
String operationName = AnnotationUtils.getStringValue(annotation, OPERATION_NAME);
if (operationName != null) {
return operationName;
}
}
return method.getElementName() + JAXWSUtils.accountForOverloadedMethods(method);
} catch (JavaModelException jme) {
JAXWSUIPlugin.log(jme.getStatus());
}
return ""; //$NON-NLS-1$
}
protected String getTargetNamespace(IType type) {
try {
IAnnotation annotation = AnnotationUtils.getAnnotation(WebService.class, type);
if (annotation != null) {
String targetNamespace = AnnotationUtils.getStringValue(annotation, TARGET_NAMESPACE);
if (targetNamespace != null && targetNamespace.length() > 0) {
return targetNamespace;
}
}
return JDTUtils.getTargetNamespaceFromPackageName(type.getPackageFragment().getElementName());
} catch (JavaModelException jme) {
JAXWSUIPlugin.log(jme.getStatus());
}
return ""; //$NON-NLS-1$
}
}
|