KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > refactoring > moveclass > JaxWsXmlMoveClassRefactoring


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.refactoring.moveclass;
21
22 import java.text.MessageFormat JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import org.netbeans.jmi.javamodel.JavaClass;
26 import org.netbeans.jmi.javamodel.Resource;
27 import org.netbeans.modules.j2ee.refactoring.jaxwssupport.JaxWsXmlRefactoringElementSupport;
28 import org.netbeans.modules.j2ee.refactoring.jaxwssupport.JaxWsXmlRefactoringSupport;
29 import org.netbeans.modules.refactoring.api.MoveClassRefactoring;
30 import org.netbeans.modules.refactoring.api.Problem;
31 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
32 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
33 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
34 import org.netbeans.modules.websvc.api.jaxws.project.config.Service;
35 import org.openide.filesystems.FileObject;
36 import org.openide.util.NbBundle;
37
38 /**
39  * This class handles renaming of a webservice imlementation class
40  * in jax-ws.xml (handles only webservices from WSDL file, other types
41  * of webservices are supported through other means).
42  *
43  * @author Erno Mononen
44  */

45 public class JaxWsXmlMoveClassRefactoring extends JaxWsXmlRefactoringSupport {
46     
47     /**
48      * Creates a new instance of JaxWsMoveClassRefactoring
49      */

50     public JaxWsXmlMoveClassRefactoring() {
51     }
52     
53     /**
54      * Finds uages in jax-ws.xml
55      */

56     public Problem prepare(MoveClassRefactoring moveClassRefactor,
57             Collection JavaDoc resources, RefactoringElementsBag refactoringElements) {
58         
59         for (Iterator JavaDoc it = resources.iterator(); it.hasNext();) {
60             Resource elem = (Resource) it.next();
61             
62             for (Iterator JavaDoc it2 = elem.getClassifiers().iterator(); it2.hasNext();) {
63                 JavaClass javaClass = (JavaClass) it2.next();
64                 
65                 JaxWsModel model = getModel(javaClass);
66                 if (model == null){
67                     // no jax-ws.xml in the project
68
return null;
69                 }
70                 if (!isWebSvcFromWsdl(javaClass)){
71                     continue;
72                 }
73                 
74                 String JavaDoc newName = moveClassRefactor.getTargetPackageName(elem) + "." + javaClass.getSimpleName();
75                 Service service = model.findServiceByImplementationClass(javaClass.getName());
76                 if (service != null){
77                     RefactoringElementImplementation refactoringElem =
78                             new JaxWsXmlMoveClassRefactoringElement(javaClass.getName(), newName, model, service, model.getJaxWsFile());
79                     
80                     refactoringElements.add(moveClassRefactor, refactoringElem);
81                     
82                 }
83             }
84         }
85         
86         return null;
87     }
88     
89     /**
90      * Move class refactoring element for jax-ws.xml
91      */

92     private static class JaxWsXmlMoveClassRefactoringElement extends JaxWsXmlRefactoringElementSupport {
93         
94         /**
95          * Creates a new instance of JaxWsXmlMoveClassRefactoringElement
96          * @param oldName the fully qualified old name of the implementation class
97          * @param newName the fully qualified new name of the implementation class
98          * @service the service whose implementation class is to be renamed
99          * @parentFile the file object representing jax-ws.xml
100          */

101         public JaxWsXmlMoveClassRefactoringElement(String JavaDoc oldName, String JavaDoc newName,
102                 JaxWsModel model, Service service, FileObject parentFile) {
103             super(oldName, newName, model, service, parentFile);
104         }
105         
106         /**
107          * Returns text describing the refactoring formatted for display (using HTML tags).
108          * @return Formatted text.
109          */

110         public String JavaDoc getDisplayText() {
111             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
112             return MessageFormat.format(NbBundle.getMessage(JaxWsXmlMoveClassRefactoring.class, "TXT_JaxWsXmlMoveClass"), args);
113         }
114         
115     }
116     
117 }
118
Popular Tags