Author: Grid.Qian
Date: 2010-03-03 04:35:43 -0500 (Wed, 03 Mar 2010)
New Revision: 20585
Modified:
branches/jbosstools-3.0.x/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ImplementationClassCreationCommand.java
Log:
JBIDE-5924: Intermittent issue with generating Web Service classes from WSDL(to 3.0.x
branch)
Modified:
branches/jbosstools-3.0.x/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ImplementationClassCreationCommand.java
===================================================================
---
branches/jbosstools-3.0.x/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ImplementationClassCreationCommand.java 2010-03-03
09:19:41 UTC (rev 20584)
+++
branches/jbosstools-3.0.x/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ImplementationClassCreationCommand.java 2010-03-03
09:35:43 UTC (rev 20585)
@@ -60,17 +60,16 @@
public class ImplementationClassCreationCommand extends
AbstractDataModelOperation {
- private static final String RESOURCE_FOLDER = "src";
+ private static final String RESOURCE_FOLDER = "src"; //$NON-NLS-1$
- private static final String PREFIX_JAXWS_ANNOTATION_CLASS = "javax.jws";
- private static final String DEFAULT_CU_SUFFIX = ".java";
+ private static final String PREFIX_JAXWS_ANNOTATION_CLASS = "javax.jws";
//$NON-NLS-1$
+ private static final String DEFAULT_CU_SUFFIX = ".java"; //$NON-NLS-1$
- private static final String ANNOTATION_WEB_SERVICE_FULLNAME =
"javax.jws.WebService";
- private static final String ANNOTATION_TYPE_NAME_WEBSERVICE = "WebService";;
- private static final String ANNOTATION_PROPERTY_NAME = "name";
- private static final String ANNOTATION_PROPERTY_SERVICE_NAME = "serviceName";
- private static final String ANNOTATION_PROPERTY_ENDPOINT_INTERFACE =
"endpointInterface";
-
+ private static final String ANNOTATION_WEB_SERVICE_FULLNAME =
"javax.jws.WebService"; //$NON-NLS-1$
+ private static final String ANNOTATION_TYPE_NAME_WEBSERVICE = "WebService";;
//$NON-NLS-1$
+ private static final String ANNOTATION_PROPERTY_NAME = "name"; //$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 ServiceModel model;
private IWorkspaceRoot fWorkspaceRoot;
@@ -84,19 +83,20 @@
@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
-
- // if the user does not check the generate implementation class button, do nothing
- if(!model.isGenImplementation()){
+
+ // if the user does not check the generate implementation class button,
+ // do nothing
+ if (!model.isGenImplementation()) {
return Status.OK_STATUS;
}
-
+
IStatus status = Status.OK_STATUS;
-
+
try {
List<String> portTypes = model.getPortTypes();
for (String portTypeName : portTypes) {
- generateImplClass(portTypeName);
- String implClsName = getImplPackageName() + "."
+ generateImplClass(formatPortTypeName(portTypeName));
+ String implClsName = getImplPackageName() + "." //$NON-NLS-1$
+ getImplClassName(portTypeName);
model.addServiceClasses(implClsName);
}
@@ -117,6 +117,16 @@
return status;
}
+ private String formatPortTypeName(String portTypeName) {
+ if (portTypeName == null || "".equals(portTypeName)) {//$NON-NLS-1$
+ return portTypeName;
+ }
+ StringBuffer buf = new StringBuffer();
+ String tem = buf.append(Character.toUpperCase(portTypeName.charAt(0)))
+ .append(portTypeName.substring(1)).toString();
+ return tem;
+ }
+
protected void generateImplClass(String portTypeName/* , IFile implJavaFile */)
throws CoreException, BadLocationException {
@@ -171,7 +181,7 @@
ast.newSimpleType(ast.newName(portTypeName)));
// add Logger variable declaration
- //createLoggerField(ast, type, portTypeName);
+ // createLoggerField(ast, type, portTypeName);
// add method implementation
TypeDeclaration inTD = (TypeDeclaration) portTypeCU.types().get(0);
@@ -186,7 +196,6 @@
}
implCu.types().add(type);
-
// try to save the Java file
TextEdit edits = implCu.rewrite(document, icu.getJavaProject()
@@ -225,7 +234,7 @@
String firstLetter = portTypeName.substring(0, 1);
String implClsName = firstLetter.toUpperCase()
+ portTypeName.substring(1);
- implClsName = implClsName + "Impl";
+ implClsName = implClsName + "Impl"; //$NON-NLS-1$
return implClsName;
}
@@ -243,7 +252,7 @@
}
private String getPortTypeInterfaceFullName(String portTypeName) {
- return model.getCustomPackage() + "." + portTypeName;
+ return model.getCustomPackage() + "." + portTypeName; //$NON-NLS-1$
}
private void addImportsToImplementationClass(CompilationUnit implCU,
@@ -260,7 +269,7 @@
implCU.imports().add(newId);
}
- // import port type interface
+ // import port type interface
ImportDeclaration importDec = implAST.newImportDeclaration();
QualifiedName portTypeImport = implAST.newQualifiedName(implAST
.newName(portTypeCU.getPackage().getName()
@@ -268,9 +277,9 @@
.newSimpleName(portTypeName));
importDec.setName(portTypeImport);
implCU.imports().add(importDec);
- //importDec = implAST.newImportDeclaration();
- //importDec.setName(implAST.newName(LOGGER_CLASS_FULLNAME));
- //implCU.imports().add(importDec);
+ // importDec = implAST.newImportDeclaration();
+ // importDec.setName(implAST.newName(LOGGER_CLASS_FULLNAME));
+ // implCU.imports().add(importDec);
// import jaxws WebService
importDec = implAST.newImportDeclaration();
@@ -310,7 +319,6 @@
return member;
}
-
protected MethodDeclaration createMethodForImplClass(AST ast,
MethodDeclaration inMethod) {
@@ -325,7 +333,7 @@
md.setReturnType2(sType);
List parameters = inMethod.parameters();
-
+
for (Object obj : parameters) {
SingleVariableDeclaration implSvd = ast
.newSingleVariableDeclaration();
@@ -339,8 +347,9 @@
// create method body
Block block = ast.newBlock();
// add log info statement
- //block.statements().add(createLoggerInvokeStatement(ast,
md.getName().getFullyQualifiedName()));
-
+ // block.statements().add(createLoggerInvokeStatement(ast,
+ // md.getName().getFullyQualifiedName()));
+
Type returnType = inMethod.getReturnType2();
ReturnStatement rs = ast.newReturnStatement();
@@ -349,28 +358,27 @@
PrimitiveType.BOOLEAN)) {
BooleanLiteral bl = ast.newBooleanLiteral(false);
rs.setExpression(bl);
- }else if(((PrimitiveType) returnType).getPrimitiveTypeCode().equals(
- PrimitiveType.VOID)) {
+ } else if (((PrimitiveType) returnType).getPrimitiveTypeCode()
+ .equals(PrimitiveType.VOID)) {
// do nothing
- }else {
+ } else {
NumberLiteral nl = ast.newNumberLiteral();
- nl.setToken("0");
+ nl.setToken("0"); //$NON-NLS-1$
rs.setExpression(nl);
}
} else if (returnType.isSimpleType()) {
String typeName = ((SimpleType) returnType).getName()
.getFullyQualifiedName();
- if ("String".equals(typeName)) {
+ if ("String".equals(typeName)) { //$NON-NLS-1$
StringLiteral sl = ast.newStringLiteral();
- sl.setLiteralValue("");
+ sl.setLiteralValue(""); //$NON-NLS-1$
rs.setExpression(sl);
- } else{
+ } else {
rs.setExpression(ast.newNullLiteral());
}
-
-
+
} else {
rs.setExpression(ast.newNullLiteral());
}
@@ -382,7 +390,6 @@
return md;
}
-
private Type copyTypeFromOtherASTNode(AST ast, Type type) {
if (type instanceof PrimitiveType) {
return ast.newPrimitiveType(((PrimitiveType) type)
@@ -398,11 +405,12 @@
.getComponentType()));
} else if (type instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType) type;
- ParameterizedType newParaType = ast.newParameterizedType(copyTypeFromOtherASTNode(ast,
ptype
- .getType()));
- for(Object arg : ptype.typeArguments()){
- if(arg instanceof Type){
- Type newArg = copyTypeFromOtherASTNode(ast, (Type)arg);
+ ParameterizedType newParaType = ast
+ .newParameterizedType(copyTypeFromOtherASTNode(ast, ptype
+ .getType()));
+ for (Object arg : ptype.typeArguments()) {
+ if (arg instanceof Type) {
+ Type newArg = copyTypeFromOtherASTNode(ast, (Type) arg);
newParaType.typeArguments().add(newArg);
}
}
@@ -432,10 +440,13 @@
return importList;
}
- private CompilationUnit getCompilationUnitForInterface(String portTypeName) throws
CoreException {
+ private CompilationUnit getCompilationUnitForInterface(String portTypeName)
+ throws CoreException {
IFile inFile = getServiceInterfaceFile(portTypeName);
- if(!inFile.exists()){
- throw new
CoreException(StatusUtils.errorStatus(JBossWSCreationCoreMessages.Error_Message_Failed_To_Generate_Code));
+ if (!inFile.exists()) {
+ throw new CoreException(
+ StatusUtils
+ .errorStatus(JBossWSCreationCoreMessages.Error_Message_Failed_To_Generate_Code));
}
ICompilationUnit icu = JBossWSCreationUtils.getJavaUnitFromFile(inFile);
ASTParser astp = ASTParser.newParser(AST.JLS3);
@@ -456,7 +467,7 @@
IProject project = JBossWSCreationUtils.getProjectByName(model
.getWebProjectName());
IFolder srcFolder = project.getFolder(RESOURCE_FOLDER);
- String pkgFolderName = model.getCustomPackage().replace(".",
+ String pkgFolderName = model.getCustomPackage().replace(".", //$NON-NLS-1$
File.separator);
return srcFolder.getFolder(pkgFolderName);