/** * Register a service * * @param service * the service * @param properties * the properties */ protected void registerService(S service, Map<String, Object> properties) { this.registry.registerObject(getOSGiServiceRank(properties), service); }
/** * Unregister a service * * @param service * the service */ protected void unregisterService(S service) { this.registry.unregisterObject(service); } }
/** * Extract the rank from the OSGi-Service properties * * @param properties * the properties * @return the rank */ public static int getOSGiServiceRank(Map<String, Object> properties) { return getServiceRank(properties, "service.ranking"); //$NON-NLS-1$ }
@Override public boolean test(Input<?> s) { synchronized (modelProviders) { return modelProviders.unsynchronizedStream().filter( m -> m.applies(s)).findFirst().isPresent(); } }
@Override public boolean openEditor(String uri) { EditorOpener opener = objectRegistry.getRankedElements() .stream() .filter( e -> e.test(uri)) .map( e -> (EditorOpener)ContextInjectionFactory.make(e.getType(uri), context)) .filter( e -> e.test(uri)) .findFirst() .orElseGet( () -> (EditorOpener)ContextInjectionFactory.make(DefaultEditorOpener.class, context)); boolean success = opener.openEditor(uri); if( ! success ) { success = ContextInjectionFactory.make(DefaultEditorOpener.class, context).openEditor(uri); } return success; }
@Override public synchronized InputContext getContext(Input<?> input) { return (InputContext)input.getTransientData().computeIfAbsent(CONTEXT_KEY, k -> providerList.unsynchronizedStream() .filter( p -> p.test(input)) .findFirst() .map( p -> p.getContext(input)) .orElse(DEFAULT)); } }
public void registerModelProvider(ConfigurationModelProvider provider, Map<String, Object> properties) { modelProviders.registerObject(getOSGiServiceRank(properties), provider); }
private Outline createOutline(IEclipseContext context) { Input<?> input = (Input<?>) context.get("activeInput"); context.set(Input.class, input); if( input != null ) { Outline rv = outlineCache.get(input); if( rv == null ) { synchronized (registry) { registry.unsynchronizedStream().filter( p -> p.test(input)).findFirst().ifPresent( p -> { outlineCache.put(input, ContextInjectionFactory.make(p.getType(input),context)); }); rv = outlineCache.get(input); } } return rv; } return null; } }
public void unregisterModelProvider(ConfigurationModelProvider provider) { modelProviders.unregisterObject(provider); }
@Reference(cardinality=ReferenceCardinality.MULTIPLE,policyOption=ReferencePolicyOption.GREEDY) public synchronized void registerInputContextProvider(InputContextProvider provider, Map<String, Object> properties) { providerList.registerObject(RankedObjectRegistry.getOSGiServiceRank(properties),provider); }
@Override public final Object compute(IEclipseContext context) { String cacheKey = getCacheKey(); Object o = context.get(cacheKey); if (o != null) { return o; } @SuppressWarnings("unchecked") S sourceValue = (S) context.get(this.selectorTypeKey); Optional<T> value; synchronized (this.registry) { value = this.registry.unsynchronizedStream().filter(d -> d.test(sourceValue)).findFirst() .map(d -> d.create(sourceValue)); } if (value.isPresent()) { o = value.get(); context.set(cacheKey, o); return o; } else { throw new IllegalStateException("Unable to find a service factory for the source value '"+sourceValue+"'"); //$NON-NLS-1$//$NON-NLS-2$ } }
public synchronized void unregisterInputContextProvider(InputContextProvider provider) { providerList.unregisterObject(provider); }
value = this.registry.unsynchronizedStream().filter(p -> p.test(s)).findFirst().map(p -> ContextInjectionFactory.make(p.getType(s), context));