KickJava   Java API By Example, From Geeks To Geeks.

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


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.Endpoint;
32 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
33 import org.openide.filesystems.FileObject;
34 import org.openide.util.NbBundle;
35
36 /**
37  * This class collects usages of classes from sun-jaxws.xml file.
38  * <i>Currently only usages of classes that are endpoint implementation classes of
39  * web service from wsdl are collected.</i>.
40  *
41  * @author Erno Mononen
42  */

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

48     public SunJaxWsXmlWhereUsedRefactoring() {
49     }
50     
51     /**
52      * Collects usages of given java class from sun-jaxws.xml.
53      */

54     public Problem prepare(AbstractRefactoring refactoring, RefObject refObject, RefactoringElementsBag refactoringElements) {
55         
56         if (!(refObject instanceof JavaClass) || !isWebSvcFromWsdl((JavaClass) refObject)){
57             return null;
58         }
59         
60         JavaClass javaClass = (JavaClass) refObject;
61         FileObject sunjaxwsFo = getSunJaxWsXmlFile(javaClass);
62         
63         for (Endpoint each : getEndpoints(javaClass)) {
64             RefactoringElementImplementation elem = new SunJaxWsXmlWhereUsedElement(javaClass.getName(), sunjaxwsFo);
65             refactoringElements.add(refactoring, elem);
66         }
67         
68         return null;
69     }
70     
71     private static class SunJaxWsXmlWhereUsedElement extends AbstractWhereUsedRefactoringElement {
72         
73         public SunJaxWsXmlWhereUsedElement(String JavaDoc name, FileObject parentFile) {
74             this.name = name;
75             this.parentFile = parentFile;
76         }
77         
78         public String JavaDoc getDisplayText() {
79             Object JavaDoc[] args = new Object JavaDoc [] {name};
80             return MessageFormat.format(NbBundle.getMessage(SunJaxWsXmlWhereUsedRefactoring.class, "TXT_SunJaxWsXmlImplementationClassWhereUsed"), args);
81         }
82     }
83 }
Popular Tags