KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > core > model > FeatureReferenceModel


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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  * James D Miles (IBM Corp.) - bug 191783, NullPointerException in FeatureDownloader
11  *******************************************************************************/

12 package org.eclipse.update.core.model;
13
14 import java.net.MalformedURLException JavaDoc;
15 import java.net.URL JavaDoc;
16
17 import org.eclipse.update.core.Site;
18 import org.eclipse.update.internal.core.UpdateCore;
19 import org.eclipse.update.internal.core.UpdateManagerUtils;
20
21 /**
22  * Feature reference model object.
23  * <p>
24  * This class may be instantiated or subclassed by clients. However, in most
25  * cases clients should instead instantiate or subclass the provided
26  * concrete implementation of this model.
27  * </p>
28  * <p>
29  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
30  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
31  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
32  * (repeatedly) as the API evolves.
33  * </p>
34  * @see org.eclipse.update.core.FeatureReference
35  * @since 2.0
36  */

37 public class FeatureReferenceModel extends ModelObject {
38
39     private String JavaDoc type;
40     private URL JavaDoc url;
41     private String JavaDoc urlString;
42     private String JavaDoc featureId;
43     private String JavaDoc featureVersion;
44     private SiteModel site;
45     private String JavaDoc label;
46     private String JavaDoc localizedLabel;
47
48     // performance
49
private URL JavaDoc bundleURL;
50     private URL JavaDoc base;
51     private boolean resolved = false;
52     private String JavaDoc os;
53     private String JavaDoc ws;
54     private String JavaDoc nl;
55     private String JavaDoc arch;
56     private String JavaDoc patch;
57
58     /**
59      * Creates an uninitialized feature reference model object.
60      *
61      * @since 2.0
62      */

63     public FeatureReferenceModel() {
64         super();
65     }
66
67     /**
68      * Constructor FeatureReferenceModel.
69      * @param ref
70      */

71     public FeatureReferenceModel(FeatureReferenceModel ref) {
72         setFeatureIdentifier(ref.getFeatureIdentifier());
73         setFeatureVersion(ref.getFeatureVersion());
74         setType(ref.getType());
75         setSiteModel(ref.getSiteModel());
76         setLabel(ref.getLabel());
77         setWS(ref.getWS());
78         setOS(ref.getOS());
79         setArch(ref.getOSArch());
80         setNL(ref.getNL());
81     }
82
83     /**
84      * Compares 2 feature reference models for equality
85      *
86      * @param object feature reference model to compare with
87      * @return <code>true</code> if the two models are equal,
88      * <code>false</code> otherwise
89      * @since 2.0
90      */

91     public boolean equals(Object JavaDoc object) {
92
93         if (object == null)
94             return false;
95         if (getURL() == null)
96             return false;
97
98         if (!(object instanceof FeatureReferenceModel))
99             return false;
100
101         FeatureReferenceModel f = (FeatureReferenceModel) object;
102
103         return UpdateManagerUtils.sameURL(getURL(), f.getURL());
104     }
105
106     /**
107      * Returns the referenced feature type.
108      *
109      * @return feature type, or <code>null</code> representing the default
110      * feature type for the site
111      * @since 2.0
112      */

113     public String JavaDoc getType() {
114         return type;
115     }
116
117     /**
118      * Returns the site model for the reference.
119      *
120      * @return site model
121      * @since 2.0
122      */

123     public SiteModel getSiteModel() {
124         return site;
125     }
126
127     /**
128      * Returns the unresolved URL string for the reference.
129      *
130      * @return url string
131      * @since 2.0
132      */

133     public String JavaDoc getURLString() {
134         return urlString;
135     }
136
137     /**
138      * Returns the resolved URL for the feature reference.
139      *
140      * @return url string
141      * @since 2.0
142      */

143     public URL JavaDoc getURL() {
144         delayedResolve();
145         return url;
146     }
147
148     /**
149      * Returns the feature identifier as a string
150      *
151      * @see org.eclipse.update.core.IFeatureReference#getVersionedIdentifier()
152      * @return feature identifier
153      * @since 2.0
154      */

155     public String JavaDoc getFeatureIdentifier() {
156         return featureId;
157     }
158
159     /**
160      * Returns the feature version as a string
161      *
162      * @see org.eclipse.update.core.IFeatureReference#getVersionedIdentifier()
163      * @return feature version
164      * @since 2.0
165      */

166     public String JavaDoc getFeatureVersion() {
167         return featureVersion;
168     }
169
170     /**
171      * Sets the referenced feature type.
172      * Throws a runtime exception if this object is marked read-only.
173      *
174      * @param type referenced feature type
175      * @since 2.0
176      */

177     public void setType(String JavaDoc type) {
178         assertIsWriteable();
179         this.type = type;
180     }
181
182     /**
183      * Sets the site for the referenced.
184      * Throws a runtime exception if this object is marked read-only.
185      *
186      * @param site site for the reference
187      * @since 2.0
188      */

189     public void setSiteModel(SiteModel site) {
190         assertIsWriteable();
191         this.site = site;
192     }
193
194     /**
195      * Sets the unresolved URL for the feature reference.
196      * Throws a runtime exception if this object is marked read-only.
197      *
198      * @param urlString unresolved URL string
199      * @since 2.0
200      */

201     public void setURLString(String JavaDoc urlString) {
202         assertIsWriteable();
203         this.urlString = urlString;
204         this.url = null;
205     }
206
207     /**
208      * Sets the feature identifier.
209      * Throws a runtime exception if this object is marked read-only.
210      *
211      * @param featureId feature identifier
212      * @since 2.0
213      */

214     public void setFeatureIdentifier(String JavaDoc featureId) {
215         assertIsWriteable();
216         this.featureId = featureId;
217     }
218
219     /**
220      * Sets the feature version.
221      * Throws a runtime exception if this object is marked read-only.
222      *
223      * @param featureVersion feature version
224      * @since 2.0
225      */

226     public void setFeatureVersion(String JavaDoc featureVersion) {
227         assertIsWriteable();
228         this.featureVersion = featureVersion;
229     }
230
231     /**
232      * Resolve the model object.
233      * Any URL strings in the model are resolved relative to the
234      * base URL argument. Any translatable strings in the model that are
235      * specified as translation keys are localized using the supplied
236      * resource bundle.
237      *
238      * @param base URL
239      * @param bundleURL resource bundle URL
240      * @exception MalformedURLException
241      * @since 2.0
242      */

243     public void resolve(URL JavaDoc base,URL JavaDoc bundleURL) throws MalformedURLException JavaDoc {
244         this.base = base;
245         this.bundleURL = bundleURL;
246     }
247
248     private void delayedResolve() {
249
250         // PERF: delay resolution
251
if (resolved)
252             return;
253
254         // resolve local elements
255
localizedLabel = resolveNLString(bundleURL, label);
256         try {
257             url = resolveURL(base, bundleURL, urlString);
258             resolved = true;
259         } catch (MalformedURLException JavaDoc e){
260             UpdateCore.warn("",e); //$NON-NLS-1$
261
}
262     }
263
264     /**
265      * @see Object#toString()
266      */

267     public String JavaDoc toString() {
268         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
269         buffer.append(getClass().toString() + " :"); //$NON-NLS-1$
270
buffer.append(" at "); //$NON-NLS-1$
271
if (url != null)
272             buffer.append(url.toExternalForm());
273         return buffer.toString();
274     }
275
276     /**
277      * @see org.eclipse.update.core.model.ModelObject#getPropertyName()
278      */

279     protected String JavaDoc getPropertyName() {
280         return Site.SITE_FILE;
281     }
282     
283     /**
284      * Retrieve the displayable label for the feature reference. If the model
285      * object has been resolved, the label is localized.
286      *
287      * @return displayable label, or <code>null</code>.
288      * @since 2.0
289      */

290     public String JavaDoc getLabel() {
291         delayedResolve();
292         if (localizedLabel != null)
293             return localizedLabel;
294         else
295             return label;
296     }
297
298     /**
299      * Retrieve the non-localized displayable label for the feature reference.
300      *
301      * @return non-localized displayable label, or <code>null</code>.
302      * @since 2.0
303      */

304     public String JavaDoc getLabelNonLocalized() {
305         return label;
306     }
307
308     /**
309      * Sets the label.
310      * @param label The label to set
311      */

312     public void setLabel(String JavaDoc label) {
313         this.label = label;
314     }
315
316     /**
317      * Get optional operating system specification as a comma-separated string.
318      *
319      * @return the operating system specification string, or <code>null</code>.
320      * @since 2.1
321      */

322     public String JavaDoc getOS() {
323         return os;
324     }
325
326
327     /**
328      * Get optional windowing system specification as a comma-separated string.
329      *
330      * @return the windowing system specification string, or <code>null</code>.
331      * @since 2.1
332      */

333     public String JavaDoc getWS() {
334         return ws;
335     }
336
337
338     /**
339      * Get optional system architecture specification as a comma-separated string.
340      *
341      * @return the system architecture specification string, or <code>null</code>.
342      * @since 2.1
343      */

344     public String JavaDoc getOSArch() {
345         return arch;
346     }
347
348
349     /**
350      * Get optional locale specification as a comma-separated string.
351      *
352      * @return the locale specification string, or <code>null</code>.
353      * @since 2.1
354      */

355     public String JavaDoc getNL() {
356         return nl;
357     }
358
359     /**
360      * Sets the operating system specification.
361      * Throws a runtime exception if this object is marked read-only.
362      *
363      * @param os operating system specification as a comma-separated list
364      * @since 2.1
365      */

366     public void setOS(String JavaDoc os) {
367         assertIsWriteable();
368         this.os = os;
369     }
370
371
372     /**
373      * Sets the windowing system specification.
374      * Throws a runtime exception if this object is marked read-only.
375      *
376      * @param ws windowing system specification as a comma-separated list
377      * @since 2.1
378      */

379     public void setWS(String JavaDoc ws) {
380         assertIsWriteable();
381         this.ws = ws;
382     }
383
384
385     /**
386      * Sets the locale specification.
387      * Throws a runtime exception if this object is marked read-only.
388      *
389      * @param nl locale specification as a comma-separated list
390      * @since 2.1
391      */

392     public void setNL(String JavaDoc nl) {
393         assertIsWriteable();
394         this.nl = nl;
395     }
396
397
398     /**
399      * Sets the system architecture specification.
400      * Throws a runtime exception if this object is marked read-only.
401      *
402      * @param arch system architecture specification as a comma-separated list
403      * @since 2.1
404      */

405     public void setArch(String JavaDoc arch) {
406         assertIsWriteable();
407         this.arch = arch;
408     }
409
410     /**
411      * Returns the patch mode.
412      */

413     public String JavaDoc getPatch() {
414         return patch;
415     }
416
417
418     /**
419      * Sets the patch mode.
420      */

421     public void setPatch(String JavaDoc patch) {
422         this.patch = patch;
423     }
424
425 }
426
Popular Tags