KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > refactoring > whereused > JaxWsXmlWhereUsedRefactoring


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.whereused;
21
22 import java.text.MessageFormat JavaDoc;
23 import javax.jmi.reflect.RefObject;
24 import org.netbeans.jmi.javamodel.JavaClass;
25 import org.netbeans.modules.j2ee.refactoring.jaxwssupport.JaxWsXmlRefactoringSupport;
26 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
27 import org.netbeans.modules.refactoring.api.Problem;
28 import org.netbeans.modules.refactoring.api.RefactoringElement;
29 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
30 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
31 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
32 import org.openide.filesystems.FileObject;
33 import org.openide.util.NbBundle;
34
35 /**
36  * This class collects usages of classes from jax-ws.xml file.
37  * <i>Currently only usages of classes that are implementation classes of
38  * web service from wsdl are collected.</i>.
39  *
40  * @author Erno Mononen
41  */

42 public class JaxWsXmlWhereUsedRefactoring extends JaxWsXmlRefactoringSupport {
43     
44     /**
45      * Creates a new instance of JaxWsXmlWhereUsedRefactoring
46      */

47     public JaxWsXmlWhereUsedRefactoring() {
48     }
49     
50     /**
51      * Collects usages of given java class from jax-ws.xml.
52      */

53     public Problem prepare(AbstractRefactoring refactoring, RefObject refObject, RefactoringElementsBag refactoringElements) {
54         
55         if (!(refObject instanceof JavaClass) || !isWebSvcFromWsdl((JavaClass) refObject)){
56             return null;
57         }
58         
59         JavaClass javaClass = (JavaClass) refObject;
60         
61         JaxWsModel model = getModel(javaClass);
62         if (model != null && model.findServiceByImplementationClass(javaClass.getName()) != null){
63             RefactoringElementImplementation elem = new JaxWsXmlWhereUsedElement(javaClass.getName(), model.getJaxWsFile());
64             refactoringElements.add(refactoring, elem);
65         }
66         
67         return null;
68         
69         
70     }
71     
72     private static class JaxWsXmlWhereUsedElement extends AbstractWhereUsedRefactoringElement {
73         
74         public JaxWsXmlWhereUsedElement(String JavaDoc name, FileObject parentFile) {
75             this.name = name;
76             this.parentFile = parentFile;
77         }
78         
79         public String JavaDoc getDisplayText() {
80             Object JavaDoc[] args = new Object JavaDoc [] {name};
81             return MessageFormat.format(NbBundle.getMessage(JaxWsXmlWhereUsedRefactoring.class, "TXT_JaxWsXmlImplementationClassWhereUsed"), args);
82         }
83         
84     }
85 }
Popular Tags