Author: dennyxu
Date: 2008-05-19 06:37:33 -0400 (Mon, 19 May 2008)
New Revision: 8176
Added:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ImplementationClassCreationCommand.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/META-INF/MANIFEST.MF
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/InitialCommand.java
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/data/ServiceModel.java
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java
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.ui/src/org/jboss/tools/ws/creation/ui/wsrt/JBossWebService.java
Log:
JBIDE-2200: generate implmentation skeleton class for every port type interface
Modified: trunk/ws/plugins/org.jboss.tools.ws.creation.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.creation.core/META-INF/MANIFEST.MF 2008-05-19
08:30:08 UTC (rev 8175)
+++ trunk/ws/plugins/org.jboss.tools.ws.creation.core/META-INF/MANIFEST.MF 2008-05-19
10:37:33 UTC (rev 8176)
@@ -22,7 +22,9 @@
org.eclipse.jst.j2ee,
org.eclipse.jst.j2ee.core,
org.eclipse.emf.common,
- org.eclipse.emf.ecore
+ org.eclipse.emf.ecore,
+ org.eclipse.jdt.core,
+ org.eclipse.jface.text
Eclipse-LazyStart: true
Export-Package: org.jboss.tools.ws.creation.core,
org.jboss.tools.ws.creation.core.commands,
Added:
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
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ImplementationClassCreationCommand.java 2008-05-19
10:37:33 UTC (rev 8176)
@@ -0,0 +1,506 @@
+package org.jboss.tools.ws.creation.core.commands;
+
+import java.io.File;
+import java.io.StringBufferInputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+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;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jdt.core.IBuffer;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.ArrayType;
+import org.eclipse.jdt.core.dom.Assignment;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.FieldAccess;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.Initializer;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.Modifier;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.NumberLiteral;
+import org.eclipse.jdt.core.dom.PackageDeclaration;
+import org.eclipse.jdt.core.dom.ParameterizedType;
+import org.eclipse.jdt.core.dom.PrimitiveType;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.QualifiedType;
+import org.eclipse.jdt.core.dom.ReturnStatement;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SimpleType;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.StringLiteral;
+import org.eclipse.jdt.core.dom.Type;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.TypeLiteral;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.WildcardType;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.text.edits.MalformedTreeException;
+import org.eclipse.text.edits.TextEdit;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.jboss.tools.ws.creation.core.data.ServiceModel;
+import org.jboss.tools.ws.creation.core.utils.JBossWSCreationUtils;
+
+public class ImplementationClassCreationCommand extends
+ AbstractDataModelOperation {
+
+ protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
+ protected static final String TAB = "\t"; //$NON-NLS-1$
+ protected static final String SPACE = " "; //$NON-NLS-1$
+ protected static final String DOT = "."; //$NON-NLS-1$
+ protected static final String COMMA = ","; //$NON-NLS-1$
+ protected static final String SEMICOLON = ";"; //$NON-NLS-1$
+ protected static final String POUND = "#"; //$NON-NLS-1$
+ protected static final String OPEN_PAR = "("; //$NON-NLS-1$
+ protected static final String CLOSE_PAR = ")"; //$NON-NLS-1$
+ protected static final String OPEN_BRA = "{"; //$NON-NLS-1$
+ protected static final String CLOSE_BRA = "}"; //$NON-NLS-1$
+ protected static final String lineSeparator =
System.getProperty("line.separator"); //$NON-NLS-1$
+
+ protected static final String JAVA_LANG_OBJECT = "java.lang.Object";
//$NON-NLS-1$
+ protected static final String PACKAGE = "package "; //$NON-NLS-1$
+ protected static final String CLASS = "class "; //$NON-NLS-1$
+ protected static final String IMPORT = "import "; //$NON-NLS-1$
+ protected static final String EXTENDS = "extends "; //$NON-NLS-1$
+ protected static final String IMPLEMENTS = "implements "; //$NON-NLS-1$
+ protected static final String THROWS = "throws "; //$NON-NLS-1$
+ protected static final String SUPER = "super"; //$NON-NLS-1$
+ protected static final String PUBLIC = "public "; //$NON-NLS-1$
+ protected static final String PROTECTED = "protected "; //$NON-NLS-1$
+ protected static final String PRIVATE = "private "; //$NON-NLS-1$
+ protected static final String STATIC = "static "; //$NON-NLS-1$
+ protected static final String ABSTRACT = "abstract "; //$NON-NLS-1$
+ protected static final String FINAL = "final "; //$NON-NLS-1$
+ protected static final String VOID = "void"; //$NON-NLS-1$
+ protected static final String INT = "int"; //$NON-NLS-1$
+ protected static final String BOOLEAN = "boolean"; //$NON-NLS-1$
+ protected static final String MAIN_METHOD = "\tpublic static void main(String[]
args) {"; //$NON-NLS-1$
+ protected static final String TODO_COMMENT = "\t\t// TODO Auto-generated method
stub"; //$NON-NLS-1$
+ protected static final String RETURN_NULL = "\t\treturn null;"; //$NON-NLS-1$
+ protected static final String RETURN_0 = "\t\treturn 0;"; //$NON-NLS-1$
+ protected static final String RETURN_FALSE = "\t\treturn false;";
//$NON-NLS-1$
+ protected static final String RESOURCE_FOLDER = "src";
+
+ protected static final String PREFIX_JAXWS_ANNOTATION_CLASS = "javax.jws";
+ protected static final String CLASS_LOGGER = "Logger";
+ protected static final String SUFFIX_PACKAGENAME_IMPL = "impl";
+ protected static final String DEFAULT_CU_SUFFIX = ".java";
+
+ private ServiceModel model;
+ private List<String> importStatements;
+ private IWorkspaceRoot fWorkspaceRoot;
+ private IJavaProject javaProject;
+
+ public ImplementationClassCreationCommand(ServiceModel model){
+ this.model = model;
+ fWorkspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
+
+ }
+
+
+
+ @Override
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+
+
+
+ IFile inFile = getServiceInterfaceFile(model.getPortTypes().get(0));
+
+ try {
+ //IFile implJavaFile = createEmptyImplJavaFile("Test");
+ //so far, it only generate implementation for first port type, neet to generate impl
class for all
+ //port type interfaces
+ generateImplClass(model.getPortTypes().get(0));
+ } catch (CoreException e) {
+ e.printStackTrace();
+ } catch (MalformedTreeException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (BadLocationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return Status.OK_STATUS;
+ }
+
+ private String getImplPackageName(){
+ return model.getCustomPackage() + ".impl";
+ }
+
+ private IPackageFragmentRoot getPackageFragmentRoot(){
+ String str = model.getWebProjectName() + File.separator + RESOURCE_FOLDER;
+ IPath path= new Path(str);
+ IResource res= fWorkspaceRoot.findMember(path);
+ IProject prj = res.getProject();
+ IJavaProject javaPrj = JavaCore.create(prj);
+ return javaPrj.getPackageFragmentRoot(res);
+
+ }
+
+ private String getCompilationUnitName(String portTypeName){
+
+ return getImplClassName(portTypeName) + DEFAULT_CU_SUFFIX;
+ }
+
+
+ private String getImplClassName(String portTypeName){
+ String firstLetter = portTypeName.substring(0,1);
+ String implClsName = firstLetter.toUpperCase() + portTypeName.substring(1);
+ implClsName = implClsName + "Impl";
+ return implClsName;
+ }
+
+ /*private CompilationUnit createASTForImplementation(String portTypeName) throws
JavaModelException {
+ IPackageFragmentRoot root= getPackageFragmentRoot();
+ IPackageFragment pack= root.getPackageFragment(getImplPackageName()); //$NON-NLS-1$
+
+ if (!pack.exists()) {
+ String packName= pack.getElementName();
+ pack= root.createPackageFragment(packName, true, null);
+ }
+
+ String cuName= getCompilationUnitName(portTypeName);
+ ICompilationUnit parentCU= pack.createCompilationUnit(cuName, "", false,
null); //$NON-NLS-1$
+ // create a working copy with a new owner
+
+ boolean needsSave= true;
+ parentCU.becomeWorkingCopy(null); // cu is now a (primary) working copy
+
+
+ ASTParser parser= ASTParser.newParser(AST.JLS3);
+ parser.setSource(parentCU);
+ parser.setResolveBindings(false);
+ parser.setFocalPosition(0);
+ return (CompilationUnit) parser.createAST(null);
+ }*/
+
+/* private IFile createEmptyImplJavaFile(String portTypeName) throws CoreException{
+
+
+ IFile inFile = getServiceInterfaceFile(portTypeName);
+ if(inFile != null && inFile.exists()){
+ IFolder implFolder = inFile.getParent().getFolder(new Path("impl"));
+ if(!implFolder.exists()){
+ implFolder.create(true, true, null);
+ }
+ IFile implJava = implFolder.getFile(model.getServiceNames().get(0) +
".java");
+ return implJava;
+ }
+ return null;
+ }*/
+
+ protected void generateImplClass(String portTypeName/*, IFile implJavaFile*/) throws
CoreException, MalformedTreeException, BadLocationException{
+
+ CompilationUnit cu = getCompilationUnitForInterface(portTypeName);
+ Object obj = cu.imports();
+ List<ImportDeclaration> imports = getImportsWithoutJaxwsAnnotation(cu);
+
+ IPackageFragmentRoot root= getPackageFragmentRoot();
+ IPackageFragment pack= root.getPackageFragment(getImplPackageName()); //$NON-NLS-1$
+
+ if (!pack.exists()) {
+ String packName= pack.getElementName();
+ pack= root.createPackageFragment(packName, true, null);
+ }
+
+ String cuName= getCompilationUnitName(portTypeName);
+ ICompilationUnit parentCU= pack.createCompilationUnit(cuName, "", true,
null); //$NON-NLS-1$
+ // create a working copy with a new owner
+
+ parentCU.becomeWorkingCopy(null); // cu is now a (primary) working copy
+
+
+ ASTParser parser= ASTParser.newParser(AST.JLS3);
+ parser.setSource(parentCU);
+ parser.setResolveBindings(false);
+ parser.setFocalPosition(0);
+
+ CompilationUnit implCu = (CompilationUnit) parser.createAST(null);
+ AST ast = implCu.getAST();
+
+ //creation of a Document and ASTRewrite
+ String source = parentCU.getBuffer().getContents();
+ Document document = new Document(source);
+
+ ASTRewrite rewrite = ASTRewrite.create(implCu.getAST());
+ implCu.recordModifications();
+
+ //start to add content implementation class
+
+
+ //add package declaration for impl class:
+ PackageDeclaration implPackage = ast.newPackageDeclaration();
+ implPackage.setName(ast.newName(pack.getElementName()));
+ implCu.setPackage(implPackage);
+
+ //add imports for implementation class
+ for(ImportDeclaration id: imports){
+ ImportDeclaration newId = ast.newImportDeclaration();
+ newId.setName(ast.newName(id.getName().getFullyQualifiedName()));
+ implCu.imports().add(newId);
+ }
+
+ //import port type interface and jboss Logger
+ ImportDeclaration id = ast.newImportDeclaration();
+ QualifiedName portTypeImport = ast.newQualifiedName(ast.newName(cu
+ .getPackage().getName().getFullyQualifiedName()), ast
+ .newSimpleName(portTypeName));
+ id.setName(portTypeImport);
+ implCu.imports().add(id);
+ id = ast.newImportDeclaration();
+ id.setName(ast.newName("org.jboss.logging.Logger"));
+ implCu.imports().add(id);
+
+ //add class declaration
+ TypeDeclaration type = ast.newTypeDeclaration();
+ type.setInterface(false);
+ type.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
+ type.setName(ast.newSimpleName(getImplClassName(portTypeName)));
+ type.superInterfaceTypes().add(ast.newSimpleType(ast.newName(portTypeName)));
+
+ //add Logger variable declaration
+ //createLoggerField(ast, type);
+
+
+ //add method implementation
+ 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
+ MethodDeclaration[] methods = inTD.getMethods();
+ for(int i = 0; i < methods.length; i++){
+ MethodDeclaration newMethod = createMethodForImplClass(ast, methods[i]);
+ type.bodyDeclarations().add(newMethod);
+ }
+
+
+ implCu.types().add(type);
+
+
+ //try to save the modification
+ TextEdit edits = implCu.rewrite(document, parentCU.getJavaProject().getOptions(true));
+ edits.apply(document);
+ String newSource = document.get();
+ parentCU.getBuffer().setContents(newSource);
+ parentCU.reconcile(ICompilationUnit.NO_AST, false, null, null);
+ parentCU.commitWorkingCopy(true, null);
+ parentCU.discardWorkingCopy();
+
+
+/* String content = implCu.toString();
+
+ if(implJavaFile.exists()){
+ implJavaFile.delete(true, null);
+ }
+
+ implJavaFile.create(new StringBufferInputStream(content), true, null);*/
+
+ }
+
+ protected FieldDeclaration createLoggerField(AST ast, TypeDeclaration type){
+ //for now, have no idea how to generate a field like:
+ // private static Logger log = Logger.getLooger(TestEdnpointImpl.class);
+ //TODO
+
+ VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment();
+ vdf.setName(ast.newSimpleName("log"));
+ Initializer clsAccesss = ast.newInitializer();
+ Block clsAccessBlk = ast.newBlock();
+ FieldAccess fa = ast.newFieldAccess();
+ fa.setExpression(ast.newSimpleName("Test"));
+ fa.setName(ast.newSimpleName("class"));
+ clsAccessBlk.statements().add(ast.newExpressionStatement(fa));
+ clsAccesss.setBody(clsAccessBlk);
+ MethodInvocation mi = ast.newMethodInvocation();
+ mi.setExpression(ast.newSimpleName("Logger"));
+ mi.setName(ast.newSimpleName("getLogger"));
+ mi.arguments().add(fa);
+ vdf.setInitializer(mi);
+
+ type.bodyDeclarations().add(vdf);
+
+ /*SingleVariableDeclaration svd = ast.newSingleVariableDeclaration();
+ svd.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD));
+ svd.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD));
+ svd.setType(ast.newSimpleType(ast.newSimpleName(CLASS_LOGGER)));
+ svd.setName(ast.newSimpleName("log"));
+ Initializer initializer = ast.newInitializer();
+ Block initBlock = ast.newBlock();
+
+ MethodInvocation mi = ast.newMethodInvocation();
+ mi.setExpression(ast.newName("Logger"));
+ mi.setName(ast.newSimpleName("getLogger"));
+
+
+ MethodInvocation invokCls = ast.newMethodInvocation();
+ invokCls.setExpression((ast.newSimpleName("TestImpl"));
+ invokCls.setName(ast.newSimpleName("class"));
+ mi.arguments().add(invokCls.getExpression();
+ svd.setInitializer(ast.newExpressionStatement(mi).getExpression());*/
+ return null;
+ }
+
+ protected MethodDeclaration createMethodForImplClass(AST ast, MethodDeclaration
inMethod){
+
+ MethodDeclaration md = ast.newMethodDeclaration();
+ md.setConstructor(false);
+ List modifiers = md.modifiers();
+ modifiers.add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
+ md.setName(ast.newSimpleName(inMethod.getName().getFullyQualifiedName()));
+
+ SimpleType sType = (SimpleType)inMethod.getReturnType2();
+ Name sTypeName = sType.getName();
+ md.setReturnType2(ast.newSimpleType(ast.newName(sTypeName.getFullyQualifiedName())));
+
+ List parameters = inMethod.parameters();;
+ for(Object obj: parameters){
+ SingleVariableDeclaration implSvd = ast.newSingleVariableDeclaration();
+ SingleVariableDeclaration svd = (SingleVariableDeclaration)obj;
+ implSvd.setName(ast.newSimpleName(svd.getName().getFullyQualifiedName()));
+ implSvd.setType(copyTypeFromOtherASTNode(ast, svd.getType()));
+ md.parameters().add(implSvd);
+ }
+
+ //create method body
+ Block block = ast.newBlock();
+ Type returnType = inMethod.getReturnType2();
+ ReturnStatement rs = ast.newReturnStatement();
+ String typeName = ((SimpleType)returnType).getName().getFullyQualifiedName();
+ if(returnType.isPrimitiveType() && returnType.isSimpleType()){
+ NumberLiteral nl = ast.newNumberLiteral();
+ nl.setToken("0");
+ rs.setExpression(nl);
+
+ }else if("String".equals(typeName)){
+ StringLiteral sl = ast.newStringLiteral();
+ sl.setLiteralValue("");
+ rs.setExpression(sl);
+
+ }else{
+ rs.setExpression(ast.newNullLiteral());
+ }
+ block.statements().add(rs);
+
+ md.setBody(block);
+
+ return md;
+ }
+
+ protected Name copyQualifiedName(AST ast, QualifiedName qname){
+ String fullQName = qname.getFullyQualifiedName();
+ StringTokenizer st = new StringTokenizer(fullQName,".");
+ Name copy = null;
+ SimpleName sn = ast.newSimpleName(st.nextToken());
+ while(st.hasMoreTokens()){
+ SimpleName snNext = ast.newSimpleName(st.nextToken());
+ if(copy == null){
+ copy = ast.newQualifiedName(sn, snNext);
+ }else{
+ //copy = ast.newn)
+ }
+ }
+
+ return null;
+ }
+
+ private Type copyTypeFromOtherASTNode(AST ast, Type type){
+ if(type instanceof PrimitiveType){
+ return ast.newPrimitiveType(((PrimitiveType)type).getPrimitiveTypeCode());
+ }
+ else if(type instanceof SimpleType){
+ SimpleType simpleType = (SimpleType)type;
+
+ return ast.newSimpleType(ast.newName(simpleType.getName().getFullyQualifiedName()));
+ }
+ else if(type instanceof ArrayType){
+ ArrayType atype = (ArrayType)type;
+ return ast.newArrayType(copyTypeFromOtherASTNode(ast, atype.getComponentType()));
+ }
+ else if(type instanceof ParameterizedType){
+ ParameterizedType ptype = (ParameterizedType)type;
+ ast.newParameterizedType(copyTypeFromOtherASTNode(ast, ptype.getType()));
+ }
+ else if(type instanceof WildcardType){
+ WildcardType sourcetype = (WildcardType)type;
+ WildcardType wtype = ast.newWildcardType();
+ wtype.setBound(sourcetype.getBound());
+ return wtype;
+ }
+
+ return null;
+ }
+ protected List<ImportDeclaration> getImportsWithoutJaxwsAnnotation(CompilationUnit
cu){
+ List<ImportDeclaration> importList = new ArrayList<ImportDeclaration>();
+ List imports = cu.imports();
+ for(Object obj: imports){
+ ImportDeclaration id = (ImportDeclaration)obj;
+ String imClsName = id.getName().getFullyQualifiedName();
+ if(!imClsName.startsWith(PREFIX_JAXWS_ANNOTATION_CLASS)){
+ importList.add(id);
+ }
+ }
+
+ return importList;
+ }
+
+ private CompilationUnit getCompilationUnitForInterface(String portTypeName){
+ IFile inFile = getServiceInterfaceFile(portTypeName);
+ IJavaElement inSrc = JavaCore.create(inFile);
+ 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){
+ String packageName = model.getCustomPackage();
+ IProject project = JBossWSCreationUtils.getProjectByName(model.getWebProjectName());
+ IFolder pkgFolder = getPackageFolder();
+ IFile inFile = pkgFolder.getFile(portTypeName + ".java");
+ return inFile;
+ }
+
+
+ private IFolder getPackageFolder(){
+ IProject project = JBossWSCreationUtils.getProjectByName(model.getWebProjectName());
+ IFolder srcFolder = project.getFolder(RESOURCE_FOLDER);
+ String pkgFolderName = model.getCustomPackage().replace(".",
File.separator);
+ return srcFolder.getFolder(pkgFolderName);
+
+ }
+
+
+
+
+
+}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/InitialCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/InitialCommand.java 2008-05-19
08:30:08 UTC (rev 8175)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/InitialCommand.java 2008-05-19
10:37:33 UTC (rev 8176)
@@ -44,6 +44,9 @@
WSDLPropertyReader reader = new WSDLPropertyReader();
reader.readWSDL(ws.getWebServiceInfo().getWsdlURL());
model.setCustomPackage(reader.packageFromTargetNamespace());
+ model.setServiceList(reader.getServiceList());
+ model.setPortTypeList(reader.getPortTypeList());
+
}catch (WSDLException e) {
return StatusUtils.errorStatus(e.getLocalizedMessage(), e);
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java 2008-05-19
08:30:08 UTC (rev 8175)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java 2008-05-19
10:37:33 UTC (rev 8176)
@@ -18,6 +18,7 @@
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
import org.jboss.tools.ws.core.JbossWSCorePlugin;
import org.jboss.tools.ws.creation.core.data.ServiceModel;
+import org.jboss.tools.ws.creation.core.utils.JBossStatusUtils;
import org.jboss.tools.ws.creation.core.utils.JBossWSCreationUtils;
public class WSDL2JavaCommand extends AbstractDataModelOperation{
@@ -50,13 +51,14 @@
String str = input.readLine();
StringBuffer result = new StringBuffer();
while(str != null){
- System.out.println(str);
result.append(str).append("\t\r");
str = input.readLine();
}
- proc.waitFor();
- System.out.print(result);
+ int exitValue = proc.waitFor();
+ if(exitValue != 0){
+ return JBossStatusUtils.errorStatus(result.toString());
+ }
} catch (IOException e) {
// TODO Auto-generated catch block
@@ -65,7 +67,7 @@
// TODO Auto-generated catch block
e.printStackTrace();
}
- SAXParserFactory spf = SAXParserFactory.newInstance();
+
refreshProject(model.getWebProjectName(), monitor);
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/data/ServiceModel.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/data/ServiceModel.java 2008-05-19
08:30:08 UTC (rev 8175)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/data/ServiceModel.java 2008-05-19
10:37:33 UTC (rev 8176)
@@ -9,10 +9,10 @@
private boolean serverStatus;
private String wsdlURI;
- private String portName;
- private String serviceName;
+ private List<String> portTypes;
+ private List<String> serviceName;
private String customPackage;
- private List<String> bindingFileLocation = new ArrayList<String>();
+ private List<String> bindingFileLocation;
private String catalog;
private String serviceClass;
private boolean isGenWSDL;
@@ -33,24 +33,37 @@
public void setCustomPackage(String packageText) {
this.customPackage = packageText;
}
- public String getPortName() {
- return portName;
+
+ public List<String> getPortTypes() {
+ if(portTypes == null){
+ portTypes = new ArrayList<String>();
+ }
+ return portTypes;
}
- public void setPortName(String portName) {
- this.portName = portName;
+ public void addPortTypes(String portType) {
+ this.getPortTypes().add(portType);
}
- public String getServiceName() {
+ public void setPortTypeList(List<String> portTypeList) {
+ this.portTypes = portTypeList;
+ }
+
+ public List<String> getServiceNames() {
return serviceName;
}
- public void setServiceName(String serviceName) {
- this.serviceName = serviceName;
+ public void addServiceName(String serviceName) {
+ this.getServiceNames().add(serviceName);
}
+ public void setServiceList(List<String> serviceList) {
+ this.serviceName = serviceList;
+ }
+
public String getWsdlURI() {
return wsdlURI;
}
public void setWsdlURI(String wsdlURI) {
this.wsdlURI = wsdlURI;
}
+
public boolean getServerStatus() {
return serverStatus;
}
@@ -66,6 +79,9 @@
}
public List<String> getBindingFiles(){
+ if(bindingFileLocation == null){
+ bindingFileLocation = new ArrayList<String>();
+ }
return this.bindingFileLocation;
}
public void addBindingFile(String bindingFileLocation){
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java 2008-05-19
08:30:08 UTC (rev 8175)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java 2008-05-19
10:37:33 UTC (rev 8176)
@@ -26,9 +26,18 @@
import java.util.Arrays;
import java.util.Locale;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaModel;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IParent;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jst.ws.internal.common.J2EEUtils;
public class JBossWSCreationUtils {
@@ -115,7 +124,6 @@
}
- //Fix for the windows build not working
private static String replaceEscapecharactors(String vulnarableString){
if (vulnarableString.indexOf("/")!=-1){
vulnarableString = vulnarableString.replace('/', File.separator.charAt(0));
@@ -162,7 +170,94 @@
return parts[parts.length-1];
}
+ // JDT utils
+ /**
+ * get JavaProject object from project name
+ */
+ public static IJavaProject getJavaProjectByName(String projectName) throws
JavaModelException {
+
+ IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
+ model.open(null);
+
+ IJavaProject[] projects = model.getJavaProjects();
+
+ for (IJavaProject proj : projects) {
+ if (proj.getProject().getName().equals(projectName)) {
+ return proj;
+ }
+ }
+
+ return null;
+ }
+ public static ICompilationUnit findUnitByFileName(IJavaElement javaElem,
+ String filePath) throws Exception {
+ ICompilationUnit unit = null;
+
+ if (!javaElem.getOpenable().isOpen()) {
+ javaElem.getOpenable().open(null);
+ }
+
+ IJavaElement[] elems = null;
+
+ if (javaElem instanceof IParent) {
+ IParent parent = (IParent) javaElem;
+ elems = parent.getChildren();
+ }
+
+ if (elems == null) {
+ return null;
+ }
+
+ for (IJavaElement elem : elems) {
+ if (elem.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) {
+ IPackageFragmentRoot root = (IPackageFragmentRoot) elem;
+
+ if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
+ unit = findUnitByFileName(elem, filePath);
+
+ if (unit != null) {
+ return unit;
+ }
+ }
+ } else if ((elem.getElementType() == IJavaElement.PACKAGE_FRAGMENT)
+ || (elem.getElementType() == IJavaElement.JAVA_PROJECT)) {
+ unit = findUnitByFileName(elem, filePath);
+
+ if (unit != null) {
+ return unit;
+ }
+ } else if (elem.getElementType() == IJavaElement.COMPILATION_UNIT) {
+ ICompilationUnit compUnit = (ICompilationUnit) elem;
+
+ if (compUnit.getPath().toString().equals(filePath)) {
+ compUnit.open(null);
+
+ return compUnit;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * get Java compilation unit by file path
+ * @param javaFile the java sour file to look
+ * @return ICompilationUnit, JDK compilation unit for this java file.
+ */
+ public static ICompilationUnit getJavaUnitFromFile(IFile javaFile) {
+ try {
+ IJavaProject project =
getJavaProjectByName(javaFile.getProject().getName());
+
+ if (project == null) {
+ return null;
+ }
+
+ return findUnitByFileName(project, javaFile.getFullPath().toString());
+ } catch (Exception e) {
+ return null;
+ }
+ }
-
}
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 2008-05-19
08:30:08 UTC (rev 8175)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/WSDLPropertyReader.java 2008-05-19
10:37:33 UTC (rev 8176)
@@ -30,20 +30,17 @@
import javax.wsdl.Definition;
import javax.wsdl.Port;
+import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.WSDLException;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.wst.command.internal.env.core.common.StatusUtils;
-
public class WSDLPropertyReader {
private Definition definition = null;
@@ -166,13 +163,13 @@
/**
- * Returns a list of service names the names are QNames
+ * Returns a list of service names the names are local parts
*
* @return
*/
- public List<QName> getServiceList() {
+ public List<String> getServiceList() {
- List<QName> returnList = new ArrayList<QName>();
+ List<String> returnList = new ArrayList<String>();
Service service;
Map serviceMap = definition.getServices();
@@ -182,12 +179,35 @@
while (serviceIterator.hasNext()) {
service = (Service) serviceIterator.next();
- returnList.add(service.getQName());
+ returnList.add(service.getQName().getLocalPart());
}
}
return returnList;
}
+
+ /**
+ * Returns a list of service names the names are local parts
+ *
+ * @return
+ */
+ public List<String> getPortTypeList() {
+
+ List<String> returnList = new ArrayList<String>();
+ PortType portType;
+ Map portTypeMap = definition.getPortTypes();
+
+ if (portTypeMap != null && !portTypeMap.isEmpty()) {
+ Iterator<Service> portTypeIterator = portTypeMap.values().iterator();
+ while (portTypeIterator.hasNext()) {
+
+ portType = (PortType) portTypeIterator.next();
+ returnList.add(portType.getQName().getLocalPart());
+ }
+ }
+ return returnList;
+ }
+
/**
* Returns a list of ports for a particular service the names are QNames
*
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.ui/src/org/jboss/tools/ws/creation/ui/wsrt/JBossWebService.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.ui/src/org/jboss/tools/ws/creation/ui/wsrt/JBossWebService.java 2008-05-19
08:30:08 UTC (rev 8175)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.ui/src/org/jboss/tools/ws/creation/ui/wsrt/JBossWebService.java 2008-05-19
10:37:33 UTC (rev 8176)
@@ -11,6 +11,7 @@
import org.eclipse.wst.ws.internal.wsrt.WebServiceInfo;
import org.eclipse.wst.ws.internal.wsrt.WebServiceScenario;
import org.jboss.tools.ws.creation.core.commands.BindingFilesValidationCommand;
+import org.jboss.tools.ws.creation.core.commands.ImplementationClassCreationCommand;
import org.jboss.tools.ws.creation.core.commands.InitialCommand;
import org.jboss.tools.ws.creation.core.commands.MergeWebXMLCommand;
import org.jboss.tools.ws.creation.core.commands.WSDL2JavaCommand;
@@ -49,6 +50,7 @@
commands.add(new InitialCommand(model, this, WebServiceScenario.TOPDOWN));
commands.add(new BindingFilesValidationCommand(model));
commands.add(new WSDL2JavaCommand(model));
+ commands.add(new ImplementationClassCreationCommand(model));
//commands.add(new
JbossWSRuntimeCommand(ResourcesPlugin.getWorkspace().getRoot().getProject(project)));
}
else if (ctx.getScenario().getValue() == WebServiceScenario.BOTTOMUP){