1
/*******************************************************************************
2
* Copyright (c) 2004, 2006 QNX Software Systems 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
9
* QNX Software Systems - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.debug.mi.core.command.factories;
13
import java.util.ArrayList;
14
import java.util.HashSet;
15
import java.util.List;
17
import java.util.StringTokenizer;
18
import org.eclipse.cdt.debug.mi.core.MIPlugin;
19
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IConfigurationElement;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Status;
26
* A command factory descriptor wrappers a configuration
27
* element for a <code>commandFactory</code> extension.
29
public class CommandFactoryDescriptor {
31
private final static String IDENTIFIER = "id"; //$NON-NLS-1$
32
private final static String CLASS = "class"; //$NON-NLS-1$
33
private final static String NAME = "name"; //$NON-NLS-1$
34
private final static String DEBUGGER_ID = "debuggerID"; //$NON-NLS-1$
35
private final static String MI_VERSIONS = "miVersions"; //$NON-NLS-1$
36
private final static String DESCRIPTION = "description"; //$NON-NLS-1$
37
private final static String PLATFORMS = "platforms"; //$NON-NLS-1$
40
* The configuration element of the extension.
42
private IConfigurationElement fElement;
45
* The set of the platforms supported by this command factory.
47
private Set fPlatforms;
50
* The mi levels supported by this command factory.
52
private String[] fMIVersions = new String[0];
55
* Constructor for CommandFactoryDescriptor.
57
protected CommandFactoryDescriptor( IConfigurationElement element ) {
61
protected IConfigurationElement getConfigurationElement() {
65
public String getIdentifier() {
66
return getConfigurationElement().getAttribute( IDENTIFIER );
69
public String getName() {
70
return getConfigurationElement().getAttribute( NAME );
73
public String getDebuggerIdentifier() {
74
return getConfigurationElement().getAttribute( DEBUGGER_ID );
77
public String[] getMIVersions() {
78
if ( fMIVersions.length == 0 ) {
79
String miVersions = getConfigurationElement().getAttribute( MI_VERSIONS );
80
if ( miVersions == null || miVersions.trim().length() == 0 )
81
miVersions = "mi"; //$NON-NLS-1$
82
StringTokenizer tokenizer = new StringTokenizer( miVersions, "," ); //$NON-NLS-1$
83
List list = new ArrayList( tokenizer.countTokens() );
84
while( tokenizer.hasMoreTokens() ) {
85
list.add( tokenizer.nextToken().trim() );
87
fMIVersions = (String[])list.toArray( new String[list.size()] );
92
public String getDescription() {
93
String desc = getConfigurationElement().getAttribute( DESCRIPTION );
94
if ( isEmpty( desc ) ) {
95
desc =""; //$NON-NLS-1$
100
protected Set getSupportedPlatforms() {
101
if ( fPlatforms == null ) {
102
String platforms = getConfigurationElement().getAttribute( PLATFORMS );
103
if ( platforms == null ) {
104
return new HashSet( 0 );
106
StringTokenizer tokenizer = new StringTokenizer( platforms, "," ); //$NON-NLS-1$
107
fPlatforms = new HashSet( tokenizer.countTokens() );
108
while( tokenizer.hasMoreTokens() ) {
109
fPlatforms.add( tokenizer.nextToken().trim() );
115
public boolean supportsPlatform( String platform ) {
116
Set all = getSupportedPlatforms();
117
return all.isEmpty() || all.contains( "*" ) || all.contains( platform ); //$NON-NLS-1$
120
public String[] getSupportedPlatformList() {
121
Set platforms = getSupportedPlatforms();
122
return (String[])platforms.toArray( new String[platforms.size()] );
125
public CommandFactory getCommandFactory() throws CoreException {
126
Object clazz = getConfigurationElement().createExecutableExtension( CLASS );
127
if ( clazz instanceof CommandFactory ) {
128
return (CommandFactory)clazz;
130
throw new CoreException( new Status( IStatus.ERROR, MIPlugin.getUniqueIdentifier(), -1, CommandFactoriesMessages.getString( "CommandFactoryDescriptor.0" ), null ) ); //$NON-NLS-1$
133
private boolean isEmpty( String str ) {
134
return ( str == null || str.trim().length() == 0 );