KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > LegacyResourceSupport


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.ui.internal;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14 import java.lang.reflect.Method JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.List JavaDoc;
18
19 import org.eclipse.core.runtime.IAdaptable;
20 import org.eclipse.core.runtime.Platform;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.jface.viewers.StructuredSelection;
23 import org.eclipse.ui.internal.util.BundleUtility;
24 import org.osgi.framework.Bundle;
25
26 /**
27  * Provides access to resource-specific classes, needed to provide
28  * backwards compatibility for resource-specific functions which
29  * could not be moved up from the generic workbench layer to the
30  * IDE layer.
31  */

32 public final class LegacyResourceSupport {
33
34     private static String JavaDoc[] resourceClassNames = {
35         "org.eclipse.core.resources.IResource", //$NON-NLS-1$
36
"org.eclipse.core.resources.IContainer", //$NON-NLS-1$
37
"org.eclipse.core.resources.IFolder", //$NON-NLS-1$
38
"org.eclipse.core.resources.IProject", //$NON-NLS-1$
39
"org.eclipse.core.resources.IFile", //$NON-NLS-1$
40
};
41     
42     /**
43      * Cached value of
44      * <code>Class.forName("org.eclipse.core.resources.IResource")</code>;
45      * <code>null</code> if not initialized or not present.
46      * @since 3.0
47      */

48     private static Class JavaDoc iresourceClass = null;
49
50     /**
51      * Cached value of
52      * <code>Class.forName("org.eclipse.core.resources.IFile")</code>;
53      * <code>null</code> if not initialized or not present.
54      * @since 3.1
55      */

56     private static Class JavaDoc ifileClass;
57     
58     /**
59      * Cached value of
60      * <code>Class.forName("org.eclipse.ui.IContributorResourceAdapter")</code>;
61      * <code>null</code> if not initialized or not present.
62      * @since 3.0
63      */

64     private static Class JavaDoc icontributorResourceAdapterClass = null;
65
66     /**
67      * Cached value of </code> org.eclipse.ui.IContributorResourceAdapter.getAdaptedResource(IAdaptable) </code>
68      * <code>null</code> if not initialized or not present.
69      *
70      * @since 3.3
71      */

72     private static Method JavaDoc getAdaptedResourceMethod = null;
73     
74     /**
75      * Cached value of </code> org.eclipse.ui.IContributorResourceAdapter2.getAdaptedResourceMapping(IAdaptable) </code>
76      * <code>null</code> if not initialized or not present.
77      *
78      * @since 3.3
79      */

80     private static Method JavaDoc getAdaptedResourceMappingMethod = null;
81     
82     /**
83      * Cached value of
84      * <code>Class.forName("org.eclipse.ui.ide.IContributorResourceAdapter2")</code>;
85      * <code>null</code> if not initialized or not present.
86      * @since 3.1
87      */

88     private static Class JavaDoc icontributorResourceAdapter2Class = null;
89     
90     /**
91      * Cached value of
92      * <code>Class.forName("org.eclipse.ui.internal.ide.DefaultContributorResourceAdapter")</code>;
93      * <code>null</code> if not initialized or not present.
94      * @since 3.0
95      */

96     private static Class JavaDoc defaultContributorResourceAdapterClass = null;
97
98     /**
99      * Cached value for reflective result of <code>DefaultContributorRessourceAdapter.getDefault()</code>.
100      * <code>null</code> if not initialized or not present.
101      *
102      * @since 3.3
103      */

104     private static Object JavaDoc defaultContributorResourceAdapter = null;
105     
106     /**
107      * Cached value of
108      * <code>Class.forName("org.eclipse.core.resources.mapping.ResourceMappingr")</code>;
109      * <code>null</code> if not initialized or not present.
110      * @since 3.0
111      */

112     private static Class JavaDoc resourceMappingClass = null;
113
114     /**
115      * Indicates whether the IDE plug-in (which supplies the
116      * resource contribution adapters) is even around.
117      */

118     private static boolean resourceAdapterPossible = true;
119
120
121     /**
122      * Returns <code>IFile.class</code> or <code>null</code> if the
123      * class is not available.
124      * <p>
125      * This method exists to avoid explicit references from the generic
126      * workbench to the resources plug-in.
127      * </p>
128      *
129      * @return <code>IFile.class</code> or <code>null</code> if class
130      * not available
131      * @since 3.1
132      */

133     public static Class JavaDoc getFileClass() {
134         if (ifileClass != null) {
135             // tried before and succeeded
136
return ifileClass;
137         }
138         Class JavaDoc c = loadClass("org.eclipse.core.resources", "org.eclipse.core.resources.IFile"); //$NON-NLS-1$ //$NON-NLS-2$
139
if (c != null) {
140             // The class was found so record it
141
ifileClass = c;
142         }
143         return c;
144     }
145
146     /**
147      * Returns <code>IResource.class</code> or <code>null</code> if the
148      * class is not available.
149      * <p>
150      * This method exists to avoid explicit references from the generic
151      * workbench to the resources plug-in.
152      * </p>
153      *
154      * @return <code>IResource.class</code> or <code>null</code> if class
155      * not available
156      * @since 3.0
157      */

158     public static Class JavaDoc getResourceClass() {
159         if (iresourceClass != null) {
160             // tried before and succeeded
161
return iresourceClass;
162         }
163         Class JavaDoc c = loadClass("org.eclipse.core.resources", "org.eclipse.core.resources.IResource"); //$NON-NLS-1$ //$NON-NLS-2$
164
if (c != null) {
165             // The class was found so record it
166
iresourceClass = c;
167         }
168         return c;
169     }
170
171     /**
172      * Returns <code>ResourceMapping.class</code> or <code>null</code> if the
173      * class is not available.
174      * <p>
175      * This method exists to avoid explicit references from the generic
176      * workbench to the resources plug-in.
177      * </p>
178      *
179      * @return <code>ResourceMapping.class</code> or <code>null</code> if class
180      * not available
181      * @since 3.1
182      */

183     public static Class JavaDoc getResourceMappingClass() {
184         if (resourceMappingClass != null) {
185             // tried before and succeeded
186
return resourceMappingClass;
187         }
188         Class JavaDoc c = loadClass("org.eclipse.core.resources", "org.eclipse.core.resources.mapping.ResourceMapping"); //$NON-NLS-1$ //$NON-NLS-2$
189
if (c != null) {
190             // The class was found so record it
191
resourceMappingClass = c;
192         }
193         return c;
194     }
195     
196     /**
197      * Returns <code>IContributorResourceAdapter.class</code> or
198      * <code>null</code> if the class is not available.
199      * <p>
200      * This method exists to avoid explicit references from the generic
201      * workbench to the IDE plug-in.
202      * </p>
203      *
204      * @return <code>IContributorResourceAdapter.class</code> or
205      * <code>null</code> if class not available
206      * @since 3.0
207      */

208     public static Class JavaDoc getIContributorResourceAdapterClass() {
209         if (icontributorResourceAdapterClass != null) {
210             // tried before and succeeded
211
return icontributorResourceAdapterClass;
212         }
213         Class JavaDoc c = loadClass("org.eclipse.ui.ide", "org.eclipse.ui.IContributorResourceAdapter"); //$NON-NLS-1$ //$NON-NLS-2$
214
if (c != null) {
215             // The class was found so record it
216
icontributorResourceAdapterClass = c;
217         }
218         return c;
219     }
220
221     /**
222      * Returns <code>IContributorResourceAdapter2.class</code> or
223      * <code>null</code> if the class is not available.
224      * <p>
225      * This method exists to avoid explicit references from the generic
226      * workbench to the IDE plug-in.
227      * </p>
228      *
229      * @return <code>IContributorResourceAdapter.class</code> or
230      * <code>null</code> if class not available
231      * @since 3.1
232      */

233     public static Class JavaDoc getIContributorResourceAdapter2Class() {
234         if (icontributorResourceAdapter2Class != null) {
235             // tried before and succeeded
236
return icontributorResourceAdapter2Class;
237         }
238         Class JavaDoc c = loadClass("org.eclipse.ui.ide", "org.eclipse.ui.ide.IContributorResourceAdapter2"); //$NON-NLS-1$ //$NON-NLS-2$
239
if (c != null) {
240             // The class was found so record it
241
icontributorResourceAdapter2Class = c;
242         }
243         return c;
244     }
245     
246     private static Class JavaDoc loadClass(String JavaDoc bundleName, String JavaDoc className) {
247         if (!resourceAdapterPossible) {
248             // tried before and failed
249
return null;
250         }
251         Bundle bundle = Platform.getBundle(bundleName);
252         if (bundle == null) {
253             // Required plug-in is not around
254
// assume that it will never be around
255
resourceAdapterPossible = false;
256             return null;
257         }
258         // Required plug-in is around
259
// it's not our job to activate the plug-in
260
if (!BundleUtility.isActivated(bundle)) {
261             // assume it might come alive later
262
resourceAdapterPossible = true;
263             return null;
264         }
265         try {
266             return bundle.loadClass(className);
267         } catch (ClassNotFoundException JavaDoc e) {
268             // unable to load the class - sounds pretty serious
269
// treat as if the plug-in were unavailable
270
resourceAdapterPossible = false;
271             return null;
272         }
273     }
274     
275     /**
276      * Returns <code>DefaultContributorResourceAdapter.class</code> or
277      * <code>null</code> if the class is not available.
278      * <p>
279      * This method exists to avoid explicit references from the generic
280      * workbench to the IDE plug-in.
281      * </p>
282      *
283      * @return <code>DefaultContributorResourceAdapter.class</code> or
284      * <code>null</code> if class not available
285      * @since 3.0
286      */

287     public static Class JavaDoc getDefaultContributorResourceAdapterClass() {
288         if (defaultContributorResourceAdapterClass != null) {
289             // tried before and succeeded
290
return defaultContributorResourceAdapterClass;
291         }
292         Class JavaDoc c = loadClass("org.eclipse.ui.ide", "org.eclipse.ui.internal.ide.DefaultContributorResourceAdapter"); //$NON-NLS-1$ //$NON-NLS-2$
293
if (c != null) {
294             // The class was found so record it
295
defaultContributorResourceAdapterClass = c;
296         }
297         return c;
298     }
299     
300     private static Object JavaDoc getDefaultContributorResourceAdapter() {
301         if (defaultContributorResourceAdapter != null) {
302             return defaultContributorResourceAdapter;
303         }
304         
305         // reflective equivalent of
306
// resourceAdapter = DefaultContributorResourceAdapter.getDefault();
307

308             Class JavaDoc c = LegacyResourceSupport.getDefaultContributorResourceAdapterClass();
309             if (c != null) {
310                 try {
311                     Method JavaDoc m = c.getDeclaredMethod("getDefault", new Class JavaDoc[0]);//$NON-NLS-1$
312
defaultContributorResourceAdapter = m.invoke(null, new Object JavaDoc[0]);
313                     return defaultContributorResourceAdapter;
314                 } catch (SecurityException JavaDoc e) {
315                     // shouldn't happen - but play it safe
316
} catch (NoSuchMethodException JavaDoc e) {
317                     // shouldn't happen - but play it safe
318
} catch (IllegalArgumentException JavaDoc e) {
319                     // shouldn't happen - but play it safe
320
} catch (IllegalAccessException JavaDoc e) {
321                     // shouldn't happen - but play it safe
322
} catch (InvocationTargetException JavaDoc e) {
323                     // shouldn't happen - but play it safe
324
}
325                 
326                 
327             }
328         
329         return null;
330
331     }
332     
333     /**
334      * Returns <code>true</code> if the provided type name is an
335      * <code>IResource</code>, and <code>false</code> otherwise.
336      * @param objectClassName
337      * @return <code>true</code> if the provided type name is an
338      * <code>IResource</code>, and <code>false</code> otherwise.
339      *
340      * @since 3.1
341      */

342     public static boolean isResourceType(String JavaDoc objectClassName) {
343         for (int i = 0; i < resourceClassNames.length; i++) {
344             if (resourceClassNames[i].equals(objectClassName)) {
345                 return true;
346             }
347         }
348         return false;
349     }
350     
351     /**
352      * Returns <code>true</code> if the provided type name is an
353      * <code>"org.eclipse.core.resources.mapping.ResourceMapping"</code>, and <code>false</code> otherwise.
354      * @param objectClassName
355      * @return <code>true</code> if the provided type name is an
356      * <code>"org.eclipse.core.resources.mapping.ResourceMapping"</code>, and <code>false</code> otherwise.
357      *
358      * @since 3.1
359      */

360     public static boolean isResourceMappingType(String JavaDoc objectClassName) {
361         return objectClassName.equals("org.eclipse.core.resources.mapping.ResourceMapping"); //$NON-NLS-1$
362
}
363     
364     /**
365      * Returns the class search order starting with <code>extensibleClass</code>.
366      * The search order is defined in this class' comment.
367      *
368      * @since 3.1
369      */

370     private static boolean isInstanceOf(Class JavaDoc clazz, String JavaDoc type) {
371         if (clazz.getName().equals(type)) {
372             return true;
373         }
374         Class JavaDoc superClass= clazz.getSuperclass();
375         if (superClass != null && isInstanceOf(superClass, type)) {
376             return true;
377         }
378         Class JavaDoc[] interfaces= clazz.getInterfaces();
379         for (int i= 0; i < interfaces.length; i++) {
380             if (isInstanceOf(interfaces[i], type)) {
381                 return true;
382             }
383         }
384         return false;
385     }
386     
387     /**
388      * Returns the adapted resource using the <code>IContributorResourceAdapter</code>
389      * registered for the given object. If the Resources plug-in is not loaded
390      * the object can not be adapted.
391      *
392      * @param object the object to adapt to <code>IResource</code>.
393      * @return returns the adapted resource using the <code>IContributorResourceAdapter</code>
394      * or <code>null</code> if the Resources plug-in is not loaded.
395      *
396      * @since 3.1
397      */

398     public static Object JavaDoc getAdaptedContributorResource(Object JavaDoc object) {
399         Class JavaDoc resourceClass = LegacyResourceSupport.getResourceClass();
400         if (resourceClass == null) {
401             return null;
402         }
403         if (resourceClass.isInstance(object)) {
404             return null;
405         }
406         if (object instanceof IAdaptable) {
407             IAdaptable adaptable = (IAdaptable) object;
408             Class JavaDoc contributorResourceAdapterClass = LegacyResourceSupport.getIContributorResourceAdapterClass();
409             if (contributorResourceAdapterClass == null) {
410                 return adaptable.getAdapter(resourceClass);
411             }
412             Object JavaDoc resourceAdapter = adaptable.getAdapter(contributorResourceAdapterClass);
413             if (resourceAdapter == null) {
414                 resourceAdapter = LegacyResourceSupport.getDefaultContributorResourceAdapter();
415                 if (resourceAdapter == null) {
416                     return null;
417                 }
418             }
419             // reflective equivalent of
420
// result = ((IContributorResourceAdapter) resourceAdapter).getAdaptedResource(adaptable);
421

422                 Method JavaDoc m = getContributorResourceAdapterGetAdaptedResourceMethod();
423                 if (m != null) {
424                     try {
425                         return m.invoke(resourceAdapter, new Object JavaDoc[]{adaptable});
426                     } catch (IllegalArgumentException JavaDoc e) {
427                         // shouldn't happen - but play it safe
428
} catch (IllegalAccessException JavaDoc e) {
429                         // shouldn't happen - but play it safe
430
} catch (InvocationTargetException JavaDoc e) {
431                         // shouldn't happen - but play it safe
432
}
433                 }
434             
435         }
436         return null;
437     }
438     
439     private static Method JavaDoc getContributorResourceAdapterGetAdaptedResourceMethod() {
440         if (getAdaptedResourceMethod != null) {
441             return getAdaptedResourceMethod;
442         }
443       
444         Class JavaDoc c = getIContributorResourceAdapterClass();
445         if (c != null) {
446             try {
447                 getAdaptedResourceMethod = c.getDeclaredMethod("getAdaptedResource", new Class JavaDoc[]{IAdaptable.class}); //$NON-NLS-1$
448
return getAdaptedResourceMethod;
449             } catch (SecurityException JavaDoc e) {
450                 // shouldn't happen - but play it safe
451
} catch (NoSuchMethodException JavaDoc e) {
452                 // shouldn't happen - but play it safe
453
}
454                 
455         }
456         
457         return null;
458     }
459
460
461     private static Method JavaDoc getContributorResourceAdapter2GetAdaptedResourceMappingMethod() {
462         if (getAdaptedResourceMappingMethod != null) {
463             return getAdaptedResourceMappingMethod;
464         }
465        
466         Class JavaDoc c = getIContributorResourceAdapter2Class();
467         if (c != null) {
468             try {
469                 getAdaptedResourceMappingMethod = c.getDeclaredMethod("getAdaptedResourceMapping", new Class JavaDoc[]{IAdaptable.class}); //$NON-NLS-1$
470
return getAdaptedResourceMappingMethod;
471             } catch (SecurityException JavaDoc e) {
472                 // do nothing - play it safe
473
} catch (NoSuchMethodException JavaDoc e) {
474                 // do nothing - play it safe
475
}
476                 
477         }
478         
479         return null;
480     }
481
482     /**
483      * Returns the adapted resource mapping using the <code>IContributorResourceAdapter2</code>
484      * registered for the given object. If the Resources plug-in is not loaded
485      * the object can not be adapted.
486      *
487      * @param object the object to adapt to <code>ResourceMapping</code>.
488      * @return returns the adapted resource using the <code>IContributorResourceAdapter2</code>
489      * or <code>null</code> if the Resources plug-in is not loaded.
490      *
491      * @since 3.1
492      */

493     public static Object JavaDoc getAdaptedContributorResourceMapping(Object JavaDoc object) {
494         Class JavaDoc resourceMappingClass = LegacyResourceSupport.getResourceMappingClass();
495         if (resourceMappingClass == null) {
496             return null;
497         }
498         if (resourceMappingClass.isInstance(object)) {
499             return null;
500         }
501         if (object instanceof IAdaptable) {
502             IAdaptable adaptable = (IAdaptable) object;
503             Class JavaDoc contributorResourceAdapterClass = LegacyResourceSupport.getIContributorResourceAdapterClass();
504             if (contributorResourceAdapterClass == null) {
505                 return adaptable.getAdapter(resourceMappingClass);
506             }
507             Class JavaDoc contributorResourceAdapter2Class = LegacyResourceSupport.getIContributorResourceAdapter2Class();
508             if (contributorResourceAdapter2Class == null) {
509                 return adaptable.getAdapter(resourceMappingClass);
510             }
511             Object JavaDoc resourceAdapter = adaptable.getAdapter(contributorResourceAdapterClass);
512             Object JavaDoc resourceMappingAdapter;
513             if (resourceAdapter != null && contributorResourceAdapter2Class.isInstance(resourceAdapter)) {
514                 // The registered adapter also handles resource mappings
515
resourceMappingAdapter = resourceAdapter;
516             } else {
517                 // Either there is no registered adapter or it doesn't handle resource mappings.
518
// In this case, we will use the default contribution adapter
519
resourceMappingAdapter = getDefaultContributorResourceAdapter();
520                 if (resourceMappingAdapter == null) {
521                     return null;
522                 }
523             }
524             
525            
526                 // reflective equivalent of
527
// result = ((IContributorResourceAdapter2) resourceAdapter).getAdaptedResource(adaptable);
528

529              Method JavaDoc m = getContributorResourceAdapter2GetAdaptedResourceMappingMethod();
530              if (m != null) {
531                     
532                 try {
533                     Object JavaDoc result = m.invoke(resourceMappingAdapter, new Object JavaDoc[]{adaptable});
534                     if (result != null) {
535                         return result;
536                     }
537                 } catch (IllegalArgumentException JavaDoc e) {
538                      // shouldn't happen - but play it safe
539
} catch (IllegalAccessException JavaDoc e) {
540                      // shouldn't happen - but play it safe
541
} catch (InvocationTargetException JavaDoc e) {
542                      // shouldn't happen - but play it safe
543
}
544                     
545              }
546             
547             
548             // If we get here, that means that the object in question doesn't adapt to resource mapping
549
// and it's contributed adapter doesn't do the adaptation either.
550
// Before we fail, we will attempt to adapt the object to IResource and then to ResourceMapping
551
Object JavaDoc r = getAdaptedContributorResource(object);
552             if (r != null) {
553                 return Platform.getAdapterManager().getAdapter(r, resourceMappingClass);
554             }
555             
556             // we've exhausted every avenue so just return null
557
return null;
558         }
559         // Fallback to querying the adapter manager directly when the object isn't an IAdaptable
560
return Platform.getAdapterManager().getAdapter(object, resourceMappingClass);
561     }
562     
563     /**
564      * Adapts a selection to the given objectClass considering the Legacy resource
565      * support. Non resource objectClasses are adapted using the <code>IAdapterManager</code>
566      * and this may load the plug-in that contributes the adapter factory.
567      * <p>
568      * The returned selection will only contain elements successfully adapted.
569      * </p>
570      * @param selection the selection to adapt
571      * @param objectClass the class name to adapt the selection to
572      * @return an adapted selection
573      *
574      * @since 3.1
575      */

576     public static IStructuredSelection adaptSelection(IStructuredSelection selection, String JavaDoc objectClass) {
577         List JavaDoc newSelection = new ArrayList JavaDoc(10);
578         for (Iterator JavaDoc it = selection.iterator(); it.hasNext();) {
579             Object JavaDoc element = it.next();
580             Object JavaDoc adaptedElement = getAdapter(element, objectClass);
581             if (adaptedElement != null) {
582                 newSelection.add(adaptedElement);
583             }
584         }
585         return new StructuredSelection(newSelection);
586     }
587     
588     /**
589      * Adapts an object to a specified objectClass considering the Legacy resource
590      * support. Non resource objectClasses are adapted using the <code>IAdapterManager</code>
591      * and this may load the plug-in that contributes the adapter factory.
592      * <p>
593      * The returned selection will be of the same size as the original, and elements that could
594      * not be adapted are added to the returned selection as is.
595      * </p>
596      * @param element the element to adapt
597      * @param objectClass the class name to adapt the selection to
598      * @return an adapted element or <code>null</code> if the
599      * element could not be adapted.
600      *
601      * @since 3.1
602      */

603     public static Object JavaDoc getAdapter(Object JavaDoc element, String JavaDoc objectClass) {
604         Object JavaDoc adaptedElement = null;
605         if (isInstanceOf(element.getClass(), objectClass)) {
606             adaptedElement = element;
607         } else {
608             // Handle IResource
609
if (LegacyResourceSupport.isResourceType(objectClass)) {
610                 adaptedElement = getAdaptedResource(element);
611             } else if (LegacyResourceSupport.isResourceMappingType(objectClass)) {
612                 adaptedElement = getAdaptedResourceMapping(element);
613                 if (adaptedElement == null) {
614                     // The object doesn't adapt directly so check if it adapts transitively
615
Object JavaDoc resource = getAdaptedResource(element);
616                     if (resource != null) {
617                         adaptedElement =( (IAdaptable)resource).getAdapter(LegacyResourceSupport.getResourceMappingClass());
618                     }
619                 }
620             } else {
621                 // Handle all other types by using the adapter factory.
622
adaptedElement = Platform.getAdapterManager().loadAdapter(element, objectClass);
623             }
624         }
625         return adaptedElement;
626     }
627
628     /**
629      * Adapt the given element to an <code>IResource</code> using the following
630      * search order:
631      * <ol>
632      * <li> using the IContributorResourceAdapter registered for the given element, or
633      * <li> directly asking the element if it adapts.
634      * </ol>
635      *
636      * @param element the element to adapt
637      * @return an <code>IResource</code> instance if the element could be adapted or <code>null</code>
638      * otherwise.
639      * @since 3.1
640      */

641     public static Object JavaDoc getAdaptedResource(Object JavaDoc element) {
642         Class JavaDoc resourceClass = LegacyResourceSupport.getResourceClass();
643         Object JavaDoc adaptedValue = null;
644         if (resourceClass != null) {
645             if (resourceClass.isInstance(element)) {
646                 adaptedValue = element;
647             } else {
648                 adaptedValue = LegacyResourceSupport.getAdaptedContributorResource(element);
649             }
650         }
651         return adaptedValue;
652     }
653
654     /**
655      * Adapt the given element to an <code>ResourceMapping</code> using the following
656      * search order:
657      * <ol>
658      * <li> using the IContributorResourceAdapter2 registered for the given element, or
659      * <li> directly asking the element if it adapts.
660      * </ol>
661      *
662      * @param element the element to adapt
663      * @return an <code>ResourceMapping</code> instance if the element could be adapted or <code>null</code>
664      * otherwise.
665      * @since 3.1
666      */

667     public static Object JavaDoc getAdaptedResourceMapping(Object JavaDoc element) {
668         Class JavaDoc resourceMappingClass = LegacyResourceSupport.getResourceMappingClass();
669         Object JavaDoc adaptedValue = null;
670         if (resourceMappingClass != null) {
671             if (resourceMappingClass.isInstance(element)) {
672                 adaptedValue = element;
673             } else {
674                 adaptedValue = LegacyResourceSupport.getAdaptedContributorResourceMapping(element);
675             }
676         }
677         return adaptedValue;
678     }
679     
680     /**
681      * Prevents construction
682      */

683     private LegacyResourceSupport() {
684         // do nothing
685
}
686
687 }
688
Popular Tags