Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: bd18c95d8fc3e3b7371554f0c494bbb12484ffc6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*******************************************************************************
 * Copyright (c) 2003, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/
/*
 * Created on Jun 21, 2004 
 * @author jsholl
 */
package org.eclipse.jst.j2ee.application.internal.operations;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jem.util.RegistryReader;
import org.eclipse.jem.util.logger.proxy.Logger;
import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;

/**
 * @author jsholl
 */
public class ExtendedImportRegistry extends RegistryReader {

	private static final String PLUGIN_ID = J2EEPlugin.PLUGIN_ID;

	private static final String EXTENSION_ID = "ExtendedModuleImport"; //$NON-NLS-1$

	private static final String FACTORY_CLASS = "factoryClass"; //$NON-NLS-1$

	private static final String MODULE_TYPE = "moduleType"; //$NON-NLS-1$

	public static final String EJB_TYPE = "EJB"; //$NON-NLS-1$

	private List ejbConfigurationElements = null;

	private List ejbFactories = null;

	private static ExtendedImportRegistry instance = null;

	public static ExtendedImportRegistry getInstance() {
		//if (null == instance) {
		instance = new ExtendedImportRegistry();
		//}
		return instance;
	}

	private ExtendedImportRegistry() {
		super(PLUGIN_ID, EXTENSION_ID);
		readRegistry();
	}

	/**
	 * returns a List of ExtendedFactories;
	 * 
	 * @param type
	 * @return
	 */
	public List getFactories(String type) {
		if (type.equals(EJB_TYPE)) {
			if (ejbFactories == null) {
				ejbFactories = new ArrayList();
				for (int i = 0; null != ejbConfigurationElements && i < ejbConfigurationElements.size(); i++) {
					try {
						ejbFactories.add(((IConfigurationElement) ejbConfigurationElements.get(i)).createExecutableExtension(FACTORY_CLASS));
					} catch (CoreException e) {
						Logger.getLogger().logError(e);
					}
				}
			}
			return ejbFactories;
		}
		return null;
	}

	public boolean readElement(IConfigurationElement element) {
		String moduleType = element.getAttribute(MODULE_TYPE);
		if (null != moduleType) {
			if (moduleType.equals(EJB_TYPE)) {
				if (ejbConfigurationElements == null) {
					ejbConfigurationElements = new ArrayList();
				}
				ejbConfigurationElements.add(element);
				return true;
			}
		}
		return false;
	}
}

Back to the top