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;
}
}
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;
}
}
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;
}
}
}
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);
}
Aggregations