KickJava   Java API By Example, From Geeks To Geeks.

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


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.pde.internal.core.feature;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.pde.internal.core.PDECore;
17 import org.eclipse.pde.internal.core.ifeature.IFeature;
18 import org.eclipse.pde.internal.core.ifeature.IFeatureChild;
19 import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
20 import org.w3c.dom.Node JavaDoc;
21
22 public class FeatureChild extends IdentifiableObject implements IFeatureChild {
23     private static final long serialVersionUID = 1L;
24     private String JavaDoc fVersion;
25     private String JavaDoc fName;
26     private boolean fOptional;
27     private int fSearchLocation = ROOT;
28     private int fMatch = NONE;
29     private String JavaDoc fOs;
30     private String JavaDoc fWs;
31     private String JavaDoc fArch;
32     private String JavaDoc fNl;
33
34     protected void reset() {
35         super.reset();
36         fVersion = null;
37         fOptional = false;
38         fName = null;
39         fSearchLocation = ROOT;
40         fMatch = NONE;
41         fOs = null;
42         fWs = null;
43         fArch = null;
44         fNl = null;
45     }
46     protected void parse(Node JavaDoc node) {
47         super.parse(node);
48         fVersion = getNodeAttribute(node, "version"); //$NON-NLS-1$
49
fName = getNodeAttribute(node, "name"); //$NON-NLS-1$
50
fOptional = getBooleanAttribute(node, "optional"); //$NON-NLS-1$
51
fOs = getNodeAttribute(node, "os"); //$NON-NLS-1$
52
fWs = getNodeAttribute(node, "ws"); //$NON-NLS-1$
53
fArch = getNodeAttribute(node, "arch"); //$NON-NLS-1$
54
fNl = getNodeAttribute(node, "nl"); //$NON-NLS-1$
55
String JavaDoc matchName = getNodeAttribute(node, "match"); //$NON-NLS-1$
56
if (matchName != null) {
57             for (int i = 0; i < RULE_NAME_TABLE.length; i++) {
58                 if (matchName.equals(RULE_NAME_TABLE[i])) {
59                     fMatch = i;
60                     break;
61                 }
62             }
63         }
64         String JavaDoc searchLocationName = getNodeAttribute(node, "search_location"); //$NON-NLS-1$
65
if (searchLocationName == null)
66             searchLocationName = getNodeAttribute(node, "search-location"); //$NON-NLS-1$
67
if (searchLocationName != null) {
68             if (searchLocationName.equals("root")) //$NON-NLS-1$
69
fSearchLocation = ROOT;
70             else if (searchLocationName.equals("self")) //$NON-NLS-1$
71
fSearchLocation = SELF;
72             else if (searchLocationName.equals("both")) //$NON-NLS-1$
73
fSearchLocation = BOTH;
74         }
75         //hookWithWorkspace();
76
}
77
78     public void loadFrom(IFeature feature) {
79         id = feature.getId();
80         fVersion = feature.getVersion();
81         fOptional = false;
82         fName = null;
83     }
84     /**
85      * @see IFeatureChild#getVersion()
86      */

87     public String JavaDoc getVersion() {
88         return fVersion;
89     }
90
91     public boolean isOptional() {
92         return fOptional;
93     }
94
95     public String JavaDoc getName() {
96         return fName;
97     }
98
99     public int getSearchLocation() {
100         return fSearchLocation;
101     }
102
103     public int getMatch() {
104         return fMatch;
105     }
106     
107     public String JavaDoc getOS() {
108         return fOs;
109     }
110     
111     public String JavaDoc getWS() {
112         return fWs;
113     }
114     
115     public String JavaDoc getArch() {
116         return fArch;
117     }
118
119     public String JavaDoc getNL() {
120         return fNl;
121     }
122
123     public IFeature getReferencedFeature() {
124         IFeatureModel workspaceModel = PDECore.getDefault()
125                 .getFeatureModelManager().findFeatureModel(getId(), fVersion);
126         if (workspaceModel != null) {
127             return workspaceModel.getFeature();
128         }
129         return null;
130     }
131
132     /**
133      * @see IFeatureChild#setVersion(String)
134      */

135     public void setVersion(String JavaDoc version) throws CoreException {
136         ensureModelEditable();
137         Object JavaDoc oldValue = this.fVersion;
138         this.fVersion = version;
139         firePropertyChanged(P_VERSION, oldValue, version);
140     }
141
142     public void setName(String JavaDoc name) throws CoreException {
143         ensureModelEditable();
144         Object JavaDoc oldValue = this.fName;
145         this.fName = name;
146         firePropertyChanged(P_NAME, oldValue, name);
147     }
148
149     public void setMatch(int match) throws CoreException {
150         ensureModelEditable();
151         Integer JavaDoc oldValue = new Integer JavaDoc(this.fMatch);
152         this.fMatch = match;
153         firePropertyChanged(P_MATCH, oldValue, new Integer JavaDoc(match));
154     }
155
156     public void setSearchLocation(int searchLocation) throws CoreException {
157         ensureModelEditable();
158         Integer JavaDoc oldValue = new Integer JavaDoc(this.fSearchLocation);
159         this.fSearchLocation = searchLocation;
160         firePropertyChanged(
161             P_SEARCH_LOCATION,
162             oldValue,
163             new Integer JavaDoc(searchLocation));
164     }
165
166     public void setOptional(boolean optional) throws CoreException {
167         ensureModelEditable();
168         Object JavaDoc oldValue = new Boolean JavaDoc(this.fOptional);
169         this.fOptional = optional;
170         firePropertyChanged(P_NAME, oldValue, new Boolean JavaDoc(optional));
171     }
172     
173     public void setOS(String JavaDoc os) throws CoreException {
174         ensureModelEditable();
175         Object JavaDoc oldValue = this.fOs;
176         this.fOs = os;
177         firePropertyChanged(P_OS, oldValue, os);
178     }
179     
180     public void setWS(String JavaDoc ws) throws CoreException {
181         ensureModelEditable();
182         Object JavaDoc oldValue = this.fWs;
183         this.fWs = ws;
184         firePropertyChanged(P_WS, oldValue, ws);
185     }
186     
187     public void setArch(String JavaDoc arch) throws CoreException {
188         ensureModelEditable();
189         Object JavaDoc oldValue = this.fArch;
190         this.fArch = arch;
191         firePropertyChanged(P_ARCH, oldValue, arch);
192     }
193
194     public void setNL(String JavaDoc nl) throws CoreException {
195         ensureModelEditable();
196         Object JavaDoc oldValue = this.fNl;
197         this.fNl = nl;
198         firePropertyChanged(P_NL, oldValue, nl);
199     }
200
201     public void restoreProperty(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue)
202         throws CoreException {
203         if (name.equals(P_VERSION)) {
204             setVersion((String JavaDoc) newValue);
205         } else if (name.equals(P_OPTIONAL)) {
206             setOptional(((Boolean JavaDoc) newValue).booleanValue());
207         } else if (name.equals(P_NAME)) {
208             setName((String JavaDoc) newValue);
209         } else if (name.equals(P_MATCH)) {
210             setMatch(newValue != null ? ((Integer JavaDoc) newValue).intValue() : NONE);
211         } else if (name.equals(P_OS)) {
212             setOS((String JavaDoc)newValue);
213         } else if (name.equals(P_WS)) {
214             setWS((String JavaDoc)newValue);
215         } else if (name.equals(P_ARCH)) {
216             setArch((String JavaDoc)newValue);
217         } else if (name.equals(P_NL)) {
218             setNL((String JavaDoc)newValue);
219         } else if (name.equals(P_SEARCH_LOCATION)) {
220             setSearchLocation(
221                 newValue != null ? ((Integer JavaDoc) newValue).intValue() : ROOT);
222         } else
223             super.restoreProperty(name, oldValue, newValue);
224     }
225
226     public void setId(String JavaDoc id) throws CoreException {
227         super.setId(id);
228     }
229
230     /**
231      * @see IWritable#write(String, PrintWriter)
232      */

233     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
234         writer.print(indent + "<includes"); //$NON-NLS-1$
235
String JavaDoc indent2 = indent + Feature.INDENT + Feature.INDENT;
236         if (getId() != null) {
237             writer.println();
238             writer.print(indent2 + "id=\"" + getId() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
239
}
240         if (getVersion() != null) {
241             writer.println();
242             writer.print(indent2 + "version=\"" + getVersion() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
243
}
244         if (getName() != null) {
245             writer.println();
246             writer.print(indent2 + "name=\"" + getName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
247
}
248         if (isOptional()) {
249             writer.println();
250             writer.print(indent2 + "optional=\"true\""); //$NON-NLS-1$
251
}
252         if (fMatch!=NONE) {
253             writer.println();
254             writer.print(indent2 + "match=\""+RULE_NAME_TABLE[fMatch]+"\""); //$NON-NLS-1$ //$NON-NLS-2$
255
}
256         if (getOS() != null) {
257             writer.println();
258             writer.print(indent2 + "os=\""+getOS() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
259
}
260         if (getWS() != null) {
261             writer.println();
262             writer.print(indent2 + "ws=\""+getWS() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
263
}
264         if (getArch() != null) {
265             writer.println();
266             writer.print(indent2 + "arch=\""+getArch() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
267
}
268         if (getNL() != null) {
269             writer.println();
270             writer.print(indent2 + "nl=\""+getNL() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
271
}
272         if (fSearchLocation!=ROOT) {
273             writer.println();
274             String JavaDoc value=fSearchLocation==SELF?"self":"both"; //$NON-NLS-1$ //$NON-NLS-2$
275
writer.print(indent2 + "search-location=\""+value+"\""); //$NON-NLS-1$ //$NON-NLS-2$
276
}
277         writer.println("/>"); //$NON-NLS-1$
278
}
279 }
280
Popular Tags