|
Line 0
Link Here
|
|
|
1 |
/******************************************************************* |
| 2 |
* Copyright (c) 2009, Versant GmbH. |
| 3 |
* The code, documentation and other materials contained herein |
| 4 |
* are the sole and exclusive property of Versant GmbH. and may |
| 5 |
* not be disclosed, used, modified, copied or distributed without |
| 6 |
* prior written consent or license from Versant GmbH. |
| 7 |
******************************************************************/ |
| 8 |
|
| 9 |
package org.eclipse.buckminster.core.internal; |
| 10 |
|
| 11 |
import java.lang.reflect.Field; |
| 12 |
import java.lang.reflect.Modifier; |
| 13 |
|
| 14 |
import org.eclipse.buckminster.core.materializer.PlatformIndependentFeature; |
| 15 |
import org.eclipse.core.runtime.IAdapterFactory; |
| 16 |
import org.eclipse.update.core.Feature; |
| 17 |
import org.eclipse.update.core.IFeature; |
| 18 |
|
| 19 |
/** |
| 20 |
* @author Markus Alexander Kuppe <buckminster-dev_eclipse.org at lemmster dot de> |
| 21 |
* |
| 22 |
*/ |
| 23 |
public class FeatureAdapterFactory implements IAdapterFactory |
| 24 |
{ |
| 25 |
|
| 26 |
/** |
| 27 |
* @param aFeature |
| 28 |
* The feature to convert into a new IFeature instance that treats platform specific bundles as regular |
| 29 |
* ones. Thus installs even non matching bundles. |
| 30 |
*/ |
| 31 |
private IFeature convertFeature(Feature aFeature) |
| 32 |
{ |
| 33 |
// A shallow copy should be sufficient |
| 34 |
IFeature piFeature = new PlatformIndependentFeature(); |
| 35 |
try |
| 36 |
{ |
| 37 |
Class<?> clazz = aFeature.getClass(); |
| 38 |
while(clazz != null) |
| 39 |
{ |
| 40 |
Field[] fields = clazz.getDeclaredFields(); |
| 41 |
for(int i = 0; i < fields.length; i++) |
| 42 |
{ |
| 43 |
Field field = fields[i]; |
| 44 |
if(!(Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) |
| 45 |
|| field.isEnumConstant()) |
| 46 |
{ |
| 47 |
field.setAccessible(true); |
| 48 |
field.set(piFeature, field.get(aFeature)); |
| 49 |
} |
| 50 |
} |
| 51 |
clazz = clazz.getSuperclass(); |
| 52 |
} |
| 53 |
} |
| 54 |
catch(IllegalArgumentException e) |
| 55 |
{ |
| 56 |
return aFeature; |
| 57 |
} |
| 58 |
catch(IllegalAccessException e) |
| 59 |
{ |
| 60 |
return aFeature; |
| 61 |
} |
| 62 |
return piFeature; |
| 63 |
} |
| 64 |
|
| 65 |
/* |
| 66 |
* (non-Javadoc) |
| 67 |
* |
| 68 |
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class) |
| 69 |
*/ |
| 70 |
public Object getAdapter(Object adaptableObject, Class adapterType) |
| 71 |
{ |
| 72 |
if(adaptableObject instanceof Feature && adapterType == PlatformIndependentFeature.class) |
| 73 |
{ |
| 74 |
return convertFeature((Feature)adaptableObject); |
| 75 |
} |
| 76 |
return adaptableObject; |
| 77 |
} |
| 78 |
|
| 79 |
/* |
| 80 |
* (non-Javadoc) |
| 81 |
* |
| 82 |
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() |
| 83 |
*/ |
| 84 |
public Class[] getAdapterList() |
| 85 |
{ |
| 86 |
return new Class[] { IFeature.class }; |
| 87 |
} |
| 88 |
} |