KickJava   Java API By Example, From Geeks To Geeks.

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


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.Utility;
28 import org.netbeans.modules.j2ee.refactoring.jaxwssupport.JaxWsXmlRefactoringSupport;
29 import org.netbeans.modules.j2ee.refactoring.jaxwssupport.SunJaxWsXmlElementSupport;
30 import org.netbeans.modules.refactoring.api.MoveClassRefactoring;
31 import org.netbeans.modules.refactoring.api.Problem;
32 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
33 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
34 import org.netbeans.modules.websvc.api.jaxws.project.config.Endpoint;
35 import org.netbeans.modules.websvc.api.jaxws.project.config.Endpoints;
36 import org.openide.filesystems.FileObject;
37 import org.openide.util.NbBundle;
38
39 /**
40  * This class handles moving of a web service endpoint imlementation class
41  * in sun-jaxws.xml (handles only webservices from WSDL file, other types
42  * of web services are supported through other means).
43  *
44  * @author Erno Mononen
45  */

46 public class SunJaxWsXmlMoveClassRefactoring extends JaxWsXmlRefactoringSupport {
47     
48     /**
49      * Creates a new instance of SunJaxWsXmlMoveClassRefactoring
50      */

51     public SunJaxWsXmlMoveClassRefactoring() {
52     }
53     
54     /**
55      * Finds uages in the sun-jaxws.xml
56      */

57     public Problem prepare(MoveClassRefactoring moveClassRefactor,
58             Collection JavaDoc resources, RefactoringElementsBag refactoringElements) {
59         
60         for (Iterator JavaDoc it = resources.iterator(); it.hasNext();) {
61             Resource elem = (Resource) it.next();
62             
63             for (Iterator JavaDoc it2 = elem.getClassifiers().iterator(); it2.hasNext();) {
64                 JavaClass javaClass = (JavaClass) it2.next();
65                 
66                 if (!isWebSvcFromWsdl(javaClass)){
67                     continue;
68                 }
69                 
70                 Endpoints model = getEndpointsModel(javaClass);
71                 if (model == null){
72                     return null;
73                 }
74                 
75                 FileObject sunjaxwsfile = getSunJaxWsXmlFile(javaClass);
76                 String JavaDoc newName = moveClassRefactor.getTargetPackageName(elem) + "." + javaClass.getSimpleName();
77                 
78                 for (Endpoint each : getEndpoints(javaClass)) {
79                     RefactoringElementImplementation refactoringElem =
80                             new SunJaxWsXmlMoveClassRefactoringElement(javaClass.getName(), newName, model, each, sunjaxwsfile);
81
82                     refactoringElements.add(moveClassRefactor, refactoringElem);
83                     
84                 }
85             }
86         }
87         return null;
88     }
89     
90     /**
91      * Move class refactoring element for sun-jaxws.xml
92      */

93     private static class SunJaxWsXmlMoveClassRefactoringElement extends SunJaxWsXmlElementSupport {
94         
95         public SunJaxWsXmlMoveClassRefactoringElement(String JavaDoc oldName, String JavaDoc newName,
96                 Endpoints model, Endpoint endpoint, FileObject parentFile) {
97             super(oldName, newName, model, endpoint, parentFile);
98         }
99         
100         public String JavaDoc getDisplayText() {
101             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
102             return MessageFormat.format(NbBundle.getMessage(SunJaxWsXmlMoveClassRefactoring.class, "TXT_SunJaxWsXmlMoveClass"), args);
103         }
104         
105     }
106     
107 }
108
Popular Tags