Author: pete.muir(a)jboss.org
Date: 2008-12-24 18:37:34 -0500 (Wed, 24 Dec 2008)
New Revision: 723
Added:
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/Naming.java
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/ResourceLoader.java
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/ResourceLoadingException.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/PropertiesBasedBootstrap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultNaming.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletBootstrap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletContextResourceLoader.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/DeploymentProperties.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockInitialContext.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockResourceLoader.java
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/DeploymentProperties.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/JNDI.java
Modified:
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/spi/WebBeanDiscovery.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EJB.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockBootstrap.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockManagerImpl.java
Log:
Expose classloader and JNDI lookup as part of SPI
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-24
22:55:14 UTC (rev 722)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -57,6 +57,7 @@
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
+import org.jboss.webbeans.resources.spi.Naming;
import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.Strings;
@@ -94,6 +95,9 @@
private Set<Interceptor> interceptors;
private EjbDescriptorCache ejbDescriptorCache;
+
+ // The Naming (JNDI) access
+ private Naming naming;
/**
* Constructor
@@ -715,5 +719,15 @@
// TODO Implement hierarchical managers
return null;
}
+
+ public Naming getNaming()
+ {
+ return naming;
+ }
+
+ public void setNaming(Naming naming)
+ {
+ this.naming = naming;
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2008-12-24
22:55:14 UTC (rev 722)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -43,7 +43,6 @@
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
-import org.jboss.webbeans.util.JNDI;
/**
* An enterprise bean representation
@@ -260,7 +259,7 @@
{
DependentContext.INSTANCE.setActive(true);
// TODO Implement enterprise bean proxies and select the correct jndiName
- return (T) JNDI.lookup(ejbDescriptor.getLocalJndiName());
+ return (T) manager.getNaming().lookup(ejbDescriptor.getLocalJndiName(),
getType());
}
catch (Exception e)
{
Deleted:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/DeploymentProperties.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/DeploymentProperties.java 2008-12-24
22:55:14 UTC (rev 722)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/DeploymentProperties.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -1,159 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, 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.webbeans.bootstrap;
-
-import static org.jboss.webbeans.util.Strings.split;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Properties;
-
-/**
- * Utility class to load deployment properties
- *
- * @author Pete Muir
- */
-public class DeploymentProperties
-{
- // The resource bundle used to control Web Beans RI deployment
- public static final String RESOURCE_BUNDLE =
"META-INF/web-beans-ri.properties";
-
- // The class to work from
- private ClassLoader classLoader;
- // An enumeration of URLs to work on
- private Enumeration<URL> urlEnum;
-
- /**
- * Constructor
- *
- * @param classLoader The classloader to work on
- */
- public DeploymentProperties(ClassLoader classLoader)
- {
- this.classLoader = classLoader;
- }
-
- /**
- * Get a list of possible values for a given key.
- *
- * First, System properties are tried, followed by the specified resource
- * bundle (first in classpath only).
- *
- * Colon (:) deliminated lists are split out. (gotta love Petes choice of
- * ASCII art for that one ;-)
- *
- * @param key The key to search for
- * @return A list of possible values. An empty list is returned if there are
- * no matches.
- */
- public List<String> getPropertyValues(String key)
- {
- List<String> values = new ArrayList<String>();
- addPropertiesFromSystem(key, values);
- addPropertiesFromResourceBundle(key, values);
- return values;
- }
-
- /**
- * Adds matches from system properties
- *
- * @param key The key to match
- * @param values The currently found values
- */
- private void addPropertiesFromSystem(String key, List<String> values)
- {
- addProperty(key, System.getProperty(key), values);
- }
-
- /**
- * Adds matches from detected resource bundles
- *
- * @param key The key to match
- * @param values The currently found values
- */
- private void addPropertiesFromResourceBundle(String key, List<String> values)
- {
- try
- {
- while (getResources().hasMoreElements())
- {
- URL url = getResources().nextElement();
- Properties properties = new Properties();
- InputStream propertyStream = url.openStream();
- try
- {
- properties.load(propertyStream);
- addProperty(key, properties.getProperty(key), values);
- }
- finally
- {
- if (propertyStream != null)
- {
- propertyStream.close();
- }
- }
- }
- }
- catch (IOException e)
- {
- // No - op, file is optional
- }
- }
-
- /**
- * Add the property to the set of properties only if it hasn't already been
- * added
- *
- * @param key The key searched for
- * @param value The value of the property
- * @param values The currently found values
- */
- private void addProperty(String key, String value, List<String> values)
- {
- if (value != null)
- {
- String[] properties = split(value, ":");
- for (String property : properties)
- {
- values.add(property);
- }
-
- }
- }
-
- /**
- * Gets all Web Beans property files relative to the provided classloader
- *
- * @return An enumeration of URLs to the property files
- * @throws IOException If the resource files could not be loaded
- */
- private Enumeration<URL> getResources() throws IOException
- {
-
- if (urlEnum == null)
- {
- urlEnum = classLoader.getResources(RESOURCE_BUNDLE);
- }
- return urlEnum;
- }
-
-}
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/PropertiesBasedBootstrap.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/PropertiesBasedBootstrap.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/PropertiesBasedBootstrap.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -0,0 +1,99 @@
+package org.jboss.webbeans.bootstrap;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.webbeans.ExecutionException;
+
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.resources.DefaultNaming;
+import org.jboss.webbeans.resources.spi.Naming;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.servlet.ServletBootstrap;
+import org.jboss.webbeans.util.DeploymentProperties;
+import org.jboss.webbeans.util.Reflections;
+
+/**
+ * An abstract extension of Bootstrap which uses deployment properties for
+ * configuring the application
+ *
+ * @author Pete Muir
+ *
+ */
+public abstract class PropertiesBasedBootstrap extends WebBeansBootstrap
+{
+
+ private static final LogProvider log =
Logging.getLogProvider(ServletBootstrap.class);
+
+ /**
+ * Returns any class constructor from the merged list defined by the
+ * specified property.
+ * No guarantee is made about which item in the list will returned.
+ *
+ * @param <T> The class type
+ * @param deploymentProperties The deployment properties to be used
+ * @param resourceLoader The resourceLoader to use for class and resource loading
+ * @param propertyName The name of the property to find in the deployment properties
+ * @param expectedType The expected type or super type of the class
+ * @param constructorArguments The arguments of the constructor to select
+ * @return
+ */
+ protected static <T> Constructor<? extends T>
getClassConstructor(DeploymentProperties deploymentProperties, ResourceLoader
resourceLoader, String propertyName, Class<T> expectedType, Class<?> ...
constructorArguments)
+ {
+ for (Class<? extends T> clazz :
DeploymentProperties.getClasses(deploymentProperties, resourceLoader, propertyName,
expectedType))
+ {
+ Constructor<? extends T> constructor =
Reflections.getConstructor((Class<? extends T>) clazz, constructorArguments);
+ if (constructor != null)
+ {
+ return constructor;
+ }
+ }
+ return null;
+ }
+
+ protected static <T> T newInstance(Constructor<T> constructor, Object...
parameters)
+ {
+ try
+ {
+ return constructor.newInstance(parameters);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new ExecutionException("Error instantiating " + constructor,
e);
+ }
+ catch (InstantiationException e)
+ {
+ throw new ExecutionException("Error instantiating " + constructor,
e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new ExecutionException("Error instantiating " + constructor,
e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new ExecutionException("Error instantiating " + constructor,
e);
+ }
+ }
+
+ /**
+ * Only safe to call once resourceloader and deployment properties are set
+ */
+ protected void initProperties()
+ {
+ Constructor<? extends Naming> namingConstructor =
getClassConstructor(getDeploymentProperties(), getResourceLoader(), Naming.PROPERTY_NAME,
Naming.class);
+ if (namingConstructor != null)
+ {
+ getManager().setNaming(newInstance(namingConstructor));
+ }
+ else
+ {
+ getManager().setNaming(new DefaultNaming());
+ }
+ }
+
+
+
+ protected abstract DeploymentProperties getDeploymentProperties();
+
+}
\ No newline at end of file
Property changes on:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/PropertiesBasedBootstrap.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2008-12-24
22:55:14 UTC (rev 722)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -41,8 +41,8 @@
import java.util.Set;
import javax.webbeans.DefinitionException;
-import javax.webbeans.Initializer;
import javax.webbeans.Fires;
+import javax.webbeans.Initializer;
import javax.webbeans.Observer;
import javax.webbeans.Observes;
import javax.webbeans.Obtains;
@@ -59,7 +59,6 @@
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.bindings.InitializedBinding;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
-import org.jboss.webbeans.contexts.DependentContext;
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedItem;
@@ -67,50 +66,52 @@
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.transaction.Transaction;
-import org.jboss.webbeans.util.JNDI;
import org.jboss.webbeans.util.Reflections;
/**
- * Bootstrapping functionality that is run at application startup and detects
+ * Common bootstrapping functionality that is run at application startup and detects
* and register beans
*
* @author Pete Muir
*/
-public class WebBeansBootstrap
+public abstract class WebBeansBootstrap
{
- // The property name of the discovery class
- public static String WEB_BEAN_DISCOVERY_PROPERTY_NAME =
"org.jboss.webbeans.bootstrap.webBeanDiscovery";
+
// The log provider
private static LogProvider log = Logging.getLogProvider(WebBeansBootstrap.class);
- // The Web Beans manager
- protected ManagerImpl manager;
-
- /**
- * Constructor
- *
- * Starts up with the singleton Manager
- */
- public WebBeansBootstrap(ManagerImpl manager)
- {
- this.manager = manager;
- registerManager();
- manager.addContext(DependentContext.INSTANCE);
- }
protected void registerManager()
{
- JNDI.bind(ManagerImpl.JNDI_KEY, manager);
- CurrentManager.setRootManager(manager);
+ getManager().getNaming().bind(ManagerImpl.JNDI_KEY, getManager());
+ CurrentManager.setRootManager(getManager());
}
- public WebBeansBootstrap()
+ public abstract ManagerImpl getManager();
+
+ protected abstract WebBeanDiscovery getWebBeanDiscovery();
+
+ public abstract ResourceLoader getResourceLoader();
+
+ protected void validateBootstrap()
{
- this(new ManagerImpl());
+ if (getManager() == null)
+ {
+ throw new IllegalStateException("getManager() is not set on
bootstrap");
+ }
+ if (getWebBeanDiscovery() == null)
+ {
+ throw new IllegalStateException("WebBeanDiscovery plugin not set on
bootstrap");
+ }
+ if (getResourceLoader() == null)
+ {
+ throw new IllegalStateException("ResourceLoader plugin not set on
bootstrap");
+ }
}
/**
- * Register any beans defined by the provided classes with the manager
+ * Register any beans defined by the provided classes with the getManager()
*
* @param classes The classes to register
*/
@@ -120,7 +121,7 @@
}
/**
- * Register the bean with the manager, including any standard (built in) beans
+ * Register the bean with the getManager(), including any standard (built in) beans
*
* @param classes The classes to register as Web Beans
*/
@@ -128,7 +129,7 @@
{
Set<AbstractBean<?, ?>> beans = createBeans(classes);
beans.addAll(createStandardBeans());
- manager.setBeans(beans);
+ getManager().setBeans(beans);
}
/**
@@ -139,14 +140,15 @@
protected Set<AbstractBean<?, ?>> createStandardBeans()
{
Set<AbstractBean<?, ?>> beans = new HashSet<AbstractBean<?,
?>>();
- createBean(BeanFactory.createSimpleBean(Transaction.class, manager), beans);
- createBean(new SimpleBean<ManagerImpl>(ManagerImpl.class, manager)
+ createBean(BeanFactory.createSimpleBean(Transaction.class, getManager()), beans);
+ final ManagerImpl managerImpl = getManager();
+ createBean(new SimpleBean<ManagerImpl>(ManagerImpl.class, getManager())
{
@Override
public ManagerImpl create()
{
- return manager;
+ return managerImpl;
}
}, beans);
@@ -169,13 +171,13 @@
Set<AbstractBean<?, ?>> beans = new HashSet<AbstractBean<?,
?>>();
for (Class<?> clazz : classes)
{
- if (manager.getEjbDescriptorCache().containsKey(clazz))
+ if (getManager().getEjbDescriptorCache().containsKey(clazz))
{
- createBean(createEnterpriseBean(clazz, manager), beans);
+ createBean(createEnterpriseBean(clazz, getManager()), beans);
}
else if (isTypeSimpleWebBean(clazz))
{
- createBean(createSimpleBean(clazz, manager), beans);
+ createBean(createSimpleBean(clazz, getManager()), beans);
}
}
return beans;
@@ -193,18 +195,18 @@
protected void createBean(AbstractClassBean<?> bean, Set<AbstractBean<?,
?>> beans)
{
beans.add(bean);
- manager.getResolver().addInjectionPoints(bean.getInjectionPoints());
+ getManager().getResolver().addInjectionPoints(bean.getInjectionPoints());
for (AnnotatedMethod<Object> producerMethod : bean.getProducerMethods())
{
- ProducerMethodBean<?> producerMethodBean =
createProducerMethodBean(producerMethod, bean, manager);
+ ProducerMethodBean<?> producerMethodBean =
createProducerMethodBean(producerMethod, bean, getManager());
beans.add(producerMethodBean);
-
manager.getResolver().addInjectionPoints(producerMethodBean.getInjectionPoints());
+
getManager().getResolver().addInjectionPoints(producerMethodBean.getInjectionPoints());
registerEvents(producerMethodBean.getInjectionPoints(), beans);
log.info("Web Bean: " + producerMethodBean);
}
for (AnnotatedField<Object> producerField : bean.getProducerFields())
{
- ProducerFieldBean<?> producerFieldBean =
createProducerFieldBean(producerField, bean, manager);
+ ProducerFieldBean<?> producerFieldBean =
createProducerFieldBean(producerField, bean, getManager());
beans.add(producerFieldBean);
log.info("Web Bean: " + producerFieldBean);
}
@@ -223,14 +225,14 @@
}
if ( injectionPoint.isAnnotationPresent(Obtains.class) )
{
- InstanceBean<Object, Field> instanceBean =
createInstanceBean(injectionPoint, manager);
+ InstanceBean<Object, Field> instanceBean =
createInstanceBean(injectionPoint, getManager());
beans.add(instanceBean);
log.info("Web Bean: " + instanceBean);
}
}
for (AnnotatedMethod<Object> observerMethod : bean.getObserverMethods())
{
- ObserverImpl<?> observer = createObserver(observerMethod, bean, manager);
+ ObserverImpl<?> observer = createObserver(observerMethod, bean,
getManager());
if (observerMethod.getAnnotatedParameters(Observes.class).size() == 1)
{
registerObserver(observer,
observerMethod.getAnnotatedParameters(Observes.class).get(0).getType(),
observerMethod.getAnnotatedParameters(Observes.class).get(0).getBindingTypesAsArray());
@@ -248,25 +250,25 @@
/**
* Starts the boot process.
*
- * Discovers the beans and registers them with the manager. Also resolves the
+ * Discovers the beans and registers them with the getManager(). Also resolves the
* injection points.
*
* @param webBeanDiscovery The discovery implementation
*/
- public synchronized void boot(WebBeanDiscovery webBeanDiscovery)
+ public void boot()
{
- log.info("Starting Web Beans RI " + getVersion());
- if (webBeanDiscovery == null)
+ synchronized (this)
{
- throw new IllegalStateException("No WebBeanDiscovery provider found, you
need to implement the org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery interface, and
tell the RI to use it by specifying -D" +
WebBeansBootstrap.WEB_BEAN_DISCOVERY_PROPERTY_NAME + "=<classname>");
+ log.info("Starting Web Beans RI " + getVersion());
+ validateBootstrap();
+ // Must populate EJB cache first, as we need it to detect whether a bean is an
EJB!
+
getManager().getEjbDescriptorCache().addAll(getWebBeanDiscovery().discoverEjbs());
+ registerBeans(getWebBeanDiscovery().discoverWebBeanClasses());
+ log.info("Validing Web Bean injection points");
+ getManager().getResolver().resolveInjectionPoints();
+ getManager().fireEvent(getManager(), new InitializedBinding());
+ log.info("Web Beans RI initialized");
}
- // Must populate EJB cache first, as we need it to detect whether a bean is an
EJB!
- manager.getEjbDescriptorCache().addAll(webBeanDiscovery.discoverEjbs());
- registerBeans(webBeanDiscovery.discoverWebBeanClasses());
- log.info("Validing Web Bean injection points");
- manager.getResolver().resolveInjectionPoints();
- manager.fireEvent(manager, new InitializedBinding());
- log.info("Web Beans RI initialized");
}
/**
@@ -281,39 +283,8 @@
}
/**
- * Gets the available discovery implementations
+ * Registers an observer with the getManager()
*
- * Parses the web-beans-ri.properties file and for each row describing a
- * discover class, instantiate that class and add it to the set
- *
- * @return A set of discovery implementations
- * @see org.jboss.webbeans.bootstrap.DeploymentProperties
- */
- @SuppressWarnings("unchecked")
- public static Set<Class<? extends WebBeanDiscovery>>
getWebBeanDiscoveryClasses()
- {
- Set<Class<? extends WebBeanDiscovery>> webBeanDiscoveryClasses = new
HashSet<Class<? extends WebBeanDiscovery>>();
- for (String className : new
DeploymentProperties(Thread.currentThread().getContextClassLoader()).getPropertyValues(WEB_BEAN_DISCOVERY_PROPERTY_NAME))
- {
- try
- {
- webBeanDiscoveryClasses.add((Class<WebBeanDiscovery>)
Class.forName(className));
- }
- catch (ClassNotFoundException e)
- {
- log.debug("Unable to load WebBeanDiscovery provider " + className,
e);
- }
- catch (NoClassDefFoundError e)
- {
- log.warn("Unable to load WebBeanDiscovery provider " + className +
" due classDependencyProblem", e);
- }
- }
- return webBeanDiscoveryClasses;
- }
-
- /**
- * Registers an observer with the manager
- *
* @param observer The observer
* @param eventType The event type to observe
* @param bindings The binding types to observe on
@@ -321,7 +292,7 @@
@SuppressWarnings("unchecked")
private <T> void registerObserver(Observer<T> observer, Class<?>
eventType, Annotation[] bindings)
{
- manager.addObserver(observer, (Class<T>) eventType, bindings);
+ getManager().addObserver(observer, (Class<T>) eventType, bindings);
}
/**
@@ -345,7 +316,7 @@
{
if ( injectionPoint.isAnnotationPresent(Fires.class) )
{
- EventBean<Object, Method> eventBean = createEventBean(injectionPoint,
manager);
+ EventBean<Object, Method> eventBean = createEventBean(injectionPoint,
getManager());
beans.add(eventBean);
log.info("Web Bean: " + eventBean);
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-12-24
22:55:14 UTC (rev 722)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -21,9 +21,9 @@
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+import javax.webbeans.ExecutionException;
import javax.webbeans.manager.Context;
import org.jboss.webbeans.util.ConcurrentCache;
@@ -63,7 +63,7 @@
{
interrupted = true;
}
- catch (ExecutionException e)
+ catch (java.util.concurrent.ExecutionException e)
{
rethrow(e);
}
@@ -94,13 +94,17 @@
{
try
{
+ if (getFuture(scopeType) == null)
+ {
+ throw new ExecutionException("No scope registered for " +
scopeType);
+ }
return getFuture(scopeType).get();
}
catch (InterruptedException e)
{
interrupted = true;
}
- catch (ExecutionException e)
+ catch (java.util.concurrent.ExecutionException e)
{
rethrow(e);
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EJB.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EJB.java 2008-12-24 22:55:14
UTC (rev 722)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EJB.java 2008-12-24 23:37:34
UTC (rev 723)
@@ -26,7 +26,7 @@
*/
public class EJB extends ApiAbstraction
{
-
+
public static final Class<?> ENTERPRISE_BEAN_CLASS;
/**
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultNaming.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultNaming.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultNaming.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -0,0 +1,66 @@
+package org.jboss.webbeans.resources;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.webbeans.ExecutionException;
+
+import org.jboss.webbeans.resources.spi.Naming;
+
+public class DefaultNaming implements Naming
+{
+
+ private transient InitialContext initialContext;
+
+ public DefaultNaming()
+ {
+ try
+ {
+ this.initialContext = new InitialContext();
+ }
+ catch (NamingException e)
+ {
+ throw new ExecutionException("Could not obtain InitialContext", e);
+ }
+ }
+
+
+
+ public InitialContext getInitialContext()
+ {
+ return initialContext;
+ }
+
+ public void bind(String key, Object value)
+ {
+ try
+ {
+ initialContext.bind(key, value);
+ }
+ catch (NamingException e)
+ {
+ throw new ExecutionException("Cannot bind " + value + " to "
+ key, e);
+ }
+ }
+
+ public <T> T lookup(String name, Class<? extends T> expectedType)
+ {
+ Object instance;
+ try
+ {
+ instance = initialContext.lookup(name);
+ }
+ catch (NamingException e)
+ {
+ throw new ExecutionException("Cannot lookup " + name, e);
+ }
+ try
+ {
+ return (T) instance;
+ }
+ catch (ClassCastException e)
+ {
+ throw new ExecutionException(instance + " not of expected type " +
expectedType, e);
+ }
+ }
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultNaming.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletBootstrap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletBootstrap.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletBootstrap.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -0,0 +1,94 @@
+package org.jboss.webbeans.servlet;
+
+
+import java.lang.reflect.Constructor;
+
+import javax.servlet.ServletContext;
+
+import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.bootstrap.PropertiesBasedBootstrap;
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
+import org.jboss.webbeans.contexts.ApplicationContext;
+import org.jboss.webbeans.contexts.DependentContext;
+import org.jboss.webbeans.contexts.RequestContext;
+import org.jboss.webbeans.contexts.SessionContext;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.util.DeploymentProperties;
+
+public class ServletBootstrap extends PropertiesBasedBootstrap
+{
+
+ private ManagerImpl manager;
+ private ResourceLoader resourceLoader;
+ private WebBeanDiscovery webBeanDiscovery;
+ private DeploymentProperties deploymentProperties;
+
+ public ServletBootstrap(ServletContext servletContext)
+ {
+ // Create the manager
+ this.manager = new ManagerImpl();
+
+ // Create a resouce loader based on the servlet context for initial loading
+ ResourceLoader servletContextResourceLoader = new
ServletContextResourceLoader(servletContext);
+ this.deploymentProperties = new
DeploymentProperties(servletContextResourceLoader);
+
+ // Attempt to create a plugin resource loader
+ Constructor<? extends ResourceLoader> resourceLoaderConstructor =
getClassConstructor(deploymentProperties, servletContextResourceLoader,
ResourceLoader.PROPERTY_NAME, ResourceLoader.class, ServletContext.class);
+ if (resourceLoaderConstructor != null)
+ {
+ this.resourceLoader = newInstance(resourceLoaderConstructor, servletContext);
+ }
+ else
+ {
+ // If no plugin resource loader, use the servlet context resource loader
+ this.resourceLoader = servletContextResourceLoader;
+ }
+
+ // Now safe to initialize other properties and register the manager
+ super.initProperties();
+ super.registerManager();
+
+ // Attempt to create a plugin web beans discovery
+ Constructor<? extends WebBeanDiscovery> webBeanDiscoveryConstructor =
getClassConstructor(deploymentProperties, resourceLoader, WebBeanDiscovery.PROPERTY_NAME,
WebBeanDiscovery.class, ServletContext.class);
+ if (webBeanDiscoveryConstructor == null)
+ {
+ throw new IllegalStateException("Cannot load Web Bean discovery plugin!
Check if Web Beans is properly installed into your container");
+ }
+ else
+ {
+ this.webBeanDiscovery = newInstance(webBeanDiscoveryConstructor,
servletContext);
+ }
+
+ // Register the contexts for the Servlet environment
+ getManager().addContext(DependentContext.INSTANCE);
+ getManager().addContext(RequestContext.INSTANCE);
+ getManager().addContext(SessionContext.INSTANCE);
+ getManager().addContext(ApplicationContext.INSTANCE);
+ ApplicationContext.INSTANCE.setBeanMap(new ApplicationBeanMap(servletContext));
+ }
+
+ @Override
+ protected DeploymentProperties getDeploymentProperties()
+ {
+ return deploymentProperties;
+ }
+
+ @Override
+ public ResourceLoader getResourceLoader()
+ {
+ return resourceLoader;
+ }
+
+ @Override
+ protected WebBeanDiscovery getWebBeanDiscovery()
+ {
+ return webBeanDiscovery;
+ }
+
+ @Override
+ public ManagerImpl getManager()
+ {
+ return manager;
+ }
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletBootstrap.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletContextResourceLoader.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletContextResourceLoader.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletContextResourceLoader.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -0,0 +1,74 @@
+package org.jboss.webbeans.servlet;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.servlet.ServletContext;
+
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.resources.spi.ResourceLoadingException;
+import org.jboss.webbeans.util.EnumerationIterable;
+
+public class ServletContextResourceLoader implements ResourceLoader
+{
+
+ private final ServletContext servletContext;
+
+ public ServletContextResourceLoader(ServletContext servletContext)
+ {
+ this.servletContext = servletContext;
+ }
+
+ public Class<?> classForName(String name)
+ {
+ try
+ {
+ return servletContext.getClass().getClassLoader().loadClass(name);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ catch (NoClassDefFoundError e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ }
+
+ public URL getResource(String name)
+ {
+ URL resource = getResourceFromServletContext(name);
+ if (resource == null)
+ {
+ String stripped = name.startsWith("/") ? name.substring(1) : name;
+ resource = servletContext.getClass().getClassLoader().getResource(name);
+ }
+ return resource;
+ }
+
+ private URL getResourceFromServletContext(String name)
+ {
+ try
+ {
+ return servletContext.getResource(name);
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
+
+ public Iterable<URL> getResources(String name)
+ {
+ try
+ {
+ // TODO load resources from servlet context!
+ return new
EnumerationIterable<URL>(servletContext.getClass().getClassLoader().getResources(name));
+ }
+ catch (IOException e)
+ {
+ throw new ResourceLoadingException("Error loading resources for " +
name, e);
+ }
+ }
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletContextResourceLoader.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java 2008-12-24
22:55:14 UTC (rev 722)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -17,23 +17,16 @@
package org.jboss.webbeans.servlet;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
-import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
-import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.contexts.ApplicationContext;
import org.jboss.webbeans.contexts.DependentContext;
import org.jboss.webbeans.contexts.RequestContext;
import org.jboss.webbeans.contexts.SessionContext;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
-import org.jboss.webbeans.util.Reflections;
/**
* Reacts to phases of the servlet life cycles
@@ -44,8 +37,6 @@
public class ServletLifecycle
{
private static LogProvider log = Logging.getLogProvider(ServletLifecycle.class);
- // The servlet context
- private static ServletContext servletContext;
/**
* Starts the application
@@ -54,15 +45,9 @@
*
* @param context The servlet context
*/
- public static void beginApplication(ServletContext context)
+ public static void beginApplication(ServletContext servletContext)
{
- servletContext = context;
- ApplicationContext.INSTANCE.setBeanMap(new ApplicationBeanMap(servletContext));
- WebBeansBootstrap webBeansBootstrap = new WebBeansBootstrap();
- CurrentManager.rootManager().addContext(RequestContext.INSTANCE);
- CurrentManager.rootManager().addContext(SessionContext.INSTANCE);
- CurrentManager.rootManager().addContext(ApplicationContext.INSTANCE);
- webBeansBootstrap.boot(getWebBeanDiscovery());
+ new ServletBootstrap(servletContext).boot();
}
/**
@@ -72,7 +57,6 @@
{
ApplicationContext.INSTANCE.destroy();
ApplicationContext.INSTANCE.setBeanMap(null);
- servletContext = null;
}
/**
@@ -121,54 +105,4 @@
SessionContext.INSTANCE.setBeanMap(null);
}
- /**
- * Gets the servlet context
- *
- * @return The servlet context
- */
- public static ServletContext getServletContext()
- {
- return servletContext;
- }
-
- /**
- * Gets the Web Beans discovery class
- *
- * @return The discoverer
- */
- private static WebBeanDiscovery getWebBeanDiscovery()
- {
- WebBeanDiscovery webBeanDiscovery = null;
-
- for (Class<? extends WebBeanDiscovery> clazz :
WebBeansBootstrap.getWebBeanDiscoveryClasses())
- {
- Constructor<? extends WebBeanDiscovery> constructor =
Reflections.getConstructor(clazz, ServletContext.class);
- if (constructor != null)
- {
- try
- {
- webBeanDiscovery = constructor.newInstance(servletContext);
- break;
- }
- catch (InstantiationException e)
- {
- log.warn("Error creating WebBeanDiscovery provider" +
clazz.getName(), e);
- }
- catch (IllegalAccessException e)
- {
- log.warn("Error creating WebBeanDiscovery provider" +
clazz.getName(), e);
- }
- catch (IllegalArgumentException e)
- {
- log.warn("Error creating WebBeanDiscovery provider" +
clazz.getName(), e);
- }
- catch (InvocationTargetException e)
- {
- log.warn("Error creating WebBeanDiscovery provider" +
clazz.getName(), e);
- }
- }
- }
- return webBeanDiscovery;
- }
-
}
Copied:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/DeploymentProperties.java (from
rev 713,
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/DeploymentProperties.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/DeploymentProperties.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/DeploymentProperties.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -0,0 +1,174 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.webbeans.util;
+
+import static org.jboss.webbeans.util.Strings.split;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.resources.spi.ResourceLoadingException;
+
+/**
+ * Utility class to load deployment properties
+ *
+ * @author Pete Muir
+ */
+public class DeploymentProperties
+{
+ // The resource bundle used to control Web Beans RI deployment
+ public static final String RESOURCE_BUNDLE =
"META-INF/web-beans-ri.properties";
+
+ private static LogProvider log = Logging.getLogProvider(DeploymentProperties.class);
+
+ // The class to work from
+ private ResourceLoader resourceLoader;
+
+ /**
+ * Constructor
+ *
+ * @param classLoader The classloader to work on
+ */
+ public DeploymentProperties(ResourceLoader classLoader)
+ {
+ this.resourceLoader = classLoader;
+ }
+
+ /**
+ * Get a list of possible values for a given key.
+ *
+ * First, System properties are tried, followed by the specified resource
+ * bundle (first in classpath only).
+ *
+ * Colon (:) deliminated lists are split out. (gotta love Petes choice of
+ * ASCII art for that one ;-)
+ *
+ * @param key The key to search for
+ * @return A list of possible values. An empty list is returned if there are
+ * no matches.
+ */
+ public List<String> getPropertyValues(String key)
+ {
+ List<String> values = new ArrayList<String>();
+ addPropertiesFromSystem(key, values);
+ addPropertiesFromResourceBundle(key, values);
+ return values;
+ }
+
+ /**
+ * Adds matches from system properties
+ *
+ * @param key The key to match
+ * @param values The currently found values
+ */
+ private void addPropertiesFromSystem(String key, List<String> values)
+ {
+ addProperty(key, System.getProperty(key), values);
+ }
+
+ /**
+ * Adds matches from detected resource bundles
+ *
+ * @param key The key to match
+ * @param values The currently found values
+ */
+ private void addPropertiesFromResourceBundle(String key, List<String> values)
+ {
+ try
+ {
+ for (URL url : resourceLoader.getResources(RESOURCE_BUNDLE))
+ {
+ Properties properties = new Properties();
+ InputStream propertyStream = url.openStream();
+ try
+ {
+ properties.load(propertyStream);
+ addProperty(key, properties.getProperty(key), values);
+ }
+ finally
+ {
+ if (propertyStream != null)
+ {
+ propertyStream.close();
+ }
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ // No - op, file is optional
+ }
+ }
+
+ /**
+ * Add the property to the set of properties only if it hasn't already been
+ * added
+ *
+ * @param key The key searched for
+ * @param value The value of the property
+ * @param values The currently found values
+ */
+ private void addProperty(String key, String value, List<String> values)
+ {
+ if (value != null)
+ {
+ String[] properties = split(value, ":");
+ for (String property : properties)
+ {
+ values.add(property);
+ }
+
+ }
+ }
+
+ /**
+ * Gets the possible implementation class for a given property for which the
+ * values are classanames
+ *
+ * @param deploymentProperties The deployment properties object to use
+ * @param resourceLoader The resource laoder to use to attempt
+ * @param propertyName The name of the property to load
+ * @return A set of classes specified
+ */
+ public static <T> Set<Class<? extends T>>
getClasses(DeploymentProperties deploymentProperties, ResourceLoader resourceLoader,
String propertyName, Class<T> expectedType)
+ {
+ Set<Class<? extends T>> classes = new HashSet<Class<? extends
T>>();
+ for (String className : deploymentProperties.getPropertyValues(propertyName))
+ {
+ try
+ {
+ classes.add((Class<? extends T>)
resourceLoader.classForName(className));
+ }
+ catch (ResourceLoadingException e)
+ {
+ log.debug("Unable to load class " + className + " for property
" + propertyName, e);
+ }
+ }
+ return classes;
+ }
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/DeploymentProperties.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/JNDI.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/JNDI.java 2008-12-24
22:55:14 UTC (rev 722)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/JNDI.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -1,127 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, 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.webbeans.util;
-
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.webbeans.ExecutionException;
-
-import org.jboss.webbeans.log.LogProvider;
-import org.jboss.webbeans.log.Logging;
-
-
-/**
- * Provides JNDI access abstraction
- *
- * @author Pete Muir
- */
-public class JNDI
-{
-
- private static final LogProvider log = Logging.getLogProvider(JNDI.class);
-
- public static InitialContext getInitialContext(Properties props) throws
NamingException
- {
- if (props==null)
- {
- throw new IllegalStateException("JNDI properties not initialized");
- }
-
- if (log.isDebugEnabled())
- {
- log.debug("JNDI InitialContext properties:" + props);
- }
-
- try {
- return props.size()==0 ?
- new InitialContext() :
- new InitialContext(props);
- }
- catch (NamingException e) {
- log.debug("Could not obtain initial context", e);
- throw e;
- }
-
- }
-
- public static InitialContext getInitialContext() throws NamingException
- {
- return getInitialContext(new Properties());
- }
-
- /**
- * Looks up a object in JNDI
- *
- * @param name The JNDI name
- * @return The object
- */
- public static Object lookup(String name)
- {
- return lookup(name, Object.class);
- }
-
- /**
- * Typed JNDI lookup
- *
- * @param <T> The type
- * @param name The JNDI name
- * @param expectedType The excpected type
- * @return The object
- */
- @SuppressWarnings("unchecked")
- public static <T> T lookup(String name, Class<? extends T> expectedType)
- {
- try
- {
- return (T) getInitialContext().lookup(name);
- }
- catch (NamingException e)
- {
- throw new ExecutionException("Error looking " + name + " up in
JNDI", e);
- }
- }
-
- public static void bind(String key, Object value)
- {
- try
- {
- getInitialContext().bind(key, value);
- }
- catch (NamingException e)
- {
- throw new ExecutionException("Error binding " + value + " to
" + key + " in JNDI", e);
- }
- }
-
- public static void bind(String env, String name, Object value)
- {
- try
- {
- Context environment = (Context) getInitialContext().lookup(env);
- environment.bind(name, value);
- }
- catch (NamingException e)
- {
- throw new ExecutionException("Error binding " + value + " to
" + name + " in JNDI", e);
- }
- }
-
-}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-12-24
22:55:14 UTC (rev 722)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -64,7 +64,7 @@
* @return The instance
* @throws ClassNotFoundException If the class if not found
*/
- public static Class<?> classForName(String name, ClassLoader classLoader) throws
ClassNotFoundException
+ private static Class<?> classForName(String name, ClassLoader classLoader)
throws ClassNotFoundException
{
try
{
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java 2008-12-24
22:55:14 UTC (rev 722)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -5,10 +5,6 @@
import javax.webbeans.Production;
import javax.webbeans.Standard;
-import org.jboss.webbeans.contexts.ApplicationContext;
-import org.jboss.webbeans.contexts.RequestContext;
-import org.jboss.webbeans.contexts.SessionContext;
-import org.jboss.webbeans.contexts.SimpleBeanMap;
import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
import org.jboss.webbeans.test.annotations.HornedAnimalDeploymentType;
import org.jboss.webbeans.test.mock.MockBootstrap;
@@ -25,20 +21,8 @@
@BeforeMethod
public final void before()
{
- manager = new MockManagerImpl();
- webBeansBootstrap = new MockBootstrap(manager);
- manager.addContext(RequestContext.INSTANCE);
- SessionContext.INSTANCE.setBeanMap(new SimpleBeanMap());
- manager.addContext(SessionContext.INSTANCE);
- ApplicationContext.INSTANCE.setBeanMap(new SimpleBeanMap());
- manager.addContext(ApplicationContext.INSTANCE);
- // Load the built in beans
- webBeansBootstrap.registerStandardBeans();
- init();
- }
-
- protected void init()
- {
+ webBeansBootstrap = new MockBootstrap();
+ manager = webBeansBootstrap.getManager();
addStandardDeploymentTypesForTests();
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java 2008-12-24
22:55:14 UTC (rev 722)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -35,7 +35,8 @@
@Test(groups="bootstrap")
public void testSingleSimpleBean()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(Tuna.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Tuna.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>,
Bean<?>>();
assert beans.size() == 1 + MockManagerImpl.BUILT_IN_BEANS;
@@ -52,7 +53,8 @@
@Test(groups="bootstrap")
public void testSingleEnterpriseBean()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(Hound.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Hound.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans.size() == 1 + MockManagerImpl.BUILT_IN_BEANS;
Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>,
Bean<?>>();
@@ -69,7 +71,8 @@
@Test(groups="bootstrap")
public void testMultipleSimpleBean()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(Tuna.class, Salmon.class,
SeaBass.class, Sole.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Tuna.class,
Salmon.class, SeaBass.class, Sole.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans.size() == 4 + MockManagerImpl.BUILT_IN_BEANS;
Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>,
Bean<?>>();
@@ -94,7 +97,8 @@
@Test(groups="bootstrap")
public void testProducerMethodBean()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(TarantulaProducer.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(TarantulaProducer.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans.size() == 2 + MockManagerImpl.BUILT_IN_BEANS;
Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>,
Bean<?>>();
@@ -115,7 +119,8 @@
@Test(groups="bootstrap")
public void testMultipleEnterpriseBean()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(Hound.class, Elephant.class,
Panther.class, Tiger.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Hound.class,
Elephant.class, Panther.class, Tiger.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans.size() == 4 + MockManagerImpl.BUILT_IN_BEANS;
Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>,
Bean<?>>();
@@ -140,7 +145,8 @@
@Test(groups="bootstrap")
public void testMultipleEnterpriseAndSimpleBean()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(Hound.class, Elephant.class,
Panther.class, Tiger.class, Tuna.class, Salmon.class, SeaBass.class, Sole.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Hound.class,
Elephant.class, Panther.class, Tiger.class, Tuna.class, Salmon.class, SeaBass.class,
Sole.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans.size() == 8 + MockManagerImpl.BUILT_IN_BEANS;
Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>,
Bean<?>>();
@@ -173,7 +179,8 @@
@Test(groups="bootstrap")
public void testRegisterProducerMethodBean()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(TarantulaProducer.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(TarantulaProducer.class));
+ webBeansBootstrap.boot();
assert manager.getBeans().size() == 2 + MockManagerImpl.BUILT_IN_BEANS;
Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>,
Bean<?>>();
for (Bean<?> bean : manager.getBeans())
@@ -194,7 +201,8 @@
@Test(groups="bootstrap")
public void testRegisterMultipleEnterpriseAndSimpleBean()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(Hound.class, Elephant.class,
Panther.class, Tiger.class, Tuna.class, Salmon.class, SeaBass.class, Sole.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Hound.class,
Elephant.class, Panther.class, Tiger.class, Tuna.class, Salmon.class, SeaBass.class,
Sole.class));
+ webBeansBootstrap.boot();
assert manager.getBeans().size() == 8 + MockManagerImpl.BUILT_IN_BEANS;
Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>,
Bean<?>>();
for (Bean<?> bean : manager.getBeans())
@@ -226,13 +234,15 @@
@Test(groups="bootstrap", expectedExceptions=IllegalStateException.class)
public void testDiscoverFails()
{
- webBeansBootstrap.boot(null);
+ webBeansBootstrap.setWebBeanDiscovery(null);
+ webBeansBootstrap.boot();
}
@Test(groups="bootstrap")
public void testDiscover()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(Hound.class, Elephant.class, Panther.class,
Tiger.class, Tuna.class, Salmon.class, SeaBass.class, Sole.class))));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(Hound.class, Elephant.class, Panther.class,
Tiger.class, Tuna.class, Salmon.class, SeaBass.class, Sole.class))));
+ webBeansBootstrap.boot();
assert manager.getBeans().size() == 8 + MockManagerImpl.BUILT_IN_BEANS;
Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>,
Bean<?>>();
@@ -266,7 +276,8 @@
public void testInitializedEvent()
{
assert !InitializedObserver.observered;
- webBeansBootstrap.boot(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(InitializedObserver.class))));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(InitializedObserver.class))));
+ webBeansBootstrap.boot();
assert InitializedObserver.observered;
}
@@ -274,13 +285,15 @@
@Test(groups="bootstrap")
public void testRequestContextActiveDuringInitializtionEvent()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(InitializedObserverWhichUsesRequestContext.class,
Tuna.class)), null, new HashSet<Class<?>>()));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(InitializedObserverWhichUsesRequestContext.class,
Tuna.class)), null, new HashSet<Class<?>>()));
+ webBeansBootstrap.boot();
}
@Test(groups="bootstrap")
public void testApplicationContextActiveDuringInitializtionEvent()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(InitializedObserverWhichUsesApplicationContext.class,
LadybirdSpider.class)), null, new HashSet<Class<?>>()));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(InitializedObserverWhichUsesApplicationContext.class,
LadybirdSpider.class)), null, new HashSet<Class<?>>()));
+ webBeansBootstrap.boot();
}
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java 2008-12-24
22:55:14 UTC (rev 722)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -324,7 +324,8 @@
@SpecAssertion(section = "8.5")
public void testObserverMethodOnEnterpriseBeanIsBusinessMethodOrStatic()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(Pomeranian.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Pomeranian.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans.size() == 1 + MockManagerImpl.BUILT_IN_BEANS;
Set<Observer<String>> observers = manager.resolveObservers("An
event");
@@ -335,7 +336,8 @@
@SpecAssertion(section = "8.5")
public void testObserverMethodOnEnterpriseBeanNotBusinessMethodOrStaticFails()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(TibetanTerrier.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(TibetanTerrier.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans.size() == 1 + MockManagerImpl.BUILT_IN_BEANS;
Set<Observer<String>> observers = manager.resolveObservers("An
event");
@@ -356,7 +358,8 @@
@SpecAssertion(section = { "8.5.1", "8.5.2" })
public void testObserverMethodMustHaveOnlyOneEventParameter()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(YorkshireTerrier.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(YorkshireTerrier.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans != null;
}
@@ -365,7 +368,8 @@
@SpecAssertion(section = "8.5.1")
public void testObserverMethodCannotObserveParameterizedEvents()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(BostonTerrier.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(BostonTerrier.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans != null;
}
@@ -375,7 +379,8 @@
public void testObserverMethodWithoutBindingTypesObservesEventsWithoutBindingTypes()
{
// This observer has no binding types specified
- webBeansBootstrap.boot(new MockWebBeanDiscovery(Pomeranian.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Pomeranian.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans.size() == 1 + MockManagerImpl.BUILT_IN_BEANS;
@@ -389,7 +394,8 @@
@SpecAssertion(section = "8.5.2")
public void testObserverMethodAnnotatedProducesFails()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(BorderTerrier.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(BorderTerrier.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans != null;
}
@@ -398,7 +404,8 @@
@SpecAssertion(section = "8.5.2")
public void testObserverMethodAnnotatedInitializerFails()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(AustralianTerrier.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(AustralianTerrier.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans != null;
}
@@ -407,7 +414,8 @@
@SpecAssertion(section = "8.5.2")
public void testObserverMethodAnnotatedDestructorFails()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(CairnsTerrier.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(CairnsTerrier.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans != null;
}
@@ -416,7 +424,8 @@
@SpecAssertion(section = "8.5.2")
public void testObserverMethodWithDisposesParamFails()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(FoxTerrier.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(FoxTerrier.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans != null;
}
@@ -425,7 +434,8 @@
@SpecAssertion(section = "8.5.2")
public void testObserverMethodMayHaveMultipleBindingTypes()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(BullTerrier.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(BullTerrier.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans != null;
// If we can resolve the observer with the two binding types,
@@ -454,7 +464,8 @@
@SpecAssertion(section = "8.5.4")
public void testObserverMethodReceivesInjectionsOnNonObservesParameters()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(BananaSpider.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(BananaSpider.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans != null;
}
@@ -467,7 +478,8 @@
@SpecAssertion(section = "8.5.5")
public void testConditionalObserver()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(RecluseSpider.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(RecluseSpider.class));
+ webBeansBootstrap.boot();
manager.fireEvent("New string event");
// Should not be notified since bean is not instantiated yet
@@ -546,7 +558,8 @@
@SpecAssertion(section = "8.5.7")
public void testEnterpriseBeanObserverMethodCalledWithCallerContext()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(Pomeranian.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Pomeranian.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans.size() == 1;
String event = "A new event";
@@ -568,7 +581,8 @@
@SpecAssertion(section = "8.5.7")
public void testNonTransactionalObserverThrownNonCheckedExceptionIsRethrown()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(TeaCupPomeranian.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(TeaCupPomeranian.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans.size() == 1 + MockManagerImpl.BUILT_IN_BEANS;
manager.fireEvent("Another event");
@@ -578,7 +592,8 @@
@SpecAssertion(section = "8.5.7")
public void testNonTransactionalObserverThrownCheckedExceptionIsWrappedAndRethrown()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(TeaCupPomeranian.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(TeaCupPomeranian.class));
+ webBeansBootstrap.boot();
List<Bean<?>> beans = manager.getBeans();
assert beans.size() == 1 + MockManagerImpl.BUILT_IN_BEANS;
manager.fireEvent(new Integer(1));
@@ -588,7 +603,8 @@
@SpecAssertion(section = "8.6")
public void testDuplicateBindingsToFireFails()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(SweeWaxbill.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(SweeWaxbill.class));
+ webBeansBootstrap.boot();
try
{
DependentContext.INSTANCE.setActive(true);
@@ -605,7 +621,8 @@
@SpecAssertion(section = "8.6")
public void testDuplicateBindingsToObservesFails()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(SweeWaxbill.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(SweeWaxbill.class));
+ webBeansBootstrap.boot();
try
{
DependentContext.INSTANCE.setActive(true);
@@ -622,7 +639,8 @@
@SpecAssertion(section = "8.6")
public void testNonBindingTypePassedToFireFails()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(OwlFinch.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(OwlFinch.class));
+ webBeansBootstrap.boot();
try
{
DependentContext.INSTANCE.setActive(true);
@@ -639,7 +657,8 @@
@SpecAssertion(section = "8.6")
public void testNonBindingTypePassedToObservesFails()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(OwlFinch.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(OwlFinch.class));
+ webBeansBootstrap.boot();
try
{
DependentContext.INSTANCE.setActive(true);
@@ -656,7 +675,8 @@
@SpecAssertion(section = "8.6")
public void testObservableAnnotationOnField()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(BlueFacedParrotFinch.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(BlueFacedParrotFinch.class));
+ webBeansBootstrap.boot();
try
{
DependentContext.INSTANCE.setActive(true);
@@ -676,7 +696,8 @@
@SpecAssertion(section = "8.6")
public void testObservableAnnotationOnParameterOfProducerMethod()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(StarFinch.class, FinchKeeper.class,
BirdCage.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(StarFinch.class,
FinchKeeper.class, BirdCage.class));
+ webBeansBootstrap.boot();
try
{
DependentContext.INSTANCE.setActive(true);
@@ -698,7 +719,8 @@
@SpecAssertion(section = "8.6")
public void testObservableAnnotationOnParameterOfInitializerMethod()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(OrangeCheekedWaxbill.class,
FinchKeeper.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(OrangeCheekedWaxbill.class, FinchKeeper.class));
+ webBeansBootstrap.boot();
try
{
DependentContext.INSTANCE.setActive(true);
@@ -727,7 +749,8 @@
@SpecAssertion(section = "8.6")
public void testObservableAnnotationOnParameterOfRemoveMethod()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(EuropeanGoldfinch.class,
FinchKeeper.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(EuropeanGoldfinch.class, FinchKeeper.class));
+ webBeansBootstrap.boot();
try
{
DependentContext.INSTANCE.setActive(true);
@@ -747,7 +770,8 @@
@SpecAssertion(section = "8.6")
public void testObservableAnnotationOnParameterOfConstructor()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(AuroraFinch.class,
FinchKeeper.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(AuroraFinch.class,
FinchKeeper.class));
+ webBeansBootstrap.boot();
try
{
DependentContext.INSTANCE.setActive(true);
@@ -766,7 +790,8 @@
@SpecAssertion(section = "8.6")
public void testObservableAnnotationOnNonEventTypeInjectionPointFails()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(CommonWaxbill.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(CommonWaxbill.class));
+ webBeansBootstrap.boot();
try
{
DependentContext.INSTANCE.setActive(true);
@@ -783,11 +808,13 @@
@SpecAssertion(section = "8.6")
public void testObservableAnnotationOnInjectionPointWithoutTypeParameterFails()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(BlackRumpedWaxbill.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(BlackRumpedWaxbill.class));
+ webBeansBootstrap.boot();
try
{
DependentContext.INSTANCE.setActive(true);
BlackRumpedWaxbill bean = manager.getInstanceByType(BlackRumpedWaxbill.class);
+ webBeansBootstrap.boot();
assert bean != null;
}
finally
@@ -800,7 +827,8 @@
@SpecAssertion(section = "8.6")
public void
testObservableAnnotationOnInjectionPointWithWildcardedTypeParameterFails()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(GoldbreastWaxbill.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(GoldbreastWaxbill.class));
+ webBeansBootstrap.boot();
try
{
DependentContext.INSTANCE.setActive(true);
@@ -817,7 +845,8 @@
@SpecAssertion(section = "8.6")
public void
testObservableAnnotationOnInjectionPointWithTypeVariabledTypeParameterFails()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(JavaSparrow.class));
+ webBeansBootstrap.setWebBeanDiscovery(new
MockWebBeanDiscovery(JavaSparrow.class));
+ webBeansBootstrap.boot();
try
{
DependentContext.INSTANCE.setActive(true);
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java 2008-12-24
22:55:14 UTC (rev 722)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -88,21 +88,24 @@
@Test
public void testClassesImplementingServletInterfacesNotDiscoveredAsSimpleBeans()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(FilterBean.class,
HttpSessionListenerBean.class, ServletBean.class, ServletContextListenerBean.class,
ServletRequestListenerBean.class)), null, new HashSet<Class<?>>()));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(FilterBean.class,
HttpSessionListenerBean.class, ServletBean.class, ServletContextListenerBean.class,
ServletRequestListenerBean.class)), null, new HashSet<Class<?>>()));
+ webBeansBootstrap.boot();
assert manager.getBeans().size() == MockManagerImpl.BUILT_IN_BEANS;
}
@Test
public void testClassesImplementingEnterpriseBeanInterfaceNotDiscoveredAsSimpleBean()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(EnterpriseBeanWebBean.class)), null, new
HashSet<Class<?>>()));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(EnterpriseBeanWebBean.class)), null, new
HashSet<Class<?>>()));
+ webBeansBootstrap.boot();
assert manager.getBeans().size() == MockManagerImpl.BUILT_IN_BEANS;
}
@Test
public void testClassExtendingUiComponentNotDiscoveredAsSimpleBean()
{
- webBeansBootstrap.boot(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(UIComponentBean.class)), null, new
HashSet<Class<?>>()));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(UIComponentBean.class)), null, new
HashSet<Class<?>>()));
+ webBeansBootstrap.boot();
assert manager.getBeans().size() == MockManagerImpl.BUILT_IN_BEANS;
}
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockBootstrap.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockBootstrap.java 2008-12-24
22:55:14 UTC (rev 722)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockBootstrap.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -1,26 +1,63 @@
package org.jboss.webbeans.test.mock;
-import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
+import org.jboss.webbeans.contexts.ApplicationContext;
+import org.jboss.webbeans.contexts.DependentContext;
+import org.jboss.webbeans.contexts.RequestContext;
+import org.jboss.webbeans.contexts.SessionContext;
+import org.jboss.webbeans.contexts.SimpleBeanMap;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
public class MockBootstrap extends WebBeansBootstrap
{
- public MockBootstrap(ManagerImpl manager)
+ private WebBeanDiscovery webBeanDiscovery;
+ private ResourceLoader resourceLoader;
+ private MockManagerImpl manager;
+
+ public MockBootstrap()
{
- super(manager);
+ this.manager = new MockManagerImpl();
+ this.resourceLoader = new MockResourceLoader();
+ registerManager();
+ registerStandardBeans();
+
+ // Set up the mock contexts
+ manager.addContext(RequestContext.INSTANCE);
+ SessionContext.INSTANCE.setBeanMap(new SimpleBeanMap());
+ manager.addContext(SessionContext.INSTANCE);
+ ApplicationContext.INSTANCE.setBeanMap(new SimpleBeanMap());
+ manager.addContext(ApplicationContext.INSTANCE);
+ manager.addContext(DependentContext.INSTANCE);
}
- public void registerStandardBeans()
+ protected void registerStandardBeans()
{
- manager.setBeans(createStandardBeans());
+ getManager().setBeans(createStandardBeans());
}
+ public void setWebBeanDiscovery(WebBeanDiscovery webBeanDiscovery)
+ {
+ this.webBeanDiscovery = webBeanDiscovery;
+ }
+
@Override
- protected void registerManager()
+ protected WebBeanDiscovery getWebBeanDiscovery()
{
- CurrentManager.setRootManager(manager);
+ return this.webBeanDiscovery;
}
+
+ @Override
+ public ResourceLoader getResourceLoader()
+ {
+ return resourceLoader;
+ }
+
+ @Override
+ public MockManagerImpl getManager()
+ {
+ return manager;
+ }
}
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockInitialContext.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockInitialContext.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockInitialContext.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -0,0 +1,17 @@
+package org.jboss.webbeans.test.mock;
+
+import java.util.Hashtable;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+public class MockInitialContext extends InitialContext
+{
+
+ public MockInitialContext(Hashtable<?, ?> arg0) throws NamingException
+ {
+ super(arg0);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockInitialContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockManagerImpl.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockManagerImpl.java 2008-12-24
22:55:14 UTC (rev 722)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockManagerImpl.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -1,10 +1,33 @@
package org.jboss.webbeans.test.mock;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.resources.spi.Naming;
public class MockManagerImpl extends ManagerImpl
{
+ private Naming naming = new Naming()
+ {
+
+ public void bind(String key, Object value)
+ {
+ // no-op
+ }
+
+ public <T> T lookup(String name, Class<? extends T> expectedType)
+ {
+ // No-op
+ return null;
+ }
+
+ };
+
public static int BUILT_IN_BEANS = 3;
+ @Override
+ public Naming getNaming()
+ {
+ return naming;
+ }
+
}
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockResourceLoader.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockResourceLoader.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockResourceLoader.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -0,0 +1,42 @@
+package org.jboss.webbeans.test.mock;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.resources.spi.ResourceLoadingException;
+import org.jboss.webbeans.util.EnumerationIterable;
+
+public class MockResourceLoader implements ResourceLoader
+{
+
+ public Class<?> classForName(String name)
+ {
+ try
+ {
+ return Thread.currentThread().getContextClassLoader().loadClass(name);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ }
+
+ public URL getResource(String name)
+ {
+ return Thread.currentThread().getContextClassLoader().getResource(name);
+ }
+
+ public Iterable<URL> getResources(String name)
+ {
+ try
+ {
+ return new
EnumerationIterable<URL>(Thread.currentThread().getContextClassLoader().getResources(name));
+ }
+ catch (IOException e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ }
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockResourceLoader.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/spi/WebBeanDiscovery.java
===================================================================
---
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/spi/WebBeanDiscovery.java 2008-12-24
22:55:14 UTC (rev 722)
+++
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/spi/WebBeanDiscovery.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -28,6 +28,9 @@
*/
public interface WebBeanDiscovery
{
+
+ public static final String PROPERTY_NAME = WebBeanDiscovery.class.getName();
+
/**
* Gets list of all classes in classpath archives with web-beans.xml files
*
Added:
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/Naming.java
===================================================================
--- ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/Naming.java
(rev 0)
+++
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/Naming.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -0,0 +1,24 @@
+package org.jboss.webbeans.resources.spi;
+
+import java.io.Serializable;
+
+
+public interface Naming extends Serializable
+{
+
+ public static final String PROPERTY_NAME = Naming.class.getName();
+
+ /**
+ * Typed JNDI lookup
+ *
+ * @param <T> The type
+ * @param name The JNDI name
+ * @param expectedType The excpected type
+ * @return The object
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T lookup(String name, Class<? extends T> expectedType);
+
+ public void bind(String key, Object value);
+
+}
Property changes on:
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/Naming.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/ResourceLoader.java
===================================================================
---
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/ResourceLoader.java
(rev 0)
+++
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/ResourceLoader.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -0,0 +1,17 @@
+package org.jboss.webbeans.resources.spi;
+
+import java.net.URL;
+
+
+public interface ResourceLoader
+{
+
+ public static final String PROPERTY_NAME = ResourceLoader.class.getName();
+
+ public Class<?> classForName(String name);
+
+ public URL getResource(String name);
+
+ public Iterable<URL> getResources(String name);
+
+}
Property changes on:
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/ResourceLoader.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/ResourceLoadingException.java
===================================================================
---
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/ResourceLoadingException.java
(rev 0)
+++
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/ResourceLoadingException.java 2008-12-24
23:37:34 UTC (rev 723)
@@ -0,0 +1,31 @@
+/**
+ *
+ */
+package org.jboss.webbeans.resources.spi;
+
+import javax.webbeans.ExecutionException;
+
+public class ResourceLoadingException extends ExecutionException
+{
+
+ public ResourceLoadingException()
+ {
+ super();
+ }
+
+ public ResourceLoadingException(String message, Throwable throwable)
+ {
+ super(message, throwable);
+ }
+
+ public ResourceLoadingException(String message)
+ {
+ super(message);
+ }
+
+ public ResourceLoadingException(Throwable throwable)
+ {
+ super(throwable);
+ }
+
+}
\ No newline at end of file
Property changes on:
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/ResourceLoadingException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain