Search in sources :

Example 11 with ObjectWithSameNameException

use of com.twinsoft.convertigo.engine.ObjectWithSameNameException 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;
    }
}
Also used : EngineException(com.twinsoft.convertigo.engine.EngineException) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EngineException(com.twinsoft.convertigo.engine.EngineException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException)

Example 12 with ObjectWithSameNameException

use of com.twinsoft.convertigo.engine.ObjectWithSameNameException 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;
    }
}
Also used : EngineException(com.twinsoft.convertigo.engine.EngineException) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EngineException(com.twinsoft.convertigo.engine.EngineException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException)

Example 13 with ObjectWithSameNameException

use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.

the class ObjectExplorerWizardPage method createBean.

private void createBean() {
    BeanInfo bi = getCurrentSelectedBeanInfo();
    if (bi != null) {
        try {
            newBean = (DatabaseObject) bi.getBeanDescriptor().getBeanClass().getConstructor().newInstance();
            if (parentObject instanceof DatabaseObject) {
                newBean.setParent((DatabaseObject) parentObject);
            }
            if (xpath != null) {
                if (newBean instanceof IXPathable) {
                    ((IXPathable) newBean).setXpath(xpath);
                }
                // case we create an "javascriptable" statement
                if (newBean instanceof XpathableStatement) {
                    ((XpathableStatement) newBean).setPureXpath(xpath);
                }
            }
            // case we create a javelinConnector
            if (newBean instanceof JavelinConnector) {
                ((JavelinConnector) newBean).setEmulatorTechnology(com.twinsoft.api.Session.AS400);
                ((JavelinConnector) newBean).emulatorID = ((JavelinConnector) newBean).findEmulatorId();
                ((JavelinConnector) newBean).setServiceCode(",DIR|localhost:23");
            }
            if (newBean instanceof FullSyncConnector && parentObject instanceof Project) {
                boolean bContinue = true;
                String name = ((Project) parentObject).getName().toLowerCase() + "_fullsync";
                while (bContinue) {
                    try {
                        newBean.setName(name);
                        bContinue = false;
                    } catch (ObjectWithSameNameException e) {
                        name = DatabaseObject.incrementName(name);
                    }
                }
            }
        } catch (Exception e) {
            newBean = null;
        }
    }
}
Also used : JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Project(com.twinsoft.convertigo.beans.core.Project) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) IXPathable(com.twinsoft.convertigo.beans.core.IXPathable) BeanInfo(java.beans.BeanInfo) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) EngineException(com.twinsoft.convertigo.engine.EngineException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) XpathableStatement(com.twinsoft.convertigo.beans.statements.XpathableStatement)

Example 14 with ObjectWithSameNameException

use of com.twinsoft.convertigo.engine.ObjectWithSameNameException 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);
}
Also used : FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) Matcher(java.util.regex.Matcher) EngineException(com.twinsoft.convertigo.engine.EngineException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement)

Aggregations

ObjectWithSameNameException (com.twinsoft.convertigo.engine.ObjectWithSameNameException)14 EngineException (com.twinsoft.convertigo.engine.EngineException)13 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)11 HandlerStatement (com.twinsoft.convertigo.beans.statements.HandlerStatement)6 Statement (com.twinsoft.convertigo.beans.core.Statement)5 HTTPStatement (com.twinsoft.convertigo.beans.statements.HTTPStatement)5 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)5 Project (com.twinsoft.convertigo.beans.core.Project)4 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)4 IOException (java.io.IOException)4 Connector (com.twinsoft.convertigo.beans.core.Connector)3 Criteria (com.twinsoft.convertigo.beans.core.Criteria)3 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)3 Sheet (com.twinsoft.convertigo.beans.core.Sheet)3 Step (com.twinsoft.convertigo.beans.core.Step)3 Transaction (com.twinsoft.convertigo.beans.core.Transaction)3 ElseStatement (com.twinsoft.convertigo.beans.statements.ElseStatement)3 ThenStatement (com.twinsoft.convertigo.beans.statements.ThenStatement)3 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)3 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)3