KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > refactoring > spi > RefactoringEngine


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.refactoring.spi;
20
21 import java.io.IOException JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.modules.xml.refactoring.DeleteRequest;
25 import org.netbeans.modules.xml.refactoring.ErrorItem;
26 import org.netbeans.modules.xml.refactoring.RefactorRequest;
27 import org.netbeans.modules.xml.refactoring.UsageGroup;
28 import org.netbeans.modules.xml.xam.Component;
29 import org.netbeans.modules.xml.xam.Model;
30 import org.netbeans.modules.xml.xam.Referenceable;
31 import org.openide.filesystems.FileObject;
32
33 /**
34  * Provides capabilities of searching and refactoring usages of a certain
35  * class of components in a certain set of models. Refactoring manager will
36  * lookup of the service through entries declared in META-INF/services files.
37  *
38  * @author Nam Nguyen
39  */

40
41 public abstract class RefactoringEngine {
42     /**
43      * @returns the component where the search for usages should start;
44      * or null if the given file is not applicable source or does not
45      * contains an applicable search entry point.
46      * @exception IOException if could not load the model source.
47      */

48     public abstract Component getSearchRoot(FileObject file) throws IOException JavaDoc;
49     
50     /**
51      * Returns usages of the given target component or null if target
52      * is not applicable to current engine. If target is root component, the
53      * search is for model references through import, include, redefine...
54      *
55      * @param target the component for which usage is search for.
56      * @param searchRoot the scope of the search.
57      * @return list of usages; or empty list if no usages found; or null if not applicable.
58      */

59     public abstract List JavaDoc<UsageGroup> findUsages(Component target, Component searchRoot);
60
61     /**
62      * Returns usages of the given target component or null if target
63      * is not applicable to current engine. If target is root component, the
64      * search is for model references through import, include, redefine...
65      *
66      * @param target the model for which usage is search for.
67      * @param searchRoot the scope of the search.
68      * @return list of usages; or empty list if no usages found; or null if not applicable.
69      */

70     public abstract List JavaDoc<UsageGroup> findUsages(Model target, Component searchRoot);
71
72     /**
73      * Returns usages of the given target component or null if search target or
74      * file is not applicable to current engine. Implemantation should override
75      * if wish to report errors during loading of the model source.
76      * @param target the component for which usage is search for.
77      * @param file the file to search.
78      * @return list of usages, or empty list if no usages found.
79      */

80     public List JavaDoc<UsageGroup> findUsages(Component target, FileObject file) {
81         if (! (target instanceof Referenceable)) {
82             return null;
83         }
84         ErrorItem error = null;
85         Component searchRoot = null;
86         try {
87             searchRoot = getSearchRoot(file);
88         } catch (Exception JavaDoc e) {
89             error = new ErrorItem(file, e.getMessage());
90         }
91
92         if (error == null) {
93             if (searchRoot != null) {
94                 return findUsages(target, searchRoot);
95             } else {
96                 return Collections.emptyList();
97             }
98         } else {
99             UsageGroup usages = new UsageGroup(this, file, (Referenceable) target);
100             usages.addError(error);
101             return Collections.singletonList(usages);
102         }
103     }
104     
105     /**
106      * Returns UI helper in displaying the usages. Implementation could override
107      * the default UI to help display usages in a more intuitive way than the
108      * generic helper.
109      */

110     public UIHelper getUIHelper() {
111         return new UIHelper();
112     }
113
114     /**
115      * Perform a pre-change checking on the refactor request.
116      * Implementation should quietly ignore unsupported refactoring type.
117      */

118     public void precheck(RefactorRequest request) {
119     if (request instanceof DeleteRequest) {
120         SharedUtils.addCascadeDeleteErrors((DeleteRequest)request, this);
121     }
122     }
123     
124     /**
125      * Refactor usages specified by request.
126      * Implementation should quietly ignore unsupported refactoring type.
127      */

128     public void refactorUsages(RefactorRequest request) throws IOException JavaDoc {
129     }
130
131     /**
132      * @param component the component to check for model reference.
133      * @return the reference string if this component is a reference to an
134      * external model, for example, the schema <import> component,
135      * otherwise returns null.
136      */

137     public String JavaDoc getModelReference(Component component) {
138         return null;
139     }
140 }
141      
Popular Tags