KickJava   Java API By Example, From Geeks To Geeks.

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


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
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.osgi.util.NLS;
18 import org.eclipse.update.core.*;
19
20 /**
21  *
22  */

23 public final class SiteTypeFactory {
24     
25
26     /**
27      * extension point ID
28      */

29     public static final String JavaDoc SIMPLE_EXTENSION_ID = "siteTypes"; //$NON-NLS-1$
30

31
32     private static SiteTypeFactory inst;
33     
34     private Map JavaDoc factories;
35
36     /**
37      * hide ctr
38      */

39     private SiteTypeFactory() {
40     }
41
42     public static SiteTypeFactory getInstance() {
43         if (inst == null)
44             inst = new SiteTypeFactory();
45         return inst;
46     }
47
48
49     /**
50      * return the factory for the type
51      */

52     public ISiteFactory getFactory(String JavaDoc type) throws CoreException {
53             //
54
Object JavaDoc instance = getFactories().get(type);
55             if (instance==null) {
56                 instance = createFactoryFor(type);
57                 getFactories().put(type,instance);
58             }
59             return (ISiteFactory) instance;
60     }
61
62     /**
63      *
64      */

65     private ISiteFactory createFactoryFor(String JavaDoc type) throws CoreException {
66         ISiteFactory result = null;
67         
68         String JavaDoc pluginID = UpdateCore.getPlugin().getBundle().getSymbolicName();
69         IExtensionRegistry registry = Platform.getExtensionRegistry();
70         IConfigurationElement[] elements = registry.getConfigurationElementsFor(pluginID,SIMPLE_EXTENSION_ID,type);
71         if (elements==null || elements.length==0){
72             throw Utilities.newCoreException(NLS.bind(Messages.SiteTypeFactory_UnableToFindSiteFactory, (new String JavaDoc[] { type })),null);
73         } else {
74             IConfigurationElement element = elements[0];
75             result = (ISiteFactory)element.createExecutableExtension("class"); //$NON-NLS-1$
76
}
77         return result;
78     }
79
80     /**
81      * Gets the actories.
82      * @return Returns a Map
83      */

84     private Map JavaDoc getFactories() {
85         if (factories==null) factories = new HashMap JavaDoc();
86             return factories;
87     }
88
89
90 }
91
Popular Tags