Index: src/org/jboss/tools/ws/creation/core/commands/InitialClientCommand.java =================================================================== --- src/org/jboss/tools/ws/creation/core/commands/InitialClientCommand.java (revision 23989) +++ src/org/jboss/tools/ws/creation/core/commands/InitialClientCommand.java (working copy) @@ -11,8 +11,6 @@ package org.jboss.tools.ws.creation.core.commands; -import javax.wsdl.WSDLException; - import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; @@ -24,11 +22,9 @@ import org.eclipse.wst.ws.internal.wsrt.IWebServiceClient; import org.eclipse.wst.ws.internal.wsrt.WebServiceScenario; import org.jboss.tools.ws.core.utils.StatusUtils; -import org.jboss.tools.ws.creation.core.JBossWSCreationCorePlugin; 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; /** * @author Grid Qian @@ -59,8 +55,10 @@ if (location.equals("")) { //$NON-NLS-1$ return StatusUtils .errorStatus(JBossWSCreationCoreMessages.Error_WS_Location); - } else if (!new Path(location).append(JBossWSCreationCoreMessages.Bin) - .append(JBossWSCreationCoreMessages.Command).toFile().exists()) { + } else if (!new Path(location) + .append(JBossWSCreationCoreMessages.Bin) + .append(JBossWSCreationCoreMessages.Command).toFile() + .exists()) { return StatusUtils .errorStatus(JBossWSCreationCoreMessages.Error_WS_Location); } @@ -70,20 +68,9 @@ } model.setTarget(JBossWSCreationCoreMessages.Value_Target_0); if (scenario == WebServiceScenario.CLIENT) { - try { - model.setWsdlURI(wsClient.getWebServiceClientInfo() - .getWsdlURL()); - WSDLPropertyReader reader = new WSDLPropertyReader(); - reader - .readWSDL(wsClient.getWebServiceClientInfo() - .getWsdlURL()); - model.setCustomPackage(""); //$NON-NLS-1$ - model.setServiceList(reader.getServiceList()); - model.setPortTypeList(reader.getPortTypeList()); - } catch (WSDLException e) { - JBossWSCreationCorePlugin.getDefault().logError(e); - return StatusUtils.errorStatus(e.getLocalizedMessage(), e); - } + model.setWsdlURI(wsClient.getWebServiceClientInfo().getWsdlURL()); + model.setCustomPackage(""); //$NON-NLS-1$ + } return Status.OK_STATUS; Index: src/org/jboss/tools/ws/creation/core/commands/ClientSampleCreationCommand.java =================================================================== --- src/org/jboss/tools/ws/creation/core/commands/ClientSampleCreationCommand.java (revision 23989) +++ src/org/jboss/tools/ws/creation/core/commands/ClientSampleCreationCommand.java (working copy) @@ -51,7 +51,6 @@ public static final String LINE_SEPARATOR = System .getProperty("line.separator"); //$NON-NLS-1$ private static final String PACAKAGE = ".*"; //$NON-NLS-1$ - private static final String PACAKAGESPLIT = "\\."; //$NON-NLS-1$ private ServiceModel model; private int serviceNum = 1; @@ -77,16 +76,45 @@ } // find web service client classes - List clientUnits = findJavaUnitsByAnnotation(project, - JBossWSCreationCoreMessages.WebserviceClient_Annotation); + List clientUnits = JBossWSCreationUtils + .findJavaUnitsByAnnotation( + project, + JBossWSCreationCoreMessages.WebserviceClient_Annotation, + model.getCustomPackage()); // find web service classes - List serviceUnits = findJavaUnitsByAnnotation( - project, - JBossWSCreationCoreMessages.Webservice_Annotation_Check); + List serviceUnits = JBossWSCreationUtils + .findJavaUnitsByAnnotation( + project, + JBossWSCreationCoreMessages.Webservice_Annotation_Check, + model.getCustomPackage()); + if (clientUnits.size() == 0) { + return status; + } + + List packageList = new LinkedList(); + for (ICompilationUnit unit : clientUnits) { + if (!packageList.contains(unit.getParent().getElementName())) { + packageList.add(unit.getParent().getElementName()); + } + } + for (int j = 0; j < packageList.size(); j++) { + status = createImplClass(packageList.get(j), project, + clientUnits, serviceUnits); + if (!status.isOK()) { + break; + } + } + + return status; + } + + private IStatus createImplClass(String packageName, IJavaProject project, + List clientUnits, + List serviceUnits) { // create a client sample class - ICompilationUnit clientCls = createJavaClass(model.getCustomPackage() + ICompilationUnit clientCls = createJavaClass(packageName + JBossWSCreationCoreMessages.Client_Sample_Package_Name, JBossWSCreationCoreMessages.Client_Sample_Class_Name, false, null, project); @@ -97,8 +125,7 @@ // add imports to client sample class try { - clientCls.createImport(model.getCustomPackage() + PACAKAGE, null, - null); + clientCls.createImport(packageName + PACAKAGE, null, null); clientCls.save(null, true); } catch (Exception e1) { JBossWSCreationCorePlugin.getDefault().logError(e1); @@ -114,12 +141,12 @@ sb.append(LINE_SEPARATOR); sb.append(" System.out.println(\"***********************\");"); //$NON-NLS-1$ sb.append(LINE_SEPARATOR); - createWebServiceClient(clientUnits, serviceUnits, sb); + createWebServiceClient(clientUnits, serviceUnits, sb,packageName); sb.append(" System.out.println(\"***********************\");"); //$NON-NLS-1$ sb.append(LINE_SEPARATOR); sb.append(" System.out.println(\"").append( //$NON-NLS-1$ - JBossWSCreationCoreMessages.Client_Sample_Run_Over).append( - "\");"); //$NON-NLS-1$ + JBossWSCreationCoreMessages.Client_Sample_Run_Over) + .append("\");"); //$NON-NLS-1$ sb.append(LINE_SEPARATOR); sb.append("}"); //$NON-NLS-1$ try { @@ -130,8 +157,7 @@ return StatusUtils .errorStatus(JBossWSCreationCoreMessages.Error_Create_Client_Sample); } - - return status; + return Status.OK_STATUS; } /** @@ -142,7 +168,6 @@ * @param method * @param sb */ - @SuppressWarnings("unchecked") private void createWebService(List serviceUnits, MethodDeclaration method, StringBuffer sb) { sb.append(" System.out.println(\"" //$NON-NLS-1$ @@ -161,10 +186,11 @@ parser.setResolveBindings(false); parser.setFocalPosition(0); CompilationUnit result = (CompilationUnit) parser.createAST(null); + @SuppressWarnings("rawtypes") List types = result.types(); TypeDeclaration typeDec1 = (TypeDeclaration) types.get(0); - if (typeDec1.getName().toString().equals( - method.getReturnType2().toString())) { + if (typeDec1.getName().toString() + .equals(method.getReturnType2().toString())) { callWebServiceOperation(typeDec1, sb); } } @@ -198,15 +224,14 @@ boolean noNull = true; for (int j = 0; j < method.parameters().size(); j++) { - noNull = createWebServiceOperationParameters(method - .parameters(), sb, j) + noNull = createWebServiceOperationParameters( + method.parameters(), sb, j) && noNull; } sb.append("));"); //$NON-NLS-1$ sb.append(LINE_SEPARATOR); if (!noNull) { - sb - .append(" //Please input the parameters instead of 'null' for the upper method!"); //$NON-NLS-1$ + sb.append(" //Please input the parameters instead of 'null' for the upper method!"); //$NON-NLS-1$ sb.append(LINE_SEPARATOR); sb.append(LINE_SEPARATOR); } @@ -222,9 +247,8 @@ * @param sb * @param j */ - @SuppressWarnings("unchecked") - private boolean createWebServiceOperationParameters(List list, - StringBuffer sb, int j) { + private boolean createWebServiceOperationParameters( + @SuppressWarnings("rawtypes") List list, StringBuffer sb, int j) { SingleVariableDeclaration para = (SingleVariableDeclaration) list .get(j); @@ -255,19 +279,21 @@ * @param serviceUnits * @param sb */ - @SuppressWarnings("unchecked") - private void createWebServiceClient(List clientUnits, - List serviceUnits, StringBuffer sb) { + private void createWebServiceClient(List clientUnits,List serviceUnits, StringBuffer sb,String packageName) { sb.append(" System.out.println(\"" //$NON-NLS-1$ + "Create Web Service Client...\");"); //$NON-NLS-1$ sb.append(LINE_SEPARATOR); for (ICompilationUnit unit : clientUnits) { // parse the unit + if(!packageName.equals(unit.getParent().getElementName())){ + continue; + } ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(unit); parser.setResolveBindings(false); parser.setFocalPosition(0); CompilationUnit result = (CompilationUnit) parser.createAST(null); + @SuppressWarnings("rawtypes") List types = result.types(); TypeDeclaration typeDec = (TypeDeclaration) types.get(0); @@ -284,8 +310,8 @@ if (method.modifiers().get(0) instanceof NormalAnnotation) { NormalAnnotation anno = (NormalAnnotation) method .modifiers().get(0); - if (anno.getTypeName().getFullyQualifiedName().equals( - JBossWSCreationCoreMessages.WebEndpoint)) { + if (anno.getTypeName().getFullyQualifiedName() + .equals(JBossWSCreationCoreMessages.WebEndpoint)) { createWebService(serviceUnits, method, sb); portNum += 1; } @@ -296,59 +322,6 @@ } /** - * find compilationunit by annotation - * - * @param project - * @param annotation - * @return - */ - public List findJavaUnitsByAnnotation( - IJavaProject project, String annotation) { - List units = new LinkedList(); - try { - ICompilationUnit[] javaFiles = null; - if (project.findPackageFragment(addPackagetoPath(project)) != null) { - javaFiles = project.findPackageFragment( - addPackagetoPath(project)).getCompilationUnits(); - } - if (javaFiles != null) { - for (ICompilationUnit unit : javaFiles) { - if (unit.getSource().contains(annotation)) { - units.add(unit); - } - } - } - } catch (JavaModelException e) { - JBossWSCreationCorePlugin.getDefault().logError(e); - } - return units; - } - - /** - * new a path by adding a java package - * - * @param project - * @return - * @throws JavaModelException - */ - private IPath addPackagetoPath(IJavaProject project) - throws JavaModelException { - String packagename = model.getCustomPackage(); - String[] names = packagename.split(PACAKAGESPLIT); - IPath path = new Path(JBossWSCreationUtils - .getJavaProjectSrcLocation(project.getProject())); - path = project.getPath().append( - path.makeRelativeTo(project.getProject().getLocation())); - - if (names != null && names.length > 0) { - for (String name : names) { - path = path.append(name); - } - } - return path; - } - - /** * create a java class * * @param packageName @@ -362,8 +335,9 @@ String className, boolean isInterface, String interfaceName, IJavaProject javaProject) { try { - IPath srcPath = new Path(JBossWSCreationUtils - .getJavaProjectSrcLocation(javaProject.getProject())); + IPath srcPath = new Path( + JBossWSCreationUtils.getJavaProjectSrcLocation(javaProject + .getProject())); srcPath = javaProject.getPath().append( srcPath.makeRelativeTo(javaProject.getProject() .getLocation())); Index: src/org/jboss/tools/ws/creation/core/commands/InitialCommand.java =================================================================== --- src/org/jboss/tools/ws/creation/core/commands/InitialCommand.java (revision 23989) +++ src/org/jboss/tools/ws/creation/core/commands/InitialCommand.java (working copy) @@ -1,7 +1,5 @@ package org.jboss.tools.ws.creation.core.commands; -import javax.wsdl.WSDLException; - import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; @@ -13,11 +11,9 @@ import org.eclipse.wst.ws.internal.wsrt.IWebService; import org.eclipse.wst.ws.internal.wsrt.WebServiceScenario; import org.jboss.tools.ws.core.utils.StatusUtils; -import org.jboss.tools.ws.creation.core.JBossWSCreationCorePlugin; 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; @SuppressWarnings("restriction") public class InitialCommand extends AbstractDataModelOperation { @@ -56,17 +52,8 @@ } model.setTarget(JBossWSCreationCoreMessages.Value_Target_0); if (scenario == WebServiceScenario.TOPDOWN) { - try { - model.setWsdlURI(ws.getWebServiceInfo().getWsdlURL()); - WSDLPropertyReader reader = new WSDLPropertyReader(); - reader.readWSDL(ws.getWebServiceInfo().getWsdlURL()); - model.setCustomPackage(""); //$NON-NLS-1$ - model.setServiceList(reader.getServiceList()); - model.setPortTypeList(reader.getPortTypeList()); - } catch (WSDLException e) { - JBossWSCreationCorePlugin.getDefault().logError(e); - return StatusUtils.errorStatus(e.getLocalizedMessage(), e); - } + model.setWsdlURI(ws.getWebServiceInfo().getWsdlURL()); + model.setCustomPackage(""); //$NON-NLS-1$ } else { model.addServiceClasses(ws.getWebServiceInfo().getImplURL()); } Index: src/org/jboss/tools/ws/creation/core/commands/ImplementationClassCreationCommand.java =================================================================== --- src/org/jboss/tools/ws/creation/core/commands/ImplementationClassCreationCommand.java (revision 23989) +++ src/org/jboss/tools/ws/creation/core/commands/ImplementationClassCreationCommand.java (working copy) @@ -5,8 +5,6 @@ import java.util.List; import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; @@ -65,13 +63,13 @@ 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; private IProject project; + private String packageName; public ImplementationClassCreationCommand(ServiceModel model) { this.model = model; @@ -90,13 +88,32 @@ } IStatus status = Status.OK_STATUS; - project = JBossWSCreationUtils.getProjectByName(model.getWebProjectName()); + project = JBossWSCreationUtils.getProjectByName(model + .getWebProjectName()); try { - List portTypes = model.getPortTypes(); - for (String portTypeName : portTypes) { - generateImplClass(formatPortTypeName(portTypeName)); - String implClsName = getImplPackageName() + "." //$NON-NLS-1$ - + getImplClassName(portTypeName); + + IJavaProject javaPrj = JavaCore.create(project); + List serviceUnits = JBossWSCreationUtils + .findJavaUnitsByAnnotation( + javaPrj, + JBossWSCreationCoreMessages.Webservice_Annotation_Check, + model.getCustomPackage()); + + packageName = model.getCustomPackage(); + boolean noPackageName = false; + if("".equals(packageName)){ //$NON-NLS-1$ + noPackageName = true; + } + for (ICompilationUnit service : serviceUnits) { + if (!service.findPrimaryType().isInterface()) { + continue; + } + if(noPackageName){ + packageName = service.getParent().getElementName(); + } + generateImplClass(service); + String implClsName = getImplPackageName() + + "." + getImplClassName(getClassName(service.getElementName())); //$NON-NLS-1$ model.addServiceClasses(implClsName); } @@ -116,25 +133,18 @@ 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; - } - @SuppressWarnings("unchecked") - protected void generateImplClass(String portTypeName/* , IFile implJavaFile */) + protected void generateImplClass(ICompilationUnit service) throws CoreException, BadLocationException { + ASTParser astp = ASTParser.newParser(AST.JLS3); + astp.setSource(service); + CompilationUnit cu = (CompilationUnit) astp.createAST(null); + IPackageFragment pack = getImplPakcage(); - CompilationUnit portTypeCU = getCompilationUnitForInterface(portTypeName); + String className = getClassName(service.getElementName()); - IPackageFragment pack = getImplPakcage(); + String implFileName = getJavaFileName(className); - String implFileName = getJavaFileName(portTypeName); ICompilationUnit icu = pack.createCompilationUnit(implFileName, "", true, null); //$NON-NLS-1$ // create a working copy with a new owner @@ -163,26 +173,26 @@ implCu.setPackage(implPackage); // add imports for implementation class - addImportsToImplementationClass(implCu, portTypeCU, portTypeName); + addImportsToImplementationClass(implCu, cu, className); // add class declaration TypeDeclaration type = ast.newTypeDeclaration(); type.setInterface(false); // add WebService annotation - String endpoint = getPortTypeInterfaceFullName(portTypeName); - NormalAnnotation ann = createAnnotation(ast, portTypeName, endpoint); + String endpoint = getServiceInterfaceFullName(className); + NormalAnnotation ann = createAnnotation(ast, className, endpoint); type.modifiers().add(ann); type.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD)); - type.setName(ast.newSimpleName(getImplClassName(portTypeName))); + type.setName(ast.newSimpleName(getImplClassName(className))); type.superInterfaceTypes().add( - ast.newSimpleType(ast.newName(portTypeName))); + ast.newSimpleType(ast.newName(className))); // add Logger variable declaration // createLoggerField(ast, type, portTypeName); // add method implementation - TypeDeclaration inTD = (TypeDeclaration) portTypeCU.types().get(0); + TypeDeclaration inTD = (TypeDeclaration) cu.types().get(0); // firstly, get all methods that declared in Interface class and then // add corresponding methods to // the impl class @@ -209,11 +219,13 @@ } private String getImplPackageName() { - return model.getCustomPackage() /* + ".impl" */; + return packageName; } - private IPackageFragmentRoot getPackageFragmentRoot() throws JavaModelException { - String str = model.getWebProjectName() + File.separator+ getSourceFolderPath(project); + private IPackageFragmentRoot getPackageFragmentRoot() + throws JavaModelException { + String str = model.getWebProjectName() + File.separator + + getSourceFolderPath(project); IPath path = new Path(str); IResource res = fWorkspaceRoot.findMember(path); IJavaProject javaPrj = JavaCore.create(project); @@ -221,19 +233,20 @@ } - private String getJavaFileName(String portTypeName) { + private String getJavaFileName(String className) { - return getImplClassName(portTypeName) + DEFAULT_CU_SUFFIX; + return getImplClassName(className) + DEFAULT_CU_SUFFIX; } - private String getImplClassName(String portTypeName) { - String firstLetter = portTypeName.substring(0, 1); - String implClsName = firstLetter.toUpperCase() - + portTypeName.substring(1); - implClsName = implClsName + "Impl"; //$NON-NLS-1$ - return implClsName; + private String getImplClassName(String className) { + return className + "Impl"; //$NON-NLS-1$ } + private String getClassName(String className) { + String clsName = className.substring(0, className.length() - 5); + return clsName; + } + private IPackageFragment getImplPakcage() throws JavaModelException { IPackageFragmentRoot root = getPackageFragmentRoot(); String implPackageName = getImplPackageName(); @@ -247,31 +260,29 @@ return pack; } - private String getPortTypeInterfaceFullName(String portTypeName) { - return model.getCustomPackage() + "." + portTypeName; //$NON-NLS-1$ + private String getServiceInterfaceFullName(String className) { + return packageName + "." + className; //$NON-NLS-1$ } @SuppressWarnings("unchecked") private void addImportsToImplementationClass(CompilationUnit implCU, - CompilationUnit portTypeCU, String portTypeName) { - List imports = getImportsWithoutJaxwsAnnotation(portTypeCU); + CompilationUnit serviceCU, String serviceName) { + List imports = getImportsWithoutJaxwsAnnotation(serviceCU); AST implAST = implCU.getAST(); // add imports for implementation class for (ImportDeclaration id : imports) { ImportDeclaration newId = implAST.newImportDeclaration(); - newId - .setName(implAST.newName(id.getName() - .getFullyQualifiedName())); + newId.setName(implAST.newName(id.getName().getFullyQualifiedName())); implCU.imports().add(newId); } // import port type interface ImportDeclaration importDec = implAST.newImportDeclaration(); - QualifiedName portTypeImport = implAST.newQualifiedName(implAST - .newName(portTypeCU.getPackage().getName() - .getFullyQualifiedName()), implAST - .newSimpleName(portTypeName)); + QualifiedName portTypeImport = implAST.newQualifiedName( + implAST.newName(serviceCU.getPackage().getName() + .getFullyQualifiedName()), + implAST.newSimpleName(serviceName)); importDec.setName(portTypeImport); implCU.imports().add(importDec); // importDec = implAST.newImportDeclaration(); @@ -289,13 +300,13 @@ * create web service annotation */ @SuppressWarnings("unchecked") - protected NormalAnnotation createAnnotation(AST ast, - String serviceName, String endpoint) { + protected NormalAnnotation createAnnotation(AST ast, String serviceName, + String endpoint) { NormalAnnotation ann = ast.newNormalAnnotation(); ann.setTypeName(ast.newSimpleName(ANNOTATION_TYPE_NAME_WEBSERVICE)); - MemberValuePair member = createMemberValuePair(ast, ANNOTATION_PROPERTY_SERVICE_NAME, - serviceName); + MemberValuePair member = createMemberValuePair(ast, + ANNOTATION_PROPERTY_SERVICE_NAME, serviceName); ann.values().add(member); member = createMemberValuePair(ast, ANNOTATION_PROPERTY_ENDPOINT_INTERFACE, endpoint); @@ -320,6 +331,7 @@ MethodDeclaration md = ast.newMethodDeclaration(); md.setConstructor(false); + @SuppressWarnings("rawtypes") List modifiers = md.modifiers(); modifiers.add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD)); md.setName(ast @@ -328,6 +340,7 @@ Type sType = copyTypeFromOtherASTNode(ast, inMethod.getReturnType2()); md.setReturnType2(sType); + @SuppressWarnings("rawtypes") List parameters = inMethod.parameters(); for (Object obj : parameters) { @@ -398,13 +411,13 @@ .getFullyQualifiedName())); } else if (type instanceof ArrayType) { ArrayType atype = (ArrayType) type; - return ast.newArrayType(copyTypeFromOtherASTNode(ast, atype - .getComponentType())); + return ast.newArrayType(copyTypeFromOtherASTNode(ast, + atype.getComponentType())); } else if (type instanceof ParameterizedType) { ParameterizedType ptype = (ParameterizedType) type; ParameterizedType newParaType = ast - .newParameterizedType(copyTypeFromOtherASTNode(ast, ptype - .getType())); + .newParameterizedType(copyTypeFromOtherASTNode(ast, + ptype.getType())); for (Object arg : ptype.typeArguments()) { if (arg instanceof Type) { Type newArg = copyTypeFromOtherASTNode(ast, (Type) arg); @@ -422,10 +435,10 @@ return null; } - @SuppressWarnings("unchecked") protected List getImportsWithoutJaxwsAnnotation( CompilationUnit cu) { List importList = new ArrayList(); + @SuppressWarnings("rawtypes") List imports = cu.imports(); for (Object obj : imports) { ImportDeclaration id = (ImportDeclaration) obj; @@ -438,41 +451,11 @@ return importList; } - private CompilationUnit getCompilationUnitForInterface(String portTypeName) - throws CoreException { - System.out.println(portTypeName); - IFile inFile = getServiceInterfaceFile(portTypeName); - 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); - astp.setSource(icu); - - CompilationUnit cu = (CompilationUnit) astp.createAST(null); - - return cu; - } - - private IFile getServiceInterfaceFile(String portTypeName) + private IPath getSourceFolderPath(IProject project) throws JavaModelException { - IFolder pkgFolder = getPackageFolder(); - IFile inFile = pkgFolder.getFile(portTypeName + DEFAULT_CU_SUFFIX); - return inFile; - } - - private IFolder getPackageFolder() throws JavaModelException { - IFolder srcFolder = project.getFolder(getSourceFolderPath(project)); - String pkgFolderName = model.getCustomPackage().replace(".", //$NON-NLS-1$ - File.separator); - return srcFolder.getFolder(pkgFolderName); - - } - - private IPath getSourceFolderPath(IProject project) throws JavaModelException{ - IPath path = new Path(JBossWSCreationUtils.getJavaProjectSrcLocation(project.getProject())); + IPath path = new Path( + JBossWSCreationUtils.getJavaProjectSrcLocation(project + .getProject())); return path.makeRelativeTo(project.getProject().getLocation()); } Index: src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java =================================================================== --- src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java (revision 23989) +++ src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java (working copy) @@ -25,6 +25,7 @@ import java.text.Collator; import java.util.ArrayList; import java.util.Arrays; +import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -34,6 +35,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; @@ -58,6 +60,7 @@ import org.jboss.tools.ws.core.facet.delegate.IJBossWSFacetDataModelProperties; import org.jboss.tools.ws.core.facet.delegate.JBossWSFacetInstallDataModelProvider; import org.jboss.tools.ws.core.utils.StatusUtils; +import org.jboss.tools.ws.creation.core.JBossWSCreationCorePlugin; import org.jboss.tools.ws.creation.core.messages.JBossWSCreationCoreMessages; public class JBossWSCreationUtils { @@ -77,8 +80,8 @@ if (hasUpperCase(keyword)) { return false; } - return (Arrays.binarySearch(javaKeyWords, keyword, Collator - .getInstance(Locale.ENGLISH)) >= 0); + return (Arrays.binarySearch(javaKeyWords, keyword, + Collator.getInstance(Locale.ENGLISH)) >= 0); } private static boolean hasUpperCase(String nodeName) { @@ -95,21 +98,25 @@ public static IProject getProjectByName(String project) { String projectString = replaceEscapecharactors(project); - return ResourcesPlugin.getWorkspace().getRoot().getProject( - getProjectNameFromFramewokNameString(projectString)); + return ResourcesPlugin + .getWorkspace() + .getRoot() + .getProject(getProjectNameFromFramewokNameString(projectString)); } public static IPath getProjectRoot(String project) { String projectString = replaceEscapecharactors(project); - return ResourcesPlugin.getWorkspace().getRoot().getProject( - getProjectNameFromFramewokNameString(projectString)) + return ResourcesPlugin + .getWorkspace() + .getRoot() + .getProject(getProjectNameFromFramewokNameString(projectString)) .getLocation(); } private static String replaceEscapecharactors(String vulnarableString) { if (vulnarableString.indexOf("/") != -1) { //$NON-NLS-1$ - vulnarableString = vulnarableString.replace('/', File.separator - .charAt(0)); + vulnarableString = vulnarableString.replace('/', + File.separator.charAt(0)); } return vulnarableString; } @@ -437,7 +444,7 @@ } return path; } - + public static File findFileByPath(String name, String path) { File ret = null; File folder = new File(path); @@ -455,6 +462,91 @@ } } return ret; - } + } + /** + * find compilationunit by annotation + * + * @param project + * @param annotation + * @return + */ + public static List findJavaUnitsByAnnotation( + IJavaProject project, String annotation, String packageName) { + List units = new LinkedList(); + try { + IPath path = addPackagetoPath(project, packageName); + if (path == null) { + IResource[] resources = JBossWSCreationUtils + .getJavaSourceRoots(project.getProject()); + if (resources != null && resources.length > 0) { + IJavaElement[] elements = project.getPackageFragmentRoot( + resources[0]).getChildren(); + for (IJavaElement element : elements) { + if (IJavaElement.PACKAGE_FRAGMENT == element + .getElementType()) { + findInPackageFragment(units, element.getPath(), + project, annotation); + } + } + } + } else { + findInPackageFragment(units, path, project, annotation); + } + } catch (JavaModelException e) { + JBossWSCreationCorePlugin.getDefault().logError(e); + } + return units; + } + + private static void findInPackageFragment(List units, + IPath path, IJavaProject project, String annotation) { + ICompilationUnit[] javaFiles = null; + try { + if (project.findPackageFragment(path) != null) { + javaFiles = project.findPackageFragment(path) + .getCompilationUnits(); + } + if (javaFiles != null) { + for (ICompilationUnit unit : javaFiles) { + if (unit.getSource().contains(annotation)) { + units.add(unit); + + } + } + } + } catch (JavaModelException e) { + JBossWSCreationCorePlugin.getDefault().logError(e); + + } + } + + /** + * new a path by adding a java package + * + * @param project + * @return + * @throws JavaModelException + */ + public static IPath addPackagetoPath(IJavaProject project, + String packageName) throws JavaModelException { + String PACAKAGESPLIT = "\\."; //$NON-NLS-1$ + if ("".equals(packageName)) { //$NON-NLS-1$ + return null; + } + IPath path = new Path( + JBossWSCreationUtils.getJavaProjectSrcLocation(project + .getProject())); + String[] names = packageName.split(PACAKAGESPLIT); + path = project.getPath().append( + path.makeRelativeTo(project.getProject().getLocation())); + + if (names != null && names.length > 0) { + for (String name : names) { + path = path.append(name); + } + } + return path; + } + } Index: src/org/jboss/tools/ws/creation/core/data/ServiceModel.java =================================================================== --- src/org/jboss/tools/ws/creation/core/data/ServiceModel.java (revision 23989) +++ src/org/jboss/tools/ws/creation/core/data/ServiceModel.java (working copy) @@ -9,8 +9,6 @@ private boolean serverStatus; private String wsdlURI; - private List portTypes; - private List serviceNames; private String customPackage; private List bindingFiles; private String catalog; @@ -58,38 +56,6 @@ this.customPackage = packageText; } - public List getPortTypes() { - if(portTypes == null){ - portTypes = new ArrayList(); - } - return portTypes; - } - public void addPortTypes(String portType) { - this.portTypes = getPortTypes(); - if(!this.portTypes.contains(portType)){ - this.portTypes.add(portType); - } - } - public void setPortTypeList(List portTypeList) { - this.portTypes = portTypeList; - } - - public List getServiceNames() { - if(serviceNames == null){ - serviceNames = new ArrayList(); - } - return serviceNames; - } - public void addServiceName(String serviceName) { - this.serviceNames = getServiceClasses(); - if(!serviceName.contains(serviceName)){ - this.serviceNames.add(serviceName); - } - } - public void setServiceList(List serviceList) { - this.serviceNames = serviceList; - } - public String getWsdlURI() { return wsdlURI; }