001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.feature;
011:
012: import java.io.PrintWriter;
013:
014: import org.eclipse.core.runtime.CoreException;
015: import org.eclipse.pde.internal.core.PDECore;
016: import org.eclipse.pde.internal.core.ifeature.IFeature;
017: import org.eclipse.pde.internal.core.ifeature.IFeatureChild;
018: import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
019: import org.w3c.dom.Node;
020:
021: public class FeatureChild extends IdentifiableObject implements
022: IFeatureChild {
023: private static final long serialVersionUID = 1L;
024: private String fVersion;
025: private String fName;
026: private boolean fOptional;
027: private int fSearchLocation = ROOT;
028: private int fMatch = NONE;
029: private String fOs;
030: private String fWs;
031: private String fArch;
032: private String fNl;
033:
034: protected void reset() {
035: super .reset();
036: fVersion = null;
037: fOptional = false;
038: fName = null;
039: fSearchLocation = ROOT;
040: fMatch = NONE;
041: fOs = null;
042: fWs = null;
043: fArch = null;
044: fNl = null;
045: }
046:
047: protected void parse(Node node) {
048: super .parse(node);
049: fVersion = getNodeAttribute(node, "version"); //$NON-NLS-1$
050: fName = getNodeAttribute(node, "name"); //$NON-NLS-1$
051: fOptional = getBooleanAttribute(node, "optional"); //$NON-NLS-1$
052: fOs = getNodeAttribute(node, "os"); //$NON-NLS-1$
053: fWs = getNodeAttribute(node, "ws"); //$NON-NLS-1$
054: fArch = getNodeAttribute(node, "arch"); //$NON-NLS-1$
055: fNl = getNodeAttribute(node, "nl"); //$NON-NLS-1$
056: String matchName = getNodeAttribute(node, "match"); //$NON-NLS-1$
057: if (matchName != null) {
058: for (int i = 0; i < RULE_NAME_TABLE.length; i++) {
059: if (matchName.equals(RULE_NAME_TABLE[i])) {
060: fMatch = i;
061: break;
062: }
063: }
064: }
065: String searchLocationName = getNodeAttribute(node,
066: "search_location"); //$NON-NLS-1$
067: if (searchLocationName == null)
068: searchLocationName = getNodeAttribute(node,
069: "search-location"); //$NON-NLS-1$
070: if (searchLocationName != null) {
071: if (searchLocationName.equals("root")) //$NON-NLS-1$
072: fSearchLocation = ROOT;
073: else if (searchLocationName.equals("self")) //$NON-NLS-1$
074: fSearchLocation = SELF;
075: else if (searchLocationName.equals("both")) //$NON-NLS-1$
076: fSearchLocation = BOTH;
077: }
078: //hookWithWorkspace();
079: }
080:
081: public void loadFrom(IFeature feature) {
082: id = feature.getId();
083: fVersion = feature.getVersion();
084: fOptional = false;
085: fName = null;
086: }
087:
088: /**
089: * @see IFeatureChild#getVersion()
090: */
091: public String getVersion() {
092: return fVersion;
093: }
094:
095: public boolean isOptional() {
096: return fOptional;
097: }
098:
099: public String getName() {
100: return fName;
101: }
102:
103: public int getSearchLocation() {
104: return fSearchLocation;
105: }
106:
107: public int getMatch() {
108: return fMatch;
109: }
110:
111: public String getOS() {
112: return fOs;
113: }
114:
115: public String getWS() {
116: return fWs;
117: }
118:
119: public String getArch() {
120: return fArch;
121: }
122:
123: public String getNL() {
124: return fNl;
125: }
126:
127: public IFeature getReferencedFeature() {
128: IFeatureModel workspaceModel = PDECore.getDefault()
129: .getFeatureModelManager().findFeatureModel(getId(),
130: fVersion);
131: if (workspaceModel != null) {
132: return workspaceModel.getFeature();
133: }
134: return null;
135: }
136:
137: /**
138: * @see IFeatureChild#setVersion(String)
139: */
140: public void setVersion(String version) throws CoreException {
141: ensureModelEditable();
142: Object oldValue = this .fVersion;
143: this .fVersion = version;
144: firePropertyChanged(P_VERSION, oldValue, version);
145: }
146:
147: public void setName(String name) throws CoreException {
148: ensureModelEditable();
149: Object oldValue = this .fName;
150: this .fName = name;
151: firePropertyChanged(P_NAME, oldValue, name);
152: }
153:
154: public void setMatch(int match) throws CoreException {
155: ensureModelEditable();
156: Integer oldValue = new Integer(this .fMatch);
157: this .fMatch = match;
158: firePropertyChanged(P_MATCH, oldValue, new Integer(match));
159: }
160:
161: public void setSearchLocation(int searchLocation)
162: throws CoreException {
163: ensureModelEditable();
164: Integer oldValue = new Integer(this .fSearchLocation);
165: this .fSearchLocation = searchLocation;
166: firePropertyChanged(P_SEARCH_LOCATION, oldValue, new Integer(
167: searchLocation));
168: }
169:
170: public void setOptional(boolean optional) throws CoreException {
171: ensureModelEditable();
172: Object oldValue = new Boolean(this .fOptional);
173: this .fOptional = optional;
174: firePropertyChanged(P_NAME, oldValue, new Boolean(optional));
175: }
176:
177: public void setOS(String os) throws CoreException {
178: ensureModelEditable();
179: Object oldValue = this .fOs;
180: this .fOs = os;
181: firePropertyChanged(P_OS, oldValue, os);
182: }
183:
184: public void setWS(String ws) throws CoreException {
185: ensureModelEditable();
186: Object oldValue = this .fWs;
187: this .fWs = ws;
188: firePropertyChanged(P_WS, oldValue, ws);
189: }
190:
191: public void setArch(String arch) throws CoreException {
192: ensureModelEditable();
193: Object oldValue = this .fArch;
194: this .fArch = arch;
195: firePropertyChanged(P_ARCH, oldValue, arch);
196: }
197:
198: public void setNL(String nl) throws CoreException {
199: ensureModelEditable();
200: Object oldValue = this .fNl;
201: this .fNl = nl;
202: firePropertyChanged(P_NL, oldValue, nl);
203: }
204:
205: public void restoreProperty(String name, Object oldValue,
206: Object newValue) throws CoreException {
207: if (name.equals(P_VERSION)) {
208: setVersion((String) newValue);
209: } else if (name.equals(P_OPTIONAL)) {
210: setOptional(((Boolean) newValue).booleanValue());
211: } else if (name.equals(P_NAME)) {
212: setName((String) newValue);
213: } else if (name.equals(P_MATCH)) {
214: setMatch(newValue != null ? ((Integer) newValue).intValue()
215: : NONE);
216: } else if (name.equals(P_OS)) {
217: setOS((String) newValue);
218: } else if (name.equals(P_WS)) {
219: setWS((String) newValue);
220: } else if (name.equals(P_ARCH)) {
221: setArch((String) newValue);
222: } else if (name.equals(P_NL)) {
223: setNL((String) newValue);
224: } else if (name.equals(P_SEARCH_LOCATION)) {
225: setSearchLocation(newValue != null ? ((Integer) newValue)
226: .intValue() : ROOT);
227: } else
228: super .restoreProperty(name, oldValue, newValue);
229: }
230:
231: public void setId(String id) throws CoreException {
232: super .setId(id);
233: }
234:
235: /**
236: * @see IWritable#write(String, PrintWriter)
237: */
238: public void write(String indent, PrintWriter writer) {
239: writer.print(indent + "<includes"); //$NON-NLS-1$
240: String indent2 = indent + Feature.INDENT + Feature.INDENT;
241: if (getId() != null) {
242: writer.println();
243: writer.print(indent2 + "id=\"" + getId() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
244: }
245: if (getVersion() != null) {
246: writer.println();
247: writer.print(indent2 + "version=\"" + getVersion() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
248: }
249: if (getName() != null) {
250: writer.println();
251: writer.print(indent2 + "name=\"" + getName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
252: }
253: if (isOptional()) {
254: writer.println();
255: writer.print(indent2 + "optional=\"true\""); //$NON-NLS-1$
256: }
257: if (fMatch != NONE) {
258: writer.println();
259: writer.print(indent2
260: + "match=\"" + RULE_NAME_TABLE[fMatch] + "\""); //$NON-NLS-1$ //$NON-NLS-2$
261: }
262: if (getOS() != null) {
263: writer.println();
264: writer.print(indent2 + "os=\"" + getOS() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
265: }
266: if (getWS() != null) {
267: writer.println();
268: writer.print(indent2 + "ws=\"" + getWS() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
269: }
270: if (getArch() != null) {
271: writer.println();
272: writer.print(indent2 + "arch=\"" + getArch() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
273: }
274: if (getNL() != null) {
275: writer.println();
276: writer.print(indent2 + "nl=\"" + getNL() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
277: }
278: if (fSearchLocation != ROOT) {
279: writer.println();
280: String value = fSearchLocation == SELF ? "self" : "both"; //$NON-NLS-1$ //$NON-NLS-2$
281: writer.print(indent2 + "search-location=\"" + value + "\""); //$NON-NLS-1$ //$NON-NLS-2$
282: }
283: writer.println("/>"); //$NON-NLS-1$
284: }
285: }
|