KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > core > PluginStringMappings


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.team.internal.core;
13
14 import java.util.*;
15
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.team.core.Team;
18
19 /**
20  *
21  */

22 public class PluginStringMappings {
23     
24     private final String JavaDoc fExtensionID;
25     private final String JavaDoc fAttributeName;
26     
27     private SortedMap fMappings;
28
29     public PluginStringMappings(String JavaDoc extensionID, String JavaDoc stringAttributeName) {
30         fExtensionID= extensionID;
31         fAttributeName= stringAttributeName;
32     }
33     
34     /**
35      * Load all the extension patterns contributed by plugins.
36      * @return a map with the patterns
37      */

38     private SortedMap loadPluginPatterns() {
39         
40         final SortedMap result= new TreeMap();
41         
42         final TeamPlugin plugin = TeamPlugin.getPlugin();
43         if (plugin == null)
44             return result;
45         
46         final IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(TeamPlugin.ID, fExtensionID);//TeamPlugin.FILE_TYPES_EXTENSION);
47
if (extension == null)
48             return result;
49         
50         final IExtension[] extensions = extension.getExtensions();
51         
52         for (int i = 0; i < extensions.length; i++) {
53             IConfigurationElement[] configElements = extensions[i].getConfigurationElements();
54             
55             for (int j = 0; j < configElements.length; j++) {
56                 
57                 final String JavaDoc ext = configElements[j].getAttribute(fAttributeName);//"extension");
58
final String JavaDoc type = configElements[j].getAttribute("type"); //$NON-NLS-1$
59
if (ext == null || type == null)
60                     continue;
61                 
62                 if (type.equals("text")) { //$NON-NLS-1$
63
result.put(ext, new Integer JavaDoc(Team.TEXT));
64                 } else if (type.equals("binary")) { //$NON-NLS-1$
65
result.put(ext, new Integer JavaDoc(Team.BINARY));
66                 }
67             }
68         }
69         return result;
70     }
71     
72     public Map referenceMap() {
73         if (fMappings == null) {
74             fMappings= loadPluginPatterns();
75         }
76         return fMappings;
77     }
78
79     public int getType(String JavaDoc filename) {
80         final Map mappings= referenceMap();
81         return mappings.containsKey(filename) ? ((Integer JavaDoc)mappings.get(filename)).intValue() : Team.UNKNOWN;
82     }
83 }
84
Popular Tags