KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Manages FeatureFactory extension point
22  */

23 public final class FeatureTypeFactory {
24
25     private static FeatureTypeFactory inst;
26     private Map JavaDoc factories;
27
28     private static final String JavaDoc SIMPLE_EXTENSION_ID = "featureTypes"; //$NON-NLS-1$
29

30     /*
31      * hide constructor
32      */

33     private FeatureTypeFactory() {
34     }
35
36     /*
37      * Singleton pattern
38      */

39     public static FeatureTypeFactory getInstance() {
40         if (inst == null)
41             inst = new FeatureTypeFactory();
42         return inst;
43     }
44
45     /*
46      * return the factory for the associated type
47      */

48     public IFeatureFactory getFactory(String JavaDoc type) throws CoreException {
49         //
50
Object JavaDoc instance = getFactories().get(type);
51         if (instance == null) {
52             instance = createFactoryFor(type);
53             getFactories().put(type, instance);
54         }
55         return (IFeatureFactory) instance;
56     }
57
58     /*
59      * creates a factory for the associated type and cache it
60      */

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

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