Source Code Cross Referenced for WSDLRefactoringPlugin.java in  » IDE-Netbeans » xml » org » netbeans » modules » xml » wsdl » refactoring » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » xml » org.netbeans.modules.xml.wsdl.refactoring 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * WSDLRefactoringPlugin.java
003:         *
004:         * Created on February 20, 2007, 2:02 PM
005:         *
006:         * To change this template, choose Tools | Template Manager
007:         * and open the template in the editor.
008:         */
009:
010:        package org.netbeans.modules.xml.wsdl.refactoring;
011:
012:        import java.io.IOException;
013:        import java.util.ArrayList;
014:        import java.util.Collection;
015:        import java.util.Collections;
016:        import java.util.Collections;
017:        import java.util.HashMap;
018:        import java.util.HashSet;
019:        import java.util.Iterator;
020:        import java.util.List;
021:        import java.util.Map;
022:        import java.util.Set;
023:        import org.netbeans.modules.refactoring.api.Problem;
024:        import org.netbeans.modules.refactoring.api.RefactoringSession;
025:        import org.netbeans.modules.refactoring.spi.ProgressProviderAdapter;
026:        import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
027:        import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
028:        import org.netbeans.modules.xml.refactoring.ErrorItem;
029:        import org.netbeans.modules.xml.refactoring.XMLRefactoringPlugin;
030:        import org.netbeans.modules.xml.refactoring.XMLRefactoringTransaction;
031:        import org.netbeans.modules.xml.refactoring.spi.SharedUtils;
032:        import org.netbeans.modules.xml.schema.model.ReferenceableSchemaComponent;
033:        import org.netbeans.modules.xml.schema.model.SchemaModel;
034:        import org.netbeans.modules.xml.wsdl.model.Definitions;
035:        import org.netbeans.modules.xml.wsdl.model.Import;
036:        import org.netbeans.modules.xml.wsdl.model.ReferenceableWSDLComponent;
037:        import org.netbeans.modules.xml.wsdl.model.WSDLModel;
038:        import org.netbeans.modules.xml.wsdl.model.WSDLModelFactory;
039:        import org.netbeans.modules.xml.wsdl.refactoring.xsd.FindSchemaUsageVisitor;
040:        import org.netbeans.modules.xml.wsdl.refactoring.xsd.SchemaUsageRefactoringEngine;
041:        import org.netbeans.modules.xml.xam.Component;
042:        import org.netbeans.modules.xml.xam.Model;
043:        import org.netbeans.modules.xml.xam.ModelSource;
044:        import org.netbeans.modules.xml.xam.Referenceable;
045:        import org.netbeans.modules.xml.xam.locator.CatalogModelException;
046:        import org.openide.ErrorManager;
047:        import org.openide.filesystems.FileObject;
048:        import org.openide.filesystems.FileUtil;
049:
050:        /**
051:         *
052:         * @author Sonali
053:         */
054:        public abstract class WSDLRefactoringPlugin extends
055:                ProgressProviderAdapter implements  RefactoringPlugin,
056:                XMLRefactoringPlugin {
057:
058:            /**
059:             * Creates a new instance of WSDLRefactoringPlugin
060:             */
061:            List<ErrorItem> findErrors;
062:            RefactoringSession session;
063:            XMLRefactoringTransaction transaction;
064:            public static final String WSDL_MIME_TYPE = "text/x-wsdl+xml";
065:
066:            public WSDLRefactoringPlugin() {
067:            }
068:
069:            public List<WSDLRefactoringElement> find(Referenceable target,
070:                    Component searchRoot) {
071:                if (target instanceof  Model) {
072:                    return findUsages((Model) target, searchRoot);
073:                } else if (target instanceof  Component) {
074:                    return findUsages((Component) target, searchRoot);
075:                } else {
076:                    return null;
077:                }
078:            }
079:
080:            public List<WSDLRefactoringElement> findUsages(Model target,
081:                    Component searchRoot) {
082:                List<WSDLRefactoringElement> elements = new ArrayList<WSDLRefactoringElement>();
083:                if (target instanceof  WSDLModel
084:                        && searchRoot instanceof  Definitions) {
085:                    Definitions definitions = (Definitions) searchRoot;
086:                    String namespace = ((WSDLModel) target).getDefinitions()
087:                            .getTargetNamespace();
088:                    // UsageGroup ug = new UsageGroup(this, searchRoot.getModel(), (WSDLModel) target);
089:                    for (Import i : definitions.getImports()) {
090:                        Model imported = null;
091:                        if (namespace.equals(i.getNamespace())) {
092:                            try {
093:                                imported = i.getImportedWSDLModel();
094:                            } catch (CatalogModelException ex) {
095:                                findErrors.add(new ErrorItem(searchRoot, ex
096:                                        .getMessage()));
097:                            }
098:                        }
099:                        if (imported == target) {
100:                            elements.add(new WSDLRefactoringElement(searchRoot
101:                                    .getModel(), target, i));
102:                        }
103:                    }
104:                }
105:
106:                SchemaUsageRefactoringEngine engine = new SchemaUsageRefactoringEngine();
107:                List<WSDLRefactoringElement> elem = engine.findUsages(target,
108:                        searchRoot);
109:                if (elem != null)
110:                    elements.addAll(elem);
111:
112:                if (elements.size() > 0)
113:                    return elements;
114:                else
115:                    return Collections.emptyList();
116:            }
117:
118:            public List<WSDLRefactoringElement> findUsages(Component target,
119:                    Component searchRoot) {
120:                List<WSDLRefactoringElement> elements = new ArrayList<WSDLRefactoringElement>();
121:                List<WSDLRefactoringElement> temp = null;
122:
123:                if (target instanceof  ReferenceableWSDLComponent
124:                        && searchRoot instanceof  Definitions) {
125:                    temp = new FindWSDLUsageVisitor().findUsages(
126:                            (ReferenceableWSDLComponent) target,
127:                            (Definitions) searchRoot);
128:                    if (temp != null && temp.size() > 0)
129:                        elements.addAll(temp);
130:                }
131:
132:                if (target instanceof  ReferenceableSchemaComponent
133:                        && searchRoot instanceof  Definitions) {
134:                    temp = new FindSchemaUsageVisitor().findUsages(
135:                            (ReferenceableSchemaComponent) target,
136:                            (Definitions) searchRoot, session, transaction);
137:                    if (temp != null && temp.size() > 0)
138:                        elements.addAll(temp);
139:                }
140:
141:                if (elements.size() == 0) {
142:                    return Collections.emptyList();
143:                } else {
144:                    return elements;
145:                }
146:            }
147:
148:            public List<Model> getModels(List<WSDLRefactoringElement> elements) {
149:                List<Model> models = new ArrayList<Model>();
150:                for (WSDLRefactoringElement element : elements) {
151:                    models.add(((Component) element.getLookup().lookup(
152:                            Component.class)).getModel());
153:                }
154:                return models;
155:            }
156:
157:            public Set<Component> getSearchRoots(Referenceable target) {
158:                Set<Component> searchRoots = new HashSet<Component>();
159:                Set<FileObject> files = SharedUtils.getSearchFiles(target);
160:                for (FileObject file : files) {
161:                    WSDLRefactoringEngine engine = new WSDLRefactoringEngine();
162:                    try {
163:                        Component root = engine.getSearchRoot(file);
164:                        searchRoots.add(root);
165:                    } catch (IOException ex) {
166:                        ErrorManager.getDefault().log(
167:                                ErrorManager.INFORMATIONAL, ex.getMessage());
168:                    }
169:                }
170:
171:                return searchRoots;
172:            }
173:
174:            public Map<Model, Set<RefactoringElementImplementation>> getModelMap(
175:                    List<RefactoringElementImplementation> elements) {
176:                Map<Model, Set<RefactoringElementImplementation>> results = new HashMap<Model, Set<RefactoringElementImplementation>>();
177:                for (RefactoringElementImplementation element : elements) {
178:                    Component comp = element.getLookup()
179:                            .lookup(Component.class);
180:                    Model model = null;
181:                    if (comp instanceof  org.netbeans.modules.xml.schema.model.Import) {
182:                        //special case of embedded schema import statements in WSDLModel
183:                        //for embedded schema, group the RE impls by Foreign Model
184:                        SchemaModel mod = (SchemaModel) comp.getModel();
185:                        if (mod != null) {
186:                            Component wsdlImport = mod.getSchema()
187:                                    .getForeignParent();
188:                            if (wsdlImport != null) {
189:                                model = wsdlImport.getModel();
190:                            }
191:                        }
192:                    } else
193:                        model = comp.getModel();
194:                    if (model == null)
195:                        continue;
196:                    Set<RefactoringElementImplementation> elementsInModel = results
197:                            .get(model);
198:                    if (elementsInModel == null) {
199:                        elementsInModel = new HashSet<RefactoringElementImplementation>();
200:                        elementsInModel.add(element);
201:                        results.put(model, elementsInModel);
202:                    } else
203:                        elementsInModel.add(element);
204:                }
205:                return results;
206:            }
207:
208:            public boolean isFatal(ErrorItem error) {
209:                if (error.getLevel() == ErrorItem.Level.FATAL)
210:                    return true;
211:                else
212:                    return false;
213:            }
214:
215:            public Problem processErrors(List<ErrorItem> errorItems) {
216:
217:                if (errorItems == null || errorItems.size() == 0) {
218:                    return null;
219:                }
220:                Problem parent = null;
221:                Problem child = null;
222:                Problem head = null;
223:                Iterator<ErrorItem> iterator = errorItems.iterator();
224:
225:                while (iterator.hasNext()) {
226:                    ErrorItem error = iterator.next();
227:                    if (parent == null) {
228:                        parent = new Problem(isFatal(error), error.getMessage());
229:                        child = parent;
230:                        head = parent;
231:                        continue;
232:                    }
233:                    child = new Problem(isFatal(error), error.getMessage());
234:                    parent.setNext(child);
235:                    parent = child;
236:
237:                }
238:
239:                return head;
240:            }
241:
242:            public String getModelReference(Component component) {
243:                if (component instanceof  Import) {
244:                    return ((Import) component).getLocation();
245:                }
246:                return null;
247:            }
248:
249:            public void setModelReference(Component component, String location) {
250:                //do nothing
251:            }
252:
253:            public Collection<Component> getExternalReferences(Model model) {
254:                Collection<Component> refs = new ArrayList<Component>();
255:                if (model instanceof  WSDLModel) {
256:                    refs.addAll(((WSDLModel) model).getDefinitions()
257:                            .getImports());
258:                }
259:                return refs;
260:            }
261:
262:            public Model getModel(ModelSource source) {
263:                FileObject fo = source.getLookup().lookup(FileObject.class);
264:                if (WSDL_MIME_TYPE.equals(FileUtil.getMIMEType(fo))) {
265:                    WSDLModel model = WSDLModelFactory.getDefault().getModel(
266:                            source);
267:                    return model;
268:                }
269:                return null;
270:            }
271:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.