Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions core/src/org/sbml/jsbml/AbstractNamedSBaseWithUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.log4j.Logger;
import org.sbml.jsbml.Unit.Kind;
import org.sbml.jsbml.util.TreeNodeChangeEvent;
import org.sbml.jsbml.validator.offline.factory.SBMLErrorCodes;

/**
* This simple implementation of the interfaces
Expand Down Expand Up @@ -283,7 +284,7 @@ public void setUnits(Kind unitKind) {
@Override
public void setUnits(String units) {
if ((units != null) && (units.trim().length() == 0)) {
units = null; // If we pass the empty String or null, the value is reset.
units = null;
}

String oldUnits = unitsID;
Expand All @@ -292,24 +293,32 @@ public void setUnits(String units) {
unitsID = null;
} else {
units = units.trim();
unitsID = units;

boolean illegalArgument = false;

if (!Unit.isValidUnit(getModel(), units)) {
illegalArgument = true; // TODO - make use of the offline validation once attributes validation is in place.
illegalArgument = true;
}
Comment thread
dyrpsf marked this conversation as resolved.
Outdated

if (illegalArgument) {
if (!isReadingInProgress()) {
throw new IllegalArgumentException(MessageFormat.format(
JSBML.ILLEGAL_UNIT_EXCEPTION_MSG, units));
SBMLDocument doc = getSBMLDocument();
if (doc != null && doc.getErrorLog() != null) {
doc.getErrorLog().add(new SBMLError(
MessageFormat.format(JSBML.ILLEGAL_UNIT_EXCEPTION_MSG, units)
));
} else {
Comment thread
dyrpsf marked this conversation as resolved.
throw new IllegalArgumentException(MessageFormat.format(
JSBML.ILLEGAL_UNIT_EXCEPTION_MSG, units));
}
Comment thread
dyrpsf marked this conversation as resolved.
} else {
logger.info(MessageFormat.format(JSBML.ILLEGAL_UNIT_EXCEPTION_MSG, units));
}
}
unitsID = units;
}

if (oldUnits != unitsID) {
if (oldUnits != null ? !oldUnits.equals(unitsID) : unitsID != null) {
firePropertyChange(TreeNodeChangeEvent.units, oldUnits, unitsID);
}
}
Expand Down