KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.*;
15
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.pde.core.*;
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 SiteBuild extends SiteBuildObject implements ISiteBuild {
30     final static String JavaDoc INDENT = " "; //$NON-NLS-1$
31
private Vector features = new Vector();
32     public static final String JavaDoc DEFAULT_PLUGIN_DIR = "plugins"; //$NON-NLS-1$
33
public static final String JavaDoc DEFAULT_FEATURE_DIR = "features"; //$NON-NLS-1$
34
private final IPath pluginLocation = new Path(DEFAULT_PLUGIN_DIR);
35     private final IPath featureLocation = new Path(DEFAULT_FEATURE_DIR);
36     private boolean useConsole;
37     private boolean autobuild;
38     private boolean scrubOutput;
39
40
41     /**
42      * @see org.eclipse.pde.internal.core.isite.ISite#getType()
43      */

44     public IPath getPluginLocation() {
45         return pluginLocation;
46     }
47
48     /**
49      * @see org.eclipse.pde.internal.core.isite.ISite#getType()
50      */

51     public IPath getFeatureLocation() {
52         return featureLocation;
53     }
54     
55     public void setAutobuild(boolean value) throws CoreException {
56         ensureModelEditable();
57         Object JavaDoc oldValue = new Boolean JavaDoc(this.autobuild);
58         this.autobuild = value;
59         firePropertyChanged(P_AUTOBUILD, oldValue, new Boolean JavaDoc(value));
60     }
61     
62     public boolean isAutobuild() {
63         return autobuild;
64     }
65     
66     public void setScrubOutput(boolean value) throws CoreException {
67         ensureModelEditable();
68         Object JavaDoc oldValue = new Boolean JavaDoc(this.scrubOutput);
69         this.scrubOutput = value;
70         firePropertyChanged(P_AUTOBUILD, oldValue, new Boolean JavaDoc(value));
71     }
72
73     public boolean getScrubOutput() {
74         return scrubOutput;
75     }
76     
77     public void setShowConsole(boolean value) throws CoreException {
78         ensureModelEditable();
79         Object JavaDoc oldValue = new Boolean JavaDoc(this.useConsole);
80         this.useConsole = value;
81         firePropertyChanged(P_SHOW_CONSOLE, oldValue, new Boolean JavaDoc(value));
82     }
83
84     public boolean getShowConsole() {
85         return useConsole;
86     }
87
88     /**
89      * @see org.eclipse.pde.internal.core.isite.ISite#addFeatures(org.eclipse.pde.internal.core.isite.ISiteFeature)
90      */

91     public void addFeatures(ISiteBuildFeature[] newFeatures) throws CoreException {
92         ensureModelEditable();
93         for (int i = 0; i < newFeatures.length; i++) {
94             ISiteBuildFeature feature = newFeatures[i];
95             ((SiteBuildFeature) feature).setInTheModel(true);
96             features.add(newFeatures[i]);
97         }
98         fireStructureChanged(newFeatures, IModelChangedEvent.INSERT);
99     }
100
101
102     /**
103      * @see org.eclipse.pde.internal.core.isite.ISite#removeFeatures(org.eclipse.pde.internal.core.isite.ISiteFeature)
104      */

105     public void removeFeatures(ISiteBuildFeature[] newFeatures)
106         throws CoreException {
107         ensureModelEditable();
108         for (int i = 0; i < newFeatures.length; i++) {
109             ISiteBuildFeature feature = newFeatures[i];
110             ((SiteBuildFeature) feature).setInTheModel(false);
111             features.remove(newFeatures[i]);
112         }
113         fireStructureChanged(newFeatures, IModelChangedEvent.REMOVE);
114     }
115
116     /**
117      * @see org.eclipse.pde.internal.core.isite.ISite#getFeatures()
118      */

119     public ISiteBuildFeature[] getFeatures() {
120         return (ISiteBuildFeature[]) features.toArray(
121             new ISiteBuildFeature[features.size()]);
122     }
123
124     protected void reset() {
125         features.clear();
126         useConsole = false;
127         autobuild = false;
128         scrubOutput = false;
129     }
130     
131     protected void parse(Node node) {
132         String JavaDoc value = getNodeAttribute(node, "plugin-location"); //$NON-NLS-1$
133
autobuild = getBooleanAttribute(node, "autobuild"); //$NON-NLS-1$
134
scrubOutput = getBooleanAttribute(node, "scrub-output"); //$NON-NLS-1$
135
useConsole = getBooleanAttribute(node, "use-console"); //$NON-NLS-1$
136
NodeList children = node.getChildNodes();
137         for (int i = 0; i < children.getLength(); i++) {
138             Node child = children.item(i);
139             if (child.getNodeType() == Node.ELEMENT_NODE) {
140                 parseChild(child);
141             }
142         }
143     }
144
145     protected void parseChild(Node child) {
146         String JavaDoc tag = child.getNodeName().toLowerCase();
147         if (tag.equals("feature")) { //$NON-NLS-1$
148
ISiteBuildFeature feature = getModel().createFeature();
149             ((SiteBuildFeature) feature).parse(child);
150             ((SiteBuildFeature) feature).setInTheModel(true);
151             features.add(feature);
152         }
153     }
154     public void restoreProperty(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue)
155         throws CoreException {
156         if (name.equals(P_AUTOBUILD)) {
157             setAutobuild(newValue!=null?((Boolean JavaDoc)newValue).booleanValue():false);
158         } else if (name.equals(P_SCRUB_OUTPUT)) {
159             setScrubOutput(newValue!=null?((Boolean JavaDoc)newValue).booleanValue():false);
160         } else if (name.equals(P_SHOW_CONSOLE)) {
161             setShowConsole(newValue!=null?((Boolean JavaDoc)newValue).booleanValue():false);
162         }
163         else
164             super.restoreProperty(name, oldValue, newValue);
165     }
166     public void write(String JavaDoc indent, PrintWriter writer) {
167         writer.print(indent + "<site-build"); //$NON-NLS-1$
168
String JavaDoc indent2 = indent + INDENT;
169         String JavaDoc indenta = indent + INDENT + INDENT;
170         writeIfDefined(indenta, writer, "autobuild", autobuild?"true":"false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
171
writeIfDefined(indenta, writer, "scrub-output", scrubOutput?"true":"false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
172
writeIfDefined(indenta, writer, "use-console", useConsole?"true":"false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
173
writer.println(">"); //$NON-NLS-1$
174

175         writeChildren(indent2, features, writer);
176         writer.println(indent + "</site-build>"); //$NON-NLS-1$
177
}
178     private void writeChildren(
179         String JavaDoc indent,
180         Vector children,
181         PrintWriter writer) {
182         for (int i = 0; i < children.size(); i++) {
183             IWritable writable = (IWritable) children.get(i);
184             writable.write(indent, writer);
185         }
186     }
187     
188     public void resetReferences() {
189         for (int i=0; i<features.size(); i++) {
190             ISiteBuildFeature sbfeature = (ISiteBuildFeature)features.get(i);
191             sbfeature.setReferencedFeature(null);
192         }
193     }
194     
195     private void writeIfDefined(
196         String JavaDoc indent,
197         PrintWriter writer,
198         String JavaDoc attName,
199         String JavaDoc attValue) {
200         if (attValue == null)
201             return;
202         writer.println();
203         writer.print(indent + attName + "=\"" + attValue + "\""); //$NON-NLS-1$ //$NON-NLS-2$
204
}
205 }
206
Popular Tags