Skip to content

Commit

Permalink
WELDSE-25: Remove final usage of Reflections and replace with Resourc…
Browse files Browse the repository at this point in the history
…eLoader
  • Loading branch information
peteroyle committed May 16, 2010
1 parent 68dc85a commit d4e9455
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 93 deletions.
45 changes: 31 additions & 14 deletions src/main/java/org/jboss/weld/environment/se/Weld.java
Expand Up @@ -25,9 +25,10 @@
import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
import org.jboss.weld.environment.se.beans.InstanceManager;
import org.jboss.weld.environment.se.discovery.SEWeldDeployment;
import org.jboss.weld.environment.se.util.Reflections;
import org.jboss.weld.environment.se.util.WeldManagerUtils;
import org.jboss.weld.manager.api.WeldManager;
import org.jboss.weld.resources.DefaultResourceLoader;
import org.jboss.weld.resources.spi.ResourceLoader;

/**
* An alternative means of booting WeldContainer form an arbitrary main method within an
Expand All @@ -46,20 +47,12 @@ public class Weld
{

private static final String BOOTSTRAP_IMPL_CLASS_NAME = "org.jboss.weld.bootstrap.WeldBootstrap";
private final Bootstrap bootstrap;
private final BeanStore applicationBeanStore;
private Bootstrap bootstrap;
private BeanStore applicationBeanStore;
private WeldManager manager;

public Weld()
{
try
{
bootstrap = Reflections.newInstance(BOOTSTRAP_IMPL_CLASS_NAME, Bootstrap.class);
} catch (Exception e)
{
throw new IllegalStateException("Error loading Weld bootstrap, check that Weld is on the classpath", e);
}
this.applicationBeanStore = new ConcurrentHashMapBeanStore();
}

/**
Expand All @@ -70,10 +63,20 @@ public Weld()
public WeldContainer initialize()
{

SEWeldDeployment deployment = new SEWeldDeployment()
this.applicationBeanStore = new ConcurrentHashMapBeanStore();
SEWeldDeployment deployment = initDeployment();

try
{
};
configureDeployment(deployment);
bootstrap = (Bootstrap) deployment.getServices().get(ResourceLoader.class).classForName(BOOTSTRAP_IMPL_CLASS_NAME).newInstance();
} catch (InstantiationException ex)
{
throw new IllegalStateException("Error loading Weld bootstrap, check that Weld is on the classpath", ex);
} catch (IllegalAccessException ex)
{
throw new IllegalStateException("Error loading Weld bootstrap, check that Weld is on the classpath", ex);
}

deployment.scan();

bootstrap.startContainer(Environments.SE, deployment, this.applicationBeanStore);
Expand All @@ -91,6 +94,20 @@ public WeldContainer initialize()

}

private SEWeldDeployment initDeployment()
{
SEWeldDeployment deployment = new SEWeldDeployment()
{
};
configureDeployment(deployment);
// configure a ResourceLoader if one hasn't been already
if (deployment.getServices().get(ResourceLoader.class) == null)
{
deployment.getServices().add(ResourceLoader.class, new DefaultResourceLoader());
}
return deployment;
}

/**
* Clients can subclass and override this method to customise the deployment
* before weld boots up. For example, to add a custom ResourceLoader, you would
Expand Down
Expand Up @@ -21,9 +21,8 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.jboss.weld.bootstrap.spi.Deployment;

import org.jboss.weld.resources.DefaultResourceLoader;
import org.jboss.weld.bootstrap.spi.Deployment;
import org.jboss.weld.resources.spi.ResourceLoader;

/**
Expand All @@ -37,7 +36,6 @@
public abstract class SEWeldDiscovery
{

private ResourceLoader resourceLoader;
private final Deployment deployment;
private final Set<Class<?>> wbClasses;
private final Set<URL> wbUrls;
Expand Down Expand Up @@ -71,21 +69,8 @@ public Set<URL> getWbUrls()

public void scan()
{
Scanner scanner = new URLScanner(resourceLoader(), this);
Scanner scanner = new URLScanner(deployment.getServices().get(ResourceLoader.class), this);
scanner.scanResources(new String[] { "META-INF/beans.xml" });
}

public synchronized ResourceLoader resourceLoader() {
if (this.resourceLoader == null)
{
ResourceLoader aResourceLoader = deployment.getServices().get(ResourceLoader.class);
if (aResourceLoader == null)
{
aResourceLoader = new DefaultResourceLoader();
}
this.resourceLoader = aResourceLoader;
}
return this.resourceLoader;
}

}
62 changes: 0 additions & 62 deletions src/main/java/org/jboss/weld/environment/se/util/Reflections.java

This file was deleted.

0 comments on commit d4e9455

Please sign in to comment.