Coverage Report - net.sourceforge.jeuclid.elements.content.semantic.Semantics
 
Classes in this File Line Coverage Branch Coverage Complexity
Semantics
13%
3/23
0%
0/6
1,3
 
 1  
 /*
 2  
  * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 /* $Id: Semantics.java,v bc1d5fde7b73 2009/06/01 14:40:54 maxberger $ */
 18  
 
 19  
 package net.sourceforge.jeuclid.elements.content.semantic;
 20  
 
 21  
 import net.sourceforge.jeuclid.elements.presentation.AbstractContainer;
 22  
 
 23  
 import org.apache.batik.dom.AbstractDocument;
 24  
 import org.w3c.dom.Node;
 25  
 import org.w3c.dom.mathml.MathMLElement;
 26  
 import org.w3c.dom.mathml.MathMLSemanticsElement;
 27  
 
 28  
 /**
 29  
  * This class represents a semantics element.
 30  
  * 
 31  
  * @version $Revision: bc1d5fde7b73 $
 32  
  */
 33  
 public final class Semantics extends AbstractContainer implements
 34  
         MathMLSemanticsElement {
 35  
 
 36  
     /**
 37  
      * The XML element from this class.
 38  
      */
 39  
     public static final String ELEMENT = "semantics";
 40  
 
 41  
     private static final long serialVersionUID = 1L;
 42  
 
 43  
     /**
 44  
      * Default constructor. Sets MathML Namespace.
 45  
      * 
 46  
      * @param qname
 47  
      *            Qualified name.
 48  
      * @param odoc
 49  
      *            Owner Document.
 50  
      */
 51  
     public Semantics(final String qname, final AbstractDocument odoc) {
 52  627
         super(qname, odoc);
 53  627
     }
 54  
 
 55  
     /** {@inheritDoc} */
 56  
     @Override
 57  
     protected Node newNode() {
 58  0
         return new Semantics(this.nodeName, this.ownerDocument);
 59  
     }
 60  
 
 61  
     /** {@inheritDoc} */
 62  
     public void deleteAnnotation(final int index) {
 63  0
         this.removeAnnotation(index);
 64  0
     }
 65  
 
 66  
     /** {@inheritDoc} */
 67  
     public MathMLElement getAnnotation(final int index) {
 68  
         // Index is 1-based!
 69  209
         return (MathMLElement) this.getChildNodes().item(index);
 70  
     }
 71  
 
 72  
     /** {@inheritDoc} */
 73  
     public MathMLElement getBody() {
 74  0
         return (MathMLElement) this.getFirstChild();
 75  
     }
 76  
 
 77  
     /** {@inheritDoc} */
 78  
     public int getNAnnotations() {
 79  0
         return Math.max(0, this.getChildNodes().getLength() - 1);
 80  
     }
 81  
 
 82  
     /** {@inheritDoc} */
 83  
     public MathMLElement insertAnnotation(final MathMLElement newAnnotation,
 84  
             final int index) {
 85  0
         if (index == 0) {
 86  0
             if (this.getNAnnotations() == 0) {
 87  0
                 this.setAnnotation(newAnnotation, 1);
 88  
             } else {
 89  0
                 this.addMathElement(newAnnotation);
 90  
             }
 91  
         } else {
 92  0
             final MathMLElement oldChild = this.getAnnotation(index);
 93  0
             if (oldChild == null) {
 94  0
                 this.setAnnotation(newAnnotation, index);
 95  
             } else {
 96  0
                 this.insertBefore(newAnnotation, oldChild);
 97  
             }
 98  
         }
 99  0
         return newAnnotation;
 100  
     }
 101  
 
 102  
     /** {@inheritDoc} */
 103  
     public MathMLElement removeAnnotation(final int index) {
 104  0
         final MathMLElement oldChild = this.getAnnotation(index);
 105  0
         return (MathMLElement) this.removeChild(oldChild);
 106  
     }
 107  
 
 108  
     /** {@inheritDoc} */
 109  
     public MathMLElement setAnnotation(final MathMLElement newAnnotation,
 110  
             final int index) {
 111  
         // Index is 1-based!
 112  0
         this.setMathElement(index, newAnnotation);
 113  0
         return newAnnotation;
 114  
     }
 115  
 
 116  
     /** {@inheritDoc} */
 117  
     public void setBody(final MathMLElement body) {
 118  0
         this.setMathElement(0, body);
 119  0
     }
 120  
 
 121  
 }