KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > core > FeaturePackagedFactory


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.core;
12 import java.io.*;
13 import java.net.*;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.osgi.util.NLS;
17 import org.eclipse.update.core.*;
18 import org.eclipse.update.core.model.*;
19
20 /**
21  * Factory for Feature Packaged
22  */

23 public class FeaturePackagedFactory extends BaseFeatureFactory {
24
25     /*
26      * @see IFeatureFactory#createFeature(URL,ISite,IProgressMonitor)
27      */

28     public IFeature createFeature(URL url,ISite site, IProgressMonitor monitor) throws CoreException {
29         Feature feature = null;
30         InputStream featureStream = null;
31         if (monitor == null)
32             monitor = new NullProgressMonitor();
33         monitor.beginTask(null,2);
34         monitor.worked(1);
35             
36                     
37         try {
38             IFeatureContentProvider contentProvider = new FeaturePackagedContentProvider(url, site);
39             ContentReference manifest = contentProvider.getFeatureManifestReference(null/*IProgressMonitor*/);
40             featureStream = manifest.getInputStream();
41             feature = (Feature)parseFeature(featureStream);
42             monitor.worked(1);
43     
44             // if there is no update URL for the Feature
45
// use the Site URL
46
if (feature.getUpdateSiteEntry()==null){
47                 URLEntryModel entryModel = createURLEntryModel();
48                 URL siteUrl = site.getURL();
49                 if (siteUrl!=null){
50                     entryModel.setURLString(siteUrl.toExternalForm());
51                     entryModel.resolve(siteUrl,null);
52                     feature.setUpdateSiteEntryModel(entryModel);
53                 }
54             }
55             feature.setFeatureContentProvider(contentProvider);
56             feature.setSite(site);
57             URL baseUrl = null;
58             try {
59                 baseUrl = new URL(manifest.asURL(),"."); // make sure we have URL to feature directory //$NON-NLS-1$
60
} catch(MalformedURLException e) {
61             }
62             feature.resolve(baseUrl, baseUrl);
63             feature.markReadOnly();
64         } catch (CoreException e){
65             throw e;
66         } catch (Exception JavaDoc e) {
67             e.printStackTrace();
68             throw Utilities.newCoreException(NLS.bind(Messages.FeatureFactory_CreatingError, (new String JavaDoc[] { url.toExternalForm() })), e);
69         }finally {
70             try {
71                 if (featureStream!=null)
72                     featureStream.close();
73             } catch (IOException e) {
74             }
75         }
76         return feature;
77     }
78     
79     public IncludedFeatureReferenceModel createIncludedFeatureReferenceModel() {
80      return new UpdateSiteIncludedFeatureReference();
81     }
82 }
83
Popular Tags