Skip to main content
summaryrefslogtreecommitdiffstats
blob: f22afe43928ebed9ad495a74bcc016fc32ffa8fc (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*******************************************************************************
 * Copyright (c) 2003, 2005 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 Feb 5, 2004
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.eclipse.jst.j2ee.internal.servertarget;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IPluginRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.jem.util.RegistryReader;
import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;

/**
 * @author vijayb
 * @deprecated
 * To change the template for this generated type comment go to Window - Preferences - Java - Code
 * Generation - Code and Comments
 */
public class TargetRuntimeExtensionHandlerReader extends RegistryReader {
	static TargetRuntimeExtensionHandlerReader instance = null;
	protected ITargetRuntimeExtensionHandler targetRuntimeExtHandler;
	protected String HANDLER_EXT_Id = "targetRuntimeExtensionHandler"; //$NON-NLS-1$
	protected TargetRuntimeExtension extension = null;
	protected String HANDLER_CLASSNAME = "className"; //$NON-NLS-1$
	protected String HANDLER_GROUP_ID = "groupID"; //$NON-NLS-1$
	protected HashMap handlerExtensions = null;

	/**
	 * @param registry
	 * @param plugin
	 * @param extensionPoint
	 */
	public TargetRuntimeExtensionHandlerReader(IPluginRegistry registry, String plugin, String extensionPoint) {
		super(plugin, extensionPoint);
	}

	/**
	 *  
	 */
	public TargetRuntimeExtensionHandlerReader() {
		super(J2EEPlugin.PLUGIN_ID, "TargetRuntimeExtHandler"); //$NON-NLS-1$
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.wst.common.frameworks.internal.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement)
	 */
	public boolean readElement(IConfigurationElement element) {
		if (!element.getName().equals(HANDLER_EXT_Id))
			return false;
		String group = element.getAttribute(HANDLER_GROUP_ID);
		String className = element.getAttribute(HANDLER_CLASSNAME);
		if (group == null) {
			logMissingAttribute(element, "Missing group target runtime extension specification."); //$NON-NLS-1$
			return false;
		}
		try {
			String pluginId = element.getDeclaringExtension().getNamespace();
			Plugin plugin = Platform.getPlugin(pluginId);
			extension = new TargetRuntimeExtension(plugin, element, group, className);
			addExtensionPoint(extension);
			return true;
		} catch (Exception ce) {
			ce.printStackTrace();
		}
		return false;
	}

	/**
	 * Sets the extension point.
	 * 
	 * @param extensions
	 *            The extensions to set
	 */
	protected void addExtensionPoint(TargetRuntimeExtension newExtension) {
		if (handlerExtensions == null)
			handlerExtensions = new HashMap();
		Collection temp = null;
		Object holder = handlerExtensions.get(newExtension.getGroupId());
		if (temp == null) {
			temp = new ArrayList();
			temp.add(newExtension);
		} else {
			handlerExtensions.remove(newExtension.getGroupId());
			temp = (Collection) holder;
			temp.add(newExtension);
		}
		handlerExtensions.put(newExtension.getGroupId(), temp);
	}

	/**
	 * Gets the instance.
	 * 
	 * @return Returns a TargetRuntimeExtensionHandlerReader
	 */
	public static TargetRuntimeExtensionHandlerReader getInstance() {
		if (instance == null)
			instance = new TargetRuntimeExtensionHandlerReader();
		return instance;
	}

	public ITargetRuntimeExtensionHandler getEJBExtHandler() {
		if (targetRuntimeExtHandler == null && handlerExtensions != null) {
			TargetRuntimeExtension codegenExt = null;
			ArrayList ibmExtensions = (ArrayList) handlerExtensions.get("IBM"); //$NON-NLS-1$
			if (ibmExtensions != null) {
				for (int i = 0; i < ibmExtensions.size(); i++) {
					Object obj = ibmExtensions.get(i);
					if (obj instanceof TargetRuntimeExtension) {
						codegenExt = (TargetRuntimeExtension) obj;
						break;
					}
				}
			}
			if (codegenExt != null) {
				IConfigurationElement cElement = codegenExt.configElement;
				try {
					targetRuntimeExtHandler = (ITargetRuntimeExtensionHandler) cElement.createExecutableExtension("run"); //$NON-NLS-1$
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return targetRuntimeExtHandler;
	}
}

Back to the top