KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > refactoring > XMLWhereUsedRefactoringPlugin


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.xml.refactoring;
21
22 import java.util.Collection JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.concurrent.ExecutionException JavaDoc;
25 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
26 import org.netbeans.modules.refactoring.api.Problem;
27 import org.netbeans.modules.refactoring.api.ProgressEvent;
28 import org.netbeans.modules.refactoring.spi.ProgressProviderAdapter;
29 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
30 import org.netbeans.modules.refactoring.api.WhereUsedQuery;
31 import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
32 import org.netbeans.modules.xml.xam.Component;
33 import org.netbeans.modules.xml.xam.Named;
34 import org.netbeans.modules.xml.xam.Referenceable;
35 import org.openide.ErrorManager;
36
37
38
39 /**
40  *
41  * @author Sonali Kochar
42  */

43 public class XMLWhereUsedRefactoringPlugin extends ProgressProviderAdapter implements RefactoringPlugin {
44     
45    
46     
47     public void cancelRequest() {
48         
49     }
50     
51     public Problem fastCheckParameters() {
52         return null;
53     }
54     
55     private WhereUsedQuery query;
56     
57     
58     /**
59      * Creates a new instance of XMLWhereUsedRefactoringPlugin
60      */

61     public XMLWhereUsedRefactoringPlugin(WhereUsedQuery refactoring) {
62         this.query = refactoring;
63     }
64     
65     /** Checks pre-conditions of the refactoring and returns problems.
66      * @return Problems found or null (if no problems were identified)
67      */

68     public Problem preCheck() {
69         return null;
70     }
71     
72     /** Checks parameters of the refactoring.
73      * @return Problems found or null (if no problems were identified)
74      */

75     public Problem checkParameters() {
76         Problem problem = null;
77        
78         return problem;
79     }
80     
81     /** Collects refactoring elements for a given refactoring.
82      * @param refactoringElements Collection of refactoring elements - the implementation of this method
83      * should add refactoring elements to this collections. It should make no assumptions about the collection
84      * content.
85      * @return Problems found or null (if no problems were identified)
86      */

87     public Problem prepare(RefactoringElementsBag refactoringElements) {
88         Referenceable ref = query.getRefactoringSource().lookup(Referenceable.class);
89         if (ref == null)
90             return null;
91         //Referenceable ref = (Referenceable)query.getRefactoredObject();
92
fireProgressListenerStart(ProgressEvent.START, -1);
93         FindUsageResult fuResult =RefactoringManager.getInstance().findUsages(ref);
94         UsageSet us = null;
95         try {
96             us = fuResult.get();
97         } catch (InterruptedException JavaDoc ex) {
98             ErrorManager.getDefault().notify(ex);
99         } catch (ExecutionException JavaDoc ex) {
100             ErrorManager.getDefault().notify(ex);
101         }
102         Collection JavaDoc<UsageGroup> usageGroups = us.getUsages();
103         for (UsageGroup ug:usageGroups){
104                     int count = ug.getItems().size();
105                     List JavaDoc<Usage> usage = ug.getItems();
106                     for(Usage u:usage){
107                        refactoringElements.add(query, new XMLRefactoringElement(u));
108                        fireProgressListenerStep();
109                     }
110         }
111         fireProgressListenerStop();
112         //System.out.println("done");
113

114       return null;
115     }
116     
117       
118     
119 }
120
121
Popular Tags