Skip to content

Commit

Permalink
Add Weld-OSGi Integration bundle files
Browse files Browse the repository at this point in the history
  • Loading branch information
arcane86 authored and jharting committed Jul 4, 2013
1 parent 6a53cbf commit 52a0e19
Show file tree
Hide file tree
Showing 19 changed files with 1,492 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ Import-Package org.jboss.weld.environment.osgi.api; \
javassist.tools.web; version=3.14.0

DynamicImport-Package *
Bundle-Activator org.osgi.cdi.impl.Activator
Bundle-Activator org.jboss.weld.environment.osgi.impl.Activator
118 changes: 118 additions & 0 deletions environments/osgi/core/integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,124 @@
</license>
</licenses>
<url>http://www.seamframework.org/Weld</url>

<dependencies>

<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-api</artifactId>
<version>1.1.Beta2</version>
</dependency>

<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-spi</artifactId>
<version>1.1.Beta2</version>
</dependency>

<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0-SP4</version>
</dependency>

<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r06</version>
</dependency>

<dependency>
<groupId>org.jboss.interceptor</groupId>
<artifactId>jboss-interceptor-spi</artifactId>
<version>2.0.0.CR1</version>
</dependency>

<dependency>
<groupId>org.jboss.interceptor</groupId>
<artifactId>jboss-interceptor-core</artifactId>
<version>2.0.0.CR1</version>
</dependency>

<dependency>
<groupId>org.jboss.interceptor</groupId>
<artifactId>jboss-interceptor-api</artifactId>
<version>1.1</version>
</dependency>

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>0.9.26</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>0.9.26</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-ext</artifactId>
<version>1.6.1</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>

<dependency>
<groupId>org.jboss.weld.osgi</groupId>
<artifactId>weld-osgi-core-spi</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.jboss.weld.osgi</groupId>
<artifactId>weld-osgi-core-extension</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>ch.qos.cal10n</groupId>
<artifactId>cal10n-api</artifactId>
<version>0.7.2</version>
</dependency>

</dependencies>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jboss.weld.environment.osgi.impl;

import org.jboss.weld.bootstrap.api.SingletonProvider;
import org.jboss.weld.environment.osgi.impl.integration.BundleSingletonProvider;
import org.jboss.weld.environment.osgi.spi.CDIContainerFactory;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This is the {@link BundleActivator} of the Weld implementation bundle.
* <p/>
* It is responsible for providing a {@link CDIContainerFactory} service using Weld as CDI implementation.
*
* @author Mathieu ANCELIN - SERLI (mathieu.ancelin@serli.com)
* @author Matthieu CLOCHARD - SERLI (matthieu.clochard@serli.com)
*/
public class WeldActivator implements BundleActivator {

private Logger logger = LoggerFactory.getLogger(WeldActivator.class);

private CDIContainerFactory factory = new WeldCDIContainerFactory();
private ServiceRegistration reg = null;

@Override
public void start(BundleContext context) throws Exception {
logger.debug("Weld implementation bundle for CDI-OSGi is starting ...");
SingletonProvider.initialize(new BundleSingletonProvider());
reg = context.registerService(CDIContainerFactory.class.getName(), factory, null);
logger.debug("Weld implementation bundle for CDI-OSGi STARTED");
}

@Override
public void stop(BundleContext context) throws Exception {
logger.debug("Weld implementation bundle for CDI-OSGi is stopping ...");
reg.unregister();
SingletonProvider.reset();
logger.debug("Weld implementation bundle for CDI-OSGi STOPPED");
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jboss.weld.environment.osgi.impl;

import org.jboss.weld.environment.osgi.impl.integration.Weld;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.event.Event;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.spi.BeanManager;
import java.util.ArrayList;
import java.util.Collection;
import org.jboss.weld.environment.osgi.api.events.InterBundleEvent;
import org.jboss.weld.environment.osgi.impl.extension.CDIOSGiExtension;
import org.jboss.weld.environment.osgi.impl.extension.ExtensionActivator;
import org.jboss.weld.environment.osgi.spi.CDIContainer;

/**
* This is the {@link CDIContainer} implementation using Weld.
*
* @author Mathieu ANCELIN - SERLI (mathieu.ancelin@serli.com)
* @author Matthieu CLOCHARD - SERLI (matthieu.clochard@serli.com)
*/
public class WeldCDIContainer implements CDIContainer {

private Logger logger = LoggerFactory.getLogger(WeldCDIContainer.class);

private final Bundle bundle;
private Weld container;
private Collection<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>();

public WeldCDIContainer(Bundle bundle) {
logger.debug("Creation of a new Weld CDI container for bundle {}", bundle);
this.bundle = bundle;
container = new Weld(bundle);
}

@Override
public void setRegistrations(Collection<ServiceRegistration> registrations) {
this.registrations = registrations;
}

@Override
public Collection<ServiceRegistration> getRegistrations() {
return registrations;
}

@Override
public Bundle getBundle() {
return bundle;
}

@Override
public boolean shutdown() {
logger.debug("Weld CDI container is shutting down for bundle {}", bundle);
return container.shutdown();
}

@Override
public void fire(InterBundleEvent event) {
logger.debug("Weld CDI container for bundle {} is firing an inter bundle event: {}", bundle, event);
Long set = CDIOSGiExtension.currentBundle.get();
CDIOSGiExtension.currentBundle.set(bundle.getBundleId());
container.getEvent().select(InterBundleEvent.class,
new ExtensionActivator.SpecificationAnnotation(event.type()),
new ExtensionActivator.SentAnnotation()).fire(event);
if (set != null) {
CDIOSGiExtension.currentBundle.set(set);
} else {
CDIOSGiExtension.currentBundle.remove();
}
}

@Override
public boolean initialize() {
return container.initialize();
}

@Override
public boolean isStarted() {
return container.isStarted();
}

@Override
public Event getEvent() {
return container.getInstance().select(Event.class).get();
}

@Override
public BeanManager getBeanManager() {
return container.getBeanManager();
}

@Override
public Instance<Object> getInstance() {
return container.getInstance();
}

@Override
public Collection<String> getBeanClasses() {
return container.getBeanClasses();
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof WeldCDIContainer)) {
return false;
}

WeldCDIContainer that = (WeldCDIContainer) o;

if (bundle != null ? !bundle.equals(that.bundle) : that.bundle != null) {
return false;
}
if (container != null ? !container.equals(that.container) : that.container != null) {
return false;
}
if (registrations != null ? !registrations.equals(that.registrations) : that.registrations != null) {
return false;
}

return true;
}

@Override
public int hashCode() {
int result = bundle != null ? bundle.hashCode() : 0;
result = 31 * result + (container != null ? container.hashCode() : 0);
result = 31 * result + (registrations != null ? registrations.hashCode() : 0);
return result;
}
}
Loading

0 comments on commit 52a0e19

Please sign in to comment.