KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > core > model > FeatureModelFactory


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.model;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.update.core.Utilities;
19 import org.eclipse.update.internal.core.Messages;
20 import org.xml.sax.SAXException JavaDoc;
21
22 /**
23  * Default feature model factory.
24  * <p>
25  * This class may be instantiated or subclassed by clients. However, in most
26  * cases clients should instead subclass the provided base implementation
27  * of this factory.
28  * </p>
29  * <p>
30  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
31  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
32  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
33  * (repeatedly) as the API evolves.
34  * </p>
35  * @see org.eclipse.update.core.BaseFeatureFactory
36  * @since 2.0
37  */

38
39 public class FeatureModelFactory {
40
41
42     //private static DefaultFeatureParser parser = new DefaultFeatureParser();
43

44     /**
45      * Creates a default model factory.
46      *
47      * @since 2.0
48      */

49     public FeatureModelFactory() {
50         super();
51     }
52
53     /**
54      * Creates and populates a default feature from stream.
55      * The parser assumes the stream contains a default feature manifest
56      * (feature.xml) as documented by the platform.
57      *
58      * @param stream feature stream
59      * @return populated feature model
60      * @exception CoreException
61      * @exception SAXException
62      * @since 2.0
63      */

64     public FeatureModel parseFeature(InputStream JavaDoc stream)
65         throws CoreException, SAXException JavaDoc {
66         return parseFeature(stream, null);
67     }
68     
69     /**
70      * Creates and populates a default feature from stream.
71      * The parser assumes the stream contains a default feature manifest
72      * (feature.xml) as documented by the platform.
73      *
74      * @param stream feature stream
75      * @param location feature location
76      * @return populated feature model
77      * @exception CoreException
78      * @exception SAXException
79      * @since 3.1
80      */

81     public FeatureModel parseFeature(InputStream JavaDoc stream, String JavaDoc location)
82         throws CoreException, SAXException JavaDoc {
83         DefaultFeatureParser parser = new DefaultFeatureParser();
84         parser.init(this, location);
85         FeatureModel featureModel = null;
86         try {
87             featureModel = parser.parse(stream);
88             if (parser.getStatus()!=null) {
89                 // some internalError were detected
90
IStatus status = parser.getStatus();
91                 throw new CoreException(status);
92             }
93         } catch (IOException JavaDoc e) {
94             throw Utilities.newCoreException(Messages.FeatureModelFactory_ErrorAccesingFeatureStream, e);
95         }
96         return featureModel;
97     }
98
99     /**
100      * Create a default feature model.
101      *
102      * @see FeatureModel
103      * @return feature model
104      * @since 2.0
105      */

106     public FeatureModel createFeatureModel() {
107         return new FeatureModel();
108     }
109
110     /**
111      * Create a default included feature reference model.
112      *
113      * @see IncludedFeatureReferenceModel
114      * @return feature model
115      * @since 2.1
116      */

117     public IncludedFeatureReferenceModel createIncludedFeatureReferenceModel() {
118         return new IncludedFeatureReferenceModel();
119     }
120
121
122     /**
123      * Create a default install handler model.
124      *
125      * @see InstallHandlerEntryModel
126      * @return install handler entry model
127      * @since 2.0
128      */

129     public InstallHandlerEntryModel createInstallHandlerEntryModel() {
130         return new InstallHandlerEntryModel();
131     }
132
133     /**
134      * Create a default import dependency model.
135      *
136      * @see ImportModel
137      * @return import dependency model
138      * @since 2.0
139      */

140     public ImportModel createImportModel() {
141         return new ImportModel();
142     }
143
144     /**
145      * Create a default plug-in entry model.
146      *
147      * @see PluginEntryModel
148      * @return plug-in entry model
149      * @since 2.0
150      */

151     public PluginEntryModel createPluginEntryModel() {
152         return new PluginEntryModel();
153     }
154
155     /**
156      * Create a default non-plug-in entry model.
157      *
158      * @see NonPluginEntryModel
159      * @return non-plug-in entry model
160      * @since 2.0
161      */

162     public NonPluginEntryModel createNonPluginEntryModel() {
163         return new NonPluginEntryModel();
164     }
165
166     /**
167      * Create a default annotated URL model.
168      *
169      * @see URLEntryModel
170      * @return annotated URL model
171      * @since 2.0
172      */

173     public URLEntryModel createURLEntryModel() {
174         return new URLEntryModel();
175     }
176 }
177
Popular Tags