Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c6d611f255bec0312ef077b2b7d5f34d5f9ec543 (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
/*******************************************************************************
 * Copyright (c) 2001, 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
 *     Jens Lukowski/Innoopract - initial renaming/restructuring
 *     
 *******************************************************************************/
package org.eclipse.wst.sse.core.internal.modelhandler;

import java.util.HashMap;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.wst.sse.core.internal.ltk.modelhandler.AbstractModelHandler;
import org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler;


/**
 * This class just converts what's in the plugins registry into a form more
 * easily useable by others, the ContentTypeRegistry.
 */
class ModelHandlerRegistryReader {
	private HashMap allReadyCreateInstances = new HashMap();
	protected String ATT_ASSOCIATED_CONTENT_TYPE = "associatedContentTypeId"; //$NON-NLS-1$
	protected String ATT_CLASS = "class"; //$NON-NLS-1$
	protected String ATT_DEFAULT = "default"; //$NON-NLS-1$
	protected String ATT_ID = "id"; //$NON-NLS-1$
	IConfigurationElement[] elements;
	protected String EXTENSION_POINT_ID = "modelHandler"; //$NON-NLS-1$
	//
	protected String PLUGIN_ID = "org.eclipse.wst.sse.core"; //$NON-NLS-1$
	protected String TAG_NAME = "modelHandler"; //$NON-NLS-1$

	//
	/**
	 * ContentTypeRegistryReader constructor comment.
	 */
	ModelHandlerRegistryReader() {
		super();
	}

	String getAssociatedContentTypeId(IConfigurationElement element) {
		String value = element.getAttribute(ATT_ASSOCIATED_CONTENT_TYPE);
		return value;
	}

	String getId(IConfigurationElement element) {
		String idValue = element.getAttribute(ATT_ID);
		return idValue;
	}

	synchronized IModelHandler getInstance(IConfigurationElement element) {
		// May need to reconsider, but for now, we'll assume all clients must
		// subclass AbstractContentTypeIdentifier. Its easier and safer, for
		// this
		// low level "system" object. (That is, we can check and set "package
		// protected"
		// attributes.
		AbstractModelHandler modelHandler = (AbstractModelHandler) allReadyCreateInstances.get(getId(element));
		if (modelHandler == null) {
			try {
				modelHandler = (AbstractModelHandler) element.createExecutableExtension(ATT_CLASS);
				if (modelHandler != null) {
					allReadyCreateInstances.put(getId(element), modelHandler);
					String defaultValue = element.getAttribute(ATT_DEFAULT);
					if (defaultValue != null && "true".equals(defaultValue)) //$NON-NLS-1$
						modelHandler.setDefault(true);
					else
						modelHandler.setDefault(false);
					// TODO -- set and check attributes vs. created instance
					//contentTypeIdentifier.setOrCheckId(element.getAttribute(ATT_ID));
				}
			} catch (CoreException e) {
				org.eclipse.wst.sse.core.internal.Logger.logException(e);
			}
		}
		return modelHandler;
	}

	public boolean isElementDefault(IConfigurationElement element) {
		String defaultValue = element.getAttribute(ATT_DEFAULT);
		if (defaultValue != null && "true".equals(defaultValue)) //$NON-NLS-1$
			return true;
		else
			return false;
	}

	ModelHandlerRegistryReader readRegistry() {
		IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
		IExtensionPoint point = extensionRegistry.getExtensionPoint(PLUGIN_ID, EXTENSION_POINT_ID);
		if (point != null) {
			// just remember the elements, so plugins don't have to
			// be activated, unless extension matches those "of interest".
			elements = point.getConfigurationElements();
		}
		return this;
	}
}

Back to the top