KickJava   Java API By Example, From Geeks To Geeks.

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


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

39 public class SiteModelFactory {
40     
41     private static DefaultSiteParser parser = new DefaultSiteParser();
42
43     /**
44      * Creates a default site factory.
45      *
46      * @since 2.0
47      */

48     public SiteModelFactory() {
49         super();
50     }
51
52     /**
53      * Indicates whether this factory can handle the specified site type. This
54      * method is intended to be overridden by subclasses.
55      *
56      * @param type site type identifier
57      * @return <code>true</code> if the type can be handled, otherwise <code>false</code>
58      * @since 2.0
59      */

60     public boolean canParseSiteType(String JavaDoc type) {
61         // return true if type was not specified (ie. is null or empty string)
62
return (type == null || type.trim().equals("")); //$NON-NLS-1$
63
}
64
65     /**
66      * Creates and populates a default site from stream.
67      * The parser assumes the stream contains a default site manifest
68      * (site.xml) as documented by the platform.
69      *
70      * @param stream site stream
71      * @return populated site model
72      * @exception CoreException
73      * @exception InvalidSiteTypeException
74      * @since 2.0
75      */

76     public SiteModel parseSite(InputStream JavaDoc stream)
77         throws CoreException, InvalidSiteTypeException {
78         SiteModel result = null;
79         try {
80             parser.init(this);
81             result = parser.parse(stream);
82             if (parser.getStatus()!=null) {
83                 // some internalError were detected
84
IStatus status = parser.getStatus();
85                 throw new CoreException(status);
86             }
87         } catch (SAXException JavaDoc e) {
88             // invalid Site type
89
if (e.getException() instanceof InvalidSiteTypeException) {
90                 throw (InvalidSiteTypeException) e.getException();
91             }
92
93             throw Utilities.newCoreException(Messages.SiteModelObject_ErrorParsingSiteStream,e);
94         } catch (IOException JavaDoc e){
95             throw Utilities.newCoreException(Messages.SiteModelObject_ErrorAccessingSiteStream,e);
96         }
97         return result;
98     }
99
100     /**
101      * Create a default site model.
102      *
103      * @see SiteModel
104      * @return site model
105      * @since 2.0
106      */

107     public SiteModel createSiteMapModel() {
108         return new SiteModel();
109     }
110
111     /**
112      * Create a default site feature reference model.
113      *
114      * @see SiteFeatureReferenceModel
115      * @return site feature reference model
116      * @since 2.0
117      */

118     public SiteFeatureReferenceModel createFeatureReferenceModel() {
119         return new SiteFeatureReferenceModel();
120     }
121
122     /**
123      * Create a default archive reference model.
124      *
125      * @see ArchiveReferenceModel
126      * @return archive reference model
127      * @since 2.0
128      */

129     public ArchiveReferenceModel createArchiveReferenceModel() {
130         return new ArchiveReferenceModel();
131     }
132
133     /**
134      * Create a default annotated URL model.
135      *
136      * @see URLEntryModel
137      * @return annotated URL model
138      * @since 2.0
139      */

140     public URLEntryModel createURLEntryModel() {
141         return new URLEntryModel();
142     }
143
144     /**
145      * Create a default category model.
146      *
147      * @see CategoryModel
148      * @return category model
149      * @since 2.0
150      */

151     public CategoryModel createSiteCategoryModel() {
152         return new CategoryModel();
153     }
154 }
155
Popular Tags