use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class AbstractValueField method setValue.
@Override
public final void setValue(VALUE rawValue) {
if (isValueChanging()) {
LOG.warn("Loop detection in {} with value {}", getClass().getName(), rawValue, new Exception());
return;
}
try {
setFieldChanging(true);
setValueChanging(true);
removeErrorStatus(ParsingFailedStatus.class);
removeErrorStatus(ValidationFailedStatus.class);
VALUE validatedValue = null;
try {
validatedValue = validateValue(rawValue);
} catch (ProcessingException v) {
handleValidationFailed(v, rawValue);
return;
} catch (Exception e) {
final String message = TEXTS.get("InvalidValueMessageX", StringUtility.emptyIfNull(rawValue));
ProcessingException pe = new ProcessingException(message, e);
LOG.warn("Unexpected Error: ", pe);
handleValidationFailed(pe, rawValue);
return;
}
//
VALUE oldValue = getValue();
boolean changed = propertySupport.setPropertyNoFire(PROP_VALUE, validatedValue);
// change text if auto-set-text enabled
updateDisplayText(validatedValue);
if (changed) {
propertySupport.firePropertyChange(PROP_VALUE, oldValue, validatedValue);
//
valueChangedInternal();
checkSaveNeeded();
checkEmpty();
fireMasterChanged();
if (isValueChangeTriggerEnabled()) {
try {
interceptChangedValue();
} catch (RuntimeException | PlatformError ex) {
BEANS.get(ExceptionHandler.class).handle(ex);
}
}
}
} finally {
setValueChanging(false);
setFieldChanging(false);
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class StatementProcessor method createInputRec.
@SuppressWarnings({ "squid:S2583", "squid:S138" })
private IBindInput createInputRec(ValueInputToken bindToken, String[] path, Object bindBase, Class nullType) {
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) {
return new TableBeanHolderInput((ITableBeanHolder) o, null, path[1], bindToken);
} else if (o instanceof TableBeanHolderFilter) {
return new TableBeanHolderInput(((TableBeanHolderFilter) o).getTableBeanHolder(), ((TableBeanHolderFilter) o).getFilteredRows(), path[1], bindToken);
} else if (o instanceof IBeanArrayHolder) {
return new BeanArrayHolderInput((IBeanArrayHolder) o, null, path[1], bindToken);
} else if (o instanceof BeanArrayHolderFilter) {
return new BeanArrayHolderInput(((BeanArrayHolderFilter) o).getBeanArrayHolder(), ((BeanArrayHolderFilter) o).getFilteredBeans(), path[1], bindToken);
} else {
if (terminal) {
return createInputTerminal(o, nullType, bindToken);
} else {
if (o == null) {
throw new ProcessingException("input bind {} resolves to null on path element: {}", bindToken, path[0]);
}
}
}
}
} 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) {
return new TableBeanHolderInput((ITableBeanHolder) o, null, path[1], bindToken);
} else if (o instanceof TableBeanHolderFilter) {
return new TableBeanHolderInput(((TableBeanHolderFilter) o).getTableBeanHolder(), ((TableBeanHolderFilter) o).getFilteredRows(), path[1], bindToken);
} else if (o instanceof IBeanArrayHolder) {
return new BeanArrayHolderInput((IBeanArrayHolder) o, null, path[1], bindToken);
} else if (o instanceof BeanArrayHolderFilter) {
return new BeanArrayHolderInput(((BeanArrayHolderFilter) o).getBeanArrayHolder(), ((BeanArrayHolderFilter) o).getFilteredBeans(), path[1], bindToken);
} else {
if (terminal) {
return createInputTerminal(o, nullType, bindToken);
} else {
if (o == null) {
throw new ProcessingException("input bind {} resolves to null on path element: {}", bindToken, path[0]);
}
}
}
}
} 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 TableBeanHolderInput(table, null, path[0], bindToken);
}
} catch (NoSuchMethodException | SecurityException t) {
found = false;
// nop
}
} else if (bindBase instanceof TableBeanHolderFilter) {
// handle all terminal cases for table holder filter
TableBeanHolderFilter filter = (TableBeanHolderFilter) bindBase;
ITableBeanHolder table = filter.getTableBeanHolder();
try {
Method m = table.getRowType().getMethod("get" + Character.toUpperCase(path[0].charAt(0)) + path[0].substring(1));
if (m != null) {
found = true;
return new TableBeanHolderInput(table, filter.getFilteredRows(), 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 BeanArrayHolderInput(holder, null, 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 BeanArrayHolderInput(holder, null, path[0], bindToken);
}
} catch (NoSuchMethodException | SecurityException t2) {
found = false;
// nop
}
}
} else if (bindBase instanceof BeanArrayHolderFilter) {
// handle all terminal cases for table holder filter
BeanArrayHolderFilter filter = (BeanArrayHolderFilter) bindBase;
IBeanArrayHolder<?> holder = filter.getBeanArrayHolder();
try {
Method m = holder.getHolderType().getMethod("get" + Character.toUpperCase(path[0].charAt(0)) + path[0].substring(1));
if (m != null) {
found = true;
return new BeanArrayHolderInput(holder, filter.getFilteredBeans(), 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 BeanArrayHolderInput(holder, null, path[0], bindToken);
}
} catch (NoSuchMethodException | SecurityException t2) {
found = false;
// nop
}
}
} else if (bindBase != null) {
if (bindBase.getClass().isArray() && terminal) {
return new BeanPropertyInput(path[0], (Object[]) bindBase, bindToken);
}
if (bindBase instanceof Collection && terminal) {
return new BeanPropertyInput(path[0], ((Collection) bindBase).toArray(), bindToken);
}
/* bean property */
try {
Object propertyBean = bindBase;
FastPropertyDescriptor pd = BeanUtility.getFastBeanInfo(propertyBean.getClass(), null).getPropertyDescriptor(path[0]);
Method getter = pd != null ? pd.getReadMethod() : null;
if (getter != null) {
// getter exists
o = getter.invoke(propertyBean);
found = true;
if (terminal) {
return createInputTerminal(o, getter.getReturnType(), bindToken);
} else {
if (o == null) {
throw new ProcessingException("input bind {} resolves to null on path element: {}", bindToken, path[0]);
}
}
}
} catch (IllegalAccessException | InvocationTargetException e) {
LOG.warn("Exception while invoking bean getter", e);
LOG.debug("Cannot access property.", e);
}
}
//
if (found) {
if (terminal) {
throw new ProcessingException("input 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);
IBindInput input = null;
if (o instanceof IHolder<?>) {
/* dereference value if current object is an IHolder. If input cannot be resolved (i.e. ProcessingException occurs),
* search given property names on holder. Hence both of the following forms are supported on holder types:
* :holder.property
* :holder.value.property
*/
try {
input = createInputRec(bindToken, newPath, ((IHolder) o).getValue(), nullType);
} catch (RuntimeException pe) {
// nop, see below
}
}
if (input == null) {
// strict search without dereferncing holder objects
input = createInputRec(bindToken, newPath, o, nullType);
}
return input;
} else {
return null;
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class StatementProcessor method createInput.
private IBindInput createInput(IToken bindToken, Object[] bindBases) {
if (bindToken instanceof ValueInputToken) {
final ValueInputToken valueInputToken = (ValueInputToken) bindToken;
final String[] path = REGEX_DOT.split(valueInputToken.getName());
IBindInput result = null;
for (final Object bindBase : bindBases) {
Class nullType = null;
if (bindBase instanceof NVPair) {
nullType = ((NVPair) bindBase).getNullType();
}
final IBindInput in = createInputRec(valueInputToken, path, bindBase, nullType);
if (in != null) {
// bind found
if (isBindDuplicateCheckEnabled()) {
if (result == null) {
// first match found for the bind -> remember
result = in;
} else {
// second match found
onDuplicateBind(valueInputToken);
return result;
}
} else {
// no duplicate check necessary: directly return the first match
return in;
}
}
}
if (result == null) {
throw new ProcessingException("Cannot find input for '{}' in bind bases.", valueInputToken);
}
return result;
} else if (bindToken instanceof FunctionInputToken) {
return new FunctionInput(m_callerService, m_bindBases, (FunctionInputToken) bindToken);
}
throw new ProcessingException("Cannot find input for {}", bindToken.getClass());
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class FormDataStatementBuilder method buildComposerEntityNodeContribution.
public EntityContribution buildComposerEntityNodeContribution(ComposerEntityNodeData node, EntityStrategy entityStrategy) {
if (getDataModel() == null) {
throw new ProcessingException("there is no data model set, call FormDataStatementBuilder.setDataModel to set one");
}
EntityPath entityPath = DataModelUtility.externalIdToEntityPath(getDataModel(), node.getEntityExternalId());
IDataModelEntity entity = (entityPath != null ? entityPath.lastElement() : null);
if (entity == null) {
LOG.warn("no entity for external id: {}", node.getEntityExternalId());
return null;
}
DataModelEntityPartDefinition def = m_dataModelEntMap.get(entity.getClass());
if (def == null) {
LOG.warn("no PartDefinition for entity: {}", entity);
return null;
}
ComposerEntityNodeData parentEntityNode = getParentNodeOfType(node, ComposerEntityNodeData.class);
Map<String, String> parentAliasMap = (parentEntityNode != null ? m_aliasMapper.getNodeAliases(parentEntityNode) : m_aliasMapper.getRootAliases());
String baseStm;
switch(entityStrategy) {
case BuildQuery:
{
baseStm = def.getSelectClause();
break;
}
case BuildConstraints:
{
baseStm = def.getWhereClause();
break;
}
default:
{
baseStm = null;
}
}
String stm = null;
if (baseStm != null) {
stm = def.createInstance(this, node, entityStrategy, baseStm, parentAliasMap);
}
if (stm == null) {
return null;
}
m_aliasMapper.addAllNodeEntitiesFrom(node, stm);
stm = m_aliasMapper.replaceMarkersByAliases(stm, m_aliasMapper.getNodeAliases(node), parentAliasMap);
switch(entityStrategy) {
case BuildQuery:
{
EntityContribution resultContrib = buildComposerEntityUnitContribution(node, entityStrategy, stm, node.getChildNodes(), isConsumeChildContributions(entityPath));
return resultContrib;
}
case BuildConstraints:
{
String s = buildComposerEntityEitherOrSplit(entityStrategy, stm, node.isNegative(), node.getChildNodes());
EntityContribution resultContrib = (s != null ? EntityContribution.create(s) : new EntityContribution());
return resultContrib;
}
default:
{
return null;
}
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class FormDataStatementBuilder method buildComposerAttributeNode.
public EntityContribution buildComposerAttributeNode(final ComposerAttributeNodeData node, AttributeStrategy attributeStrategy) {
if (getDataModel() == null) {
throw new ProcessingException("there is no data model set, call FormDataStatementBuilder.setDataModel to set one");
}
AttributePath attPath = DataModelUtility.externalIdToAttributePath(getDataModel(), node.getAttributeExternalId());
IDataModelAttribute attribute = (attPath != null ? attPath.getAttribute() : null);
if (attribute == null) {
LOG.warn("no attribute for external id: {}", node.getAttributeExternalId());
return new EntityContribution();
}
DataModelAttributePartDefinition def = m_dataModelAttMap.get(attribute.getClass());
if (def == null) {
Integer agg = node.getAggregationType();
if (agg != null && agg == AGGREGATION_COUNT) {
def = new DataModelAttributePartDefinition(null, "1", false);
}
}
if (def == null) {
LOG.warn("no PartDefinition for attribute: {}", attribute);
return new EntityContribution();
}
List<Object> bindValues = new ArrayList<Object>();
if (node.getValues() != null) {
bindValues.addAll(node.getValues());
}
List<String> bindNames = new ArrayList<String>(bindValues.size());
for (int i = 0; i < bindValues.size(); i++) {
bindNames.add("" + (char) (((int) 'a') + i));
}
AliasMapper aliasMap = getAliasMapper();
ComposerEntityNodeData parentEntityNode = FormDataStatementBuilder.getParentNodeOfType(node, ComposerEntityNodeData.class);
Map<String, String> parentAliasMap = parentEntityNode != null ? aliasMap.getNodeAliases(parentEntityNode) : aliasMap.getRootAliases();
String stm = null;
switch(attributeStrategy) {
case BuildConstraintOfAttribute:
case BuildConstraintOfContext:
case BuildConstraintOfAttributeWithContext:
{
stm = def.getWhereClause();
break;
}
case BuildQueryOfAttributeAndConstraintOfContext:
{
stm = def.getSelectClause();
break;
}
}
EntityContribution contrib = null;
if (stm != null) {
contrib = def.createInstance(this, node, attributeStrategy, stm, bindNames, bindValues, parentAliasMap);
}
if (contrib == null) {
contrib = new EntityContribution();
}
switch(attributeStrategy) {
case BuildQueryOfAttributeAndConstraintOfContext:
{
if (contrib.getSelectParts().isEmpty()) {
contrib.getSelectParts().add("NULL");
contrib.getGroupByParts().add("NULL");
}
break;
}
}
if (hasInjections()) {
injectPostBuildAttribute(node, attributeStrategy, contrib);
}
return contrib;
}
Aggregations