KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > core > Property


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.ant.core;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.variables.VariablesPlugin;
15
16 /**
17  * Represents a Ant property.
18  * Clients may instantiate this class; it is not intended to be subclassed.
19  * @since 2.1
20  */

21 public class Property {
22
23     private String JavaDoc name;
24     private String JavaDoc value;
25     private String JavaDoc className;
26     private IAntPropertyValueProvider valueProvider;
27     private String JavaDoc pluginLabel;
28     private ClassLoader JavaDoc loader;
29     private boolean eclipseRuntime= true;
30
31     public Property(String JavaDoc name, String JavaDoc value) {
32         this.name= name;
33         this.value= value;
34     }
35
36     public Property() {
37     }
38     
39     /**
40      * Gets the name
41      * @return Returns a String
42      */

43     public String JavaDoc getName() {
44         return name;
45     }
46
47     /**
48      * Sets the name
49      * @param name The name to set
50      */

51     public void setName(String JavaDoc name) {
52         this.name= name;
53     }
54     
55     /*
56      * @see Object#equals()
57      */

58     public boolean equals(Object JavaDoc other) {
59         if (other.getClass().equals(getClass())) {
60             Property elem= (Property)other;
61             return name.equals(elem.getName());
62         }
63         return false;
64     }
65     
66     /*
67      * @see Object#hashCode()
68      */

69     public int hashCode() {
70         return name.hashCode();
71     }
72     
73     /**
74      * Returns the value.
75      * Equivalent to calling #getValue(true);
76      * @return String
77      */

78     public String JavaDoc getValue() {
79         return getValue(true);
80     }
81     
82     /**
83      * Returns the value.
84      *
85      * @param substituteVariables whether the value has any variables resolved.
86      * @return String
87      * @since 3.0
88      */

89     public String JavaDoc getValue(boolean substituteVariables) {
90         if (className != null) {
91             Class JavaDoc cls = null;
92             try {
93                 cls = loader.loadClass(className);
94             } catch (ClassNotFoundException JavaDoc e) {
95                 AntCorePlugin.log(e);
96                 return null;
97             }
98             try {
99                 valueProvider = (IAntPropertyValueProvider)cls.newInstance();
100             } catch (InstantiationException JavaDoc e) {
101                 AntCorePlugin.log(e);
102                 return null;
103             } catch (IllegalAccessException JavaDoc ex) {
104                 AntCorePlugin.log(ex);
105                 return null;
106             }
107             loader= null;
108             className= null;
109         }
110         
111         if (valueProvider != null) {
112             return valueProvider.getAntPropertyValue(name);
113         }
114         if (substituteVariables) {
115             try {
116                 String JavaDoc expanded = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(value);
117                 return expanded;
118             } catch (CoreException e) {
119             }
120         } else {
121             return value;
122         }
123         return value;
124     }
125
126     /**
127      * Sets the value.
128      * @param value The value to set
129      */

130     public void setValue(String JavaDoc value) {
131         this.value = value;
132     }
133     
134     /**
135      * Returns whether this Ant property has been created because of an extension
136      * point definition.
137      *
138      * @return boolean
139      * @since 3.0
140      */

141     public boolean isDefault() {
142         return pluginLabel != null;
143     }
144
145     /**
146      * Sets the label of the plug-in that contributed this Ant property via an extension
147      * point.
148      *
149      * @param pluginLabel The label of the plug-in
150      * @since 3.0
151      */

152     public void setPluginLabel(String JavaDoc pluginLabel) {
153         this.pluginLabel = pluginLabel;
154     }
155     
156     /**
157      * Returns the label of the plug-in that contributed this Ant property via an extension
158      * point.
159      *
160      * @return pluginLabel The label of the plug-in
161      * @since 3.0
162      */

163     public String JavaDoc getPluginLabel() {
164         return this.pluginLabel;
165     }
166     
167     /**
168      * Sets the name of the class that is an <code>IAntPropertyValueProvider</code> to be used to dynamically provide a
169      * value for this property.
170      * Sets the class loader to load the <code>IAntPropertyValueProvider</code> to be used to dynamically provide a
171      * value for this property.
172      *
173      * @param className The name of the value provider class to use to resolve the value of this property
174      * @param loader The class loader to use to load the value provider class to use to resolve the value of this property
175      * @since 3.0
176      */

177     public void setValueProvider(String JavaDoc className, ClassLoader JavaDoc loader) {
178         this.className= className;
179         this.loader= loader;
180     }
181
182     /* (non-Javadoc)
183      * @see java.lang.Object#toString()
184      */

185     public String JavaDoc toString() {
186         StringBuffer JavaDoc buff= new StringBuffer JavaDoc("\""); //$NON-NLS-1$
187
buff.append(getName());
188         buff.append("\"= \""); //$NON-NLS-1$
189
buff.append(getValue(false));
190         buff.append("\""); //$NON-NLS-1$
191
return buff.toString();
192     }
193     
194     /**
195      * Returns whether this property requires the Eclipse runtime to be
196      * relevant. Defaults value is <code>true</code>
197      *
198      * @return whether this property requires the Eclipse runtime
199      * @since 3.0
200      */

201     public boolean isEclipseRuntimeRequired() {
202         return eclipseRuntime;
203     }
204     
205     public void setEclipseRuntimeRequired(boolean eclipseRuntime) {
206         this.eclipseRuntime= eclipseRuntime;
207     }
208 }
209
Popular Tags