1 6 7 package SOFA.SOFAnet.Repository; 8 9 import java.io.*; 10 import java.util.*; 11 import SOFA.SOFAnode.TR.Impl.ComponentInfoImpl; 12 import SOFA.SOFAnode.TR.ComponentInfo; 13 import SOFA.Util.XML; 14 import org.w3c.dom.*; 15 import org.xml.sax.SAXException ; 16 17 28 public class BundleContent extends XMLStorageItem implements StorageItem, Serializable 29 { 30 private List components; 31 32 33 public BundleContent(String name, File file) 34 { 35 super(name, file, "bundle_content"); 36 components = Collections.synchronizedList(new LinkedList()); 37 } 38 39 42 protected void reset() 43 { 44 components.clear(); 45 } 46 47 64 public void loadFromXML(Element element) throws SAXException 65 { 66 synchronized (components) 67 { 68 components.clear(); 69 NodeList nl = element.getChildNodes(); 70 for (int i = 0; i < nl.getLength(); i++) 71 { 72 Node node = nl.item(i); 73 if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().compareTo("component") == 0) 74 { 75 Element e = (Element)node; 76 String name = e.getAttribute("name"); 77 String version = e.getAttribute("implementation_version"); 78 if (name.length() == 0) throw new SAXException ("Missing 'name' attribute in 'component' tag"); 79 if (version.length() == 0) throw new SAXException ("Missing 'implementation_version' attribute in 'component' tag"); 80 components.add(new ComponentInfoImpl(name, version)); 81 } 82 } 83 } 84 } 85 86 89 public void saveToXML(Element element) 90 { 91 synchronized (components) 92 { 93 Document doc = element.getOwnerDocument(); 94 Iterator it = components.iterator(); 95 while (it.hasNext()) 96 { 97 ComponentInfo ci = (ComponentInfo)it.next(); 98 Element el = doc.createElement("component"); 99 el.setAttribute("name", ci.getName()); 100 el.setAttribute("implementation_version", ci.getImplementationVersion()); 101 element.appendChild(el); 102 } 103 } 104 } 105 106 107 public List getComponents() 108 { 109 return components; 110 } 111 112 } 113 | Popular Tags |