1 6 7 package SOFA.SOFAnet.Repository; 8 9 import java.util.*; 10 import org.w3c.dom.*; 11 import org.xml.sax.SAXException ; 12 import java.io.Serializable ; 13 14 19 public class NodeNameList implements Cloneable , Serializable 20 { 21 private List list; 22 23 24 public NodeNameList() 25 { 26 list = Collections.synchronizedList(new LinkedList()); 27 } 28 29 public Object clone() 30 { 31 NodeNameList clone = null; 32 try 33 { 34 clone = (NodeNameList)super.clone(); 35 } 36 catch (CloneNotSupportedException e) 37 { 38 throw new InternalError (); 39 } 40 clone.list = Collections.synchronizedList(new LinkedList()); 41 clone.list.addAll(list); 42 return clone; 43 } 44 45 public List getList() 46 { 47 return list; 48 } 49 50 public void add(String nodeName) 51 { 52 list.add(nodeName); 53 } 54 55 public void add(NodeNameList nodeNameList) 56 { 57 if (nodeNameList != null) 58 { 59 List li = nodeNameList.getList(); 60 synchronized (li) 61 { 62 Iterator it = li.iterator(); 63 while (it.hasNext()) 64 { 65 String nodeName = (String )it.next(); 66 list.add(nodeName); 67 } 68 } 69 } 70 } 71 72 public boolean contains(String nodeName) 73 { 74 return list.contains(nodeName); 75 } 76 77 public void remove(String nodeName) 78 { 79 list.remove(nodeName); 80 } 81 82 89 public void loadFromXML(Element element) throws SAXException 90 { 91 synchronized (list) 92 { 93 NodeList nl = element.getChildNodes(); 94 for (int i = 0; i < nl.getLength(); i++) 95 { 96 Node node = nl.item(i); 97 if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().compareTo("node") == 0) 98 { 99 Element el = (Element)node; 100 String name = el.getAttribute("name"); 101 list.add(name); 102 } 103 } 104 } 105 } 106 107 public void saveToXML(Element element) 108 { 109 synchronized (list) 110 { 111 Document doc = element.getOwnerDocument(); 112 113 Iterator it = list.iterator(); 114 while (it.hasNext()) 115 { 116 String name = (String )it.next(); 117 118 Element el = doc.createElement("node"); 119 el.setAttribute("name", name); 120 element.appendChild(el); 121 } 122 } 123 } 124 125 } 126 | Popular Tags |