Skip to content

Instantly share code, notes, and snippets.

View mathieuancelin's full-sized avatar

Mathieu ANCELIN mathieuancelin

View GitHub Profile
<dependency>
<groupId>org.jboss.weld.osgi</groupId>
<artifactId>weld-osgi-core-api</artifactId>
<version>1.1.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
@Inject Bundle bundle;
@Inject BundleContext context;
@Inject @BundleHeaders Map<String, String> headers;
@Inject @BundleHeader("Bundle-SymbolicName") String symbolicName;
@Inject @BundleDataFile("text.txt") File text;
@Publish
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);
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()
@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 {
@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 / 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 / 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; \
public class ServiceListener {
public void bindService(MyService service) {
}
public void unbindService(MyService service) {
}
}
// with configuration
@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");