1 19 package org.netbeans.modules.xml.core.cookies; 20 21 import java.util.Map ; 22 import java.util.HashMap ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 26 import org.openide.nodes.CookieSet; 27 import org.openide.loaders.DataObject; 28 29 import org.netbeans.modules.xml.core.lib.LookupManager; 30 31 35 public final class CookieManager extends LookupManager { 36 37 private final DataObject dataObject; 38 39 private final CookieSet cookieSet; 40 41 private final Map factoryMap; 42 43 44 48 50 public CookieManager (DataObject dataObject, CookieSet cookieSet, Class clazz) { 51 if ( CookieFactoryCreator.class.isAssignableFrom (clazz) == false ) { 52 throw new IllegalArgumentException ("Parameter class must extend CookieFactoryCreator class."); 53 } 54 55 this.dataObject = dataObject; 56 this.cookieSet = cookieSet; 57 this.factoryMap = new HashMap (); 58 59 register (clazz); 60 61 addedToResult (getResult()); 62 } 63 64 65 69 71 protected void removedFromResult (Collection removed) { 72 Iterator it = removed.iterator(); 73 while ( it.hasNext() ) { 74 CookieFactoryCreator creator = (CookieFactoryCreator) it.next(); 75 CookieFactory factory = (CookieFactory) this.factoryMap.remove (creator); 76 if ( factory != null ) { 77 factory.unregisterCookies (this.cookieSet); 78 } 79 } 80 } 81 82 84 protected void addedToResult (Collection added) { 85 87 Iterator it = getResult().iterator(); 88 while ( it.hasNext() ) { 89 CookieFactoryCreator creator = (CookieFactoryCreator) it.next(); 90 CookieFactory factory = creator.createCookieFactory (this.dataObject); 91 if ( factory != null ) { 92 this.factoryMap.put (creator, factory); 93 factory.registerCookies (this.cookieSet); 94 } 95 } 96 } 97 98 } 99 | Popular Tags |