Skip to content

Instantly share code, notes, and snippets.

View mathieuancelin's full-sized avatar

Mathieu ANCELIN mathieuancelin

View GitHub Profile
@mathieuancelin
mathieuancelin / CurrentBundleSingletonProvider.java
Created March 25, 2011 10:51
The custom SingletonProvider using the current class context
package org.jboss.weld.environment.osgi.integration;
import java.util.Hashtable;
import java.util.Map;
import org.jboss.weld.bean.proxy.ProxyMethodHandler;
import org.jboss.weld.bootstrap.api.Singleton;
import org.jboss.weld.bootstrap.api.SingletonProvider;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
package com.sample.ws;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.service.model.MessagePartInfo;
import org.apache.cxf.service.model.OperationInfo;
@ApplicationScoped
public class ServiceListener {
public void bindService(@Observes @Specification(MyService.class) ServiceArrival event) {
System.out.println("A new service just arrived");
MyService arrived = event.type(MyService.class).getService();
}
public void unbindService(@Observes @Specification(MyService.class) ServiceDeparture event) {
System.out.println("A service just went out");
public class ServiceListener {
public void bindService(MyService service) {
}
public void unbindService(MyService service) {
}
}
// with configuration
@mathieuancelin
mathieuancelin / cdi-osgi-api.bnd
Created April 22, 2011 12:10
cdi-osgi-api.bnd
Embed-Dependency *; scope=compile; inline=true; artifactId=!org.osgi.core,
Export-Package org.osgi.cdi.api.extension; \
org.osgi.cdi.api.extension.annotation; \
org.osgi.cdi.api.extension.events; \
org.osgi.cdi.api.integration; \
javax.el; \
javax.inject; \
javax.decorator; \
javax.annotation; \
@mathieuancelin
mathieuancelin / cdi-osgi-impl.bnd
Created April 22, 2011 12:11
cdi-osgi-impl.bnd
Export-Package org.osgi.cdi.impl; \
org.osgi.cdi.impl.extension; \
org.osgi.cdi.impl.extension.services; \
org.osgi.cdi.impl.integration
Import-Package org.osgi.cdi.api.extension; \
org.osgi.cdi.api.extension.annotation; \
org.osgi.cdi.api.extension.events; \
org.osgi.cdi.api.integration; \
javax.inject; \
@mathieuancelin
mathieuancelin / weld-osgi-impl.bnd
Created April 22, 2011 12:12
weld-osgi-impl.bnd
Embed-Dependency *; scope=compile; inline=true; artifactId=!cdi-osgi-api|cdi-osgi-impl|jboss-interceptor-api|javax.inject|jsr250-api|cdi-api|el-api, \
slf4j-jdk14; inline=true
-exportcontents org.jboss.weld.context; \
org.jboss.weld.ejb; \
org.jboss.weld.bean; \
org.jboss.weld.bean.builtin; \
org.jboss.weld.bean.proxy; \
org.jboss.weld.environment.osgi; \
org.jboss.weld.environment.osgi.integration; \
@mathieuancelin
mathieuancelin / OSGiBridge.java
Created May 13, 2011 08:24
OSGi bridge for hybrid Java EE app
import java.util.Collection;
import java.util.Properties;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleListener;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
public interface OSGiBridge {
import tools.nsc.interpreter.Results._
import tools.nsc.interpreter.IMain
import tools.nsc.Settings
class ResultHolder(var value : Any)
class ScalaInterpreter(settings: Settings) extends IMain(settings) {
val writer = new java.io.StringWriter()
private InjectionTarget it;
private AnnotatedType annotated;
private BeanManager beanManager;
public <T> T create(CreationalContext<T> creationalContext) {
annotated = beanManager.createAnnotatedType(myType);
it = manager.createInjectionTarget(annotated);
T instance = (T) it.produce(creationalContext);
it.inject(instance, creationalContext);
it.postConstruct(instance);