From: <nik...@us...> - 2015-12-15 11:58:09
|
Revision: 2456 http://sourceforge.net/p/jsbml/code/2456 Author: niko-rodrigue Date: 2015-12-15 11:58:07 +0000 (Tue, 15 Dec 2015) Log Message: ----------- added a field and some methods in ASTNode to handle the semantics annotations Modified Paths: -------------- trunk/core/src/org/sbml/jsbml/ASTNode.java Modified: trunk/core/src/org/sbml/jsbml/ASTNode.java =================================================================== --- trunk/core/src/org/sbml/jsbml/ASTNode.java 2015-12-15 11:56:29 UTC (rev 2455) +++ trunk/core/src/org/sbml/jsbml/ASTNode.java 2015-12-15 11:58:07 UTC (rev 2456) @@ -48,6 +48,7 @@ import org.sbml.jsbml.util.compilers.MathMLXMLStreamCompiler; import org.sbml.jsbml.util.compilers.UnitsCompiler; import org.sbml.jsbml.util.filters.Filter; +import org.sbml.jsbml.xml.XMLNode; import org.sbml.jsbml.xml.stax.SBMLReader; /** @@ -1391,6 +1392,12 @@ private String encoding; /** + * XMLNode that will hold the content of the 'semantics' mathML element. + */ + private List<XMLNode> semanticsAnnotationList; + + + /** * Tells if the type attribute of the cn element was set and we need to * write it back or if it is set to the default (REAL). * @@ -1498,6 +1505,14 @@ listOfNodes.add(c); } } + + if (astNode.semanticsAnnotationList != null) { + semanticsAnnotationList = new ArrayList<XMLNode>(); + + for (XMLNode semanticsAnnotation : astNode.semanticsAnnotationList) { + semanticsAnnotationList.add(semanticsAnnotation.clone()); + } + } } /** @@ -2272,6 +2287,8 @@ if (equal && isSetUnits()) { equal &= getUnits().equals(ast.getUnits()); } + + // TODO - semanticsAnnotationList not part of equals or hashcode ? } return equal; } @@ -2355,6 +2372,8 @@ @Override public TreeNode getChildAt(int i) { return getChild(i); + + // TODO - add semantics XMLNode ?? } /* (non-Javadoc) @@ -2363,6 +2382,8 @@ @Override public int getChildCount() { return listOfNodes == null ? 0 : listOfNodes.size(); + + // TODO - add semantics XMLNode ?? } /** @@ -2803,6 +2824,12 @@ if (isSetClassName()) { hashCode += prime * getClassName().hashCode(); } + if (isSetUnits()) { + hashCode += prime * getUnits().hashCode(); + } + // TODO - semanticsAnnotationList not part of equals or hashcode ? + + return hashCode; } @@ -4356,4 +4383,102 @@ return tree; } + /** + * Adds the given {@link XMLNode} as a MathML <code><semantics></code> element to this {@link ASTNode}. + * + * <p> + * The {@code <semantics>} element is a MathML 2.0 construct + * that can be used to associate additional information with a MathML + * construct. The construct can be used to decorate a MathML expressions with + * a sequence of one or more {@code <annotation>} or + * {@code <annotation-xml>} elements. Each such element contains a + * pair of items; the first is a symbol that acts as an attribute or key, and + * the second is the value associated with the attribute or key. Please refer + * to the MathML 2.0 documentation, particularly the <a target="_blank" + * href="http://www.w3.org/TR/2007/WD-MathML3-20071005/chapter5.html#mixing.semantic.annotations">Section + * 5.2, Semantic Annotations</a> for more information about these constructs. + * + * @param semanticsAnnotation the annotation to add. + * @return the added {@link XMLNode}. + */ + public XMLNode addSemanticsAnnotation(XMLNode semanticsAnnotation) { + if (semanticsAnnotation == null) { + return null; + } + if (semanticsAnnotationList == null) { + semanticsAnnotationList = new ArrayList<XMLNode>(); + } + + semanticsAnnotationList.add(semanticsAnnotation); + + return semanticsAnnotation; + } + + /** + * Gets the number of <em>semantic annotation</em> elements inside this node. + * + * <p> + * The <code><semantics></code> element is a MathML 2.0 construct + * that can be used to associate additional information with a MathML + * construct. The construct can be used to decorate a MathML expressions with + * a sequence of one or more <code><annotation></code> or + * <code><annotation-xml></code> elements. Each such element contains a + * pair of items; the first is a symbol that acts as an attribute or key, and + * the second is the value associated with the attribute or key. Please refer + * to the MathML 2.0 documentation, particularly the <a target="_blank" + * href="http://www.w3.org/TR/2007/WD-MathML3-20071005/chapter5.html#mixing.semantic.annotations">Section + * 5.2, Semantic Annotations</a> for more information about these constructs. + * + * @return the number of annotations of this {@link ASTNode}. + * @see ASTNode#addSemanticsAnnotation(XMLNode semanticsAnnotation) + */ + public int getNumSemanticsAnnotations() { + if (semanticsAnnotationList == null) { + return 0; + } + + return semanticsAnnotationList.size(); + } + + /** + * Gets the nth <code><semantics></code> annotation of this node. + * + * <p> + * The <code><semantics></code> element is a MathML 2.0 construct + * that can be used to associate additional information with a MathML + * construct. The construct can be used to decorate a MathML expressions with + * a sequence of one or more <code><annotation></code> or + * <code><annotation-xml></code> elements. Each such element contains a + * pair of items; the first is a symbol that acts as an attribute or key, and + * the second is the value associated with the attribute or key. Please refer + * to the MathML 2.0 documentation, particularly the <a target="_blank" + * href="http://www.w3.org/TR/2007/WD-MathML3-20071005/chapter5.html#mixing.semantic.annotations">Section + * 5.2, Semantic Annotations</a> for more information about these constructs. + * + * @return the nth annotation of this {@link ASTNode}, or <code>null</code> if this node has + * no nth annotation (<code>n ></code> + * {@link ASTNode#getNumSemanticsAnnotations()} + * <code>- 1</code> or n < 0). + * @see ASTNode#addSemanticsAnnotation(XMLNode sAnnotation) + */ + public XMLNode getSemanticsAnnotation(int n) { + if (semanticsAnnotationList == null || n < 0 || (n > (getNumSemanticsAnnotations() -1))) { + return null; + } + + return semanticsAnnotationList.get(n); + } + + /** + * Returns the list of semantics annotations of this node. + * + * @return the list of semantics annotations of this node or null if no semantics annotation are present. + */ + public List<XMLNode> getListOfSemanticsAnnotations() { + return semanticsAnnotationList; + } + + // TODO - removeSemanticsAnnotation + // TODO - unsetsemanticsAnnotation + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |