KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > core > BaseSiteFactory


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.core;
12  
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.net.MalformedURLException JavaDoc;
16 import java.net.URL JavaDoc;
17 import java.net.URLClassLoader JavaDoc;
18 import java.util.Locale JavaDoc;
19 import java.util.MissingResourceException JavaDoc;
20 import java.util.ResourceBundle JavaDoc;
21
22 import org.eclipse.core.runtime.CoreException;
23 import org.eclipse.osgi.util.NLS;
24 import org.eclipse.update.core.model.ArchiveReferenceModel;
25 import org.eclipse.update.core.model.CategoryModel;
26 import org.eclipse.update.core.model.InvalidSiteTypeException;
27 import org.eclipse.update.core.model.SiteModel;
28 import org.eclipse.update.core.model.SiteModelFactory;
29 import org.eclipse.update.core.model.URLEntryModel;
30 import org.eclipse.update.internal.core.Messages;
31 import org.eclipse.update.internal.core.UpdateCore;
32 import org.eclipse.update.internal.core.UpdateManagerUtils;
33 import org.eclipse.update.internal.core.connection.ConnectionFactory;
34 import org.eclipse.update.internal.core.connection.IResponse;
35
36 /**
37  * Base implementation of a site factory.
38  * The factory is responsible for constructing the correct
39  * concrete implementation of the model objects for each particular
40  * site type. This class creates model objects that correspond
41  * to the concrete implementation classes provided in this package.
42  * The actual site creation method is subclass responsibility.
43  * <p>
44  * This class must be subclassed by clients.
45  * </p>
46  * <p>
47  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
48  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
49  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
50  * (repeatedly) as the API evolves.
51  * </p>
52  * @see org.eclipse.update.core.ISiteFactory
53  * @see org.eclipse.update.core.model.SiteModelFactory
54  * @since 2.0
55  */

56 public abstract class BaseSiteFactory extends SiteModelFactory implements ISiteFactory {
57
58
59     /**
60      * Create site. Implementation of this method must be provided by
61      * subclass
62      *
63      * @see ISiteFactory#createSite(URL)
64      * @since 2.0
65      */

66     public abstract ISite createSite(URL JavaDoc url) throws CoreException, InvalidSiteTypeException;
67
68     /**
69      * Helper method to access resouce bundle for site. The default
70      * implementation attempts to load the appropriately localized
71      * site.properties file.
72      *
73      * @param url base URL used to load the resource bundle.
74      * @return resource bundle, or <code>null</code>.
75      * @since 2.0
76      */

77     protected ResourceBundle JavaDoc getResourceBundle(URL JavaDoc url) {
78         ResourceBundle JavaDoc bundle = null;
79
80         try {
81             url = UpdateManagerUtils.asDirectoryURL(url);
82             ClassLoader JavaDoc l = new URLClassLoader JavaDoc(new URL JavaDoc[] { url }, null);
83             bundle = ResourceBundle.getBundle(Site.SITE_FILE, Locale.getDefault(), l);
84         } catch (MissingResourceException JavaDoc e) {
85             UpdateCore.warn(e.getLocalizedMessage() + ":" + url.toExternalForm()); //$NON-NLS-1$
86
} catch (MalformedURLException JavaDoc e) {
87             UpdateCore.warn(NLS.bind(Messages.BaseSiteFactory_CannotRetriveParentDirectory, (new String JavaDoc[] { url.toExternalForm() })));
88         }
89
90         return bundle;
91     }
92
93     /**
94      * Create a concrete implementation of site model.
95      *
96      * @see Site
97      * @return site model
98      * @since 2.0
99      */

100     public SiteModel createSiteMapModel() {
101         return new Site();
102     }
103
104
105     /**
106      * Create a concrete implementation of feature reference model.
107      *
108      * @see FeatureReference
109      * @return feature reference model
110      * @since 2.0
111      */

112     public SiteFeatureReferenceModel createFeatureReferenceModel() {
113         return new SiteFeatureReference();
114     }
115
116     /**
117      * Create a concrete implementation of archive reference model.
118      *
119      * @see ArchiveReference
120      * @return archive reference model
121      * @since 2.0
122      */

123     public ArchiveReferenceModel createArchiveReferenceModel() {
124         return new ArchiveReference();
125     }
126
127
128     /**
129      * Create a concrete implementation of annotated URL model.
130      *
131      * @see URLEntry
132      * @return annotated URL model
133      * @since 2.0
134      */

135     public URLEntryModel createURLEntryModel() {
136         return new URLEntry();
137     }
138
139
140     /**
141      * Create a concrete implementation of category model.
142      *
143      * @see Category
144      * @return category model
145      * @since 2.0
146      */

147     public CategoryModel createSiteCategoryModel() {
148         return new Category();
149     }
150
151     /**
152      * Open a stream on a URL.
153      * manages a time out if the connection is locked or fails
154      *
155      * @param resolvedURL
156      * @return InputStream
157      */

158     protected InputStream JavaDoc openStream(URL JavaDoc resolvedURL) throws IOException JavaDoc {
159         IResponse response = ConnectionFactory.get(resolvedURL);
160         return response.getInputStream();
161     }
162
163 }
164
Popular Tags