/** * Unsets the namespace that is associated to this {@link SBase}. * <p> * This is an internal method of JSBML that should be used with caution. */ public void unsetNamespace() { String old = elementNamespace; elementNamespace = null; firePropertyChange(TreeNodeChangeEvent.namespace, old, null); }
@Override public void setNotes(XMLNode notes) { XMLNode oldNotes = notesXMLNode; notesXMLNode = notes; if (notesXMLNode != null) { notesXMLNode.setParent(this); } firePropertyChange(TreeNodeChangeEvent.notes, oldNotes, notesXMLNode); }
/** * Sets the parent of the current {@link SBase}. * * @param parent the parent of this element. */ protected void setParentSBML(SBase parent) { SBase oldParent = getParent(); this.parent = parent; firePropertyChange(TreeNodeChangeEvent.parentSBMLObject, oldParent, parent); }
@Override public void unsetAnnotation() { if (isSetAnnotation()) { Annotation oldAnnotation = annotation; annotation = null; firePropertyChange(TreeNodeChangeEvent.annotation, oldAnnotation, annotation); } }
/** * Removes a namespace from the set of declared namespaces of this * {@link SBase}. * * @param namespace the namespace to remove */ public void removeDeclaredNamespaceByNamespace(String namespace) { if (namespace == null) { return; } String prefixToRemove = null; for (String prefix : declaredNamespaces.keySet()) { String namespaceForPrefix = declaredNamespaces.get(prefix); if (namespace.equals(namespaceForPrefix)) { prefixToRemove = prefix; break; } } if (prefixToRemove != null) { declaredNamespaces.remove(prefixToRemove); firePropertyChange(TreeNodeChangeEvent.addDeclaredNamespace, namespace, null); } }
/** * Removes a namespace from the set of declared namespaces of this * {@link SBase}. * * @param prefix * the prefix of the namespace to remove */ public void removeDeclaredNamespaceByPrefix(String prefix) { if (prefix == null) { return; } if ((!prefix.startsWith("xmlns:")) && (!prefix.equals("xmlns"))) { if (prefix.indexOf(':') != -1) { throw new IllegalArgumentException( resourceBundle.getString("AbstractSBase.addDeclaredNamespace")); } prefix = "xmlns:" + prefix; } String removedNamespace = declaredNamespaces.remove(prefix); if (removedNamespace != null) { firePropertyChange(TreeNodeChangeEvent.addDeclaredNamespace, removedNamespace, null); } }
/** * Adds an additional name space to the set of declared namespaces of this * {@link SBase}. * * @param prefix * the prefix of the namespace to add * @param namespace * the namespace to add */ @Override public void addDeclaredNamespace(String prefix, String namespace) { if ((!prefix.startsWith("xmlns:")) && (!prefix.equals("xmlns"))) { if (prefix.indexOf(':') != -1) { throw new IllegalArgumentException( resourceBundle.getString("AbstractSBase.addDeclaredNamespace")); } prefix = "xmlns:" + prefix; } declaredNamespaces.put(prefix, namespace); firePropertyChange(TreeNodeChangeEvent.addDeclaredNamespace, null, namespace); }
elementNamespace = namespace; firePropertyChange(TreeNodeChangeEvent.namespace, old, namespace);
@Override public void unsetExtension(String nameOrUri) { // use always the package name in the map PackageParser packageParser = ParserManager.getManager().getPackageParser(nameOrUri); if (packageParser != null) { SBasePlugin sbasePlugin = extensions.remove(packageParser.getPackageName()); firePropertyChange(TreeNodeChangeEvent.extension, sbasePlugin, null); return; } throw new IllegalArgumentException(format( resourceBundle.getString("AbstractSBase.createPlugin"), nameOrUri)); }
@Override public void unsetNotes() { if (isSetNotes()) { XMLNode oldNotes = notesXMLNode; notesXMLNode = null; firePropertyChange(TreeNodeChangeEvent.notes, oldNotes, getNotes()); } }
@Override public void setSBOTerm(int term) { if ((getLevelAndVersion().compareTo(Integer.valueOf(2), Integer.valueOf(2)) < 0) && (!isReadingInProgress())) { throw new PropertyNotAvailableException(TreeNodeChangeEvent.sboTerm, this); } if ((term != -1) && !SBO.checkTerm(term) && !isReadingInProgress()) { throw new IllegalArgumentException(format( resourceBundle.getString("AbstractSBase.setSBOTerm"), term)); } Integer oldTerm = Integer.valueOf(sboTerm); sboTerm = term; firePropertyChange(TreeNodeChangeEvent.sboTerm, oldTerm, sboTerm); }
@Override public void setAnnotation(Annotation annotation) { Annotation oldAnnotation = this.annotation; this.annotation = annotation; this.annotation.parent = this; if (isSetMetaId()) { this.annotation.setAbout('#' + getMetaId()); } firePropertyChange(TreeNodeChangeEvent.setAnnotation, oldAnnotation, this.annotation); }
@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); }
@Override public void setHistory(History history) { History oldHistory = isSetHistory() ? getHistory() : null; getAnnotation().setHistory(history); firePropertyChange(TreeNodeChangeEvent.history, oldHistory, history); }
@Override public void appendNotes(String notes) throws XMLStreamException { XMLNode addedNotes = XMLNode.convertStringToXMLNode(StringTools.toXMLNotesString(notes)); if (isSetNotes()) { XMLNode oldNotes = notesXMLNode.clone(); appendNotes(addedNotes); firePropertyChange(TreeNodeChangeEvent.notes, oldNotes, notesXMLNode); } else { setNotes(addedNotes); } }
@Override public void addExtension(String nameOrUri, SBasePlugin sbasePlugin) { if (!isPackageEnabled(nameOrUri)) { enablePackage(nameOrUri); } // use always the package name in the map PackageParser packageParser = ParserManager.getManager().getPackageParser(nameOrUri); if (packageParser != null) { // unset the previous plugin if needed if (extensions.get(packageParser.getPackageName()) != null) { unsetPlugin(packageParser.getPackageName()); } extensions.put(packageParser.getPackageName(), sbasePlugin); // Making sure that the correct extendedSBase is set in the SBasePlugin // And that all the ids and metaids are registered if ((sbasePlugin.getExtendedSBase() == null) || (sbasePlugin.getExtendedSBase() != this)) { ((AbstractSBasePlugin) sbasePlugin).setExtendedSBase(this); } // the package namespace and version will be set in firePropertyChange firePropertyChange(TreeNodeChangeEvent.addExtension, null, sbasePlugin); } else { throw new IllegalArgumentException(format( resourceBundle.getString("AbstractSBase.addExtensionExc"), nameOrUri)); } }
@Override public void setVersion(int version) { SBase parent = getParent(); if ((parent != null) && (parent != this) && parent.isSetVersion()) { if (version != parent.getVersion()) { throw new LevelVersionError(parent, this); } } Integer oldVersion = getLevelAndVersion().getV(); lv.setV(version); firePropertyChange(TreeNodeChangeEvent.version, oldVersion, version); }
@Override public void setLevel(int level) { SBase parent = getParent(); if ((parent != null) && (parent != this) && parent.isSetLevel()) { if (level != parent.getLevel()) { throw new LevelVersionError(this, parent); } } Integer oldLevel = getLevelAndVersion().getL(); lv.setL(level); firePropertyChange(TreeNodeChangeEvent.level, oldLevel, lv.getL()); }
@Override public void setPackageVersion(int packageVersion) { int oldPackageVersion = this.packageVersion; SBase parent = getParent(); SBasePlugin parentPlugin = null; if ((parent != null) && (parent != this)) { int parentPackageVersion = -1; if (parent.getPackageName().equals(packageName)) { parentPackageVersion = parent.getPackageVersion(); } else if (parent.isSetPlugin(packageName)) { parentPlugin = parent.getPlugin(packageName); parentPackageVersion = parentPlugin.getPackageVersion(); } if (packageVersion != -1 && parentPackageVersion != -1 && packageVersion != parentPackageVersion) { if (parentPlugin != null) { throw new LevelVersionError(parentPlugin, this); } else { throw new LevelVersionError(parent, this); } } } this.packageVersion = packageVersion; firePropertyChange(TreeNodeChangeEvent.packageVersion, oldPackageVersion, packageVersion); }