001 package jigcell.sbml2; 002 003 import java.util.Iterator; 004 import java.util.List; 005 import org.xml.sax.Attributes; 006 007 /** 008 * Contains the notes, annotations, and metadata for an SBML element. 009 * 010 * <p> 011 * This code is licensed under the DARPA BioCOMP Open Source License. See LICENSE for more details. 012 * </p> 013 * 014 * @author Nicholas Allen 015 */ 016 017 public class SBase extends XMLElement { 018 private final Annotations annotations; 019 private final Notes notes; 020 private String metaid; 021 private String rdf; 022 023 final static SBaseId searchListForId (List elements, String id) { 024 if (id == null) 025 return null; 026 for (Iterator iterator = elements.iterator (); iterator.hasNext (); ) { 027 SBaseId element = (SBaseId) iterator.next (); 028 if (id.equals (element.getId ())) 029 return element; 030 } 031 return null; 032 } 033 034 final static SBaseId searchListForName (List elements, String name) { 035 if (name == null) 036 return null; 037 for (Iterator iterator = elements.iterator (); iterator.hasNext (); ) { 038 SBaseId element = (SBaseId) iterator.next (); 039 if (name.equals (element.getName ())) 040 return element; 041 } 042 return null; 043 } 044 045 public final Annotations getAnnotations () { 046 return annotations; 047 } 048 049 public final String getMetaid () { 050 return metaid; 051 } 052 053 public final Notes getNotes () { 054 return notes; 055 } 056 057 public final String getRDF () { 058 return rdf; 059 } 060 061 public boolean isValid (Model model) { 062 return true; 063 } 064 065 public final void setMetaid (String metaid) { 066 this.metaid = metaid; 067 } 068 069 public final void setRDF (String rdf) { 070 this.rdf = rdf; 071 } 072 073 public final void setRDF (String rdf, String metaid) { 074 setRDF (rdf); 075 setMetaid (metaid); 076 } 077 078 protected SBase () { 079 annotations = new Annotations (); 080 notes = new Notes (); 081 } 082 083 protected void parse (Attributes attributes) { 084 setMetaid (attributes.getValue ("metaid")); 085 } 086 087 protected XMLPrinter print (XMLPrinter parent, String name) { 088 XMLPrinter printer = super.print (parent, name); 089 String notesText = getNotes ().toString ().trim (); 090 if (notesText.length () > 0) 091 printer.addText (notesText); 092 String annotationsText = getAnnotations ().toString ().trim (); 093 if (annotationsText.length () > 0) 094 printer.addText (annotationsText); 095 String rdfText = getRDF (); 096 if (rdfText != null) { 097 rdfText = rdfText.trim (); 098 if (rdfText.length () > 0) 099 printer.addText (rdfText); 100 } 101 printer.addAttribute ("metaid", getMetaid ()); 102 return printer; 103 } 104 }