KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > api > Context


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
20 package org.netbeans.modules.refactoring.api;
21
22 import org.openide.util.Lookup;
23 import org.openide.util.Lookup.Result;
24 import org.openide.util.Lookup.Template;
25 import org.openide.util.lookup.AbstractLookup;
26 import org.openide.util.lookup.InstanceContent;
27
28 /**
29  * Context contains "enviroment" in which the refactoring was invoked
30  * e.g. Java refactoring might put instance of ClasspathInfo here
31  * @see AbstractRefactoring
32  * @author Jan Becicka
33  */

34 public final class Context extends Lookup {
35
36     private InstanceContent instanceContent;
37     private AbstractLookup delegate;
38
39     Context(InstanceContent instanceContent) {
40         super();
41         delegate = new AbstractLookup(instanceContent);
42         this.instanceContent = instanceContent;
43     }
44
45     /**
46      * Adds value instance into this context
47      * for instance Java impl. puts instance of ClasspathInfo here.
48      * If there is an instance already set for this context, old
49      * value is replaced by new one.
50      */

51     public void add(Object JavaDoc value) {
52         Object JavaDoc old = lookup(value.getClass());
53         if (old!=null) {
54             instanceContent.remove(old);
55         }
56         instanceContent.add(value);
57     }
58
59     public <T> T lookup(Class JavaDoc<T> clazz) {
60         return delegate.lookup(clazz);
61     }
62
63     public <T> Result<T> lookup(Template<T> template) {
64         return delegate.lookup(template);
65     }
66 }
67
Popular Tags