1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.mindcrimeilab.xsanalyzer.actions;
19
20 import java.beans.PropertyChangeEvent;
21 import java.beans.PropertyChangeListener;
22 import java.util.Map;
23 import java.util.concurrent.ExecutionException;
24
25 import javax.swing.JFrame;
26 import javax.xml.namespace.QName;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.xerces.xs.XSModel;
31 import org.apache.xerces.xs.XSObjectList;
32 import org.springframework.richclient.application.Application;
33 import org.springframework.richclient.command.support.ApplicationWindowAwareCommand;
34
35 import de.mindcrimeilab.swing.util.VisualProgressWorker;
36 import de.mindcrimeilab.xsanalyzer.SameNameDifferentTypeFinderWorker;
37 import de.mindcrimeilab.xsanalyzer.XsModelWalker;
38 import de.mindcrimeilab.xsanalyzer.model.XsAnalyzerApplicationModel;
39
40
41
42
43
44
45
46
47 public class SameNameDifferentTypeCommand extends ApplicationWindowAwareCommand {
48
49 private static final String ID = "sameNameDifferentTypeCommand";
50
51
52 private static final Log logger = LogFactory.getLog("xsAnalyzerApplicationLogger");
53
54
55
56
57 public SameNameDifferentTypeCommand() {
58 super(SameNameDifferentTypeCommand.ID);
59 }
60
61
62
63
64
65
66 @Override
67 protected void doExecuteCommand() {
68 final XsAnalyzerApplicationModel model = (XsAnalyzerApplicationModel) Application.instance().getApplicationContext().getBean("applicationModel");
69 final JFrame parent = Application.instance().getActiveWindow().getControl();
70 final VisualProgressWorker<Map<QName, ? extends XSObjectList>, Map.Entry<QName, ? extends XSObjectList>> worker = new VisualProgressWorker<Map<QName, ? extends XSObjectList>, Map.Entry<QName, ? extends XSObjectList>>(parent) {
71
72 @Override
73 protected Map<QName, ? extends XSObjectList> doInBackground() throws Exception {
74 final XSModel xsmodel = model.getSchemaModel();
75
76 final PropertyChangeListener changeListener = new PropertyChangeListener() {
77
78 @Override
79 public void propertyChange(PropertyChangeEvent evt) {
80 setDetailMessage("Examining type:" + evt.getNewValue());
81 }
82
83 };
84
85 final SameNameDifferentTypeFinderWorker sameNameFinder = new SameNameDifferentTypeFinderWorker();
86 final XsModelWalker walker = new XsModelWalker();
87 walker.addPropertyChangeListener(changeListener);
88 walker.addWorker(sameNameFinder);
89 walker.walkModel(xsmodel);
90
91 return sameNameFinder.getTypesWithSameName();
92 }
93
94 @SuppressWarnings("unchecked")
95 @Override
96 protected void done() {
97 try {
98 Map<QName, XSObjectList> sameNames = (Map<QName, XSObjectList>) get();
99 logger.debug("Found different types with same name [" + sameNames + "]");
100 model.setSameNamesDifferentTypes(sameNames);
101 Application.instance().getActiveWindow().getPage().showView("sameNameDifferentTypesView");
102 Application.instance().getApplicationContext().publishEvent(new XsAnalyzerApplicationEvent(EventType.SAME_NAMES, this));
103 }
104 catch (InterruptedException e) {
105 logger.error("Failed to analyze schema for same names with different types.", e);
106 e.printStackTrace();
107 }
108 catch (ExecutionException e) {
109 logger.error("Failed to analyze schema for same names with different types.", e);
110 e.printStackTrace();
111 }
112 finally {
113 super.done();
114 }
115 }
116
117 };
118 worker.setTitle("Operation in progress...");
119 worker.setActionText("Searching for similar type definitions");
120 worker.showProgressDialog();
121 worker.execute();
122 }
123 }