[weld-commits] Weld SVN: r6233 - in java-se/trunk/src/main/java/org/jboss/weld/environment/se: discovery and 1 other directories.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Sun May 16 04:35:10 EDT 2010
Author: peteroyle
Date: 2010-05-16 04:35:10 -0400 (Sun, 16 May 2010)
New Revision: 6233
Removed:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/util/Reflections.java
Modified:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java
Log:
WELDSE-25: Remove final usage of Reflections and replace with ResourceLoader
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java 2010-05-14 12:49:32 UTC (rev 6232)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java 2010-05-16 08:35:10 UTC (rev 6233)
@@ -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
@@ -46,20 +47,12 @@
{
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();
}
/**
@@ -70,10 +63,20 @@
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);
@@ -91,6 +94,20 @@
}
+ 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
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java 2010-05-14 12:49:32 UTC (rev 6232)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java 2010-05-16 08:35:10 UTC (rev 6233)
@@ -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;
/**
@@ -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;
@@ -71,21 +69,8 @@
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;
- }
}
Deleted: java-se/trunk/src/main/java/org/jboss/weld/environment/se/util/Reflections.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/util/Reflections.java 2010-05-14 12:49:32 UTC (rev 6232)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/util/Reflections.java 2010-05-16 08:35:10 UTC (rev 6233)
@@ -1,62 +0,0 @@
-/**
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.se.util;
-
-/**
- * Reflection utilities
- *
- * @author Pete Muir
- *
- */
-public abstract class Reflections
-{
-
- private Reflections()
- {
- // TODO Auto-generated constructor stub
- }
-
- public static <T> T newInstance(String className, Class<T> expectedType) throws InstantiationException, IllegalAccessException, ClassNotFoundException
- {
- return loadClass(className, expectedType).newInstance();
- }
-
- public static <T> Class<? extends T> loadClass(String className, Class<T> expectedType) throws ClassNotFoundException
- {
- if (Thread.currentThread().getContextClassLoader() != null)
- {
- return Thread.currentThread().getContextClassLoader().loadClass(className).asSubclass(expectedType);
- }
- else
- {
- return Class.forName(className).asSubclass(expectedType);
- }
- }
-
- public static ClassLoader getClassLoader()
- {
- if (Thread.currentThread().getContextClassLoader() != null)
- {
- return Thread.currentThread().getContextClassLoader();
- }
- else
- {
- return Reflections.class.getClassLoader();
- }
- }
-
-}
More information about the weld-commits
mailing list