use of org.eclipse.scout.rt.platform.holders.IHolder in project scout.rt by eclipse.
the class ServiceUtility method filterHolderArguments.
/**
* Holders and nvpairs need to be copied as value clones. A smartfield for example is a holder and must not go to
* backend. NVPairs with holder values ae replaced by NVPair with serializable holder arguments
*/
public Object[] filterHolderArguments(Object[] callerArgs) {
Object[] serializableArgs = new Object[callerArgs.length];
new AbstractHolderArgumentVisitor() {
@SuppressWarnings("unchecked")
@Override
public void visitHolder(IHolder input, IHolder output) {
if (!HolderUtility.containEqualValues(output, input)) {
output.setValue(input.getValue());
}
}
@Override
public void visitOther(Object[] input, Object[] output, int index) {
output[index] = input[index];
}
}.startVisiting(callerArgs, serializableArgs, 1, true);
return serializableArgs;
}
use of org.eclipse.scout.rt.platform.holders.IHolder in project scout.rt by eclipse.
the class AbstractForm method getClientPartOfExtensionOrContributionRec.
private Object getClientPartOfExtensionOrContributionRec(final Object extToSearch, Object owner) {
Object ext = getClientPartOfExtensionOrContribution(extToSearch, owner);
if (ext != null) {
return ext;
}
// search for the extension in the children
final IHolder<Object> result = new Holder<Object>(Object.class);
IFormFieldVisitor visitor = new IFormFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
result.setValue(getClientPartOfExtensionOrContribution(extToSearch, field));
return result.getValue() == null;
}
};
if (owner instanceof IForm) {
((IForm) owner).visitFields(visitor);
} else if (owner instanceof IFormField) {
((IFormField) owner).acceptVisitor(visitor, 0, 0, true);
}
return result.getValue();
}
use of org.eclipse.scout.rt.platform.holders.IHolder in project scout.rt by eclipse.
the class FunctionInput method produceSqlBindAndSetReplaceToken.
@Override
public SqlBind produceSqlBindAndSetReplaceToken(ISqlStyle sqlStyle) {
if (isBatch() || !m_valueSet) {
if (m_callerService instanceof AbstractSqlService) {
m_value = ((AbstractSqlService) m_callerService).callbackCustomBindFunction(m_target.getName(), m_target.getArgs(), m_bindBases);
} else {
throw new ProcessingException("don't know how to resolve custom bind function '" + m_target.getName() + "' on service " + m_callerService.getClass().getName());
}
m_valueSet = true;
}
Object value = null;
if (isBatch() && m_batchIndex >= 1) {
value = null;
} else {
value = m_value;
}
Class<?> nullType = null;
if (value instanceof IHolder<?>) {
IHolder h = (IHolder<?>) value;
value = h.getValue();
nullType = h.getHolderType();
}
//
if (m_target.isPlainToken()) {
m_target.setReplaceToken(m_target.getParsedToken());
return null;
} else 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, nullType);
}
}
use of org.eclipse.scout.rt.platform.holders.IHolder 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.holders.IHolder 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);
}
}
}
}
Aggregations