1 package JSci.mathml; 2 3 import org.w3c.dom.*; 4 import org.w3c.dom.mathml.*; 5 import org.apache.xerces.dom.*; 6 7 12 public class MathMLMatrixrowElementImpl extends MathMLElementImpl implements MathMLMatrixrowElement { 13 16 public MathMLMatrixrowElementImpl(MathMLDocumentImpl owner, String qualifiedName) { 17 super(owner, qualifiedName); 18 } 19 20 public int getNEntries() { 21 return getEntriesGetLength(); 22 } 23 24 public MathMLContentElement getEntry(int index) throws DOMException { 25 Node entry = getEntriesItem(index-1); 26 if (entry == null) { 27 throw new DOMException(DOMException.INDEX_SIZE_ERR, "Index out of bounds"); 28 } 29 return (MathMLContentElement) entry; 30 } 31 public MathMLContentElement setEntry(MathMLContentElement newEntry, int index) throws DOMException { 32 final int entriesLength = getEntriesGetLength(); 33 34 if ((index < 1) || (index > entriesLength+1)) { 35 throw new DOMException(DOMException.INDEX_SIZE_ERR, "Index out of bounds"); 36 } 37 if (index == entriesLength+1) { 38 return (MathMLContentElement) appendChild(newEntry); 39 } else { 40 return (MathMLContentElement) replaceChild(newEntry, getEntriesItem(index-1)); 41 } 42 } 43 public MathMLContentElement insertEntry(MathMLContentElement newEntry, int index) throws DOMException { 44 final int entriesLength = getEntriesGetLength(); 45 46 if ((index < 0) || (index > entriesLength+1)) { 47 throw new DOMException(DOMException.INDEX_SIZE_ERR, "Index out of bounds"); 48 } 49 if ((index == 0) || (index == entriesLength+1)) { 50 return (MathMLContentElement) appendChild(newEntry); 51 } else { 52 return (MathMLContentElement) insertBefore(newEntry, getEntriesItem(index-1)); 53 } 54 } 55 public MathMLContentElement removeEntry(int index) throws DOMException { 56 Node entry = getEntriesItem(index-1); 57 if (entry == null) { 58 throw new DOMException(DOMException.INDEX_SIZE_ERR, "Index out of bounds"); 59 } 60 return (MathMLContentElement) removeChild(entry); 61 } 62 public void deleteEntry(int index) throws DOMException { 63 removeEntry(index); 64 } 65 66 private int getEntriesGetLength() { 67 final int length = getLength(); 68 int numEntries = 0; 69 70 for (int i = 0; i < length; i++) { 71 if (item(i) instanceof MathMLContentElement) { 72 numEntries++; 73 } 74 } 75 return numEntries; 76 } 77 private Node getEntriesItem(int index) { 78 final int entriesLength = getEntriesGetLength(); 79 80 if ((index < 0) || (index >= entriesLength)) 81 return null; 82 83 Node node = null; 84 int n = -1; 85 for (int i = 0; n < index; i++) { 86 node = item(i); 87 if (node instanceof MathMLContentElement) { 88 n++; 89 } 90 } 91 return node; 92 } 93 } 94 95 | Popular Tags |