From 44ed81a5ca5ed823d0819ed4710952882fe27c80 Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Fri, 16 Nov 2012 13:41:30 +0400 Subject: [PATCH] Changes --- .../android/calculator/CalculatorImpl.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java index 2ef7e607..d37e77a0 100644 --- a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java +++ b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java @@ -17,6 +17,8 @@ import org.solovyev.android.calculator.model.Var; import org.solovyev.android.calculator.text.TextProcessor; import org.solovyev.android.calculator.units.CalculatorNumeralBase; import org.solovyev.common.history.HistoryAction; +import org.solovyev.common.msg.ListMessageRegistry; +import org.solovyev.common.msg.Message; import org.solovyev.common.msg.MessageRegistry; import org.solovyev.common.msg.MessageType; import org.solovyev.common.text.StringUtils; @@ -175,12 +177,27 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener { try { - final Generic result = operation.evaluateGeneric(jsclExpression, CalculatorLocatorImpl.getInstance().getEngine().getMathEngine()); + final CalculatorMathEngine mathEngine = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine(); + + final MessageRegistry messageRegistry = new ListMessageRegistry(); + CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0().setMessageRegistry(messageRegistry); + + final Generic result = operation.evaluateGeneric(jsclExpression, mathEngine); // NOTE: toString() method must be called here as ArithmeticOperationException may occur in it (just to avoid later check!) result.toString(); - final CalculatorOutput data = CalculatorOutputImpl.newOutput(operation.getFromProcessor().process(result), operation, result); + final CalculatorLogger logger = CalculatorLocatorImpl.getInstance().getLogger(); + try { + while (messageRegistry.hasMessage()) { + handleJsclMessage(messageRegistry.getMessage()); + } + } catch (Throwable e) { + // todo serso: not good be we need proper synchronization + logger.error("Calculator", e.getMessage(), e); + } + + final CalculatorOutput data = CalculatorOutputImpl.newOutput(operation.getFromProcessor().process(result), operation, result); fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_result, data); } catch (AbstractJsclArithmeticException e) { @@ -204,6 +221,11 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener { } } + private void handleJsclMessage(@NotNull Message message) { + final CalculatorNotifier notifier = CalculatorLocatorImpl.getInstance().getNotifier(); + notifier.showMessage(message); + } + @NotNull @Override public PreparedExpression prepareExpression(@NotNull String expression) throws CalculatorParseException {