use of org.eclipse.e4.core.di.suppliers.IObjectDescriptor in project eclipse.platform.runtime by eclipse.
the class PreferencesObjectSupplier method getNodePath.
private String getNodePath(IObjectDescriptor descriptor, Class<?> requestingObject) {
if (descriptor == null)
return null;
Preference qualifier = descriptor.getQualifier(Preference.class);
String nodePath = qualifier.nodePath();
if (nodePath == null || nodePath.length() == 0) {
if (requestingObject == null)
return null;
nodePath = FrameworkUtil.getBundle(requestingObject).getSymbolicName();
}
return nodePath;
}
use of org.eclipse.e4.core.di.suppliers.IObjectDescriptor in project eclipse.platform.runtime by eclipse.
the class ContextObjectSupplier method get.
@Override
public void get(IObjectDescriptor[] descriptors, Object[] actualArgs, final IRequestor requestor, boolean initial, boolean track, boolean group) {
final String[] keys = new String[descriptors.length];
final boolean[] active = new boolean[descriptors.length];
for (int i = 0; i < descriptors.length; i++) {
String key = getKey(descriptors[i]);
if ((actualArgs[i] == IInjector.NOT_A_VALUE))
keys[i] = key;
else if (// allow provider to override IEclipseContext
ECLIPSE_CONTEXT_NAME.equals(key))
keys[i] = ECLIPSE_CONTEXT_NAME;
else
keys[i] = null;
if (descriptors[i] == null)
active[i] = false;
else
active[i] = (descriptors[i].hasQualifier(Active.class));
}
if (requestor != null && track) {
// only track if requested
if (initial) {
RunAndTrack trackable = new ContextInjectionListener(context, actualArgs, keys, active, requestor, group);
context.runAndTrack(trackable);
} else {
// we do track if this is done inside a computation, but don't create another runnable
fillArgs(actualArgs, keys, active);
}
} else {
if (descriptors.length > 0) {
pauseRecording();
try {
fillArgs(actualArgs, keys, active);
} finally {
resumeRecording();
}
}
}
}
use of org.eclipse.e4.core.di.suppliers.IObjectDescriptor in project eclipse.platform.runtime by eclipse.
the class OSGiObjectSupplier method get.
@Override
public Object get(IObjectDescriptor descriptor, IRequestor requestor, boolean track, boolean group) {
final Class<?> requestingObjectClass = requestor.getRequestingObjectClass();
final Type desiredType = descriptor.getDesiredType();
if (BundleContext.class.equals(desiredType)) {
final Bundle bundle = FrameworkUtil.getBundle(requestingObjectClass);
// Iff track is request and there is no listener yet, lets track the bundle
if (track) {
if (!requestor2listener.containsKey(requestor)) {
track(bundle, requestor);
}
// Handlers only executed once and thus don't track the BC/Bundle.
// Still guard to now de-register a non-existing listener.
} else if (requestor2listener.containsKey(requestor)) {
untrack(requestor);
}
final BundleContext bundleContext = bundle.getBundleContext();
if (bundleContext != null) {
return bundleContext;
} else if (descriptor.getQualifier(Optional.class) != null) {
// Do not have a bundle context but requestor has marked the parameter/field optional
return null;
}
// $NON-NLS-1$ //$NON-NLS-2$
throw new InjectionException("Unable to inject BundleContext: " + bundle.getSymbolicName() + " bundle is not active or starting/stopping");
} else if (Bundle.class.equals(desiredType)) {
// state. However, the requestor will go away along with its bundle anyway.
return FrameworkUtil.getBundle(requestingObjectClass);
}
// Annotation used with unsupported type
return null;
}
use of org.eclipse.e4.core.di.suppliers.IObjectDescriptor in project eclipse.platform.runtime by eclipse.
the class ServiceSupplier method get.
@Override
public Object get(IObjectDescriptor descriptor, IRequestor requestor, boolean track, boolean group) {
Type desiredType = descriptor.getDesiredType();
Bundle b = FrameworkUtil.getBundle(requestor.getRequestingObjectClass());
Service qualifier = descriptor.getQualifier(Service.class);
if (desiredType instanceof ParameterizedType) {
ParameterizedType t = (ParameterizedType) desiredType;
if (t.getRawType() == Collections.class || t.getRawType() == List.class) {
return handleCollection(b, t.getActualTypeArguments()[0], requestor, track && qualifier.dynamic(), qualifier);
}
}
return handleSingle(b, desiredType, requestor, descriptor, track && qualifier.dynamic(), qualifier);
}
use of org.eclipse.e4.core.di.suppliers.IObjectDescriptor in project eclipse.platform.runtime by eclipse.
the class ExtendedSupplierInjectionTests method testSupplierOrdering.
/**
* bug 428837: ensure suppliers are ranked by service.ranking
*/
@Test
public void testSupplierOrdering() {
BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext();
ExtendedObjectSupplier supplier = new ExtendedObjectSupplier() {
@Override
public Object get(IObjectDescriptor descriptor, IRequestor requestor, boolean track, boolean group) {
// TODO Auto-generated method stub
return null;
}
};
Dictionary<String, Object> properties = new Hashtable<>();
properties.put(ExtendedObjectSupplier.SERVICE_CONTEXT_KEY, EventTopic.class.getName());
properties.put(Constants.SERVICE_RANKING, 100);
ServiceRegistration<?> sr = bc.registerService(ExtendedObjectSupplier.SERVICE_NAME, supplier, properties);
try {
assertEquals(supplier, ProviderHelper.findProvider(EventTopic.class.getName(), null));
} finally {
sr.unregister();
}
}
Aggregations