use of com.twinsoft.convertigo.beans.statements.HandlerStatement in project convertigo by convertigo.
the class ChangeToScExitHandlerStatementAction method run.
/* (non-Javadoc)
* @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#run()
*/
@Override
public void run() {
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) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
DatabaseObject databaseObject = treeObject.getObject();
// For ScEntryHandler statement
if ((databaseObject != null) && (databaseObject instanceof ScEntryHandlerStatement || databaseObject instanceof ScEntryDefaultHandlerStatement)) {
HandlerStatement scEntryHandlerStatement = (HandlerStatement) databaseObject;
DatabaseObjectTreeObject parentTreeObject = treeObject.getOwnerDatabaseObjectTreeObject();
if (parentTreeObject != null) {
// New ScExitHandler statement
HandlerStatement scExitHandlerStatement = databaseObject instanceof ScEntryHandlerStatement ? new ScExitHandlerStatement() : new ScExitDefaultHandlerStatement();
// Set properties
String handlerResult = scEntryHandlerStatement.getHandlerResult();
if (ScHandlerStatement.RETURN_REDETECT.equals(handlerResult)) {
handlerResult = ScHandlerStatement.RETURN_ACCUMULATE;
} else if (ScHandlerStatement.RETURN_SKIP.equals(handlerResult)) {
handlerResult = "";
}
scExitHandlerStatement.setHandlerResult(handlerResult);
scExitHandlerStatement.setComment(scEntryHandlerStatement.getComment());
scExitHandlerStatement.setEnabled(scEntryHandlerStatement.isEnabled());
scExitHandlerStatement.setPreventFromLoops(scEntryHandlerStatement.preventFromLoops());
scExitHandlerStatement.setParent(scEntryHandlerStatement.getParent());
scExitHandlerStatement.setReturnedValue(scEntryHandlerStatement.getReturnedValue());
scExitHandlerStatement.setVersion(scEntryHandlerStatement.getVersion());
if (databaseObject instanceof ScEntryHandlerStatement) {
ScExitHandlerStatement scExit = (ScExitHandlerStatement) scExitHandlerStatement;
ScEntryHandlerStatement scEntry = (ScEntryHandlerStatement) scEntryHandlerStatement;
scExit.setNormalizedScreenClassName(scEntry.getNormalizedScreenClassName());
scExit.setName("on" + scEntry.getNormalizedScreenClassName() + "Exit");
}
// Change status of scExitHanlder statement
scExitHandlerStatement.bNew = true;
scExitHandlerStatement.hasChanged = true;
// Add new ScExitHandler statement to parent
DatabaseObject parentDbo = scEntryHandlerStatement.getParent();
parentDbo.add(scExitHandlerStatement);
// Add new ScExitHandler statement in Tree
StatementTreeObject statementTreeObject = new StatementTreeObject(explorerView.viewer, scExitHandlerStatement);
parentTreeObject.addChild(statementTreeObject);
for (Statement statement : scEntryHandlerStatement.getStatements()) {
scExitHandlerStatement.addStatement(statement);
}
// Delete ScEntryHandler statement
scEntryHandlerStatement.delete();
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
DatabaseObjectTreeObject newTreeObject = parentTreeObject.findDatabaseObjectTreeObjectChild(scExitHandlerStatement);
explorerView.setSelectedTreeObject(newTreeObject);
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change screen class entry handler statement to screen class exit handler statement!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.statements.HandlerStatement in project convertigo by convertigo.
the class HtmlConnectorDesignComposite method modelChanged.
public void modelChanged(HttpProxyEvent event) {
if (!checkProxySource(event)) {
return;
}
String requestString = event.getRequest();
String responseString = event.getResponse();
boolean https = event.isHttps();
int status = Integer.parseInt(event.getStatus());
// do not record client redirection
if ((status == HttpStatus.SC_MOVED_TEMPORARILY) || (status == HttpStatus.SC_MOVED_PERMANENTLY) || (status == HttpStatus.SC_SEE_OTHER) || (status == HttpStatus.SC_TEMPORARY_REDIRECT)) {
return;
}
/*if (requestString.indexOf(getServer()) == -1) {
return;
}*/
Map<String, String> headers = parseResponseString(responseString);
String contentType = headers.get(HeaderName.ContentType.value().toLowerCase());
// record only text/html or null Content-Type ...
if (contentType == null) {
return;
}
if (MimeType.Html.is(contentType) && MimeType.Plain.is(contentType)) {
return;
}
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) Learning statement...");
try {
String url, method, handlerName, transactionName, statementName, scHandlerName;
String normalizedScreenClassName, screenClassName;
HtmlTransaction htmlTransaction = null;
HTTPStatement httpStatement = null;
HtmlScreenClass htmlScreenClass = null;
HandlerStatement handlerStatement = null;
ScHandlerStatement scHandlerStatement = null;
// Document dom = null;
// Log log = null;
int size, index1;
boolean bContinue;
index1 = 0;
bContinue = true;
normalizedScreenClassName = "Unknown";
htmlTransaction = (HtmlTransaction) htmlConnector.getLearningTransaction();
synchronized (htmlConnector) {
// dom = htmlConnector.getCurrentXmlDocument();
htmlScreenClass = htmlConnector.getCurrentScreenClass();
}
screenClassName = htmlScreenClass.getName();
normalizedScreenClassName = StringUtils.normalize(htmlScreenClass.getName());
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) current screen class is '" + screenClassName + "'");
if (htmlTransaction != null) {
transactionName = htmlTransaction.getName();
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) creating new HTTPStatement");
ConvertigoPlugin.logDebug2(requestString);
httpStatement = parseRequestString(requestString);
httpStatement.setHttps(https);
httpStatement.setPort(https ? 443 : 80);
method = httpStatement.getMethod().toLowerCase();
// size = httpStatement.getVariablesDefinitionSize();
size = httpStatement.numberOfVariables();
url = httpStatement.getUrl(htmlConnector.isHttps(), htmlConnector.getServer(), htmlConnector.getPort());
while (bContinue) {
statementName = method + ((index1 == 0) ? " " : " " + index1) + " (" + url + " - " + size + ")";
statementName = StringUtils.normalize(statementName);
httpStatement.setName(statementName);
httpStatement.hasChanged = true;
httpStatement.bNew = true;
if (htmlScreenClass == null) {
try {
httpStatement.priority = 0;
htmlTransaction.addStatement(httpStatement);
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement to default transaction '" + transactionName + "'");
fireObjectChanged(new CompositeEvent(htmlTransaction));
Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
bContinue = false;
} catch (ObjectWithSameNameException owsne) {
index1++;
}
} else {
if (htmlConnector.isAccumulating())
handlerName = "on" + normalizedScreenClassName + "Exit";
else
handlerName = "on" + normalizedScreenClassName + "Entry";
handlerStatement = htmlTransaction.getHandlerStatement(handlerName);
if (handlerStatement != null) {
try {
handlerStatement.addStatement(httpStatement);
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement to handler '" + handlerName + "' of transaction '" + transactionName + "'");
fireObjectChanged(new CompositeEvent(handlerStatement));
Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
bContinue = false;
} catch (ObjectWithSameNameException owsne) {
index1++;
}
} else {
try {
if (htmlConnector.isAccumulating())
scHandlerStatement = new ScExitHandlerStatement(normalizedScreenClassName);
else
scHandlerStatement = new ScEntryHandlerStatement(normalizedScreenClassName);
scHandlerName = scHandlerStatement.getName();
scHandlerStatement.setName(scHandlerName);
scHandlerStatement.hasChanged = true;
scHandlerStatement.bNew = true;
scHandlerStatement.priority = 0;
htmlTransaction.addStatement(scHandlerStatement);
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new ScExitHandlerStatement '" + handlerName + "' of transaction '" + transactionName + "'");
try {
scHandlerStatement.addStatement(httpStatement);
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement '" + statementName + "' to ScExitHandlerStatement '" + handlerName + "'");
fireObjectChanged(new CompositeEvent(htmlTransaction));
Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
bContinue = false;
} catch (ObjectWithSameNameException owsne) {
index1++;
}
}// Should not append
catch (ObjectWithSameNameException owsne) {
throw new EngineException(owsne.getMessage());
}
}
}
}
} else {
throw new EngineException("Found none learning transaction");
}
} catch (EngineException e) {
ConvertigoPlugin.logException(e, "An exception occured while learning");
}
}
use of com.twinsoft.convertigo.beans.statements.HandlerStatement in project convertigo by convertigo.
the class ComponentObjectWizard method doFinish.
private void doFinish(IProgressMonitor monitor) throws CoreException {
String dboName, name;
boolean bContinue = true;
int index = 0;
try {
newBean = getCreatedBean();
if (newBean != null) {
monitor.setTaskName("Object created");
monitor.worked(1);
dboName = newBean.getName();
if (!StringUtils.isNormalized(dboName))
throw new EngineException("Bean name is not normalized : \"" + dboName + "\".");
// Verify if a child object with same name exist and change name
while (bContinue) {
if (index == 0)
name = dboName;
else
name = dboName + index;
newBean.setName(name);
newBean.hasChanged = true;
newBean.bNew = true;
try {
new WalkHelper() {
boolean root = true;
boolean find = false;
@Override
protected boolean before(DatabaseObject dbo, Class<? extends DatabaseObject> dboClass) {
boolean isInstance = dboClass.isInstance(newBean);
find |= isInstance;
return isInstance;
}
@Override
protected void walk(DatabaseObject dbo) throws Exception {
if (root) {
root = false;
super.walk(dbo);
if (!find) {
throw new EngineException("You cannot add to a " + parentObject.getClass().getSimpleName() + " a database object of type " + newBean.getClass().getSimpleName());
}
} else {
if (newBean.getName().equalsIgnoreCase(dbo.getName())) {
throw new ObjectWithSameNameException("Unable to add the object because an object with the same name already exists in target.");
}
}
}
}.init(parentObject);
bContinue = false;
} catch (ObjectWithSameNameException owsne) {
// Silently ignore
index++;
} catch (EngineException ee) {
throw ee;
} catch (Exception e) {
throw new EngineException("Exception in create", e);
}
}
// Now add bean to target
try {
parentObject.add(newBean);
monitor.setTaskName("Object added");
monitor.worked(1);
ConvertigoPlugin.logInfo("New object class '" + this.className + "' named '" + newBean.getName() + "' has been added");
monitor.setTaskName("Object setted up");
monitor.worked(1);
bContinue = false;
} catch (com.twinsoft.convertigo.engine.ObjectWithSameNameException owsne) {
if (newBean instanceof HandlerStatement) {
throw owsne;
}
index++;
}
} else {
throw new Exception("Could not instantiate bean!");
}
} catch (Exception e) {
String message = "Unable to create a new object from class '" + this.className + "'.";
ConvertigoPlugin.logException(e, message);
if (objectExplorerPage != null) {
objectExplorerPage.doCancel();
}
newBean = null;
}
}
use of com.twinsoft.convertigo.beans.statements.HandlerStatement in project convertigo by convertigo.
the class ComponentObjectWizard method doFinish.
private void doFinish(IProgressMonitor monitor) throws CoreException {
String dboName, name;
boolean bContinue = true;
int index = 0;
try {
newBean = getCreatedBean();
if (newBean != null) {
monitor.setTaskName("Object created");
monitor.worked(1);
dboName = newBean.getName();
if (!StringUtils.isNormalized(dboName))
throw new EngineException("Bean name is not normalized : \"" + dboName + "\".");
// Verify if a child object with same name exist and change name
while (bContinue) {
if (index == 0)
name = dboName;
else
name = dboName + index;
newBean.setName(name);
newBean.hasChanged = true;
newBean.bNew = true;
try {
new WalkHelper() {
boolean root = true;
boolean find = false;
@Override
protected boolean before(DatabaseObject dbo, Class<? extends DatabaseObject> dboClass) {
boolean isInstance = dboClass.isInstance(newBean);
find |= isInstance;
return isInstance;
}
@Override
protected void walk(DatabaseObject dbo) throws Exception {
if (root) {
root = false;
super.walk(dbo);
if (!find) {
throw new EngineException("You cannot add to a " + newBean.getClass().getSimpleName() + " a database object of type " + parentObject.getClass().getSimpleName());
}
} else {
if (newBean.getName().equalsIgnoreCase(dbo.getName())) {
throw new ObjectWithSameNameException("Unable to add the object because an object with the same name already exists in target.");
}
}
}
}.init(parentObject);
bContinue = false;
} catch (ObjectWithSameNameException owsne) {
// Silently ignore
index++;
} catch (EngineException ee) {
throw ee;
} catch (Exception e) {
throw new EngineException("Exception in create", e);
}
}
// Now add bean to target
try {
parentObject.add(newBean);
monitor.setTaskName("Object added");
monitor.worked(1);
ConvertigoPlugin.logInfo("New object class '" + this.className + "' named '" + newBean.getName() + "' has been added");
monitor.setTaskName("Object setted up");
monitor.worked(1);
bContinue = false;
} catch (com.twinsoft.convertigo.engine.ObjectWithSameNameException owsne) {
if (newBean instanceof HandlerStatement) {
throw owsne;
}
index++;
}
} else {
throw new Exception("Could not instantiate bean!");
}
} catch (Exception e) {
String message = "Unable to create a new object from class '" + this.className + "'.";
ConvertigoPlugin.logException(e, message);
if (objectExplorerPage != null) {
objectExplorerPage.doCancel();
}
newBean = null;
}
}
use of com.twinsoft.convertigo.beans.statements.HandlerStatement in project convertigo by convertigo.
the class ObjectInfoWizardPage method dialogChanged.
private void dialogChanged(boolean increment) {
DatabaseObject dbo = ((ObjectExplorerWizardPage) getWizard().getPage("ObjectExplorerWizardPage")).getCreatedBean();
if (dbo instanceof FunctionStatement) {
beanName.setEnabled(true);
if (dbo instanceof HandlerStatement) {
beanName.setEnabled(false);
}
}
String name = getBeanName();
if (name.length() == 0) {
updateStatus("Name must be specified");
return;
}
if (!StringUtils.isNormalized(name)) {
updateStatus("Name must be normalized.\nDon't start with number and don't use non ASCII caracters");
return;
}
Matcher m = Pattern.compile("\\d+$").matcher("");
boolean sameName;
do {
sameName = false;
try {
dbo.setName(name);
if (treeItemName != null) {
if (dbo instanceof ScHandlerStatement)
((ScHandlerStatement) dbo).setNormalizedScreenClassName(treeItemName);
else if (dbo instanceof HandlerStatement)
((HandlerStatement) dbo).setHandlerType(treeItemName);
}
} catch (ObjectWithSameNameException e) {
if (!increment) {
updateStatus("Name already used by siblings");
return;
}
sameName = true;
m.reset(name);
if (m.find()) {
name = name.substring(0, m.start()) + (Integer.parseInt(m.group()) + 1);
} else {
name = name + "_1";
}
setBeanName(name);
} catch (EngineException e) {
updateStatus("Name could not be set on bean");
return;
} catch (NullPointerException e) {
updateStatus("New Bean has not been instanciated");
return;
}
} while (sameName);
updateStatus(null);
}
Aggregations