use of com.twinsoft.convertigo.eclipse.dialogs.TransactionXSDTypesDialog in project convertigo by convertigo.
the class UpdateXSDTypesAction method run.
public void run() {
final Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
ProjectTreeObject projectTreeObject = treeObject.getProjectTreeObject();
MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION | SWT.APPLICATION_MODAL);
String message = "Do you really want to extract the schema?\nWarning: the previous one will be replaced.";
messageBox.setMessage(message);
if (messageBox.open() == SWT.YES) {
RequestableObject requestable = (RequestableObject) treeObject.getObject();
String requestableName = StringUtils.normalize(requestable.getName(), true);
Document document = null;
String result = null;
if (!(requestableName.equals(requestable.getName()))) {
throw new Exception("Requestable name should be normalized");
}
if (requestable instanceof Transaction) {
Connector connector = (Connector) requestable.getParent();
String connectorName = StringUtils.normalize(connector.getName(), true);
if (!(connectorName.equals(connector.getName()))) {
throw new Exception("Connector name should be normalized");
}
if (connector.getDefaultTransaction() == null) {
throw new Exception("Connector must have a default transaction");
}
if (requestable instanceof HtmlTransaction) {
if (extract) {
ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
if (connectorEditor == null) {
ConvertigoPlugin.infoMessageBox("Please open connector first.");
return;
}
document = connectorEditor.getLastGeneratedDocument();
if (document == null) {
ConvertigoPlugin.infoMessageBox("You should first generate the document data before trying to extract the XSD types.");
return;
}
result = requestable.generateXsdTypes(document, extract);
} else {
HtmlTransaction defaultTransaction = (HtmlTransaction) connector.getDefaultTransaction();
String defaultTransactionName = StringUtils.normalize(defaultTransaction.getName(), true);
if (!(defaultTransactionName.equals(defaultTransaction.getName()))) {
throw new Exception("Default transaction name should be normalized");
}
String defaultXsdTypes = defaultTransaction.generateXsdTypes(null, false);
if (requestable.equals(defaultTransaction))
result = defaultXsdTypes;
else {
TransactionXSDTypesDialog dlg = new TransactionXSDTypesDialog(shell, requestable);
if (dlg.open() == Window.OK) {
result = dlg.result;
result += defaultXsdTypes;
}
}
}
} else {
if (extract) {
ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
if (connectorEditor == null) {
ConvertigoPlugin.infoMessageBox("Please open connector first.");
return;
}
document = connectorEditor.getLastGeneratedDocument();
if (document == null) {
ConvertigoPlugin.infoMessageBox("You should first generate the document data before trying to extract the XSD types.");
return;
}
String prefix = requestable.getXsdTypePrefix();
document.getDocumentElement().setAttribute("transaction", prefix + requestableName);
}
if (requestable instanceof XmlHttpTransaction) {
XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) requestable;
XmlQName xmlQName = xmlHttpTransaction.getXmlElementRefAffectation();
String reqn = xmlHttpTransaction.getResponseElementQName();
if (extract && ((!xmlQName.isEmpty()) || (!reqn.equals("")))) {
if (!xmlQName.isEmpty()) {
ConvertigoPlugin.infoMessageBox("You should first unset 'Assigned element QName' property.");
return;
}
if (!reqn.equals("")) {
ConvertigoPlugin.infoMessageBox("You should first unset 'Schema of XML response root element' property.");
return;
}
}
}
result = requestable.generateXsdTypes(document, extract);
}
}
if ((result != null) && (!result.equals(""))) {
String xsdTypes = result;
if (requestable instanceof Transaction) {
if (requestable instanceof XmlHttpTransaction) {
XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) requestable;
XmlQName xmlQName = xmlHttpTransaction.getXmlElementRefAffectation();
String reqn = xmlHttpTransaction.getResponseElementQName();
if (!extract && ((!xmlQName.isEmpty()) || (!reqn.equals("")))) {
// ignore
;
} else
((Transaction) requestable).writeSchemaToFile(xsdTypes);
} else
((Transaction) requestable).writeSchemaToFile(xsdTypes);
}
requestable.hasChanged = true;
Engine.theApp.schemaManager.clearCache(requestable.getProject().getName());
explorerView.refreshFirstSelectedTreeObject();
explorerView.objectSelected(new CompositeEvent(requestable));
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to update schema!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations