File indexing completed on 2024-12-15 04:19:54
0001 package mso.generator.utils; 0002 0003 import java.io.IOException; 0004 import java.util.ArrayList; 0005 import java.util.List; 0006 0007 import org.w3c.dom.Document; 0008 import org.w3c.dom.Element; 0009 import org.w3c.dom.NodeList; 0010 0011 public class MSO { 0012 public final List<Struct> structs; 0013 public final List<Stream> streams; 0014 0015 public static MSO parse(Document dom) throws IOException { 0016 final TypeRegistry typeRegistry = new TypeRegistry(); 0017 final List<Struct> structs = new ArrayList<Struct>(); 0018 final List<Stream> streams = new ArrayList<Stream>(); 0019 0020 // retrieve all the structs 0021 List<Element> orderedElements = ParserGeneratorUtils 0022 .getOrderedStructureList(dom); 0023 for (Element e : orderedElements) { 0024 String typeName = e.getAttribute("name"); 0025 Type t = typeRegistry.getType(typeName); 0026 Struct s = null; 0027 if (t instanceof Struct) { 0028 s = (Struct) t; 0029 } else { 0030 s = new Struct(typeRegistry, e); 0031 } 0032 structs.add(s); 0033 } 0034 // check that all members have a non-null type 0035 for (Struct s : structs) { 0036 for (Member m : s.members) { 0037 if (m.type() == null) { 0038 throw new Error("Member " + m.name + " of structure " 0039 + s.name + " has no parsed type."); 0040 } 0041 } 0042 } 0043 0044 NodeList l = dom.getElementsByTagName("stream"); 0045 for (int i = 0; i < l.getLength(); ++i) { 0046 streams.add(new Stream((Element) l.item(i))); 0047 } 0048 return new MSO(structs, streams); 0049 } 0050 0051 private MSO(List<Struct> structs, List<Stream> streams) { 0052 this.structs = structs; 0053 this.streams = streams; 0054 } 0055 }