KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > core > cookies > CookieManager


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.core.cookies;
20
21 import java.util.Map JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
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 /**
32  * @author Libor Kramolis
33  * @version 0.1
34  */

35 public final class CookieManager extends LookupManager {
36     /** */
37     private final DataObject dataObject;
38     /** */
39     private final CookieSet cookieSet;
40     /** */
41     private final Map JavaDoc factoryMap;
42
43
44     //
45
// init
46
//
47

48     /**
49      */

50     public CookieManager (DataObject dataObject, CookieSet cookieSet, Class JavaDoc clazz) {
51         if ( CookieFactoryCreator.class.isAssignableFrom (clazz) == false ) {
52             throw new IllegalArgumentException JavaDoc ("Parameter class must extend CookieFactoryCreator class.");
53         }
54
55         this.dataObject = dataObject;
56         this.cookieSet = cookieSet;
57         this.factoryMap = new HashMap JavaDoc();
58
59         register (clazz);
60
61         addedToResult (getResult());
62     }
63
64
65     //
66
// itself
67
//
68

69     /**
70      */

71     protected void removedFromResult (Collection JavaDoc removed) {
72         Iterator JavaDoc 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     /**
83      */

84     protected void addedToResult (Collection JavaDoc added) {
85         //??? is getResult() meant here (rather than added)?
86

87         Iterator JavaDoc 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