1 18 19 package org.objectweb.jac.core; 20 21 import java.util.Collection ; 22 import java.util.HashMap ; 23 import java.util.HashSet ; 24 import java.util.Hashtable ; 25 import java.util.Iterator ; 26 import java.util.Map ; 27 28 48 49 public class Collaboration implements java.io.Serializable { 50 51 53 public static Object GLOBAL=new Integer (1); 54 55 transient static Hashtable attrTypes=new Hashtable (); 56 57 69 public static boolean isGlobal(String attrName) { 70 if(attrTypes.get(attrName)==GLOBAL) { 71 return true; 72 } else { 73 return false; 74 } 75 } 76 77 85 public static void setGlobal(String attrName) { 86 attrTypes.put(attrName,GLOBAL); 87 } 88 89 90 transient static Hashtable collaborations = new Hashtable (); 91 92 93 94 static { 95 Thread current = Thread.currentThread(); 96 collaborations.put ( current, new Collaboration() ); 97 } 98 99 104 public static Collaboration get() { 105 Thread current = Thread.currentThread(); 106 Collaboration ret = (Collaboration) collaborations.get(current); 107 if ( ret == null ) { 108 collaborations.put ( current, ret = new Collaboration() ); 109 } 110 return ret; 111 } 112 113 118 public static void set(Collaboration collaboration) { 119 Thread current = Thread.currentThread(); 120 collaborations.put(current, collaboration); 121 } 122 123 124 private HashMap attrs; 125 126 139 public Collaboration() { 140 reset(); 141 } 142 143 149 public Collaboration(Collaboration parent) { 150 reset(); 151 if (parent!=null) { 152 Iterator it = parent.attributeNames().iterator(); 153 while (it.hasNext()) { 154 String attrName = (String )it.next(); 155 addAttribute( 156 attrName,parent.getAttribute(attrName)); 157 } 158 } 159 } 160 161 164 public Collection attributeNames() { 165 HashSet names = new HashSet (); 166 names.addAll(attrs.keySet()); 167 return names; 168 } 169 170 public static Collection globalAttributeNames() { 171 HashSet names = new HashSet (); 172 names.addAll(attrTypes.keySet()); 173 return names; 174 } 175 176 179 public Map getAttributes() { 180 return (Map )attrs.clone(); 181 } 182 183 187 public void setAttributes(Map attributes) { 188 Iterator it = attributes.entrySet().iterator(); 189 while (it.hasNext()) { 190 Map.Entry entry = (Map.Entry )it.next(); 191 if (!attrs.containsKey(entry.getKey())) 192 attrs.put(entry.getKey(),entry.getValue()); 193 } 194 } 195 196 200 public void reset() { 201 attrs = new HashMap (); 202 } 203 204 214 public Object addAttribute(String name, Object att) { 215 if ( name != null ) { 216 attrs.put(name, att); 217 } 218 return att; 219 } 220 221 232 public Object getAttribute(String name) { 233 if (attrs.containsKey(name)) { 234 return attrs.get(name); 235 } 236 return null; 237 } 238 239 242 public void removeAttribute(String name) { 243 attrs.remove(name); 244 } 245 246 String cur_App; 247 248 public final void setCurApp(String app) { 249 this.cur_App = app; 250 } 251 252 public final String getCurApp() { 253 return cur_App; 254 } 255 256 259 public String toString() { 260 return "Collaboration: \n" + 261 "attributes = " + attrs.toString(); 262 } 263 264 265 } 266 | Popular Tags |