Author: bfitzpat
Date: 2010-10-05 10:09:08 -0400 (Tue, 05 Oct 2010)
New Revision: 25492
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ImplementationClassCreationCommand.java
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/WSDLPropertyReader.java
Log:
JBIDE-7234: JAX-WS generated portType implementation has incorrect @WebService annotation
- now we get the service name and target namespace from the WSDL if they're available
and use them as defaults
https://jira.jboss.org/browse/JBIDE-7234
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ImplementationClassCreationCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ImplementationClassCreationCommand.java 2010-10-05
13:55:18 UTC (rev 25491)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ImplementationClassCreationCommand.java 2010-10-05
14:09:08 UTC (rev 25492)
@@ -1,9 +1,13 @@
package org.jboss.tools.ws.creation.core.commands;
import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
+import javax.wsdl.WSDLException;
+
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -54,6 +58,7 @@
import org.jboss.tools.ws.creation.core.data.ServiceModel;
import org.jboss.tools.ws.creation.core.messages.JBossWSCreationCoreMessages;
import org.jboss.tools.ws.creation.core.utils.JBossWSCreationUtils;
+import org.jboss.tools.ws.creation.core.utils.WSDLPropertyReader;
public class ImplementationClassCreationCommand extends
AbstractDataModelOperation {
@@ -65,6 +70,7 @@
private static final String ANNOTATION_TYPE_NAME_WEBSERVICE = "WebService";;
//$NON-NLS-1$
private static final String ANNOTATION_PROPERTY_SERVICE_NAME = "serviceName";
//$NON-NLS-1$
private static final String ANNOTATION_PROPERTY_ENDPOINT_INTERFACE =
"endpointInterface"; //$NON-NLS-1$
+ private static final String ANNOTATION_PROPERTY_TNS = "targetNamespace";
//$NON-NLS-1$
private ServiceModel model;
private IWorkspaceRoot fWorkspaceRoot;
@@ -133,6 +139,42 @@
return status;
}
+ protected String getTNSFromWSDL() {
+ WSDLPropertyReader reader = new WSDLPropertyReader();
+ try {
+ URI fileURI = new URI(model.getWsdlURI());
+ File tempFile = new File(fileURI);
+ reader.readWSDL(tempFile.getAbsolutePath());
+ return reader.getTargetnamespace();
+ } catch (WSDLException e) {
+ e.printStackTrace();
+ } catch (URISyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ protected String getServiceNameFromWSDL() {
+ WSDLPropertyReader reader = new WSDLPropertyReader();
+
+ try {
+ URI fileURI = new URI(model.getWsdlURI());
+ File tempFile = new File(fileURI);
+ reader.readWSDL(tempFile.getAbsolutePath());
+ List<String> services = reader.getServiceList();
+ if (services != null && services.size() > 0) {
+ return services.get(0);
+ }
+ } catch (WSDLException e) {
+ e.printStackTrace();
+ } catch (URISyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
@SuppressWarnings("unchecked")
protected void generateImplClass(ICompilationUnit service)
throws CoreException, BadLocationException {
@@ -144,6 +186,10 @@
String className = getClassName(service.getElementName());
String implFileName = getJavaFileName(className);
+
+ String serviceName = getServiceNameFromWSDL();
+
+ String targetNamespace = getTNSFromWSDL();
ICompilationUnit icu = pack.createCompilationUnit(implFileName,
"", true, null); //$NON-NLS-1$
@@ -180,7 +226,12 @@
type.setInterface(false);
// add WebService annotation
String endpoint = getServiceInterfaceFullName(className);
- NormalAnnotation ann = createAnnotation(ast, className, endpoint);
+ NormalAnnotation ann = null;
+ if (serviceName != null) {
+ ann = createAnnotation(ast, serviceName, endpoint, targetNamespace);
+ } else {
+ ann = createAnnotation(ast, className, endpoint, targetNamespace);
+ }
type.modifiers().add(ann);
type.modifiers().add(
ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
@@ -301,7 +352,7 @@
*/
@SuppressWarnings("unchecked")
protected NormalAnnotation createAnnotation(AST ast, String serviceName,
- String endpoint) {
+ String endpoint, String targetNamespace) {
NormalAnnotation ann = ast.newNormalAnnotation();
ann.setTypeName(ast.newSimpleName(ANNOTATION_TYPE_NAME_WEBSERVICE));
@@ -311,6 +362,11 @@
member = createMemberValuePair(ast,
ANNOTATION_PROPERTY_ENDPOINT_INTERFACE, endpoint);
ann.values().add(member);
+ if (targetNamespace != null) {
+ member = createMemberValuePair(ast,
+ ANNOTATION_PROPERTY_TNS, targetNamespace);
+ ann.values().add(member);
+ }
return ann;
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/WSDLPropertyReader.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/WSDLPropertyReader.java 2010-10-05
13:55:18 UTC (rev 25491)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/WSDLPropertyReader.java 2010-10-05
14:09:08 UTC (rev 25492)
@@ -226,4 +226,9 @@
return returnList;
}
+ public String getTargetnamespace() {
+ String tns = definition.getTargetNamespace();
+ return tns;
+ }
+
}