c4950c6ae8e7fd75e89b9eeb2b680bbbed26df58
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / externaltools / internal / registry / ArgumentVariable.java
1 package net.sourceforge.phpdt.externaltools.internal.registry;
2
3 /**********************************************************************
4 Copyright (c) 2002 IBM Corp. and others. All rights reserved.
5 This file is made available under the terms of the Common Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/cpl-v10.html
8  
9 Contributors:
10 **********************************************************************/
11
12 import org.eclipse.core.runtime.IConfigurationElement;
13 import net.sourceforge.phpdt.externaltools.variable.ExpandVariableContext;
14 import net.sourceforge.phpdt.externaltools.variable.IVariableTextExpander;
15
16 /**
17  * Represents the variable for the argument
18  */
19 public final class ArgumentVariable extends ExternalToolVariable {
20         private static final DefaultTextExpander defaultExpander = new DefaultTextExpander();
21         
22         private IVariableTextExpander expander = null;
23
24         /**
25          * Creates an argument variable
26          * 
27          * @param tag the variable tag
28          * @param description a short description of what the variable will expand to
29          * @param element the configuration element
30          */
31         /*package*/ ArgumentVariable(String tag, String description, IConfigurationElement element) {
32                 super(tag, description, element);
33         }
34
35         /**
36          * Returns the object that can expand the variable
37          * as text.
38          */
39         public IVariableTextExpander getExpander() {
40                 if (expander == null) {
41                         try {
42                                 expander = (IVariableTextExpander) createObject(ExternalToolVariableRegistry.TAG_EXPANDER_CLASS);
43                         } catch (ClassCastException exception) {
44                         }
45                         if (expander == null) {
46                                 expander = defaultExpander;
47                         }
48                 }
49                 return expander;
50         }
51
52
53         /**
54          * Default variable text expander implementation which does
55          * not expand variables, but just returns <code>null</code>.
56          */     
57         private static final class DefaultTextExpander implements IVariableTextExpander {
58                 /* (non-Javadoc)
59                  * Method declared on IVariableTextExpander.
60                  */
61                 public String getText(String varTag, String varValue, ExpandVariableContext context) {
62                         return null;
63                 }
64         }
65 }