From ff419a74c4be492f3cc461d8d841989416a48460 Mon Sep 17 00:00:00 2001 From: Tom Schindl Date: Mon, 20 Jan 2014 11:11:18 +0100 Subject: Bug 426090 - Add abstraction for ContextInjectionFactory --- .../META-INF/MANIFEST.MF | 4 +-- .../services/scopedobjectfactoryfunction.xml | 8 +++++ .../build.properties | 3 +- .../internal/ScopedObjectFactoryFunction.java | 40 ++++++++++++++++++++++ .../eclipse/fx/core/di/ScopedObjectFactory.java | 26 ++++++++++++++ 5 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/scopedobjectfactoryfunction.xml create mode 100644 bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ScopedObjectFactoryFunction.java create mode 100644 bundles/runtime/org.eclipse.fx.core.di/src/org/eclipse/fx/core/di/ScopedObjectFactory.java (limited to 'bundles') diff --git a/bundles/runtime/org.eclipse.fx.core.di.context/META-INF/MANIFEST.MF b/bundles/runtime/org.eclipse.fx.core.di.context/META-INF/MANIFEST.MF index dc0a1ada6..327b13d5c 100644 --- a/bundles/runtime/org.eclipse.fx.core.di.context/META-INF/MANIFEST.MF +++ b/bundles/runtime/org.eclipse.fx.core.di.context/META-INF/MANIFEST.MF @@ -44,5 +44,5 @@ Import-Package: javafx.animation;version="2.2.0";resolution:=optional, javafx.util.converter;version="2.2.0";resolution:=optional, javax.annotation;version="1.1.0", javax.inject;version="1.0.0" -Service-Component: OSGI-INF/services/obervableadapter.xml,OSGI-INF/services/fxpropertyadapter.xml, - OSGI-INF/services/valuesupplier.xml +Service-Component: OSGI-INF/services/obervableadapter.xml,OSGI-INF/services/fxpropertyadapter.xml,OSGI-INF/services/valuesupplier.xml, + OSGI-INF/services/scopedobjectfactoryfunction.xml diff --git a/bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/scopedobjectfactoryfunction.xml b/bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/scopedobjectfactoryfunction.xml new file mode 100644 index 000000000..53f4d2ca7 --- /dev/null +++ b/bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/scopedobjectfactoryfunction.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/bundles/runtime/org.eclipse.fx.core.di.context/build.properties b/bundles/runtime/org.eclipse.fx.core.di.context/build.properties index 20a57cbde..246e7fc12 100644 --- a/bundles/runtime/org.eclipse.fx.core.di.context/build.properties +++ b/bundles/runtime/org.eclipse.fx.core.di.context/build.properties @@ -2,7 +2,8 @@ output.. = bin/ bin.includes = META-INF/,\ .,\ OSGI-INF/,\ - OSGI-INF/services/valuesupplier.xml + OSGI-INF/services/valuesupplier.xml,\ + OSGI-INF/services/scopedobjectfactoryfunction.xml source.. = src/ additional.bundles = org.eclipse.jdt.annotation jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation diff --git a/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ScopedObjectFactoryFunction.java b/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ScopedObjectFactoryFunction.java new file mode 100644 index 000000000..8d5fc1741 --- /dev/null +++ b/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ScopedObjectFactoryFunction.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2013 BestSolution.at and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tom Schindl - initial API and implementation + *******************************************************************************/ +package org.eclipse.fx.core.di.context.internal; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.fx.core.di.ScopedObjectFactory; + +/** + * Context function to create requested object factory + */ +public class ScopedObjectFactoryFunction extends ContextFunction { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return new ScopedObjectFactoryImpl(context); + } + + static class ScopedObjectFactoryImpl implements ScopedObjectFactory { + private final IEclipseContext context; + + ScopedObjectFactoryImpl(IEclipseContext context) { + this.context = context; + } + + @Override + public C newInstance(Class c) { + return ContextInjectionFactory.make(c, this.context); + } + + } +} diff --git a/bundles/runtime/org.eclipse.fx.core.di/src/org/eclipse/fx/core/di/ScopedObjectFactory.java b/bundles/runtime/org.eclipse.fx.core.di/src/org/eclipse/fx/core/di/ScopedObjectFactory.java new file mode 100644 index 000000000..e9fe34035 --- /dev/null +++ b/bundles/runtime/org.eclipse.fx.core.di/src/org/eclipse/fx/core/di/ScopedObjectFactory.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2013 BestSolution.at and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tom Schindl - initial API and implementation + *******************************************************************************/ +package org.eclipse.fx.core.di; + +/** + * An object factory is bound to the local context and is able to create instances using a the backing DI + * container + */ +public interface ScopedObjectFactory { + /** + * Create a new instance of the class + * + * @param c + * the class + * @return the instance + */ + public C newInstance(Class c); +} -- cgit v1.2.3