KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > feature > Feature


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  *******************************************************************************/

11 package org.eclipse.pde.internal.core.feature;
12
13 import java.io.PrintWriter JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Locale JavaDoc;
17 import java.util.Vector JavaDoc;
18
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.pde.core.IModelChangedEvent;
21 import org.eclipse.pde.core.plugin.IPluginBase;
22 import org.eclipse.pde.core.plugin.IPluginImport;
23 import org.eclipse.pde.core.plugin.IPluginModelBase;
24 import org.eclipse.pde.core.plugin.PluginRegistry;
25 import org.eclipse.pde.internal.core.ifeature.IFeature;
26 import org.eclipse.pde.internal.core.ifeature.IFeatureChild;
27 import org.eclipse.pde.internal.core.ifeature.IFeatureData;
28 import org.eclipse.pde.internal.core.ifeature.IFeatureImport;
29 import org.eclipse.pde.internal.core.ifeature.IFeatureInfo;
30 import org.eclipse.pde.internal.core.ifeature.IFeatureInstallHandler;
31 import org.eclipse.pde.internal.core.ifeature.IFeaturePlugin;
32 import org.eclipse.pde.internal.core.ifeature.IFeatureURL;
33 import org.eclipse.pde.internal.core.util.VersionUtil;
34 import org.w3c.dom.Node JavaDoc;
35 import org.w3c.dom.NodeList JavaDoc;
36
37 public class Feature extends VersionableObject implements IFeature {
38     private static final long serialVersionUID = 1L;
39     final static String JavaDoc INDENT = " "; //$NON-NLS-1$
40
private String JavaDoc fProviderName;
41     private IFeatureURL fUrl;
42     private IFeatureInfo[] fInfos = new IFeatureInfo[3];
43     private Vector JavaDoc fData = new Vector JavaDoc();
44     private Vector JavaDoc fChildren = new Vector JavaDoc();
45     private Vector JavaDoc fPlugins = new Vector JavaDoc();
46     private Vector JavaDoc fImports = new Vector JavaDoc();
47     private String JavaDoc fOs;
48     private String JavaDoc fWs;
49     private String JavaDoc fNl;
50     private String JavaDoc fArch;
51     private String JavaDoc fImageName;
52     private IFeatureInstallHandler fHandler;
53     private boolean fPrimary;
54     private boolean fExclusive;
55     private String JavaDoc fColocationAffinity;
56     private String JavaDoc fApplication;
57     private String JavaDoc fPlugin;
58     private boolean fValid;
59     private String JavaDoc fCopyright;
60
61     public void addPlugins(IFeaturePlugin[] newPlugins) throws CoreException {
62         ensureModelEditable();
63         for (int i = 0; i < newPlugins.length; i++) {
64             fPlugins.add(newPlugins[i]);
65             ((FeaturePlugin) newPlugins[i]).setInTheModel(true);
66         }
67         fireStructureChanged(newPlugins, IModelChangedEvent.INSERT);
68     }
69
70     public void addData(IFeatureData[] newData) throws CoreException {
71         ensureModelEditable();
72         for (int i = 0; i < newData.length; i++) {
73             fData.add(newData[i]);
74             ((FeatureData) newData[i]).setInTheModel(true);
75         }
76         fireStructureChanged(newData, IModelChangedEvent.INSERT);
77     }
78
79     public void addIncludedFeatures(IFeatureChild[] features)
80             throws CoreException {
81         ensureModelEditable();
82         for (int i = 0; i < features.length; i++) {
83             fChildren.add(features[i]);
84             ((FeatureChild) features[i]).setInTheModel(true);
85         }
86         fireStructureChanged(features, IModelChangedEvent.INSERT);
87     }
88
89     public void addImports(IFeatureImport[] iimports) throws CoreException {
90         ensureModelEditable();
91         for (int i = 0; i < iimports.length; i++) {
92             fImports.add(iimports[i]);
93             ((FeatureImport) iimports[i]).setInTheModel(true);
94         }
95         fireStructureChanged(iimports, IModelChangedEvent.INSERT);
96     }
97
98     public IFeaturePlugin[] getPlugins() {
99         IFeaturePlugin[] result = new IFeaturePlugin[fPlugins.size()];
100         fPlugins.copyInto(result);
101         return result;
102     }
103
104     public IFeatureData[] getData() {
105         IFeatureData[] result = new IFeatureData[fData.size()];
106         fData.copyInto(result);
107         return result;
108     }
109
110     public IFeatureChild[] getIncludedFeatures() {
111         IFeatureChild[] result = new IFeatureChild[fChildren.size()];
112         fChildren.copyInto(result);
113         return result;
114     }
115     public IFeatureImport[] getImports() {
116         IFeatureImport[] result = new IFeatureImport[fImports.size()];
117         fImports.copyInto(result);
118         return result;
119     }
120     public String JavaDoc getProviderName() {
121         return fProviderName;
122     }
123
124     public String JavaDoc getPlugin() {
125         return fPlugin;
126     }
127
128     public IPluginModelBase getReferencedModel(IFeaturePlugin reference) {
129         IPluginModelBase model = PluginRegistry.findModel(reference.getId());
130         return (model != null && model.isEnabled()) ? model : null;
131     }
132     public IFeatureURL getURL() {
133         return fUrl;
134     }
135     public IFeatureInstallHandler getInstallHandler() {
136         return fHandler;
137     }
138
139     public IFeatureInfo getFeatureInfo(int index) {
140         return fInfos[index];
141     }
142
143     public boolean isPrimary() {
144         return fPrimary;
145     }
146
147     public boolean isExclusive() {
148         return fExclusive;
149     }
150
151     protected void parse(Node JavaDoc node) {
152         super.parse(node);
153         fProviderName = getNodeAttribute(node, "provider-name"); //$NON-NLS-1$
154
fPlugin = getNodeAttribute(node, "plugin"); //$NON-NLS-1$
155
fOs = getNodeAttribute(node, "os"); //$NON-NLS-1$
156
fWs = getNodeAttribute(node, "ws"); //$NON-NLS-1$
157
fNl = getNodeAttribute(node, "nl"); //$NON-NLS-1$
158
fArch = getNodeAttribute(node, "arch"); //$NON-NLS-1$
159
fImageName = getNodeAttribute(node, "image"); //$NON-NLS-1$
160
fColocationAffinity = getNodeAttribute(node, "colocation-affinity"); //$NON-NLS-1$
161
fApplication = getNodeAttribute(node, "application"); //$NON-NLS-1$
162
fPrimary = getBooleanAttribute(node, "primary"); //$NON-NLS-1$
163
fExclusive = getBooleanAttribute(node, "exclusive"); //$NON-NLS-1$
164
NodeList JavaDoc children = node.getChildNodes();
165         fValid = true;
166
167         for (int i = 0; i < children.getLength(); i++) {
168             Node JavaDoc child = children.item(i);
169             if (child.getNodeType() == Node.ELEMENT_NODE) {
170                 String JavaDoc tag = child.getNodeName().toLowerCase(Locale.ENGLISH);
171                 if (tag.equals("description")) { //$NON-NLS-1$
172
IFeatureInfo info = getModel().getFactory().createInfo(
173                             IFeature.INFO_DESCRIPTION);
174                     ((FeatureInfo) info).setInTheModel(true);
175                     ((FeatureInfo) info).parse(child);
176                     fInfos[IFeature.INFO_DESCRIPTION] = info;
177                 } else if (tag.equals("license")) { //$NON-NLS-1$
178
IFeatureInfo info = getModel().getFactory().createInfo(
179                             IFeature.INFO_LICENSE);
180                     ((FeatureInfo) info).setInTheModel(true);
181                     ((FeatureInfo) info).parse(child);
182                     fInfos[IFeature.INFO_LICENSE] = info;
183                 } else if (tag.equals("copyright")) { //$NON-NLS-1$
184
IFeatureInfo info = getModel().getFactory().createInfo(
185                             IFeature.INFO_COPYRIGHT);
186                     ((FeatureInfo) info).setInTheModel(true);
187                     ((FeatureInfo) info).parse(child);
188                     fInfos[IFeature.INFO_COPYRIGHT] = info;
189                 } else if (tag.equals("url")) { //$NON-NLS-1$
190
if (fUrl == null) {
191                         fUrl = getModel().getFactory().createURL();
192                         ((FeatureURL) fUrl).setInTheModel(true);
193                         ((FeatureURL) fUrl).parse(child);
194                     }
195                 } else if (tag.equals("requires")) { //$NON-NLS-1$
196
parseRequires(child);
197                 } else if (tag.equals("install-handler")) { //$NON-NLS-1$
198
IFeatureInstallHandler handler = getModel().getFactory()
199                             .createInstallHandler();
200                     ((FeatureInstallHandler) handler).parse(child);
201                     ((FeatureInstallHandler) handler).setInTheModel(true);
202                     this.fHandler = handler;
203                 } else if (tag.equals("plugin")) { //$NON-NLS-1$
204
IFeaturePlugin plugin = getModel().getFactory()
205                             .createPlugin();
206                     ((FeaturePlugin) plugin).parse(child);
207                     ((FeaturePlugin) plugin).setInTheModel(true);
208                     fPlugins.add(plugin);
209                 } else if (tag.equals("data")) { //$NON-NLS-1$
210
IFeatureData newData = getModel().getFactory().createData();
211                     ((FeatureData) newData).parse(child);
212                     ((FeatureData) newData).setInTheModel(true);
213                     fData.add(newData);
214                 } else if (tag.equals("includes")) { //$NON-NLS-1$
215
IFeatureChild newChild = getModel().getFactory()
216                             .createChild();
217                     ((FeatureChild) newChild).parse(child);
218                     ((FeatureChild) newChild).setInTheModel(true);
219                     this.fChildren.add(newChild);
220                 }
221             }
222         }
223         fValid = hasRequiredAttributes();
224     }
225     private void parseRequires(Node JavaDoc node) {
226         NodeList JavaDoc children = node.getChildNodes();
227         for (int i = 0; i < children.getLength(); i++) {
228             Node JavaDoc child = children.item(i);
229             if (child.getNodeType() == Node.ELEMENT_NODE) {
230                 if (child.getNodeName().equalsIgnoreCase("import")) { //$NON-NLS-1$
231
IFeatureImport iimport = getModel().getFactory()
232                             .createImport();
233                     ((FeatureImport) iimport).parse(child);
234                     ((FeatureImport) iimport).setInTheModel(true);
235                     fImports.add(iimport);
236                 }
237             }
238         }
239     }
240
241     public void computeImports() throws CoreException {
242         // some existing imports may valid and can be preserved
243
Vector JavaDoc preservedImports = new Vector JavaDoc(fImports.size());
244         // new imports
245
ArrayList JavaDoc newImports = new ArrayList JavaDoc();
246         for (int i = 0; i < fPlugins.size(); i++) {
247             IFeaturePlugin fp = (IFeaturePlugin) fPlugins.get(i);
248             IPluginModelBase model = PluginRegistry.findModel(fp.getId());
249             if (model != null) {
250                 addPluginImports(preservedImports, newImports, model.getPluginBase());
251             }
252         }
253         // preserve imports of features
254
for (int i = 0; i < fImports.size(); i++) {
255             IFeatureImport iimport = (IFeatureImport) fImports.get(i);
256             if (iimport.getType() == IFeatureImport.FEATURE)
257                 preservedImports.add(iimport);
258         }
259         // removed = old - preserved
260
Vector JavaDoc removedImports = ((Vector JavaDoc) fImports.clone());
261         removedImports.removeAll(preservedImports);
262         // perform remove
263
fImports = preservedImports;
264         if (removedImports.size() > 0) {
265             fireStructureChanged((IFeatureImport[]) removedImports
266                     .toArray(new IFeatureImport[removedImports.size()]),
267                     IModelChangedEvent.REMOVE);
268         }
269         // perform add
270
if (newImports.size() > 0) {
271             fImports.addAll(newImports);
272             fireStructureChanged((IFeatureImport[]) newImports
273                     .toArray(new IFeatureImport[newImports.size()]),
274                     IModelChangedEvent.INSERT);
275         }
276     }
277
278     /**
279      * Creates IFeatureImports based on IPluginImports. Ensures no duplicates in
280      * preservedImports + newImports
281      *
282      * @param preservedImports
283      * out for valid existing imports
284      * @param newImports
285      * out for new imports
286      * @param plugin
287      * @throws CoreException
288      */

289     private void addPluginImports(List JavaDoc preservedImports, List JavaDoc newImports,
290             IPluginBase plugin) throws CoreException {
291         IPluginImport[] pluginImports = plugin.getImports();
292         for (int i = 0; i < pluginImports.length; i++) {
293             IPluginImport pluginImport = pluginImports[i];
294             if (pluginImport.isOptional()) {
295                 continue;
296             }
297             String JavaDoc id = pluginImport.getId();
298             String JavaDoc version = pluginImport.getVersion();
299             int match = pluginImport.getMatch();
300             if (findFeaturePlugin(id, version, match) != null) {
301                 // don't add imports to local plug-ins
302
continue;
303             }
304             if (findImport(preservedImports, id, version, match) != null) {
305                 // already seen
306
continue;
307             }
308             if (findImport(newImports, id, version, match) != null) {
309                 // already seen
310
continue;
311             }
312             IFeatureImport iimport = findImport(fImports, id, version, match);
313             if (iimport != null) {
314                 // import still valid
315
preservedImports.add(iimport);
316                 continue;
317             }
318             // a new one is needed
319
iimport = getModel().getFactory().createImport();
320             iimport.setId(id);
321             iimport.setVersion(version);
322             iimport.setMatch(match);
323             ((FeatureImport) iimport).setInTheModel(true);
324             newImports.add(iimport);
325         }
326     }
327
328     /**
329      * Finds a given import in the list
330      * @param imports list of imports
331      * @param id
332      * @param version
333      * @param match
334      * @return IFeatureImport or null
335      */

336     private IFeatureImport findImport(List JavaDoc imports, String JavaDoc id, String JavaDoc version, int match) {
337         for (int i = 0; i < imports.size(); i++) {
338             IFeatureImport iimport = (IFeatureImport) imports.get(i);
339             if (iimport.getId().equals(id)) {
340                 if (version == null)
341                     return iimport;
342                 if (version.equals(iimport.getVersion())
343                         && match == iimport.getMatch())
344                     return iimport;
345             }
346         }
347         return null;
348     }
349
350     private IFeaturePlugin findFeaturePlugin(String JavaDoc id, String JavaDoc version,
351             int match) {
352
353         for (int i = 0; i < fPlugins.size(); i++) {
354             IFeaturePlugin fp = (IFeaturePlugin) fPlugins.get(i);
355             String JavaDoc pid = fp.getId();
356             String JavaDoc pversion = fp.getVersion();
357             if (VersionUtil.compare(id, version, pid, pversion, match))
358                 return fp;
359         }
360         return null;
361     }
362
363     public void removePlugins(IFeaturePlugin[] removed) throws CoreException {
364         ensureModelEditable();
365         for (int i = 0; i < removed.length; i++) {
366             fPlugins.remove(removed[i]);
367             ((FeaturePlugin) removed[i]).setInTheModel(false);
368         }
369         fireStructureChanged(removed, IModelChangedEvent.REMOVE);
370     }
371
372     public void removeData(IFeatureData[] removed) throws CoreException {
373         ensureModelEditable();
374         for (int i = 0; i < removed.length; i++) {
375             fData.remove(removed[i]);
376             ((FeatureData) removed[i]).setInTheModel(false);
377         }
378         fireStructureChanged(removed, IModelChangedEvent.REMOVE);
379     }
380
381     public void removeIncludedFeatures(IFeatureChild[] features)
382             throws CoreException {
383         ensureModelEditable();
384         for (int i = 0; i < features.length; i++) {
385             fChildren.remove(features[i]);
386             ((FeatureChild) features[i]).setInTheModel(false);
387         }
388         fireStructureChanged(features, IModelChangedEvent.REMOVE);
389     }
390     public void removeImports(IFeatureImport[] iimports) throws CoreException {
391         ensureModelEditable();
392         for (int i = 0; i < iimports.length; i++) {
393             fImports.remove(iimports[i]);
394             ((FeatureImport) iimports[i]).setInTheModel(false);
395         }
396         fireStructureChanged(iimports, IModelChangedEvent.REMOVE);
397     }
398
399     public String JavaDoc getOS() {
400         return fOs;
401     }
402
403     public String JavaDoc getWS() {
404         return fWs;
405     }
406
407     public String JavaDoc getNL() {
408         return fNl;
409     }
410
411     public String JavaDoc getArch() {
412         return fArch;
413     }
414
415     public String JavaDoc getColocationAffinity() {
416         return fColocationAffinity;
417     }
418
419     public String JavaDoc getApplication() {
420         return fApplication;
421     }
422
423     public void setOS(String JavaDoc os) throws CoreException {
424         ensureModelEditable();
425         Object JavaDoc oldValue = this.fOs;
426         this.fOs = os;
427         firePropertyChanged(P_OS, oldValue, os);
428     }
429     public void setWS(String JavaDoc ws) throws CoreException {
430         ensureModelEditable();
431         Object JavaDoc oldValue = this.fWs;
432         this.fWs = ws;
433         firePropertyChanged(P_WS, oldValue, ws);
434     }
435     public void setNL(String JavaDoc nl) throws CoreException {
436         ensureModelEditable();
437         Object JavaDoc oldValue = this.fNl;
438         this.fNl = nl;
439         firePropertyChanged(P_NL, oldValue, nl);
440     }
441     public void setArch(String JavaDoc arch) throws CoreException {
442         ensureModelEditable();
443         Object JavaDoc oldValue = this.fArch;
444         this.fArch = arch;
445         firePropertyChanged(P_ARCH, oldValue, arch);
446     }
447
448     public void setPrimary(boolean newValue) throws CoreException {
449         if (this.fPrimary == newValue)
450             return;
451         ensureModelEditable();
452         Boolean JavaDoc oldValue = this.fPrimary ? Boolean.TRUE : Boolean.FALSE;
453         this.fPrimary = newValue;
454         firePropertyChanged(P_PRIMARY, oldValue, newValue
455                 ? Boolean.TRUE
456                 : Boolean.FALSE);
457     }
458
459     public void setExclusive(boolean newValue) throws CoreException {
460         if (this.fExclusive == newValue)
461             return;
462         ensureModelEditable();
463         Boolean JavaDoc oldValue = this.fExclusive ? Boolean.TRUE : Boolean.FALSE;
464         this.fExclusive = newValue;
465         firePropertyChanged(P_EXCLUSIVE, oldValue, newValue
466                 ? Boolean.TRUE
467                 : Boolean.FALSE);
468     }
469
470     public void setColocationAffinity(String JavaDoc newValue) throws CoreException {
471         ensureModelEditable();
472         Object JavaDoc oldValue = this.fColocationAffinity;
473         this.fColocationAffinity = newValue;
474         firePropertyChanged(P_COLLOCATION_AFFINITY, oldValue, newValue);
475     }
476
477     public void setApplication(String JavaDoc newValue) throws CoreException {
478         ensureModelEditable();
479         Object JavaDoc oldValue = this.fApplication;
480         this.fApplication = newValue;
481         firePropertyChanged(P_APPLICATION, oldValue, newValue);
482     }
483
484     public void setProviderName(String JavaDoc providerName) throws CoreException {
485         ensureModelEditable();
486         Object JavaDoc oldValue = this.fProviderName;
487         this.fProviderName = providerName;
488         firePropertyChanged(P_PROVIDER, oldValue, providerName);
489     }
490
491     public void setPlugin(String JavaDoc plugin) throws CoreException {
492         ensureModelEditable();
493         Object JavaDoc oldValue = this.fPlugin;
494         this.fPlugin = plugin;
495         firePropertyChanged(P_PLUGIN, oldValue, plugin);
496     }
497     public void setURL(IFeatureURL url) throws CoreException {
498         ensureModelEditable();
499         Object JavaDoc oldValue = this.fUrl;
500         if (this.fUrl != null) {
501             ((FeatureURL) this.fUrl).setInTheModel(false);
502         }
503         this.fUrl = url;
504         firePropertyChanged(P_URL, oldValue, url);
505     }
506     public void setInstallHandler(IFeatureInstallHandler handler)
507             throws CoreException {
508         ensureModelEditable();
509         Object JavaDoc oldValue = this.fHandler;
510         if (this.fHandler != null) {
511             ((FeatureInstallHandler) this.fHandler).setInTheModel(false);
512         }
513         this.fHandler = handler;
514         firePropertyChanged(P_INSTALL_HANDLER, oldValue, handler);
515     }
516
517     public void setFeatureInfo(IFeatureInfo info, int index)
518             throws CoreException {
519         ensureModelEditable();
520         Object JavaDoc oldValue = fInfos[index];
521         if (oldValue != null) {
522             ((FeatureInfo) oldValue).setInTheModel(true);
523         }
524         fInfos[index] = info;
525         String JavaDoc property;
526         switch (index) {
527             case INFO_DESCRIPTION :
528                 property = P_DESCRIPTION;
529                 break;
530             case INFO_LICENSE :
531                 property = P_LICENSE;
532                 break;
533             case INFO_COPYRIGHT :
534                 property = P_COPYRIGHT;
535                 break;
536             default :
537                 return;
538         }
539         firePropertyChanged(property, oldValue, info);
540     }
541
542     /**
543      * Sets the imageName.
544      *
545      * @param imageName
546      * The imageName to set
547      */

548     public void setImageName(String JavaDoc imageName) throws CoreException {
549         ensureModelEditable();
550         Object JavaDoc oldValue = this.fImageName;
551         this.fImageName = imageName;
552         firePropertyChanged(P_IMAGE, oldValue, imageName);
553     }
554
555     public void restoreProperty(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue)
556             throws CoreException {
557         if (name.equals(P_OS)) {
558             setOS((String JavaDoc) newValue);
559         } else if (name.equals(P_WS)) {
560             setWS((String JavaDoc) newValue);
561         } else if (name.equals(P_NL)) {
562             setNL((String JavaDoc) newValue);
563         } else if (name.equals(P_ARCH)) {
564             setArch((String JavaDoc) newValue);
565         } else if (name.equals(P_COLLOCATION_AFFINITY)) {
566             setColocationAffinity((String JavaDoc) newValue);
567         } else if (name.equals(P_APPLICATION)) {
568             setApplication((String JavaDoc) newValue);
569         } else if (name.equals(P_PRIMARY)) {
570             setPrimary(newValue != null
571                     ? ((Boolean JavaDoc) newValue).booleanValue()
572                     : false);
573         } else if (name.equals(P_EXCLUSIVE)) {
574             setExclusive(newValue != null
575                     ? ((Boolean JavaDoc) newValue).booleanValue()
576                     : false);
577         } else if (name.equals(P_PROVIDER)) {
578             setProviderName((String JavaDoc) newValue);
579         } else if (name.equals(P_PLUGIN)) {
580             setPlugin((String JavaDoc) newValue);
581         } else if (name.equals(P_URL)) {
582             setURL((IFeatureURL) newValue);
583         } else if (name.equals(P_INSTALL_HANDLER)) {
584             setInstallHandler((IFeatureInstallHandler) newValue);
585         } else if (name.equals(P_DESCRIPTION)) {
586             setFeatureInfo((IFeatureInfo) newValue, INFO_DESCRIPTION);
587         } else if (name.equals(P_LICENSE)) {
588             setFeatureInfo((IFeatureInfo) newValue, INFO_LICENSE);
589         } else if (name.equals(P_COPYRIGHT)) {
590             setFeatureInfo((IFeatureInfo) newValue, INFO_COPYRIGHT);
591         } else if (name.equals(P_IMAGE)) {
592             setImageName((String JavaDoc) newValue);
593         } else
594             super.restoreProperty(name, oldValue, newValue);
595     }
596
597     public void reset() {
598         super.reset();
599         fData.clear();
600         fPlugins.clear();
601         fImports.clear();
602         fChildren.clear();
603         fUrl = null;
604         fProviderName = null;
605         fPlugin = null;
606         fOs = null;
607         fWs = null;
608         fNl = null;
609         fArch = null;
610         fInfos[0] = null;
611         fInfos[1] = null;
612         fInfos[2] = null;
613         fPrimary = false;
614         fExclusive = false;
615         fColocationAffinity = null;
616         fApplication = null;
617         fValid = false;
618     }
619
620     public boolean isValid() {
621         return fValid;
622     }
623
624     private boolean hasRequiredAttributes() {
625         // Verify that all the required attributes are
626
// defined.
627
if (id == null)
628             return false;
629         if (version == null)
630             return false;
631
632         for (int i = 0; i < fChildren.size(); i++) {
633             IFeatureChild child = (IFeatureChild) fChildren.elementAt(i);
634             if (child.getId() == null || child.getVersion() == null)
635                 return false;
636         }
637         for (int i = 0; i < fPlugins.size(); i++) {
638             IFeaturePlugin plugin = (IFeaturePlugin) fPlugins.elementAt(i);
639             if (plugin.getId() == null || plugin.getVersion() == null)
640                 return false;
641
642         }
643         for (int i = 0; i < fData.size(); i++) {
644             IFeatureData entry = (IFeatureData) fData.elementAt(i);
645             if (entry.getId() == null)
646                 return false;
647         }
648         for (int i = 0; i < fImports.size(); i++) {
649             IFeatureImport iimport = (IFeatureImport) fImports.elementAt(i);
650             if (iimport.getId() == null)
651                 return false;
652         }
653         return true;
654     }
655
656     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
657         if (fCopyright != null) {
658             writer.println("<!--" + fCopyright + "-->"); //$NON-NLS-1$ //$NON-NLS-2$
659
}
660         writer.print(indent + "<feature"); //$NON-NLS-1$
661
String JavaDoc indent2 = indent + INDENT;
662         String JavaDoc indenta = indent + INDENT + INDENT;
663         writeIfDefined(indenta, writer, "id", getId()); //$NON-NLS-1$
664
writeIfDefined(indenta, writer, "label", getWritableString(getLabel())); //$NON-NLS-1$
665
writeIfDefined(indenta, writer, "version", getVersion()); //$NON-NLS-1$
666
writeIfDefined(indenta, writer, "provider-name", //$NON-NLS-1$
667
getWritableString(fProviderName));
668         writeIfDefined(indenta, writer, "plugin", //$NON-NLS-1$
669
getPlugin());
670         writeIfDefined(indenta, writer, "os", fOs); //$NON-NLS-1$
671
writeIfDefined(indenta, writer, "ws", fWs); //$NON-NLS-1$
672
writeIfDefined(indenta, writer, "nl", fNl); //$NON-NLS-1$
673
writeIfDefined(indenta, writer, "arch", fArch); //$NON-NLS-1$
674
if (fImageName != null)
675             writeIfDefined(indenta, writer,
676                     "image", getWritableString(fImageName)); //$NON-NLS-1$
677
if (isPrimary()) {
678             writer.println();
679             writer.print(indenta + "primary=\"true\""); //$NON-NLS-1$
680
}
681         if (isExclusive()) {
682             writer.println();
683             writer.print(indenta + "exclusive=\"true\""); //$NON-NLS-1$
684
}
685         writeIfDefined(indenta, writer,
686                 "colocation-affinity", fColocationAffinity); //$NON-NLS-1$
687
writeIfDefined(indenta, writer, "application", fApplication); //$NON-NLS-1$
688

689         writer.println(">"); //$NON-NLS-1$
690
if (fHandler != null) {
691             fHandler.write(indent2, writer);
692         }
693
694         for (int i = 0; i < 3; i++) {
695             IFeatureInfo info = fInfos[i];
696             if (info != null && !info.isEmpty())
697                 info.write(indent2, writer);
698         }
699
700         if (fUrl != null) {
701             fUrl.write(indent2, writer);
702         }
703         for (int i = 0; i < fChildren.size(); i++) {
704             IFeatureChild child = (IFeatureChild) fChildren.elementAt(i);
705             writer.println();
706             child.write(indent2, writer);
707         }
708         if (fImports.size() > 0) {
709             writer.println();
710             writer.println(indent2 + "<requires>"); //$NON-NLS-1$
711
for (int i = 0; i < fImports.size(); i++) {
712                 IFeatureImport iimport = (IFeatureImport) fImports.get(i);
713                 iimport.write(indenta, writer);
714             }
715             writer.println(indent2 + "</requires>"); //$NON-NLS-1$
716
}
717         for (int i = 0; i < fPlugins.size(); i++) {
718             IFeaturePlugin plugin = (IFeaturePlugin) fPlugins.elementAt(i);
719             writer.println();
720             plugin.write(indent2, writer);
721         }
722         for (int i = 0; i < fData.size(); i++) {
723             IFeatureData entry = (IFeatureData) fData.elementAt(i);
724             writer.println();
725             entry.write(indent2, writer);
726         }
727         writer.println();
728         writer.println(indent + "</feature>"); //$NON-NLS-1$
729
}
730     private void writeIfDefined(String JavaDoc indent, PrintWriter JavaDoc writer,
731             String JavaDoc attName, String JavaDoc attValue) {
732         if (attValue == null || attValue.trim().length() == 0)
733             return;
734         writer.println();
735         writer.print(indent + attName + "=\"" + attValue + "\""); //$NON-NLS-1$ //$NON-NLS-2$
736
}
737     /**
738      * Gets the imageName.
739      *
740      * @return Returns a String
741      */

742     public String JavaDoc getImageName() {
743         return fImageName;
744     }
745     
746     
747     public String JavaDoc getCopyright() {
748         return fCopyright;
749     }
750     
751     public void setCopyright(String JavaDoc copyright) {
752         fCopyright = copyright;
753     }
754 }
755
Popular Tags