KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > expressions > DefaultVariable


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.expressions;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.core.runtime.CoreException;
15
16 import org.eclipse.core.expressions.IEvaluationContext;
17
18 /**
19  * An evaluation context that can be used to add a new default variable
20  * to a hierarchy of evaluation contexts.
21  *
22  * @since 3.0
23  */

24 public final class DefaultVariable implements IEvaluationContext {
25
26     private Object JavaDoc fDefaultVariable;
27     private IEvaluationContext fParent;
28     private IEvaluationContext fManagedPool;
29     
30     /**
31      * Constructs a new variable pool for a single default variable.
32      *
33      * @param parent the parent context for the default variable. Must not
34      * be <code>null</code>.
35      * @param defaultVariable the default variable
36      */

37     public DefaultVariable(IEvaluationContext parent, Object JavaDoc defaultVariable) {
38         Assert.isNotNull(parent);
39         Assert.isNotNull(defaultVariable);
40         fParent= parent;
41         while (parent instanceof DefaultVariable) {
42             parent= parent.getParent();
43         }
44         fManagedPool= parent;
45         fDefaultVariable= defaultVariable;
46     }
47
48     /**
49      * {@inheritDoc}
50      */

51     public IEvaluationContext getParent() {
52         return fParent;
53     }
54
55     /**
56      * {@inheritDoc}
57      */

58     public IEvaluationContext getRoot() {
59         return fParent.getRoot();
60     }
61
62     /**
63      * {@inheritDoc}
64      */

65     public Object JavaDoc getDefaultVariable() {
66         return fDefaultVariable;
67     }
68     
69     /**
70      * {@inheritDoc}
71      */

72     public void setAllowPluginActivation(boolean value) {
73         fParent.setAllowPluginActivation(value);
74     }
75     
76     /**
77      * {@inheritDoc}
78      */

79     public boolean getAllowPluginActivation() {
80         return fParent.getAllowPluginActivation();
81     }
82
83     /**
84      * {@inheritDoc}
85      */

86     public void addVariable(String JavaDoc name, Object JavaDoc value) {
87         fManagedPool.addVariable(name, value);
88     }
89
90     /**
91      * {@inheritDoc}
92      */

93     public Object JavaDoc removeVariable(String JavaDoc name) {
94         return fManagedPool.removeVariable(name);
95     }
96
97     /**
98      * {@inheritDoc}
99      */

100     public Object JavaDoc getVariable(String JavaDoc name) {
101         return fManagedPool.getVariable(name);
102     }
103
104     /**
105      * {@inheritDoc}
106      */

107     public Object JavaDoc resolveVariable(String JavaDoc name, Object JavaDoc[] args) throws CoreException {
108         return fManagedPool.resolveVariable(name, args);
109     }
110 }
111
Popular Tags