@Override public boolean hasValidLevelVersionNamespaceCombination() { return isValidLevelAndVersionCombination(getLevel(), getVersion()); }
setMetaId(value); return true; } else if (attributeName.equals("id") && (getLevel() > 1)) {
@Override public String getNamespace() { if (getPackageName().equals("core") && elementNamespace == null) { return JSBML.getNamespaceFrom(getLevel(), getVersion()); } return elementNamespace; }
/** * Checks if the sID is a valid identifier. * * @param sID * the identifier to be checked. If null or an invalid * identifier, an exception will be thrown. * @return {@code true} only if the sID is a valid identifier. * Otherwise this method throws an {@link IllegalArgumentException}. * This is an intended behavior. * @throws IllegalArgumentException * if the given id is not valid in this model. */ protected boolean checkIdentifier(String sID) { if ((sID == null) || !SyntaxChecker.isValidId(sID, getLevel(), getVersion())) { throw new IllegalArgumentException(format( resourceBundle.getString("AbstractNamedSBase.checkIdentifier"), sID, getElementName())); } return true; }
@Override public void setName(String name) { // removed the call to the trim() function as a name with only space // should be considered valid. String oldName = this.name; if ((name == null) || (name.length() == 0)) { this.name = null; } else { this.name = name; } if (!isSetId() && (getLevel() == 1)) { /* * Note: In Level 1 there is no id attribute but the name is actually the * id. Since Level 2 the name attribute has been intended to be a human-readable * name, not a unique identifier (this was the meaning in Level 1). JSBML therefore * has to set the id (and not the name) when calling this method in Level 1 models. */ setId(name); } else { // else part to avoid calling this method twice. firePropertyChange(TreeNodeChangeEvent.name, oldName, this.name); } }
@Override public void setId(String id) { String property = getLevel() == 1 ? TreeNodeChangeEvent.name : TreeNodeChangeEvent.id; String oldId = this.id; IdManager idManager = getIdManager(this); if (idManager != null) { // (oldId != null) // As the register and unregister are recursive, we need to call the unregister all the time until we have a non recursive method // Delete previous identifier only if defined. idManager.unregister(this); // TODO - do we need non recursive method on the IdManager interface ?? } if ((id == null) || (id.trim().length() == 0)) { this.id = null; } else if (checkIdentifier(id)) { this.id = id; } if ((idManager != null) && !idManager.register(this)) { IdentifierException exc = IdentifierException.createIdentifierExceptionForId(this, this.id); this.id = oldId; // restore the previous setting! throw new IllegalArgumentException(exc); } firePropertyChange(property, oldId, this.id); }
/** * Checks if the attribute conforms to the SBML specifications of the level * and version of this object. The final values of {@link TreeNodeChangeEvent} * could be used as attribute name. * * <p>WARNING: this is a placeholder method, most classes have no attribute * validations implemented. * * @param attributeName - the attribute name * @return {@code true} if the attribute conforms the the SBML specifications. */ protected boolean checkAttribute(String attributeName) { // do not do the checks if we are reading a model or in the process of cloning any TreeNode if (! (isReadingInProgress() || isCloningInProgress())) { AbstractSBase.attributeValidator.setLevelAndVersion(getLevel(), getVersion()); Class<?> clazz = this.getClass(); attributeValidator.loadConstraintsForAttribute(clazz, attributeName); boolean valid = attributeValidator.validate(this); if (!valid) { logger.error("Invalid value for attribute " + attributeName + " on " + clazz.getSimpleName() + " with id = " + metaId + "!"); } return valid; } return true; }
} else if (getLevel() == 1) { throw new PropertyNotAvailableException(TreeNodeChangeEvent.metaId, this);