use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class StatementProcessor method createOutputRec.
@SuppressWarnings({ "unchecked", "squid:S2583", "squid:S138" })
private IBindOutput createOutputRec(ValueOutputToken bindToken, String[] path, final Object bindBase) {
boolean terminal = (path.length == 1);
Object o = null;
boolean found = false;
if (bindBase instanceof Map) {
// handle all terminal cases for map
o = ((Map) bindBase).get(path[0]);
if (o != null) {
found = true;
} else if (((Map) bindBase).containsKey(path[0])) {
found = true;
}
if (found) {
if (o instanceof ITableBeanHolder) {
ITableBeanHolder table = (ITableBeanHolder) o;
return new TableBeanHolderOutput(table, path[1], bindToken);
} else if (o instanceof IBeanArrayHolder) {
IBeanArrayHolder holder = (IBeanArrayHolder) o;
return new BeanArrayHolderOutput(holder, path[1], bindToken);
} else if (o instanceof IHolder) {
if (terminal) {
return createOutputTerminal((IHolder) o, bindToken);
} else {
o = ((IHolder) o).getValue();
}
} else if (o == null) {
if (terminal) {
return new MapOutput((Map) bindBase, path[0], bindToken);
} else {
throw new ProcessingException("output bind {} resolves to null on path element: {}", bindToken, path[0]);
}
} else {
if (terminal) {
return new MapOutput((Map) bindBase, path[0], bindToken);
}
}
}
} else if (bindBase instanceof NVPair) {
// handle all terminal cases for nvpair
if (((NVPair) bindBase).getName().equals(path[0])) {
o = ((NVPair) bindBase).getValue();
found = true;
if (o instanceof ITableBeanHolder) {
ITableBeanHolder table = (ITableBeanHolder) o;
return new TableBeanHolderOutput(table, path[1], bindToken);
} else if (o instanceof IBeanArrayHolder) {
IBeanArrayHolder holder = (IBeanArrayHolder) o;
return new BeanArrayHolderOutput(holder, path[1], bindToken);
} else if (o instanceof IHolder) {
if (terminal) {
return createOutputTerminal((IHolder) o, bindToken);
} else {
o = ((IHolder) o).getValue();
}
} else if (o == null) {
throw new ProcessingException("output bind {} resolves to null on path element: {}", bindToken, path[0]);
} else {
if (terminal) {
throw new ProcessingException("output bind {} is not a valid output container", bindToken);
}
}
}
} else if (bindBase instanceof ITableBeanHolder) {
// handle all terminal cases for table holder
ITableBeanHolder table = (ITableBeanHolder) bindBase;
try {
Method m = table.getRowType().getMethod("get" + Character.toUpperCase(path[0].charAt(0)) + path[0].substring(1));
if (m != null) {
found = true;
return new TableBeanHolderOutput(table, path[0], bindToken);
}
} catch (NoSuchMethodException | SecurityException t) {
// nop
found = false;
}
} else if (bindBase instanceof IBeanArrayHolder) {
// handle all terminal cases for BeanArrayHolder
IBeanArrayHolder holder = (IBeanArrayHolder) bindBase;
try {
Method m = holder.getHolderType().getMethod("get" + Character.toUpperCase(path[0].charAt(0)) + path[0].substring(1));
if (m != null) {
found = true;
return new BeanArrayHolderOutput(holder, path[0], bindToken);
}
} catch (NoSuchMethodException | SecurityException t1) {
try {
Method m = holder.getHolderType().getMethod("is" + Character.toUpperCase(path[0].charAt(0)) + path[0].substring(1));
if (m != null) {
found = true;
return new BeanArrayHolderOutput(holder, path[0], bindToken);
}
} catch (NoSuchMethodException | SecurityException t2) {
found = false;
// nop
}
}
} else /* bean property */
{
// handle all terminal cases for bean property
try {
FastPropertyDescriptor pd = BeanUtility.getFastBeanInfo(bindBase.getClass(), null).getPropertyDescriptor(path[0]);
if (terminal) {
Method setter = pd != null ? pd.getWriteMethod() : null;
if (setter != null) {
found = true;
return new AbstractBeanPropertyOutput(bindBase.getClass(), path[0], bindToken) {
@Override
protected Object[] getFinalBeanArray() {
return new Object[] { bindBase };
}
};
} else {
Method getter = pd != null ? pd.getReadMethod() : null;
if (getter != null) {
o = getter.invoke(bindBase, (Object[]) null);
if (o instanceof ITableBeanHolder) {
throw new ProcessingException("output bind '{}' is a table bean and should not be a terminal", bindToken.getName());
} else if (o instanceof IBeanArrayHolder) {
throw new ProcessingException("output bind '{}' is a bean array and should not be a terminal", bindToken.getName());
} else if (o instanceof IHolder) {
return createOutputTerminal((IHolder) o, bindToken);
} else {
return null;
}
}
}
} else {
Method getter = pd != null ? pd.getReadMethod() : null;
if (getter != null) {
Object readValue = getter.invoke(bindBase, (Object[]) null);
o = readValue;
found = true;
}
}
} catch (IllegalAccessException | InvocationTargetException e) {
LOG.warn("Exception while invoking bean getter", e);
}
}
//
if (found) {
if (terminal) {
throw new ProcessingException("output bind '{}' was not recognized as a terminal", bindToken.getName());
}
// continue
String[] newPath = new String[path.length - 1];
System.arraycopy(path, 1, newPath, 0, newPath.length);
return createOutputRec(bindToken, newPath, o);
} else {
return null;
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class AliasMapper method replaceMarkersByAliases.
/**
* Resolve and replace all entity definitions and references inthe statement part.
* <p>
* Example entity: <code>SELECT 1 FROM Person @Person@ where @Person@.personNr=@parent.Person@.personNr</code> ->
* <code>SELECT 1 FROM Person a002 where a002.personNr=a001.personNr</code>
* <p>
* Example attribute: <code>lastName</code> -> <code>lastName</code>
* <p>
* Example attribute: <code>@Person@.lastName</code> -> <code>a002.lastName</code>
* <p>
* Example attribute: <code>@parent.Person@.lastName</code> -> <code>a002.lastName</code>
* <p>
* <b>Note that on attributes @parent.Person@ and @Person@ is the same and is both supported since an attribute is
* attached to an entity. Therefore both declarations are equally "correct" and mean the same entitie's alias.
*/
public String replaceMarkersByAliases(String statementPart, Map<String, String> aliasMap, Map<String, String> parentAliasMap) {
String s = statementPart;
Matcher m = ENTITY_NAME.matcher(s);
while (m.find()) {
boolean parent = m.group(1) != null && m.group(1).length() > 0;
String name = cleanEntityName(m.group(2));
String replacement = null;
if (parent) {
replacement = parentAliasMap.get(name);
} else {
replacement = aliasMap.get(name);
}
if (replacement == null) {
throw new ProcessingException("missing alias '" + name + "' for entity '" + m.group() + "' in statement part: " + statementPart + "; map=" + aliasMap + " parentMap=" + parentAliasMap);
}
s = s.substring(0, m.start()) + replacement + s.substring(m.end());
// next
m = ENTITY_NAME.matcher(s);
}
return s;
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class AbstractBeanPropertyOutput method finishBatch.
@Override
public void finishBatch() {
FastPropertyDescriptor desc = null;
Object[] beans = getFinalBeanArray();
if (beans != null) {
int accSize = m_accumulator.size();
for (int i = 0; i < beans.length; i++) {
try {
Object bean = beans[i];
if (bean != null) {
if (desc == null) {
desc = BeanUtility.getFastBeanInfo(bean.getClass(), null).getPropertyDescriptor(m_propertyName);
}
Object value = null;
if (i < accSize) {
value = m_accumulator.get(i);
}
if (IHolder.class.isAssignableFrom(desc.getPropertyType())) {
@SuppressWarnings("unchecked") IHolder<Object> h = (IHolder<Object>) desc.getReadMethod().invoke(bean);
if (h != null) {
Object castValue = TypeCastUtility.castValue(value, h.getHolderType());
h.setValue(castValue);
}
} else {
Object castValue = TypeCastUtility.castValue(value, desc.getPropertyType());
desc.getWriteMethod().invoke(bean, castValue);
}
}
} catch (Exception e) {
throw new ProcessingException("property " + m_propertyName, e);
}
}
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class BeanPropertyInput method produceSqlBindAndSetReplaceToken.
@Override
public SqlBind produceSqlBindAndSetReplaceToken(ISqlStyle sqlStyle) {
if (isBatch()) {
Object value = null;
Class<?> valueType = m_propertyDesc != null ? m_propertyDesc.getPropertyType() : null;
if (m_batchIndex < m_beans.length) {
Object bean = m_beans[m_batchIndex];
if (bean != null && m_propertyDesc != null) {
try {
value = m_propertyDesc.getReadMethod().invoke(bean);
} catch (Exception e) {
throw new ProcessingException("property " + m_propertyName, e);
}
}
}
//
if (m_target.isPlainValue()) {
m_target.setReplaceToken(sqlStyle.toPlainText(value));
return null;
} else if (m_target.isPlainSql()) {
m_target.setReplaceToken("" + value);
return null;
} else {
m_target.setReplaceToken("?");
return sqlStyle.buildBindFor(value, valueType);
}
} else {
return applyMultivalued(sqlStyle);
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class ParsingFailedStatusTest method testConstructorWithoutCode.
@Test
public void testConstructorWithoutCode() {
ProcessingException veto = new VetoException("Foo");
ParsingFailedStatus status = new ParsingFailedStatus(veto, "Bar");
assertEquals("Foo", status.getMessage());
// default value for in members
assertEquals(0, status.getCode());
}
Aggregations