~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/CommandFactoryDescriptor.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 * QNX Software Systems - Initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.debug.mi.core.command.factories; 
 
12
 
 
13
import java.util.ArrayList;
 
14
import java.util.HashSet;
 
15
import java.util.List;
 
16
import java.util.Set;
 
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;
 
24
 
 
25
/**
 
26
 * A command factory descriptor wrappers a configuration
 
27
 * element for a <code>commandFactory</code> extension.
 
28
 */
 
29
public class CommandFactoryDescriptor {
 
30
        
 
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$
 
38
 
 
39
        /**
 
40
         * The configuration element of the extension.
 
41
         */
 
42
        private IConfigurationElement fElement;
 
43
 
 
44
        /**
 
45
         * The set of the platforms supported by this command factory.
 
46
         */
 
47
        private Set fPlatforms;
 
48
 
 
49
        /**
 
50
         * The mi levels supported by this command factory.
 
51
         */
 
52
        private String[] fMIVersions = new String[0];
 
53
 
 
54
        /** 
 
55
         * Constructor for CommandFactoryDescriptor. 
 
56
         */
 
57
        protected CommandFactoryDescriptor( IConfigurationElement element ) {
 
58
                fElement = element;
 
59
        }
 
60
 
 
61
        protected IConfigurationElement getConfigurationElement() {
 
62
                return fElement;
 
63
        }
 
64
 
 
65
        public String getIdentifier() {
 
66
                return getConfigurationElement().getAttribute( IDENTIFIER );
 
67
        }
 
68
 
 
69
        public String getName() {
 
70
                return getConfigurationElement().getAttribute( NAME );
 
71
        }
 
72
 
 
73
        public String getDebuggerIdentifier() {
 
74
                return getConfigurationElement().getAttribute( DEBUGGER_ID );
 
75
        }
 
76
 
 
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() );
 
86
                        }
 
87
                        fMIVersions = (String[])list.toArray( new String[list.size()] );
 
88
                }
 
89
                return fMIVersions;
 
90
        }
 
91
 
 
92
        public String getDescription() {
 
93
                String desc = getConfigurationElement().getAttribute( DESCRIPTION );
 
94
                if ( isEmpty( desc ) ) {
 
95
                        desc =""; //$NON-NLS-1$
 
96
                }
 
97
                return desc;
 
98
        }
 
99
 
 
100
        protected Set getSupportedPlatforms() {
 
101
                if ( fPlatforms == null ) {
 
102
                        String platforms = getConfigurationElement().getAttribute( PLATFORMS );
 
103
                        if ( platforms == null ) {
 
104
                                return new HashSet( 0 );
 
105
                        }
 
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() );
 
110
                        }                       
 
111
                }
 
112
                return fPlatforms;
 
113
        }
 
114
 
 
115
        public boolean supportsPlatform( String platform ) {
 
116
                Set all = getSupportedPlatforms();
 
117
                return all.isEmpty() || all.contains( "*" ) || all.contains( platform ); //$NON-NLS-1$
 
118
        }
 
119
 
 
120
        public String[] getSupportedPlatformList() {
 
121
                Set platforms = getSupportedPlatforms();
 
122
                return (String[])platforms.toArray( new String[platforms.size()] );
 
123
        }
 
124
 
 
125
        public CommandFactory getCommandFactory() throws CoreException {
 
126
                Object clazz = getConfigurationElement().createExecutableExtension( CLASS );
 
127
                if ( clazz instanceof CommandFactory ) {
 
128
                        return (CommandFactory)clazz;
 
129
                }
 
130
                throw new CoreException( new Status( IStatus.ERROR, MIPlugin.getUniqueIdentifier(), -1, CommandFactoriesMessages.getString( "CommandFactoryDescriptor.0" ), null ) ); //$NON-NLS-1$
 
131
        }
 
132
 
 
133
        private boolean isEmpty( String str ) {
 
134
                return ( str == null || str.trim().length() == 0 );
 
135
        }
 
136
}