KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > resources > mapping > CompositeResourceMapping


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.core.resources.mapping;
12
13 import java.util.*;
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.core.runtime.*;
16
17 /**
18  * A resource mapping that obtains the traversals for its model object
19  * from a set of child mappings.
20  * <p>
21  * This class is not intended to be subclasses by clients.
22  *
23  * @since 3.2
24  */

25 public final class CompositeResourceMapping extends ResourceMapping {
26
27     private final ResourceMapping[] mappings;
28     private final Object JavaDoc modelObject;
29     private IProject[] projects;
30     private String JavaDoc providerId;
31
32     /**
33      * Create a composite mapping that obtains its traversals from a set of sub-mappings.
34      * @param modelObject the model object for this mapping
35      * @param mappings the sub-mappings from which the traversals are obtained
36      */

37     public CompositeResourceMapping(String JavaDoc providerId, Object JavaDoc modelObject, ResourceMapping[] mappings) {
38         this.modelObject = modelObject;
39         this.mappings = mappings;
40         this.providerId = providerId;
41     }
42
43     /* (non-Javadoc)
44      * @see org.eclipse.core.resources.mapping.ResourceMapping#contains(org.eclipse.core.resources.mapping.ResourceMapping)
45      */

46     public boolean contains(ResourceMapping mapping) {
47         for (int i = 0; i < mappings.length; i++) {
48             ResourceMapping childMapping = mappings[i];
49             if (childMapping.contains(mapping)) {
50                 return true;
51             }
52         }
53         return false;
54     }
55
56     /**
57      * Return the resource mappings contained in this composite.
58      * @return Return the resource mappings contained in this composite.
59      */

60     public ResourceMapping[] getMappings() {
61         return mappings;
62     }
63
64     /* (non-Javadoc)
65      * @see org.eclipse.core.resources.mapping.ResourceMapping#getModelObject()
66      */

67     public Object JavaDoc getModelObject() {
68         return modelObject;
69     }
70
71     /* (non-Javadoc)
72      * @see org.eclipse.core.resources.mapping.ResourceMapping#getModelProviderId()
73      */

74     public String JavaDoc getModelProviderId() {
75         return providerId;
76     }
77
78     /* (non-Javadoc)
79      * @see org.eclipse.core.resources.mapping.ResourceMapping#getProjects()
80      */

81     public IProject[] getProjects() {
82         if (projects == null) {
83             Set result = new HashSet();
84             for (int i = 0; i < mappings.length; i++) {
85                 ResourceMapping mapping = mappings[i];
86                 result.addAll(Arrays.asList(mapping.getProjects()));
87             }
88             projects = (IProject[]) result.toArray(new IProject[result.size()]);
89         }
90         return projects;
91     }
92
93     /* (non-Javadoc)
94      * @see org.eclipse.core.resources.mapping.ResourceMapping#getTraversals(org.eclipse.core.internal.resources.mapping.ResourceMappingContext, org.eclipse.core.runtime.IProgressMonitor)
95      */

96     public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
97         if (monitor == null)
98             monitor = new NullProgressMonitor();
99         try {
100             monitor.beginTask("", 100 * mappings.length); //$NON-NLS-1$
101
List result = new ArrayList();
102             for (int i = 0; i < mappings.length; i++) {
103                 ResourceMapping mapping = mappings[i];
104                 result.addAll(Arrays.asList(mapping.getTraversals(context, new SubProgressMonitor(monitor, 100))));
105             }
106             return (ResourceTraversal[]) result.toArray(new ResourceTraversal[result.size()]);
107         } finally {
108             monitor.done();
109         }
110     }
111
112 }
113
Popular Tags