From: <and...@us...> - 2012-10-04 15:51:49
|
Revision: 1423 http://jsbml.svn.sourceforge.net/jsbml/?rev=1423&view=rev Author: andreas-draeger Date: 2012-10-04 15:51:38 +0000 (Thu, 04 Oct 2012) Log Message: ----------- * New Features: - Syntax check for metaids in the setMetaId method. * Bug Fixes: - The method nextMetaId in SBMLDocument sometimes created metaIds containing the invalid character '-', but only underscores are allowed there. Modified Paths: -------------- trunk/NEWS.txt trunk/core/src/org/sbml/jsbml/AbstractNamedSBase.java trunk/core/src/org/sbml/jsbml/AbstractSBase.java trunk/core/src/org/sbml/jsbml/SBMLDocument.java Modified: trunk/NEWS.txt =================================================================== --- trunk/NEWS.txt 2012-10-04 10:06:29 UTC (rev 1422) +++ trunk/NEWS.txt 2012-10-04 15:51:38 UTC (rev 1423) @@ -6,6 +6,8 @@ * New Features: + - Syntax check for metaids in the setMetaId method. + - Some additional methods for more convenient working with tree data structures in TreeNodeWithChangeSupport. @@ -63,6 +65,9 @@ * Bug Fixes: + - The method nextMetaId in SBMLDocument sometimes created metaIds containing + the invalid character '-', but only underscores are allowed there. + - Several improvements and corrections in the work with TreeNodeChangeListeners. In many cases listeners were notified too early or sometimes even not at all because of inconsistent Modified: trunk/core/src/org/sbml/jsbml/AbstractNamedSBase.java =================================================================== --- trunk/core/src/org/sbml/jsbml/AbstractNamedSBase.java 2012-10-04 10:06:29 UTC (rev 1422) +++ trunk/core/src/org/sbml/jsbml/AbstractNamedSBase.java 2012-10-04 15:51:38 UTC (rev 1423) @@ -50,7 +50,7 @@ private static final String idChar = "[" + letter + digit + underscore + "]"; private static final String SIdL2 = "^[" + letter + underscore + "]" + idChar + '*'; private static final Pattern SIdL2Pattern = Pattern.compile(SIdL2); - + /** * Checks whether the given idCandidate is a valid identifier according to * the SBML specifications. @@ -300,8 +300,7 @@ * @see org.sbml.jsbml.NamedSBase#setId(java.lang.String) */ public void setId(String id) { - String property = getLevel() == 1 ? TreeNodeChangeEvent.name - : TreeNodeChangeEvent.id; + String property = getLevel() == 1 ? TreeNodeChangeEvent.name : TreeNodeChangeEvent.id; String oldId = this.id; Model model = getModel(); if ((oldId != null) && (model != null)) { Modified: trunk/core/src/org/sbml/jsbml/AbstractSBase.java =================================================================== --- trunk/core/src/org/sbml/jsbml/AbstractSBase.java 2012-10-04 10:06:29 UTC (rev 1422) +++ trunk/core/src/org/sbml/jsbml/AbstractSBase.java 2012-10-04 15:51:38 UTC (rev 1423) @@ -1430,6 +1430,11 @@ if ((metaId != null) && (getLevel() == 1)) { throw new PropertyNotAvailableException(TreeNodeChangeEvent.metaId, this); } + // Meta-ids must follow the same restrictions as Ids and are defined since Level 2 (checked above). + if ((metaId == null) || !AbstractNamedSBase.isValidId(metaId, getLevel(), getVersion())) { + throw new IllegalArgumentException(MessageFormat.format( + "\"{0}\" is not a valid meta-identifier for this {1}.", metaId, getElementName())); + } SBMLDocument doc = getSBMLDocument(); String oldMetaId = this.metaId; if (doc != null) { Modified: trunk/core/src/org/sbml/jsbml/SBMLDocument.java =================================================================== --- trunk/core/src/org/sbml/jsbml/SBMLDocument.java 2012-10-04 10:06:29 UTC (rev 1422) +++ trunk/core/src/org/sbml/jsbml/SBMLDocument.java 2012-10-04 15:51:38 UTC (rev 1423) @@ -693,26 +693,34 @@ } /** - * @return true if the model of this SBMLDocument is not null. + * @return true if the {@link Model} of this {@link SBMLDocument} is not {@code null}. */ public boolean isSetModel() { return model != null; } - /** - * - * @return - */ + /** + * Randomly creates a new {@link String} that can be used as a metaid, i.e., a + * String that is a valid metaid and that is not yet used by any other element + * within this {@link SBMLDocument}. + * + * @return + */ public String nextMetaId() { String idOne; do { - idOne = '_' + UUID.randomUUID().toString(); + idOne = UUID.randomUUID().toString().replace('-', '_'); + if (Character.isDigit(idOne.charAt(0))) { + // Add an underscore at the beginning of the new metaid only if necessary. + idOne = '_' + idOne; + } } while (containsMetaId(idOne)); return idOne; } /** * + * @param stream */ public void printErrors(PrintStream stream) { int nbErrors = listOfErrors.getErrorCount(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |