KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > resources > mapping > ResourceModelProvider


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.internal.resources.mapping;
12
13 import java.util.*;
14 import org.eclipse.core.resources.IContainer;
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.core.resources.mapping.*;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19
20 /**
21  * A simple model provider that represents the resource model itself.
22  *
23  * @since 3.2
24  */

25 public final class ResourceModelProvider extends ModelProvider {
26
27     /* (non-Javadoc)
28      * @see org.eclipse.core.resources.mapping.ModelProvider#getMappings(org.eclipse.core.resources.IResource, org.eclipse.core.resources.mapping.ResourceMappingContext, org.eclipse.core.runtime.IProgressMonitor)
29      */

30     public ResourceMapping[] getMappings(IResource resource, ResourceMappingContext context, IProgressMonitor monitor) {
31         return new ResourceMapping[] {new SimpleResourceMapping(resource)};
32     }
33
34     /* (non-Javadoc)
35      * @see org.eclipse.core.resources.mapping.ModelProvider#getMappings(org.eclipse.core.resources.mapping.ResourceTraversal[], org.eclipse.core.resources.mapping.ResourceMappingContext, org.eclipse.core.runtime.IProgressMonitor)
36      */

37     public ResourceMapping[] getMappings(ResourceTraversal[] traversals, ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
38         Set result = new HashSet();
39         for (int i = 0; i < traversals.length; i++) {
40             ResourceTraversal traversal = traversals[i];
41             IResource[] resources = traversal.getResources();
42             int depth = traversal.getDepth();
43             for (int j = 0; j < resources.length; j++) {
44                 IResource resource = resources[j];
45                 switch (depth) {
46                     case IResource.DEPTH_INFINITE :
47                         result.add(resource);
48                         break;
49                     case IResource.DEPTH_ONE :
50                         if (resource.getType() == IResource.FILE) {
51                             result.add(resource);
52                         } else {
53                             result.add(new ShallowContainer((IContainer)resource));
54                         }
55                         break;
56                     case IResource.DEPTH_ZERO :
57                         if (resource.getType() == IResource.FILE)
58                             result.add(resource);
59                         break;
60                 }
61             }
62         }
63         ResourceMapping[] mappings = new ResourceMapping[result.size()];
64         int i = 0;
65         for (Iterator iter = result.iterator(); iter.hasNext();) {
66             Object JavaDoc element = iter.next();
67             if (element instanceof IResource) {
68                 mappings[i++] = new SimpleResourceMapping((IResource) element);
69             } else {
70                 mappings[i++] = new ShallowResourceMapping((ShallowContainer)element);
71             }
72         }
73         return mappings;
74     }
75 }
76
Popular Tags