@Override public void attributeChanged(final Attribute attribute) throws IllegalActionException { try { if (attribute == function) { final String functionName = function.stringValue(); if (functionName.equals("exp")) { _function = _EXP; if (secondOperand != null) { secondOperand.setContainer(null); } } else if (functionName.equals("log")) { _function = _LOG; if (secondOperand != null) { secondOperand.setContainer(null); } } else if (functionName.equals("modulo")) { _function = _MODULO; _createSecondPort(); } else if (functionName.equals("sign")) { _function = _SIGN; if (secondOperand != null) { secondOperand.setContainer(null); } } else if (functionName.equals("square")) { _function = _SQUARE; if (secondOperand != null) { secondOperand.setContainer(null); } } else if (functionName.equals("sqrt")) { _function = _SQRT; if (secondOperand != null) { secondOperand.setContainer(null); } } else { throw new IllegalActionException(this, "Unrecognized math function: " + functionName); } } else { super.attributeChanged(attribute); } } catch (final NameDuplicationException nameDuplication) { throw new InternalErrorException(this, nameDuplication, "Unexpected name duplication"); } }
/** Create the second port needed by modulo function */ private void _createSecondPort() throws NameDuplicationException, IllegalActionException { // Go looking for the port in case somebody else created the port // already. For example, this might // happen in shallow code generation. secondOperand = (Port) getPort("secondOperand"); if (secondOperand == null) { secondOperand = PortFactory.getInstance().createInputPort(this, "secondOperand", Double.class); } else if (secondOperand.getContainer() == null) { secondOperand.setContainer(this); } }