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 ShareGroups implements Cloneable , Serializable 20 { 21 private List list; 23 24 public ShareGroups() 25 { 26 list = Collections.synchronizedList(new LinkedList()); 27 } 28 29 public Object clone() 30 { 31 ShareGroups clone = null; 32 try 33 { 34 clone = (ShareGroups)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 46 public List getList() 47 { 48 return list; 49 } 50 51 public void add(String group) 52 { 53 list.add(group); 54 } 55 56 public void add(ShareGroups shareGroups) 57 { 58 if (shareGroups != null) 59 { 60 List li = shareGroups.getList(); 61 synchronized (li) 62 { 63 Iterator it = li.iterator(); 64 while (it.hasNext()) 65 { 66 String group = (String )it.next(); 67 list.add(group); 68 } 69 } 70 } 71 } 72 73 public boolean contains(String shareGroup) 74 { 75 return list.contains(shareGroup); 76 } 77 78 87 public void loadFromXML(Element element) throws SAXException 88 { 89 synchronized (list) 90 { 91 NodeList nl = element.getChildNodes(); 92 for (int i = 0; i < nl.getLength(); i++) 93 { 94 Node node = nl.item(i); 95 if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().compareTo("share_group") == 0) 96 { 97 Element el = (Element)node; 98 String name = el.getAttribute("name"); 99 list.add(name); 100 } 101 } 102 } 103 } 104 105 108 public void saveToXML(Element element) 109 { 110 synchronized (list) 111 { 112 Document doc = element.getOwnerDocument(); 113 114 Iterator it = list.iterator(); 115 while (it.hasNext()) 116 { 117 String name = (String )it.next(); 118 119 Element el = doc.createElement("share_group"); 120 el.setAttribute("name", name); 121 element.appendChild(el); 122 } 123 } 124 } 125 126 } 127 | Popular Tags |