KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > core > mapping > AbstractResourceMappingScope


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 package org.eclipse.team.internal.core.mapping;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.core.resources.mapping.*;
17 import org.eclipse.team.core.mapping.ISynchronizationScope;
18 import org.eclipse.team.internal.core.subscribers.AbstractSynchronizationScope;
19
20 /**
21  * Class that contains common resource mapping scope code.
22  */

23 public abstract class AbstractResourceMappingScope extends AbstractSynchronizationScope implements ISynchronizationScope {
24
25     /* (non-Javadoc)
26      * @see org.eclipse.team.core.mapping.IResourceMappingScope#getMapping(java.lang.Object)
27      */

28     public ResourceMapping getMapping(Object JavaDoc modelObject) {
29         ResourceMapping[] mappings = getMappings();
30         for (int i = 0; i < mappings.length; i++) {
31             ResourceMapping mapping = mappings[i];
32             if (mapping.getModelObject().equals(modelObject))
33                 return mapping;
34         }
35         return null;
36     }
37
38     /* (non-Javadoc)
39      * @see org.eclipse.team.core.mapping.IResourceMappingScope#getMappings(java.lang.String)
40      */

41     public ResourceMapping[] getMappings(String JavaDoc id) {
42         Set JavaDoc result = new HashSet JavaDoc();
43         ResourceMapping[] mappings = getMappings();
44         for (int i = 0; i < mappings.length; i++) {
45             ResourceMapping mapping = mappings[i];
46             if (mapping.getModelProviderId().equals(id)) {
47                 result.add(mapping);
48             }
49         }
50         return (ResourceMapping[]) result.toArray(new ResourceMapping[result.size()]);
51     
52     }
53     
54     /* (non-Javadoc)
55      * @see org.eclipse.team.core.mapping.ISynchronizationScope#getTraversals(java.lang.String)
56      */

57     public ResourceTraversal[] getTraversals(String JavaDoc modelProviderId) {
58         ResourceMapping[] mappings = getMappings(modelProviderId);
59         CompoundResourceTraversal traversal = new CompoundResourceTraversal();
60         for (int i = 0; i < mappings.length; i++) {
61             ResourceMapping mapping = mappings[i];
62             ResourceTraversal[] traversals = getTraversals(mapping);
63             if (traversals != null)
64                 traversal.addTraversals(traversals);
65         }
66         return traversal.asTraversals();
67     }
68
69     /* (non-Javadoc)
70      * @see org.eclipse.team.core.mapping.IResourceMappingScope#getModelProviders()
71      */

72     public ModelProvider[] getModelProviders() {
73         Set JavaDoc result = new HashSet JavaDoc();
74         ResourceMapping[] mappings = getMappings();
75         for (int i = 0; i < mappings.length; i++) {
76             ResourceMapping mapping = mappings[i];
77             ModelProvider modelProvider = mapping.getModelProvider();
78             if (modelProvider != null)
79                 result.add(modelProvider);
80         }
81         return (ModelProvider[]) result.toArray(new ModelProvider[result.size()]);
82     }
83     
84 }
85
Popular Tags