001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: ******************************************************************************/package org.eclipse.ui.internal.statushandlers;
011:
012: import java.util.HashMap;
013: import java.util.Map;
014:
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.core.runtime.IConfigurationElement;
017: import org.eclipse.ui.IPluginContribution;
018: import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
019: import org.eclipse.ui.statushandlers.AbstractStatusHandler;
020:
021: /**
022: * The status handler descriptor.
023: *
024: * @since 3.3
025: */
026: public class StatusHandlerDescriptor implements IPluginContribution {
027:
028: private AbstractStatusHandler cachedInstance;
029:
030: private final static String PREFIX = "prefix"; //$NON-NLS-1$
031:
032: private IConfigurationElement configElement;
033:
034: private String id;
035:
036: private String pluginId;
037:
038: private String prefix;
039:
040: /**
041: * @param configElement
042: */
043: public StatusHandlerDescriptor(IConfigurationElement configElement) {
044: super ();
045: this .configElement = configElement;
046: id = configElement
047: .getAttribute(IWorkbenchRegistryConstants.ATT_ID);
048: pluginId = configElement.getContributor().getName();
049: }
050:
051: /**
052: * Gets an instance of the status handler defined in the descriptor.
053: *
054: * @return the status handler
055: * @throws CoreException
056: * thrown if there is a problem creating the handler
057: */
058: public synchronized AbstractStatusHandler getStatusHandler()
059: throws CoreException {
060: if (cachedInstance == null) {
061: AbstractStatusHandler statusHandler = (AbstractStatusHandler) configElement
062: .createExecutableExtension(IWorkbenchRegistryConstants.ATT_CLASS);
063: statusHandler.setId(configElement
064: .getAttribute(IWorkbenchRegistryConstants.ATT_ID));
065:
066: IConfigurationElement parameters[] = configElement
067: .getChildren(IWorkbenchRegistryConstants.TAG_PARAMETER);
068:
069: Map params = new HashMap();
070:
071: for (int i = 0; i < parameters.length; i++) {
072: params
073: .put(
074: parameters[i]
075: .getAttribute(IWorkbenchRegistryConstants.ATT_NAME),
076: parameters[i]
077: .getAttribute(IWorkbenchRegistryConstants.ATT_VALUE));
078: }
079:
080: statusHandler.setParams(params);
081: cachedInstance = statusHandler;
082: }
083: return cachedInstance;
084: }
085:
086: /**
087: * Gets prefix parameter for the status handler defined in the descriptor.
088: *
089: * @return prefix parameter
090: */
091: public String getPrefix() {
092: IConfigurationElement parameters[] = configElement
093: .getChildren(IWorkbenchRegistryConstants.TAG_PARAMETER);
094:
095: for (int i = 0; i < parameters.length; i++) {
096: if (parameters[i].getAttribute(
097: IWorkbenchRegistryConstants.ATT_NAME)
098: .equals(PREFIX)) {
099: prefix = parameters[i]
100: .getAttribute(IWorkbenchRegistryConstants.ATT_VALUE);
101: }
102: }
103: return prefix;
104: }
105:
106: /**
107: * Returns the id of the status handler.
108: *
109: * @return the id
110: */
111: public String getId() {
112: return id;
113: }
114:
115: /*
116: * (non-Javadoc)
117: *
118: * @see org.eclipse.ui.IPluginContribution#getLocalId()
119: */
120: public String getLocalId() {
121: return id;
122: }
123:
124: /*
125: * (non-Javadoc)
126: *
127: * @see org.eclipse.ui.IPluginContribution#getPluginId()
128: */
129: public String getPluginId() {
130: return pluginId;
131: }
132: }
|