KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > site > SiteBuildFeature


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.site;
12
13 import java.io.*;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.pde.internal.core.*;
17 import org.eclipse.pde.internal.core.ifeature.*;
18 import org.eclipse.pde.internal.core.isite.*;
19 import org.w3c.dom.*;
20
21 /**
22  * @author dejan
23  *
24  * To change this generated comment edit the template variable "typecomment":
25  * Window>Preferences>Java>Templates.
26  * To enable and disable the creation of type comments go to
27  * Window>Preferences>Java>Code Generation.
28  */

29 public class SiteBuildFeature
30     extends SiteBuildObject
31     implements ISiteBuildFeature {
32     private String JavaDoc id;
33     private String JavaDoc version;
34     private IFeature feature;
35
36     /**
37      * @see org.eclipse.pde.internal.core.isite.ISiteFeature#getType()
38      */

39     public String JavaDoc getId() {
40         return id;
41     }
42
43     /**
44      * @see org.eclipse.pde.internal.core.isite.ISiteFeature#getURL()
45      */

46     public String JavaDoc getVersion() {
47         return version;
48     }
49
50     /**
51      * @see org.eclipse.pde.internal.core.isite.ISiteFeature#setType(java.lang.String)
52      */

53     public void setId(String JavaDoc id) throws CoreException {
54         ensureModelEditable();
55         Object JavaDoc oldValue = this.id;
56         this.id = id;
57         firePropertyChanged(P_ID, oldValue, id);
58     }
59
60     public void setVersion(String JavaDoc version) throws CoreException {
61         ensureModelEditable();
62         Object JavaDoc oldValue = this.version;
63         this.version = version;
64         firePropertyChanged(P_VERSION, oldValue, version);
65     }
66
67     protected void parse(Node node) {
68         id = getNodeAttribute(node, "id"); //$NON-NLS-1$
69
version = getNodeAttribute(node, "version"); //$NON-NLS-1$
70
}
71
72     public IFeature getReferencedFeature() {
73         if (feature == null) {
74             WorkspaceModelManager manager =
75                 PDECore.getDefault().getWorkspaceModelManager();
76             IFeatureModel[] models = manager.getFeatureModels();
77             for (int i = 0; i < models.length; i++) {
78                 IFeatureModel model = models[i];
79                 IFeature feature = model.getFeature();
80                 if (feature.getId().equals(id)
81                     && feature.getVersion().equals(version)) {
82                     this.feature = feature;
83                     break;
84                 }
85             }
86             // look it up
87
}
88         return feature;
89     }
90
91     public void setReferencedFeature(IFeature feature) {
92         this.feature = feature;
93         if (feature != null) {
94             id = feature.getId();
95             version = feature.getVersion();
96         }
97     }
98
99     protected void reset() {
100         id = null;
101         version = null;
102         feature = null;
103     }
104
105     public void restoreProperty(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue)
106         throws CoreException {
107         if (name.equals(P_ID)) {
108             setId(newValue != null ? newValue.toString() : null);
109         } else if (name.equals(P_VERSION)) {
110             setVersion(newValue != null ? newValue.toString() : null);
111         } else
112             super.restoreProperty(name, oldValue, newValue);
113     }
114
115     /**
116      * @see org.eclipse.pde.core.IWritable#write(java.lang.String, java.io.PrintWriter)
117      */

118     public void write(String JavaDoc indent, PrintWriter writer) {
119         writer.print(indent);
120         writer.print("<feature"); //$NON-NLS-1$
121
if (id != null)
122             writer.print(" id=\"" + id + "\""); //$NON-NLS-1$ //$NON-NLS-2$
123
if (version != null)
124             writer.print(" version=\"" + version + "\""); //$NON-NLS-1$ //$NON-NLS-2$
125
writer.println("/>"); //$NON-NLS-1$
126
}
127     
128     public String JavaDoc getTargetURL() {
129         ISiteBuild siteBuild = getSiteBuild();
130         IPath featureLocation = siteBuild.getFeatureLocation();
131         String JavaDoc jar = id + "_"+version+".jar"; //$NON-NLS-1$ //$NON-NLS-2$
132
return featureLocation.append(jar).toString();
133     }
134 }
135
Popular Tags