Source code: javax/ide/extension/spi/DefaultExtension.java
1 package javax.ide.extension.spi;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5
6 import javax.ide.Identifiable;
7 import javax.ide.extension.Extension;
8 import javax.ide.extension.ExtensionDependency;
9 import javax.ide.extension.PlatformInfo;
10 import javax.ide.net.URIPath;
11 import javax.ide.util.Version;
12
13 /**
14 * This class maintains general information about an extension. Information
15 * gathered from the extension manifest is stored in this class.
16 * Such information include the extension's id, owner, version information,
17 * etc..
18 * <p>
19 * IDE providers can use this class to to record the extension information
20 * section of the extension manifest.
21 */
22
23 public final class DefaultExtension implements Extension, Identifiable, Comparable
24 {
25 private String _id;
26 private String _name;
27 private Version _version;
28 private Version _edkVersion;
29 private String _owner;
30 private Collection _dependencies = new ArrayList();
31 private URIPath _classpath;
32 private PlatformInfo _platformInfo;
33 private ExtensionSource _source;
34
35 //---------------------------------------------------------------------------
36 // Public methods.
37 //---------------------------------------------------------------------------
38
39 /**
40 * Default constructor.
41 */
42 public DefaultExtension()
43 {
44 }
45
46 public DefaultExtension( String id )
47 {
48 _id = id;
49 }
50
51 public void setSource( ExtensionSource source )
52 {
53 _source = source;
54 }
55
56 public ExtensionSource getSource()
57 {
58 return _source;
59 }
60
61 public String getID()
62 {
63 return _id;
64 }
65
66 /*-
67 * Extension method.
68 */
69 public String getName()
70 {
71 return _name;
72 }
73
74 /*-
75 * Extension method.
76 */
77 public String getOwner()
78 {
79 return _owner;
80 }
81
82 /*-
83 * Extension method.
84 */
85 public Version getVersion()
86 {
87 return _version;
88 }
89
90 /*-
91 * Extension method.
92 */
93 public Version getEDKVersion()
94 {
95 return _edkVersion;
96 }
97
98 /*-
99 * Extension interface method.
100 */
101 public PlatformInfo getPlatformInfo()
102 {
103 return _platformInfo;
104 }
105
106 /*-
107 * Extension method.
108 */
109 public Collection getDependencies()
110 {
111 return _dependencies;
112 }
113
114 /*-
115 * Extension method.
116 */
117 public URIPath getClassPath()
118 {
119 return _classpath;
120 }
121
122 //---------------------------------------------------------------------------
123 // Methods used by IDE providers to set property values defined in the
124 // extension manifest.
125 //---------------------------------------------------------------------------
126
127 /**
128 * Set the name of this extension. The name should not include
129 * the extension version label.
130 *
131 * @param name short name for this extension.
132 */
133 public void setName( String name )
134 {
135 _name = name;
136 }
137
138 /**
139 * Set the extension owner name.
140 *
141 * @param owner label identifying the extension writer.
142 */
143 public void setOwner( String owner )
144 {
145 _owner = owner;
146 }
147
148 /**
149 * Set the extension version information.
150 *
151 * @param version the extension version specification.
152 */
153 public void setVersion( Version version )
154 {
155 _version = version;
156 }
157
158 /**
159 * Set the EDK version.
160 *
161 * @param edkVersion The version of the EDK used to implement this extension.
162 */
163 public void setEDKVersion( Version edkVersion )
164 {
165 _edkVersion = edkVersion;
166 }
167
168 /**
169 * Set the platform specific info required for this extension to work.
170 *
171 * @param info The {@link PlatformInfo}.
172 */
173 public void setPlatformInfo( PlatformInfo info )
174 {
175 _platformInfo = info;
176 }
177
178 /**
179 * Set a list of {@link Extension} identifiers this extension depends on.
180 *
181 * @param dependency Dependencies list.
182 */
183 public void addDependency( ExtensionDependency dependency )
184 {
185 _dependencies.add( dependency );
186 }
187
188 /**
189 * Set an additional classpath where classes used by this extension
190 * can be found.
191 *
192 * @param classpath Classpath where classes used by this extension are
193 * found.
194 */
195 public void setClassPath( URIPath classpath )
196 {
197 _classpath = classpath;
198 }
199
200 public String toString()
201 {
202 return getID() + " " + String.valueOf( getVersion() );
203 }
204
205 /**
206 * Compare two extensions on their names.
207 *
208 * @param o the extension to compare.
209 * @return the value 0 if the argument string is equal to this string;
210 * a value less than 0 if this string is lexicographically less than the
211 * string argument; and a value greater than 0 if this string is
212 * lexicographically greater than the string argument
213 */
214 public int compareTo(Object o)
215 {
216 if ( o instanceof Extension )
217 {
218 return getName().compareTo( ((Extension)o).getName() );
219 }
220 return -1;
221 }
222 }