KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > model > InstallConfigurationParser


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.update.internal.model;
12 import java.io.File JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.net.URL JavaDoc;
15 import java.util.Date JavaDoc;
16
17 import org.eclipse.core.runtime.Assert;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.FileLocator;
20 import org.eclipse.update.configurator.IPlatformConfiguration;
21 import org.eclipse.update.core.ISite;
22 import org.eclipse.update.core.SiteFeatureReference;
23 import org.eclipse.update.core.SiteManager;
24 import org.eclipse.update.core.model.SiteModel;
25 import org.eclipse.update.internal.configurator.FeatureEntry;
26 import org.eclipse.update.internal.configurator.PlatformConfiguration;
27 import org.eclipse.update.internal.configurator.SiteEntry;
28 import org.eclipse.update.internal.core.BaseSiteLocalFactory;
29 import org.eclipse.update.internal.core.Messages;
30 import org.eclipse.update.internal.core.UpdateCore;
31 import org.eclipse.update.internal.core.UpdateManagerUtils;
32
33
34 /**
35  * parse the default site.xml
36  */

37
38 public class InstallConfigurationParser {
39     private PlatformConfiguration platformConfig;
40     private URL JavaDoc siteURL;
41     private InstallConfigurationModel config;
42     private ConfiguredSiteModel configSite;
43
44     /**
45      * Constructor for DefaultSiteParser
46      */

47     public InstallConfigurationParser(
48         IPlatformConfiguration platformConfig,
49         InstallConfigurationModel config, boolean light)
50         throws IOException JavaDoc, CoreException {
51
52         Assert.isTrue(platformConfig instanceof PlatformConfiguration);
53         this.platformConfig = (PlatformConfiguration)platformConfig;
54         
55         this.config = config;
56
57         // DEBUG:
58
if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) {
59             UpdateCore.debug("Start parsing Configuration:" + (config).getURL().toExternalForm()); //$NON-NLS-1$
60
}
61         
62         if (light) {
63             processConfigurationLight(this.platformConfig);
64         } else {
65             processConfig(this.platformConfig);
66         }
67     }
68     
69     
70
71
72
73     /**
74      * process the Site info
75      */

76     private void processSite(SiteEntry siteEntry) throws CoreException, IOException JavaDoc {
77
78         //site url
79
siteURL = siteEntry.getURL();
80         try {
81             siteURL = FileLocator.toFileURL(siteURL);
82             // TODO workaround bug in platform url resolution
83
if (siteURL.getProtocol().equals("file")) //$NON-NLS-1$
84
siteURL = new File JavaDoc(siteURL.getFile()).toURL();
85         } catch (IOException JavaDoc e) {
86             // keep original url
87
}
88
89         // policy
90
ISite site = SiteManager.getSite(siteURL,null);
91
92         // configuration site
93
BaseSiteLocalFactory factory = new BaseSiteLocalFactory();
94         configSite = factory.createConfigurationSiteModel((SiteModel) site, siteEntry.getSitePolicy().getType());
95
96         //platform url
97
configSite.setPlatformURLString(siteEntry.getURL().toExternalForm());
98         
99         // configured
100
configSite.setEnabled(siteEntry.isEnabled());
101
102         // check if the site exists and is updatable
103
configSite.setUpdatable(siteEntry.isUpdateable());
104         
105         // add to install configuration
106
config.addConfigurationSiteModel(configSite);
107         configSite.setInstallConfigurationModel(config);
108         
109         FeatureEntry[] features = siteEntry.getFeatureEntries();
110         for (int i=0; i<features.length; i++) {
111             processFeature(features[i]);
112         }
113     }
114
115     /**
116      * process the DefaultFeature info
117      */

118     private void processFeature(FeatureEntry feature) throws CoreException, IOException JavaDoc {
119
120         // url
121
String JavaDoc path = feature.getURL();
122         URL JavaDoc url = UpdateManagerUtils.getURL(siteURL, path, null);
123
124         if (url != null) {
125             SiteFeatureReference ref = new SiteFeatureReference();
126             ref.setSite((ISite) configSite.getSiteModel());
127             ref.setURL(url);
128             (configSite.getConfigurationPolicyModel()).addConfiguredFeatureReference(ref);
129
130             //updateURL
131
//TODO do we need the update url and to resolve it?
132
// String updateURLString = attributes.getValue("updateURL"); //$NON-NLS-1$
133
// URLEntry entry = new URLEntry();
134
// entry.setURLString(updateURLString);
135
// entry.resolve(siteURL,null);
136

137             // DEBUG:
138
if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) {
139                 UpdateCore.debug("End Processing DefaultFeature Tag: url:" + url.toExternalForm()); //$NON-NLS-1$
140
}
141
142         } else {
143             UpdateCore.log( Messages.InstallConfigurationParser_FeatureReferenceNoURL, new Exception JavaDoc());
144         }
145
146     }
147
148     /**
149      * process the Activity info
150      */

151 // private void processActivity(Attributes attributes) {
152
//
153
// // action
154
// String actionString = attributes.getValue("action"); //$NON-NLS-1$
155
// int action = Integer.parseInt(actionString);
156
//
157
// // create
158
// ConfigurationActivityModel activity =
159
// new BaseSiteLocalFactory().createConfigurationActivityModel();
160
// activity.setAction(action);
161
//
162
// // label
163
// String label = attributes.getValue("label"); //$NON-NLS-1$
164
// if (label != null)
165
// activity.setLabel(label);
166
//
167
// // date
168
// String dateString = attributes.getValue("date"); //$NON-NLS-1$
169
// Date date = new Date(Long.parseLong(dateString));
170
// activity.setDate(date);
171
//
172
// // status
173
// String statusString = attributes.getValue("status"); //$NON-NLS-1$
174
// int status = Integer.parseInt(statusString);
175
// activity.setStatus(status);
176
//
177
// config.addActivityModel(activity);
178
//
179
// // DEBUG:
180
// if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) {
181
// UpdateCore.debug("End Processing Activity: action:" + actionString + " label: " + label + " date:" + dateString + " status" + statusString); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
182
// }
183
//
184
// }
185

186     /**
187      * process the Config info
188      */

189     private void processConfig(PlatformConfiguration platformConfig) throws IOException JavaDoc, CoreException {
190
191         // date
192
processConfigurationLight(platformConfig);
193         
194         //timeline
195
// String timelineString = attributes.getValue("timeline"); //$NON-NLS-1$
196
// long timeline = config.getCreationDate().getTime();
197
// if (timelineString!=null) {
198
// timeline = Long.parseLong(timelineString);
199
// }
200
// config.setTimeline(timeline);
201

202         SiteEntry[] sites = platformConfig.getConfiguration().getSites();
203         for (int i=0; i<sites.length; i++)
204             processSite(sites[i]);
205
206     }
207
208
209
210     private void processConfigurationLight(PlatformConfiguration platformConfig) {
211         Date JavaDoc date = new Date JavaDoc(platformConfig.getChangeStamp());
212         config.setCreationDate(date);
213         config.setLabel(date.toString());
214         
215         config.setCurrent( date.equals(org.eclipse.update.internal.configurator.PlatformConfiguration.getCurrent().getConfiguration().getDate()));
216     }
217     
218 }
219
Popular Tags