Created
June 28, 2011 10:00
-
-
Save anpieber/1050835 to your computer and use it in GitHub Desktop.
injection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/service/src/main/java/org/ops4j/pax/wicket/api/PaxWicketApplicationFactory.java b/service/src/main/java/org/ops4j/pax/wicket/api/PaxWicketApplicationFactory.java | |
| index d724980..6b9a800 100644 | |
| --- a/service/src/main/java/org/ops4j/pax/wicket/api/PaxWicketApplicationFactory.java | |
| +++ b/service/src/main/java/org/ops4j/pax/wicket/api/PaxWicketApplicationFactory.java | |
| @@ -97,6 +97,8 @@ public final class PaxWicketApplicationFactory implements IWebApplicationFactory | |
| private ServiceRegistration bdciRegistration; | |
| private BundleDelegatingComponentInstanciationListener bdci; | |
| + private final String defaultInjectionSource; | |
| + | |
| /** | |
| * Construct an instance of {@code PaxWicketApplicationFactory} with the specified arguments. | |
| * | |
| @@ -114,7 +116,7 @@ public final class PaxWicketApplicationFactory implements IWebApplicationFactory | |
| String mountPoint, | |
| String applicationName) | |
| throws IllegalArgumentException { | |
| - this(context, homepageClass, mountPoint, applicationName, null, null); | |
| + this(context, homepageClass, mountPoint, applicationName, null, null, null); | |
| } | |
| /** | |
| @@ -136,7 +138,7 @@ public final class PaxWicketApplicationFactory implements IWebApplicationFactory | |
| String mountPoint, | |
| String applicationName, ApplicationFactory applicationFactory) | |
| throws IllegalArgumentException { | |
| - this(context, homepageClass, mountPoint, applicationName, applicationFactory, null); | |
| + this(context, homepageClass, mountPoint, applicationName, applicationFactory, null, null); | |
| } | |
| /** | |
| @@ -157,8 +159,11 @@ public final class PaxWicketApplicationFactory implements IWebApplicationFactory | |
| BundleContext context, | |
| Class<? extends Page> homepageClass, | |
| String mountPoint, | |
| - String applicationName, ApplicationFactory applicationFactory, Map<?, ?> contextParams) | |
| + String applicationName, ApplicationFactory applicationFactory, Map<?, ?> contextParams, | |
| + String defaultInjectionSource) | |
| throws IllegalArgumentException { | |
| + this.defaultInjectionSource = | |
| + defaultInjectionSource == null ? PaxWicketBean.INJECTION_SOURCE_UNDEFINED : defaultInjectionSource; | |
| validateNotNull(context, "context"); | |
| validateNotNull(homepageClass, "homepageClass"); | |
| validateNotNull(mountPoint, "mountPoint"); | |
| @@ -384,7 +389,9 @@ public final class PaxWicketApplicationFactory implements IWebApplicationFactory | |
| bdcr = new BundleDelegatingClassResolver(bundleContext, applicationName, bundle); | |
| bdcrRegistration = bundleContext.registerService(IClassResolver.class.getName(), bdcr, config); | |
| - bdci = new BundleDelegatingComponentInstanciationListener(bundleContext, applicationName, bundle); | |
| + bdci = | |
| + new BundleDelegatingComponentInstanciationListener(bundleContext, applicationName, bundle, | |
| + defaultInjectionSource); | |
| bdciRegistration = | |
| bundleContext.registerService(PaxWicketInjector.class.getName(), bdci, config); | |
| } | |
| diff --git a/service/src/main/java/org/ops4j/pax/wicket/api/PaxWicketBean.java b/service/src/main/java/org/ops4j/pax/wicket/api/PaxWicketBean.java | |
| index 8fbd3c7..505cf64 100644 | |
| --- a/service/src/main/java/org/ops4j/pax/wicket/api/PaxWicketBean.java | |
| +++ b/service/src/main/java/org/ops4j/pax/wicket/api/PaxWicketBean.java | |
| @@ -32,8 +32,26 @@ import java.lang.annotation.Target; | |
| @Documented | |
| public @interface PaxWicketBean { | |
| + /** | |
| + * Will always (and only) search for a spring application context | |
| + */ | |
| public static final String INJECTION_SOURCE_SPRING = "spring"; | |
| + /** | |
| + * Will always (and only) search for a blueprint application context | |
| + */ | |
| public static final String INJECTION_SOURCE_BLUEPRINT = "blueprint"; | |
| + /** | |
| + * Will scan for blueprint and spring context; if none or both are found INJECTION_SOURCE_NULL is used. | |
| + */ | |
| + public static final String INJECTION_SOURCE_SCAN = "scan"; | |
| + /** | |
| + * Will simply inject null instead of a proxy | |
| + */ | |
| + public static final String INJECTION_SOURCE_NULL = "null"; | |
| + /** | |
| + * Uses other, general default values | |
| + */ | |
| + public static final String INJECTION_SOURCE_UNDEFINED = "null"; | |
| /** | |
| * Optional attribute for specifying the name of the bean. If not specified, the bean will be looked up by the type | |
| @@ -41,4 +59,9 @@ public @interface PaxWicketBean { | |
| */ | |
| String name() default ""; | |
| + /** | |
| + * Allows to override the source of the injection directly in the source code | |
| + */ | |
| + String injectionSource() default INJECTION_SOURCE_UNDEFINED; | |
| + | |
| } | |
| diff --git a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/AbstractProxyTargetLocator.java b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/AbstractProxyTargetLocator.java | |
| index 4ec67c7..1c83c13 100644 | |
| --- a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/AbstractProxyTargetLocator.java | |
| +++ b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/AbstractProxyTargetLocator.java | |
| @@ -43,6 +43,17 @@ public abstract class AbstractProxyTargetLocator<Container> implements IProxyTar | |
| this.overwrites = overwrites; | |
| } | |
| + public boolean hasApplicationContext() { | |
| + String filter = getApplicationContextFilter(bundleContext.getBundle().getSymbolicName()); | |
| + ServiceReference[] references = null; | |
| + try { | |
| + references = bundleContext.getServiceReferences(getContainerClass().getName(), filter); | |
| + } catch (InvalidSyntaxException e) { | |
| + throw new IllegalStateException("not possible", e); | |
| + } | |
| + return references != null && references.length != 0; | |
| + } | |
| + | |
| public Object locateProxyTarget() { | |
| if (bundleContext == null) { | |
| throw new IllegalStateException("Bundle context is not allowed to be null"); | |
| diff --git a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/ApplicationDecorator.java b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/ApplicationDecorator.java | |
| index 4ac63ce..aa612ca 100644 | |
| --- a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/ApplicationDecorator.java | |
| +++ b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/ApplicationDecorator.java | |
| @@ -23,6 +23,7 @@ import java.util.Map; | |
| import org.apache.wicket.Page; | |
| import org.ops4j.pax.wicket.api.ApplicationFactory; | |
| import org.ops4j.pax.wicket.api.PaxWicketApplicationFactory; | |
| +import org.ops4j.pax.wicket.api.PaxWicketBean; | |
| import org.osgi.framework.BundleContext; | |
| import org.osgi.framework.ServiceRegistration; | |
| import org.slf4j.Logger; | |
| @@ -40,6 +41,7 @@ public class ApplicationDecorator implements InjectionAwareDecorator { | |
| private Map<String, String> contextParams; | |
| private PaxWicketApplicationFactory paxWicketApplicationService; | |
| private ServiceRegistration serviceRegistration; | |
| + private String injectionSource = PaxWicketBean.INJECTION_SOURCE_UNDEFINED; | |
| public ApplicationDecorator() { | |
| } | |
| @@ -68,6 +70,10 @@ public class ApplicationDecorator implements InjectionAwareDecorator { | |
| this.contextParams = contextParams; | |
| } | |
| + public void setInjectionSource(String injectionSource) { | |
| + this.injectionSource = injectionSource; | |
| + } | |
| + | |
| public void start() throws Exception { | |
| LOGGER.info("Trying to register pax-wicket application with the following settings: bundleContext: {}, " | |
| + "homepageClass: {}, mountPoint: {}, applicationName: {}, applicationFactory: {}", | |
| @@ -78,7 +84,7 @@ public class ApplicationDecorator implements InjectionAwareDecorator { | |
| LOGGER.debug("ApplicationFactory is provided; creating paxwicket applicaiton"); | |
| paxWicketApplicationService = | |
| new PaxWicketApplicationFactory(bundleContext, homepageClass, mountPoint, applicationName, | |
| - applicationFactory, contextParams); | |
| + applicationFactory, contextParams, injectionSource); | |
| } else { | |
| LOGGER.debug("No own application factory found; falling back to old method"); | |
| paxWicketApplicationService = | |
| diff --git a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/BundleAnalysingComponentInstantiationListener.java b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/BundleAnalysingComponentInstantiationListener.java | |
| index b4eb6b7..114523b 100644 | |
| --- a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/BundleAnalysingComponentInstantiationListener.java | |
| +++ b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/BundleAnalysingComponentInstantiationListener.java | |
| @@ -39,10 +39,12 @@ public class BundleAnalysingComponentInstantiationListener extends AbstractPaxWi | |
| private final BundleContext bundleContext; | |
| private String bundleResources = ""; | |
| + private final String defaultInjectionSource; | |
| @SuppressWarnings("unchecked") | |
| - public BundleAnalysingComponentInstantiationListener(BundleContext bundleContext) { | |
| + public BundleAnalysingComponentInstantiationListener(BundleContext bundleContext, String defaultInjectionSource) { | |
| this.bundleContext = bundleContext; | |
| + this.defaultInjectionSource = defaultInjectionSource; | |
| Enumeration<URL> entries = bundleContext.getBundle().findEntries("/", "*.class", true); | |
| while (entries.hasMoreElements()) { | |
| String urlRepresentation = | |
| @@ -75,6 +77,9 @@ public class BundleAnalysingComponentInstantiationListener extends AbstractPaxWi | |
| injectionSource = ((OverwriteProxy) ((Factory) component).getCallback(0)).getInjectionSource(); | |
| realClass = realClass.getSuperclass(); | |
| } | |
| + if (injectionSource == null || injectionSource.equals("")) { | |
| + injectionSource = defaultInjectionSource; | |
| + } | |
| Thread.currentThread().setContextClassLoader(realClass.getClassLoader()); | |
| List<Field> fields = getFields(realClass); | |
| @@ -82,6 +87,10 @@ public class BundleAnalysingComponentInstantiationListener extends AbstractPaxWi | |
| if (!field.isAnnotationPresent(PaxWicketBean.class)) { | |
| continue; | |
| } | |
| + PaxWicketBean annotation = field.getAnnotation(PaxWicketBean.class); | |
| + if (!annotation.injectionSource().equals(PaxWicketBean.INJECTION_SOURCE_UNDEFINED)) { | |
| + injectionSource = annotation.injectionSource(); | |
| + } | |
| Object proxy = createProxy(field, realClass, overwrites, injectionSource); | |
| setField(component, field, proxy); | |
| } | |
| @@ -97,23 +106,51 @@ public class BundleAnalysingComponentInstantiationListener extends AbstractPaxWi | |
| private IProxyTargetLocator createProxyTargetLocator(Field field, Class<?> page, Map<String, String> overwrites, | |
| String injectionSource) { | |
| + if (PaxWicketBean.INJECTION_SOURCE_NULL.equals(injectionSource) | |
| + || PaxWicketBean.INJECTION_SOURCE_UNDEFINED.equals(injectionSource)) { | |
| + return null; | |
| + } | |
| PaxWicketBean annotation = field.getAnnotation(PaxWicketBean.class); | |
| + AbstractProxyTargetLocator<?> springBeanTargetLocator = | |
| + resolveSpringBeanTargetLocator(field, page, annotation, overwrites); | |
| + AbstractProxyTargetLocator<?> blueprintBeanTargetLocator = | |
| + resolveBlueprintBeanTargetLocator(field, page, annotation, overwrites); | |
| if (PaxWicketBean.INJECTION_SOURCE_SPRING.equals(injectionSource)) { | |
| - return resolveSpringBeanTargetLocator(field, page, annotation, overwrites); | |
| + return springBeanTargetLocator; | |
| } | |
| if (PaxWicketBean.INJECTION_SOURCE_BLUEPRINT.equals(injectionSource)) { | |
| - return resolveBlueprintBeanTargetLocator(field, page, annotation, overwrites); | |
| + return blueprintBeanTargetLocator; | |
| + } | |
| + if (PaxWicketBean.INJECTION_SOURCE_SCAN.equals(injectionSource)) { | |
| + boolean springBeanTargetLocatorHasApplicationContext = springBeanTargetLocator.hasApplicationContext(); | |
| + boolean blueprintBeanTargetLocatorHasApplicationContext = | |
| + blueprintBeanTargetLocator.hasApplicationContext(); | |
| + if (springBeanTargetLocatorHasApplicationContext && blueprintBeanTargetLocatorHasApplicationContext) { | |
| + throw new IllegalStateException( | |
| + "INJECTION_SOURCE_SCAN cannot be used if spring & blueprint context exist."); | |
| + } | |
| + if (!springBeanTargetLocatorHasApplicationContext && !blueprintBeanTargetLocatorHasApplicationContext) { | |
| + throw new IllegalStateException( | |
| + "INJECTION_SOURCE_SCAN cannot be used with neither blueprint nor spring context"); | |
| + } | |
| + if (springBeanTargetLocatorHasApplicationContext) { | |
| + return springBeanTargetLocator; | |
| + } | |
| + if (blueprintBeanTargetLocatorHasApplicationContext) { | |
| + return blueprintBeanTargetLocator; | |
| + } | |
| } | |
| - LOGGER.warn("No injection source found for field [{}] in class [{}]", field.getName(), page.getName()); | |
| - return null; | |
| + throw new IllegalStateException(String.format("No injection source found for field [%s] in class [%s]", | |
| + field.getName(), page.getName())); | |
| } | |
| - private IProxyTargetLocator resolveSpringBeanTargetLocator(Field field, Class<?> page, | |
| + private AbstractProxyTargetLocator<?> resolveSpringBeanTargetLocator(Field field, Class<?> page, | |
| PaxWicketBean annotation, Map<String, String> overwrites) { | |
| return new SpringBeanProxyTargetLocator(bundleContext, annotation, getBeanType(field), page, overwrites); | |
| } | |
| - private IProxyTargetLocator resolveBlueprintBeanTargetLocator(Field field, Class<?> page, PaxWicketBean annotation, | |
| + private AbstractProxyTargetLocator<?> resolveBlueprintBeanTargetLocator(Field field, Class<?> page, | |
| + PaxWicketBean annotation, | |
| Map<String, String> overwrites) { | |
| return new BlueprintBeanProxyTargetLocator(bundleContext, annotation, getBeanType(field), page, overwrites); | |
| } | |
| diff --git a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/BundleDelegatingComponentInstanciationListener.java b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/BundleDelegatingComponentInstanciationListener.java | |
| index 074d561..3028f97 100644 | |
| --- a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/BundleDelegatingComponentInstanciationListener.java | |
| +++ b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/BundleDelegatingComponentInstanciationListener.java | |
| @@ -55,14 +55,19 @@ public class BundleDelegatingComponentInstanciationListener extends ServiceTrack | |
| private final String applicationName; | |
| private final Bundle paxWicketBundle; | |
| + private final String injectionSource; | |
| + | |
| public BundleDelegatingComponentInstanciationListener(BundleContext context, String applicationName, | |
| - Bundle paxWicketBundle) { | |
| + Bundle paxWicketBundle, String injectionSource) { | |
| super(context, createFilter(context), null); | |
| this.applicationName = applicationName; | |
| this.paxWicketBundle = paxWicketBundle; | |
| + this.injectionSource = injectionSource; | |
| + | |
| listeners = new HashSet<BundleAnalysingComponentInstantiationListener>(); | |
| - listeners.add(new BundleAnalysingComponentInstantiationListener(paxWicketBundle.getBundleContext())); | |
| + listeners.add(new BundleAnalysingComponentInstantiationListener(paxWicketBundle.getBundleContext(), | |
| + injectionSource)); | |
| open(true); | |
| } | |
| @@ -85,13 +90,13 @@ public class BundleDelegatingComponentInstanciationListener extends ServiceTrack | |
| LOGGER.debug("Applicationname {} does not match service application name {}", appName, applicationName); | |
| return null; | |
| } | |
| - LOGGER.info("Adding bundle {} to DelegatingComponentInstanciationListener", | |
| + LOGGER.info("Adding bundle {} to DelegatingComponentInstanciationListener", | |
| serviceReference.getBundle().getSymbolicName()); | |
| synchronized (this) { | |
| Bundle bundle = serviceReference.getBundle(); | |
| HashSet<BundleAnalysingComponentInstantiationListener> clone = | |
| (HashSet<BundleAnalysingComponentInstantiationListener>) listeners.clone(); | |
| - clone.add(new BundleAnalysingComponentInstantiationListener(bundle.getBundleContext())); | |
| + clone.add(new BundleAnalysingComponentInstantiationListener(bundle.getBundleContext(), injectionSource)); | |
| listeners = clone; | |
| } | |
| return super.addingService(serviceReference); | |
| @@ -106,7 +111,8 @@ public class BundleDelegatingComponentInstanciationListener extends ServiceTrack | |
| } | |
| HashSet<BundleAnalysingComponentInstantiationListener> revisedSet = | |
| new HashSet<BundleAnalysingComponentInstantiationListener>(); | |
| - revisedSet.add(new BundleAnalysingComponentInstantiationListener(paxWicketBundle.getBundleContext())); | |
| + revisedSet.add(new BundleAnalysingComponentInstantiationListener(paxWicketBundle.getBundleContext(), | |
| + injectionSource)); | |
| try { | |
| LOGGER.info("Removing bundle {} to DelegatingClassLoader", serviceReference.getBundle().getSymbolicName()); | |
| synchronized (this) { | |
| @@ -114,7 +120,7 @@ public class BundleDelegatingComponentInstanciationListener extends ServiceTrack | |
| if (serviceReferences != null) { | |
| for (ServiceReference ref : serviceReferences) { | |
| revisedSet.add(new BundleAnalysingComponentInstantiationListener(ref.getBundle() | |
| - .getBundleContext())); | |
| + .getBundleContext(), injectionSource)); | |
| } | |
| } | |
| listeners = revisedSet; | |
| diff --git a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/BundleInjectionProviderHelperDecorator.java b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/BundleInjectionProviderHelperDecorator.java | |
| index c0c2d0c..c48f661 100644 | |
| --- a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/BundleInjectionProviderHelperDecorator.java | |
| +++ b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/BundleInjectionProviderHelperDecorator.java | |
| @@ -23,12 +23,14 @@ public class BundleInjectionProviderHelperDecorator implements InjectionAwareDec | |
| private String applicationName; | |
| private BundleContext bundleContext; | |
| private BundleInjectionProviderHelper bundleInjectionProviderHelper; | |
| + private String injectionSource; | |
| public BundleInjectionProviderHelperDecorator() { | |
| } | |
| public void start() throws Exception { | |
| - bundleInjectionProviderHelper = new BundleInjectionProviderHelper(bundleContext, applicationName); | |
| + bundleInjectionProviderHelper = | |
| + new BundleInjectionProviderHelper(bundleContext, applicationName, injectionSource); | |
| bundleInjectionProviderHelper.register(); | |
| } | |
| @@ -44,4 +46,8 @@ public class BundleInjectionProviderHelperDecorator implements InjectionAwareDec | |
| this.applicationName = applicationName; | |
| } | |
| + public void setInjectionSource(String injectionSource) { | |
| + this.injectionSource = injectionSource; | |
| + } | |
| + | |
| } | |
| diff --git a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/ContentSourceFactoryDecorator.java b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/ContentSourceFactoryDecorator.java | |
| index 957d9d2..3e6a565 100644 | |
| --- a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/ContentSourceFactoryDecorator.java | |
| +++ b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/ContentSourceFactoryDecorator.java | |
| @@ -141,14 +141,14 @@ public class ContentSourceFactoryDecorator implements TabContentSource<ITab>, Co | |
| public ITab createSourceTab() { | |
| BundleAnalysingComponentInstantiationListener componentInstantiationListener = | |
| - new BundleAnalysingComponentInstantiationListener(bundleContext); | |
| + new BundleAnalysingComponentInstantiationListener(bundleContext, injectionSource); | |
| ClassLoader originalClassloader = Thread.currentThread().getContextClassLoader(); | |
| try { | |
| Thread.currentThread().setContextClassLoader(contentSourceClass.getClassLoader()); | |
| ITab tab = null; | |
| Enhancer e = new Enhancer(); | |
| e.setSuperclass(contentSourceClass); | |
| - e.setCallback(new ComponentProxy(injectionSource, overwrites)); | |
| + e.setCallback(new ComponentProxy(null, overwrites)); | |
| tab = (ITab) e.create(); | |
| componentInstantiationListener.inject(tab); | |
| return tab; | |
| @@ -162,14 +162,14 @@ public class ContentSourceFactoryDecorator implements TabContentSource<ITab>, Co | |
| public ITab createSourceTab(String title) { | |
| BundleAnalysingComponentInstantiationListener componentInstantiationListener = | |
| - new BundleAnalysingComponentInstantiationListener(bundleContext); | |
| + new BundleAnalysingComponentInstantiationListener(bundleContext, injectionSource); | |
| ClassLoader originalClassloader = Thread.currentThread().getContextClassLoader(); | |
| try { | |
| Thread.currentThread().setContextClassLoader(contentSourceClass.getClassLoader()); | |
| ITab tab = null; | |
| Enhancer e = new Enhancer(); | |
| e.setSuperclass(contentSourceClass); | |
| - e.setCallback(new ComponentProxy(injectionSource, overwrites)); | |
| + e.setCallback(new ComponentProxy(null, overwrites)); | |
| tab = (ITab) e.create(new Class[]{ Model.class }, new Object[]{ new Model<String>(title) }); | |
| componentInstantiationListener.inject(tab); | |
| return tab; | |
| diff --git a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/blueprint/BlueprintApplicationBeanDefinitionParser.java b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/blueprint/BlueprintApplicationBeanDefinitionParser.java | |
| index 1119e4a..cf3c83c 100644 | |
| --- a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/blueprint/BlueprintApplicationBeanDefinitionParser.java | |
| +++ b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/blueprint/BlueprintApplicationBeanDefinitionParser.java | |
| @@ -17,6 +17,7 @@ package org.ops4j.pax.wicket.internal.injection.blueprint; | |
| import org.apache.aries.blueprint.ParserContext; | |
| import org.apache.aries.blueprint.mutable.MutableBeanMetadata; | |
| +import org.ops4j.pax.wicket.api.PaxWicketBean; | |
| import org.ops4j.pax.wicket.internal.injection.ApplicationDecorator; | |
| import org.ops4j.pax.wicket.internal.injection.InjectionParserUtil; | |
| import org.w3c.dom.Element; | |
| @@ -37,6 +38,13 @@ public class BlueprintApplicationBeanDefinitionParser extends AbstractBlueprintB | |
| addPropertyReferenceFromElement("applicationFactory", element, context, beanMetadata); | |
| addPropertyReferenceForMap("contextParams", context, beanMetadata, | |
| InjectionParserUtil.retrieveContextParam(element)); | |
| + String injectionSource = element.getAttribute("injectionSource"); | |
| + if (injectionSource == null || injectionSource.isEmpty()) { | |
| + beanMetadata.addProperty("injectionSource", | |
| + createStringValue(context, PaxWicketBean.INJECTION_SOURCE_BLUEPRINT)); | |
| + } else { | |
| + beanMetadata.addProperty("injectionSource", createStringValue(context, injectionSource)); | |
| + } | |
| } | |
| } | |
| diff --git a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/blueprint/BlueprintInjectionResolverDefinitionParser.java b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/blueprint/BlueprintInjectionResolverDefinitionParser.java | |
| index c7c9496..dd342d8 100644 | |
| --- a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/blueprint/BlueprintInjectionResolverDefinitionParser.java | |
| +++ b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/blueprint/BlueprintInjectionResolverDefinitionParser.java | |
| @@ -17,6 +17,7 @@ package org.ops4j.pax.wicket.internal.injection.blueprint; | |
| import org.apache.aries.blueprint.ParserContext; | |
| import org.apache.aries.blueprint.mutable.MutableBeanMetadata; | |
| +import org.ops4j.pax.wicket.api.PaxWicketBean; | |
| import org.ops4j.pax.wicket.internal.injection.BundleInjectionProviderHelperDecorator; | |
| import org.w3c.dom.Element; | |
| @@ -31,6 +32,8 @@ public class BlueprintInjectionResolverDefinitionParser extends AbstractBlueprin | |
| protected void extractRemainingMetaData(Element element, ParserContext context, MutableBeanMetadata beanMetadata) | |
| throws Exception { | |
| addPropertyValueFromElement("applicationName", element, context, beanMetadata); | |
| + beanMetadata.addProperty("injectionSource", | |
| + createStringValue(context, PaxWicketBean.INJECTION_SOURCE_BLUEPRINT)); | |
| } | |
| } | |
| diff --git a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/spring/SpringApplicationBeanDefinitionParser.java b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/spring/SpringApplicationBeanDefinitionParser.java | |
| index ce3a954..2e75555 100644 | |
| --- a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/spring/SpringApplicationBeanDefinitionParser.java | |
| +++ b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/spring/SpringApplicationBeanDefinitionParser.java | |
| @@ -18,6 +18,7 @@ | |
| package org.ops4j.pax.wicket.internal.injection.spring; | |
| +import org.ops4j.pax.wicket.api.PaxWicketBean; | |
| import org.ops4j.pax.wicket.internal.injection.ApplicationDecorator; | |
| import org.ops4j.pax.wicket.internal.injection.InjectionParserUtil; | |
| import org.springframework.beans.factory.support.BeanDefinitionBuilder; | |
| @@ -37,6 +38,12 @@ public class SpringApplicationBeanDefinitionParser extends AbstractSpringBeanDef | |
| addPropertyValueFromElement("applicationName", element, bean); | |
| addPropertyReferenceFromElement("applicationFactory", element, bean); | |
| bean.addPropertyValue("contextParams", InjectionParserUtil.retrieveContextParam(element)); | |
| + String injectionSource = element.getAttribute("injectionSource"); | |
| + if (injectionSource == null || injectionSource.isEmpty()) { | |
| + bean.addPropertyValue("injectionSource", PaxWicketBean.INJECTION_SOURCE_SPRING); | |
| + } else { | |
| + bean.addPropertyValue("injectionSource", injectionSource); | |
| + } | |
| } | |
| } | |
| diff --git a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/spring/SpringInjectionResolverDefinitionParser.java b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/spring/SpringInjectionResolverDefinitionParser.java | |
| index 4b786f4..8f6e271 100644 | |
| --- a/service/src/main/java/org/ops4j/pax/wicket/internal/injection/spring/SpringInjectionResolverDefinitionParser.java | |
| +++ b/service/src/main/java/org/ops4j/pax/wicket/internal/injection/spring/SpringInjectionResolverDefinitionParser.java | |
| @@ -15,6 +15,7 @@ | |
| */ | |
| package org.ops4j.pax.wicket.internal.injection.spring; | |
| +import org.ops4j.pax.wicket.api.PaxWicketBean; | |
| import org.ops4j.pax.wicket.internal.injection.BundleInjectionProviderHelperDecorator; | |
| import org.springframework.beans.factory.support.BeanDefinitionBuilder; | |
| import org.w3c.dom.Element; | |
| @@ -29,6 +30,7 @@ public class SpringInjectionResolverDefinitionParser extends AbstractSpringBeanD | |
| @Override | |
| protected void prepareInjection(Element element, BeanDefinitionBuilder builder) { | |
| addPropertyValueFromElement("applicationName", element, builder); | |
| + builder.addPropertyValue("injectionSource", PaxWicketBean.INJECTION_SOURCE_SPRING); | |
| } | |
| } | |
| diff --git a/service/src/main/java/org/ops4j/pax/wicket/util/BundleInjectionProviderHelper.java b/service/src/main/java/org/ops4j/pax/wicket/util/BundleInjectionProviderHelper.java | |
| index 5220d79..f2fd40a 100644 | |
| --- a/service/src/main/java/org/ops4j/pax/wicket/util/BundleInjectionProviderHelper.java | |
| +++ b/service/src/main/java/org/ops4j/pax/wicket/util/BundleInjectionProviderHelper.java | |
| @@ -25,6 +25,7 @@ import java.util.Dictionary; | |
| import java.util.Properties; | |
| import org.ops4j.pax.wicket.api.NoBeanAvailableForInjectionException; | |
| +import org.ops4j.pax.wicket.api.PaxWicketBean; | |
| import org.ops4j.pax.wicket.api.PaxWicketInjector; | |
| import org.ops4j.pax.wicket.internal.injection.BundleAnalysingComponentInstantiationListener; | |
| import org.osgi.framework.BundleContext; | |
| @@ -48,13 +49,16 @@ public final class BundleInjectionProviderHelper { | |
| private BundleAnalysingComponentInstantiationListener bundleAnalysingComponentInstantiationListener; | |
| private final Object lock = new Object(); | |
| + private final String injectionSource; | |
| private ServiceRegistration serviceRegistration; | |
| /** | |
| - * Construct an instance of {@code BundleClassResolver}. | |
| + * Construct an instance of {@code BundleClassResolver}. The injectionSource is defined as constant in | |
| + * {@link PaxWicketBean}. | |
| */ | |
| - public BundleInjectionProviderHelper(BundleContext bundleContext, String applicationName) | |
| + public BundleInjectionProviderHelper(BundleContext bundleContext, String applicationName, String injectionSource) | |
| throws IllegalArgumentException { | |
| + this.injectionSource = injectionSource; | |
| validateNotNull(bundleContext, "bundle"); | |
| this.bundleContext = bundleContext; | |
| serviceProperties = new Properties(); | |
| @@ -99,7 +103,7 @@ public final class BundleInjectionProviderHelper { | |
| } else { | |
| serviceProperties.put(APPLICATION_NAME, applicationName); | |
| bundleAnalysingComponentInstantiationListener = | |
| - new BundleAnalysingComponentInstantiationListener(bundleContext); | |
| + new BundleAnalysingComponentInstantiationListener(bundleContext, injectionSource); | |
| } | |
| if (serviceRegistration != null) { | |
| diff --git a/service/src/main/resources/org/ops4j/pax/wicket/internal/injection/blueprint/wicket.xsd b/service/src/main/resources/org/ops4j/pax/wicket/internal/injection/blueprint/wicket.xsd | |
| index 79edc2c..4403c90 100644 | |
| --- a/service/src/main/resources/org/ops4j/pax/wicket/internal/injection/blueprint/wicket.xsd | |
| +++ b/service/src/main/resources/org/ops4j/pax/wicket/internal/injection/blueprint/wicket.xsd | |
| @@ -36,6 +36,7 @@ | |
| <xsd:attribute name="mountPoint" type="xsd:string" use="required" /> | |
| <xsd:attribute name="applicationName" type="xsd:string" use="required" /> | |
| <xsd:attribute name="applicationFactory" type="xsd:string" /> | |
| + <xsd:attribute name="injectionSource" type="xsd:string" use="optional"/> | |
| </xsd:extension> | |
| </xsd:complexContent> | |
| </xsd:complexType> | |
| diff --git a/service/src/main/resources/org/ops4j/pax/wicket/internal/injection/spring/wicket.xsd b/service/src/main/resources/org/ops4j/pax/wicket/internal/injection/spring/wicket.xsd | |
| index 71ae3e1..0c693d1 100644 | |
| --- a/service/src/main/resources/org/ops4j/pax/wicket/internal/injection/spring/wicket.xsd | |
| +++ b/service/src/main/resources/org/ops4j/pax/wicket/internal/injection/spring/wicket.xsd | |
| @@ -33,6 +33,7 @@ | |
| <xsd:attribute name="mountPoint" type="xsd:string" use="required" /> | |
| <xsd:attribute name="applicationName" type="xsd:string" use="required" /> | |
| <xsd:attribute name="applicationFactory" type="xsd:string" /> | |
| + <xsd:attribute name="injectionSource" type="xsd:string" use="optional"/> | |
| </xsd:extension> | |
| </xsd:complexContent> | |
| </xsd:complexType> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment