[webbeans-commits] Webbeans SVN: r1561 - in ri/trunk: porting-package/src/main/java/org/jboss/webbeans/tck and 11 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Tue Feb 17 13:58:25 EST 2009
Author: pete.muir at jboss.org
Date: 2009-02-17 13:58:25 -0500 (Tue, 17 Feb 2009)
New Revision: 1561
Added:
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/api/
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java
ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/helpers/AbstractNamingContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/PropertiesBasedInitialization.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockEjBResolver.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockNamingContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultNamingContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultResourceLoader.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletInitialization.java
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/PropertiesBasedBootstrap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/SimpleResourceLoader.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockBootstrap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resource/
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/AbstractNamingContext.java
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/test/java/org/jboss/webbeans/test/unit/AbstractEjbEmbeddableTest.java
Modified:
ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/AbstractContainersImpl.java
ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/StandaloneContainersImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansListener.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/AbstractTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/bootstrap/BootstrapTest.java
Log:
Start to factor out the Bootstrap API
Modified: ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/AbstractContainersImpl.java
===================================================================
--- ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/AbstractContainersImpl.java 2009-02-17 18:35:44 UTC (rev 1560)
+++ ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/AbstractContainersImpl.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -25,7 +25,7 @@
public abstract class AbstractContainersImpl implements Configurable, Containers
{
- public static String JAVA_OPTS = "-ea";
+ public static String JAVA_OPTS = " -ea";
public static final String JBOSS_HOME_PROPERTY_NAME = "jboss.home";
public static final String JAVA_OPTS_PROPERTY_NAME = "java.opts";
@@ -145,7 +145,7 @@
if (!isJBossUp())
{
jbossWasStarted = true;
- launch(jbossHome, "run", "");
+ launch("run", "");
log.info("Starting JBoss instance");
// Wait for JBoss to come up
long timeoutTime = System.currentTimeMillis() + bootTimeout;
@@ -172,7 +172,7 @@
}
// If we got this far something went wrong
log.warn("Unable to connect to JBoss instance after " + bootTimeout + "ms, giving up!");
- launch(jbossHome, "shutdown", "-S");
+ launch("shutdown", "-S");
throw new IllegalStateException("Error connecting to JBoss instance");
}
else
@@ -192,11 +192,11 @@
private void shutDownJBoss() throws IOException
{
- launch(jbossHome, "shutdown", "-S");
+ launch("shutdown", "-S");
log.info("Shut down JBoss AS");
}
- private static void launch(String jbossHome, String scriptFileName, String params) throws IOException
+ private void launch(String scriptFileName, String params) throws IOException
{
String osName = System.getProperty("os.name");
Runtime runtime = Runtime.getRuntime();
@@ -207,7 +207,7 @@
String command[] = {
"cmd.exe",
"/C",
- "set JAVA_OPTS=" + JAVA_OPTS + " & cd " + jbossHome + "\\bin & " + scriptFileName + ".bat " + params
+ "set JAVA_OPTS=" + javaOpts + " & cd /D " + jbossHome + "\\bin & " + scriptFileName + ".bat " + params
};
p = runtime.exec(command);
}
@@ -216,7 +216,7 @@
String command[] = {
"sh",
"-c",
- "cd /D " + jbossHome + "/bin;set JAVA_OPTS=" + JAVA_OPTS + " ./" + scriptFileName + ".sh " + params
+ "cd " + jbossHome + "/bin;JAVA_OPTS=" + javaOpts + " ./" + scriptFileName + ".sh " + params
};
p = runtime.exec(command);
}
@@ -232,7 +232,7 @@
{
try
{
- DataOutputStream out = new DataOutputStream(new FileOutputStream(System.getProperty("java.io.tmpdir") + "jboss.log"));
+ DataOutputStream out = new DataOutputStream(new FileOutputStream(System.getProperty("java.io.tmpdir") + File.separator + "jboss.log"));
int c;
while((c = is.read()) != -1)
{
Modified: ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/StandaloneContainersImpl.java
===================================================================
--- ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/StandaloneContainersImpl.java 2009-02-17 18:35:44 UTC (rev 1560)
+++ ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/StandaloneContainersImpl.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -7,7 +7,7 @@
import org.jboss.jsr299.tck.api.DeploymentException;
import org.jboss.jsr299.tck.spi.StandaloneContainers;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.mock.MockBootstrap;
+import org.jboss.webbeans.mock.MockLifecycle;
import org.jboss.webbeans.mock.MockWebBeanDiscovery;
public class StandaloneContainersImpl implements StandaloneContainers
@@ -22,20 +22,19 @@
{
try
{
- MockBootstrap bootstrap = new MockBootstrap();
- ManagerImpl manager = bootstrap.getManager();
+ MockLifecycle lifecycle = new MockLifecycle();
+ ManagerImpl manager = lifecycle.getBootstrap().getManager();
if (enabledDeploymentTypes != null)
{
manager.setEnabledDeploymentTypes(enabledDeploymentTypes);
}
- MockWebBeanDiscovery discovery = new MockWebBeanDiscovery();
+ MockWebBeanDiscovery discovery = lifecycle.getWebBeanDiscovery();
discovery.setWebBeanClasses(classes);
if (beansXml != null)
{
discovery.setWebBeansXmlFiles(beansXml);
}
- bootstrap.setWebBeanDiscovery(discovery);
- bootstrap.boot();
+ lifecycle.beginApplication();
}
catch (Exception e)
{
Deleted: 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 2009-02-17 18:35:44 UTC (rev 1560)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/PropertiesBasedBootstrap.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -1,111 +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 java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
-import javax.inject.ExecutionException;
-
-import org.jboss.webbeans.log.LogProvider;
-import org.jboss.webbeans.log.Logging;
-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
-{
-
- // The log provider
- 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;
- }
-
- /**
- * Creates an instance of the type
- *
- * @param constructor The constructor to use
- * @param parameters The parameters to pass to the constructor
- * @return An instance of the type
- */
- 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);
- }
- }
-
- /**
- * Gets the deployment properties
- *
- * @return The deployment properties
- *
- * @see org.jboss.webbeans.util.DeploymentProperties
- */
- protected abstract DeploymentProperties getDeploymentProperties();
-
-}
\ No newline at end of file
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/PropertiesBasedInitialization.java (from rev 1554, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/PropertiesBasedBootstrap.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/PropertiesBasedInitialization.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/PropertiesBasedInitialization.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -0,0 +1,102 @@
+/*
+ * 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 java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.inject.ExecutionException;
+
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.servlet.ServletInitialization;
+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 PropertiesBasedInitialization
+{
+
+ // The log provider
+ private static final LogProvider log = Logging.getLogProvider(ServletInitialization.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;
+ }
+
+ /**
+ * Creates an instance of the type
+ *
+ * @param constructor The constructor to use
+ * @param parameters The parameters to pass to the constructor
+ * @return An instance of the type
+ */
+ 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);
+ }
+ }
+
+}
\ No newline at end of file
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/PropertiesBasedInitialization.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/SimpleResourceLoader.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/SimpleResourceLoader.java 2009-02-17 18:35:44 UTC (rev 1560)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/SimpleResourceLoader.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -1,93 +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 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;
-
-/**
- * A simple resource loader.
- *
- * Uses {@link SimpleResourceLoader}'s classloader if the Thread Context
- * Classloader isn't available
- *
- * @author Pete Muir
- *
- */
-public class SimpleResourceLoader implements ResourceLoader
-{
-
- public Class<?> classForName(String name)
- {
-
- try
- {
- if (Thread.currentThread().getContextClassLoader() != null)
- {
- return Thread.currentThread().getContextClassLoader().loadClass(name);
- }
- else
- {
- return Class.forName(name);
- }
- }
- catch (ClassNotFoundException e)
- {
- throw new ResourceLoadingException(e);
- }
- catch (NoClassDefFoundError e)
- {
- throw new ResourceLoadingException(e);
- }
- }
-
- public URL getResource(String name)
- {
- if (Thread.currentThread().getContextClassLoader() != null)
- {
- return Thread.currentThread().getContextClassLoader().getResource(name);
- }
- else
- {
- return getClass().getResource(name);
- }
- }
-
- public Iterable<URL> getResources(String name)
- {
- try
- {
- if (Thread.currentThread().getContextClassLoader() != null)
- {
- return new EnumerationIterable<URL>(Thread.currentThread().getContextClassLoader().getResources(name));
- }
- else
- {
- return new EnumerationIterable<URL>(getClass().getClassLoader().getResources(name));
- }
- }
- catch (IOException e)
- {
- throw new ResourceLoadingException(e);
- }
- }
-
-}
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 2009-02-17 18:35:44 UTC (rev 1560)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -25,19 +25,18 @@
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.bean.standard.InjectionPointBean;
import org.jboss.webbeans.bean.standard.ManagerBean;
-import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
-import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
+import org.jboss.webbeans.bootstrap.api.Bootstrap;
+import org.jboss.webbeans.bootstrap.api.helpers.AbstractBootstrap;
import org.jboss.webbeans.conversation.ConversationImpl;
import org.jboss.webbeans.conversation.JavaSEConversationTerminator;
import org.jboss.webbeans.conversation.NumericConversationIdGenerator;
import org.jboss.webbeans.conversation.ServletConversationManager;
-import org.jboss.webbeans.ejb.spi.EjbResolver;
import org.jboss.webbeans.literal.DeployedLiteral;
import org.jboss.webbeans.literal.InitializedLiteral;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
-import org.jboss.webbeans.resources.spi.NamingContext;
-import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.resources.DefaultNamingContext;
+import org.jboss.webbeans.resources.DefaultResourceLoader;
import org.jboss.webbeans.servlet.HttpSessionManager;
import org.jboss.webbeans.transaction.Transaction;
@@ -47,7 +46,7 @@
*
* @author Pete Muir
*/
-public abstract class WebBeansBootstrap
+public class WebBeansBootstrap extends AbstractBootstrap implements Bootstrap
{
// The log provider
@@ -55,40 +54,35 @@
// The Web Beans manager
private ManagerImpl manager;
-
- protected void initManager(NamingContext namingContext, EjbResolver ejbResolver, ResourceLoader resourceLoader)
+ public WebBeansBootstrap()
{
- this.manager = new ManagerImpl(namingContext, ejbResolver, resourceLoader);
- manager.getNaming().bind(ManagerImpl.JNDI_KEY, getManager());
- CurrentManager.setRootManager(manager);
+ setResourceLoader(new DefaultResourceLoader());
+ setNamingContext(new DefaultNamingContext());
}
- public ManagerImpl getManager()
+ public void initialize()
{
- return manager;
- }
-
- protected abstract WebBeanDiscovery getWebBeanDiscovery();
-
- protected abstract EjbDiscovery getEjbDiscovery();
-
- public abstract ResourceLoader getResourceLoader();
-
- protected void validateBootstrap()
- {
- if (getManager() == null)
+ if (getResourceLoader() == null)
{
- throw new IllegalStateException("getManager() is not set on bootstrap");
+ throw new IllegalStateException("ResourceLoader not set");
}
- if (getWebBeanDiscovery() == null)
+ if (getNamingContext() == null)
{
- throw new IllegalStateException("WebBeanDiscovery plugin not set on bootstrap");
+ throw new IllegalStateException("NamingContext is not set");
}
- if (getResourceLoader() == null)
+ if (getEjbResolver() == null)
{
- throw new IllegalStateException("ResourceLoader plugin not set on bootstrap");
+ throw new IllegalStateException("EjbResolver is not set");
}
+ this.manager = new ManagerImpl(getNamingContext(), getEjbResolver(), getResourceLoader());
+ getManager().getNaming().bind(ManagerImpl.JNDI_KEY, getManager());
+ CurrentManager.setRootManager(manager);
}
+
+ public ManagerImpl getManager()
+ {
+ return manager;
+ }
/**
* Register the bean with the getManager(), including any standard (built in)
@@ -110,38 +104,44 @@
beanDeployer.addClass(HttpSessionManager.class);
beanDeployer.deploy();
}
-
-
- /**
- * Starts the boot process.
- *
- * Discovers the beans and registers them with the getManager(). Also
- * resolves the injection points.
- *
- * @param webBeanDiscovery The discovery implementation
- */
+
public void boot()
{
synchronized (this)
{
log.info("Starting Web Beans RI " + getVersion());
- validateBootstrap();
+ if (manager == null)
+ {
+ throw new IllegalStateException("Manager has not been initialized");
+ }
+ if (getWebBeanDiscovery() == null)
+ {
+ throw new IllegalStateException("WebBeanDiscovery not set");
+ }
+ if (getEjbDiscovery() == null)
+ {
+ throw new IllegalStateException("EjbDiscovery is not set");
+ }
+ if (getResourceLoader() == null)
+ {
+ throw new IllegalStateException("ResourceLoader not set");
+ }
// Must populate EJB cache first, as we need it to detect whether a
// bean is an EJB!
- getManager().getEjbDescriptorCache().addAll(getEjbDiscovery().discoverEjbs());
+ manager.getEjbDescriptorCache().addAll(getEjbDiscovery().discoverEjbs());
BeansXmlParser parser = new BeansXmlParser(getResourceLoader(), getWebBeanDiscovery().discoverWebBeansXml());
parser.parse();
List<Class<? extends Annotation>> enabledDeploymentTypes = parser.getEnabledDeploymentTypes();
if (enabledDeploymentTypes != null)
{
- getManager().setEnabledDeploymentTypes(enabledDeploymentTypes);
+ manager.setEnabledDeploymentTypes(enabledDeploymentTypes);
}
registerBeans(getWebBeanDiscovery().discoverWebBeanClasses());
- getManager().fireEvent(getManager(), new InitializedLiteral());
+ manager.fireEvent(manager, new InitializedLiteral());
log.info("Web Beans initialized. Validating beans.");
- getManager().getResolver().resolveInjectionPoints();
+ manager.getResolver().resolveInjectionPoints();
new BeanValidator(manager).validate();
- getManager().fireEvent(getManager(), new DeployedLiteral());
+ manager.fireEvent(manager, new DeployedLiteral());
}
}
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockBootstrap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockBootstrap.java 2009-02-17 18:35:44 UTC (rev 1560)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockBootstrap.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -1,226 +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.mock;
-
-import java.lang.annotation.Annotation;
-
-import javax.annotation.Resource;
-import javax.ejb.EJB;
-import javax.inject.manager.InjectionPoint;
-import javax.naming.Context;
-import javax.persistence.PersistenceContext;
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.TransactionManager;
-import javax.transaction.UserTransaction;
-
-import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
-import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
-import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
-import org.jboss.webbeans.ejb.spi.EjbResolver;
-import org.jboss.webbeans.mock.context.MockApplicationContext;
-import org.jboss.webbeans.mock.context.MockDependentContext;
-import org.jboss.webbeans.mock.context.MockRequestContext;
-import org.jboss.webbeans.mock.context.MockSessionContext;
-import org.jboss.webbeans.resource.AbstractNamingContext;
-import org.jboss.webbeans.resources.spi.NamingContext;
-import org.jboss.webbeans.resources.spi.ResourceLoader;
-
-public class MockBootstrap extends WebBeansBootstrap
-{
-
- public static class MockNaming extends AbstractNamingContext
- {
-
- private Context context;
-
- public void setContext(Context context)
- {
- this.context = context;
- }
-
- public Context getContext()
- {
- return context;
- }
-
- public void bind(String key, Object value)
- {
- if (context != null)
- {
- super.bind(key, value);
- }
- }
-
- public <T> T lookup(String name, Class<? extends T> expectedType)
- {
- if (context != null)
- {
- T instance = overrideLookup(name, expectedType);
- if (instance == null)
- {
- instance = super.lookup(name, expectedType);
- }
- return instance;
- }
- else
- {
- return null;
- }
- }
-
- @SuppressWarnings("unchecked")
- private <T> T overrideLookup(String name, Class<? extends T> expectedType)
- {
- // JBoss Embedded EJB 3.1 doesn't seem to bind this!
- if (name.equals("java:comp/UserTransaction"))
- {
- final TransactionManager tm = super.lookup("java:/TransactionManager", TransactionManager.class);
- return (T) new UserTransaction()
- {
-
- public void begin() throws NotSupportedException, SystemException
- {
- tm.begin();
- }
-
- public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
- {
- tm.commit();
- }
-
- public int getStatus() throws SystemException
- {
- return tm.getStatus();
- }
-
- public void rollback() throws IllegalStateException, SecurityException, SystemException
- {
- tm.rollback();
- }
-
- public void setRollbackOnly() throws IllegalStateException, SystemException
- {
- tm.setRollbackOnly();
- }
-
- public void setTransactionTimeout(int seconds) throws SystemException
- {
- tm.setTransactionTimeout(seconds);
- }
-
- };
- }
- else
- {
- return null;
- }
- }
-
- };
-
- private static final EjbResolver MOCK_EJB_RESOLVER = new EjbResolver()
- {
-
- public Class<? extends Annotation> getEJBAnnotation()
- {
- return EJB.class;
- }
-
- public Class<? extends Annotation> getPersistenceContextAnnotation()
- {
- return PersistenceContext.class;
- }
-
- public Object resolveEjb(InjectionPoint injectionPoint, NamingContext namingContext)
- {
- return null;
- }
-
- public Object resolvePersistenceContext(InjectionPoint injectionPoint, NamingContext namingContext)
- {
- return null;
- }
-
- public Class<? extends Annotation> getResourceAnnotation()
- {
- return Resource.class;
- }
-
- public Object resolveResource(InjectionPoint injectionPoint, NamingContext namingContext)
- {
- return null;
- }
-
-
-
- };
-
- private WebBeanDiscovery webBeanDiscovery;
- private EjbDiscovery ejbDiscovery;
- private ResourceLoader resourceLoader;
-
- private MockNaming mockNaming;
-
- public MockBootstrap()
- {
- this.resourceLoader = new MockResourceLoader();
- this.mockNaming = new MockNaming();
- initManager(mockNaming, MOCK_EJB_RESOLVER, resourceLoader);
- setupContexts();
- }
-
- protected void setupContexts()
- {
- getManager().addContext(new MockRequestContext());
- getManager().addContext(new MockSessionContext());
- getManager().addContext(new MockApplicationContext());
- getManager().addContext(new MockDependentContext());
- }
-
- public void setWebBeanDiscovery(WebBeanDiscovery webBeanDiscovery)
- {
- this.webBeanDiscovery = webBeanDiscovery;
- }
-
- @Override
- protected WebBeanDiscovery getWebBeanDiscovery()
- {
- return this.webBeanDiscovery;
- }
-
- @Override
- public ResourceLoader getResourceLoader()
- {
- return resourceLoader;
- }
-
- public MockNaming getNaming()
- {
- return mockNaming;
- }
-
- @Override
- protected EjbDiscovery getEjbDiscovery()
- {
- return new MockEjbDiscovery(webBeanDiscovery.discoverWebBeanClasses());
- }
-
-}
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockEjBResolver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockEjBResolver.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockEjBResolver.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -0,0 +1,47 @@
+/**
+ *
+ */
+package org.jboss.webbeans.mock;
+
+import java.lang.annotation.Annotation;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.inject.manager.InjectionPoint;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.webbeans.ejb.spi.EjbResolver;
+import org.jboss.webbeans.resources.spi.NamingContext;
+
+final class MockEjBResolver implements EjbResolver
+{
+ public Class<? extends Annotation> getEJBAnnotation()
+ {
+ return EJB.class;
+ }
+
+ public Class<? extends Annotation> getPersistenceContextAnnotation()
+ {
+ return PersistenceContext.class;
+ }
+
+ public Object resolveEjb(InjectionPoint injectionPoint, NamingContext namingContext)
+ {
+ return null;
+ }
+
+ public Object resolvePersistenceContext(InjectionPoint injectionPoint, NamingContext namingContext)
+ {
+ return null;
+ }
+
+ public Class<? extends Annotation> getResourceAnnotation()
+ {
+ return Resource.class;
+ }
+
+ public Object resolveResource(InjectionPoint injectionPoint, NamingContext namingContext)
+ {
+ return null;
+ }
+}
\ No newline at end of file
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockEjBResolver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java (from rev 1554, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockBootstrap.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -0,0 +1,79 @@
+/*
+ * 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.mock;
+
+
+
+import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
+import org.jboss.webbeans.ejb.spi.EjbResolver;
+import org.jboss.webbeans.mock.context.MockApplicationContext;
+import org.jboss.webbeans.mock.context.MockDependentContext;
+import org.jboss.webbeans.mock.context.MockRequestContext;
+import org.jboss.webbeans.mock.context.MockSessionContext;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+
+public class MockLifecycle
+{
+
+ private static final EjbResolver MOCK_EJB_RESOLVER = new MockEjBResolver();
+ private static final ResourceLoader MOCK_RESOURCE_LOADER = new MockResourceLoader();
+
+ private final WebBeansBootstrap bootstrap;
+ private final MockWebBeanDiscovery webBeanDiscovery;
+
+ public MockLifecycle()
+ {
+ this(new MockWebBeanDiscovery());
+ }
+
+ public MockLifecycle(MockWebBeanDiscovery mockWebBeanDiscovery)
+ {
+ this.webBeanDiscovery = mockWebBeanDiscovery;
+ if (webBeanDiscovery == null)
+ {
+ throw new IllegalStateException("No WebBeanDiscovery is available");
+ }
+ bootstrap = new WebBeansBootstrap();
+ bootstrap.setNamingContext(new MockNamingContext(null));
+ bootstrap.setEjbResolver(MOCK_EJB_RESOLVER);
+ bootstrap.setResourceLoader(MOCK_RESOURCE_LOADER);
+ bootstrap.setWebBeanDiscovery(webBeanDiscovery);
+ bootstrap.initialize();
+
+ bootstrap.getManager().addContext(new MockRequestContext());
+ bootstrap.getManager().addContext(new MockSessionContext());
+ bootstrap.getManager().addContext(new MockApplicationContext());
+ bootstrap.getManager().addContext(new MockDependentContext());
+ }
+
+ public MockWebBeanDiscovery getWebBeanDiscovery()
+ {
+ return webBeanDiscovery;
+ }
+
+ public WebBeansBootstrap getBootstrap()
+ {
+ return bootstrap;
+ }
+
+ public void beginApplication()
+ {
+ bootstrap.setEjbDiscovery(new MockEjbDiscovery(webBeanDiscovery.discoverWebBeanClasses()));
+ bootstrap.boot();
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockNamingContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockNamingContext.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockNamingContext.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -0,0 +1,106 @@
+/**
+ *
+ */
+package org.jboss.webbeans.mock;
+
+import javax.naming.Context;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
+
+import org.jboss.webbeans.resources.spi.helpers.AbstractNamingContext;
+
+public class MockNamingContext extends AbstractNamingContext
+{
+
+ private final Context context;
+
+ public MockNamingContext(Context context)
+ {
+ this.context = context;
+ }
+
+ public void bind(String key, Object value)
+ {
+ if (context != null)
+ {
+ super.bind(key, value);
+ }
+ }
+
+ public <T> T lookup(String name, Class<? extends T> expectedType)
+ {
+ if (context != null)
+ {
+ T instance = overrideLookup(name, expectedType);
+ if (instance == null)
+ {
+ instance = super.lookup(name, expectedType);
+ }
+ return instance;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T> T overrideLookup(String name, Class<? extends T> expectedType)
+ {
+ // JBoss Embedded EJB 3.1 doesn't seem to bind this!
+ if (name.equals("java:comp/UserTransaction"))
+ {
+ final TransactionManager tm = super.lookup("java:/TransactionManager", TransactionManager.class);
+ return (T) new UserTransaction()
+ {
+
+ public void begin() throws NotSupportedException, SystemException
+ {
+ tm.begin();
+ }
+
+ public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
+ {
+ tm.commit();
+ }
+
+ public int getStatus() throws SystemException
+ {
+ return tm.getStatus();
+ }
+
+ public void rollback() throws IllegalStateException, SecurityException, SystemException
+ {
+ tm.rollback();
+ }
+
+ public void setRollbackOnly() throws IllegalStateException, SystemException
+ {
+ tm.setRollbackOnly();
+ }
+
+ public void setTransactionTimeout(int seconds) throws SystemException
+ {
+ tm.setTransactionTimeout(seconds);
+ }
+
+ };
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ @Override
+ public Context getContext()
+ {
+ return context;
+ }
+
+}
\ No newline at end of file
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockNamingContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources (from rev 1554, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resource)
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/AbstractNamingContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resource/AbstractNamingContext.java 2009-02-16 23:56:49 UTC (rev 1554)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/AbstractNamingContext.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -1,102 +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.resource;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.inject.ExecutionException;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-import org.jboss.webbeans.resources.spi.NamingContext;
-
-/**
- * Provides common functionality required by a NamingContext
- *
- * @author Pete Muir
- *
- */
-public abstract class AbstractNamingContext implements NamingContext
-{
-
- public abstract Context getContext();
-
- /**
- * Binds in item to JNDI
- *
- * @param key The key to bind under
- * @param value The value to bind
- */
- public void bind(String key, Object value)
- {
- try
- {
- List<String> parts = splitIntoContexts(key);
- Context context = getContext();
- for (int i = 0; i < parts.size() - 1; i++)
- {
- context = (Context) context.lookup(parts.get(i));
- }
- context.bind(parts.get(parts.size() - 1), value);
- }
- catch (NamingException e)
- {
- throw new ExecutionException("Cannot bind " + value + " to " + key, e);
- }
- }
-
- /**
- * Lookup an item from JNDI
- *
- * @param name The key
- * @param expectedType The expected return type
- * @return The found item
- */
- public <T> T lookup(String name, Class<? extends T> expectedType)
- {
- Object instance;
- try
- {
- instance = getContext().lookup(name);
- }
- catch (NamingException e)
- {
- throw new ExecutionException("Cannot lookup " + name, e);
- }
- try
- {
- return expectedType.cast(instance);
- }
- catch (ClassCastException e)
- {
- throw new ExecutionException(instance + " not of expected type " + expectedType, e);
- }
- }
-
- private static List<String> splitIntoContexts(String key)
- {
- List<String> parts = new ArrayList<String>();
- for (String part : key.split("/"))
- {
- parts.add(part);
- }
- return parts;
- }
-
-}
\ No newline at end of file
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultNaming.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resource/DefaultNaming.java 2009-02-16 23:56:49 UTC (rev 1554)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultNaming.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -1,60 +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.resource;
-
-import javax.inject.ExecutionException;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-/**
- * The default naming provider
- *
- * @author Pete Muir
- */
-public class DefaultNaming extends AbstractNamingContext
-{
- private static final long serialVersionUID = 1L;
- // The initial lookup context
- private transient InitialContext initialContext;
-
- /**
- * Constructor
- */
- public DefaultNaming()
- {
- try
- {
- this.initialContext = new InitialContext();
- }
- catch (NamingException e)
- {
- throw new ExecutionException("Could not obtain InitialContext", e);
- }
- }
-
- /**
- * Gets the initial context
- *
- * @return The initial context
- */
- public InitialContext getContext()
- {
- return initialContext;
- }
-
-}
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultNamingContext.java (from rev 1554, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resource/DefaultNaming.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultNamingContext.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultNamingContext.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -0,0 +1,62 @@
+/*
+ * 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.resources;
+
+import javax.inject.ExecutionException;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.webbeans.resources.spi.helpers.AbstractNamingContext;
+
+/**
+ * The default naming provider
+ *
+ * @author Pete Muir
+ */
+public class DefaultNamingContext extends AbstractNamingContext
+{
+ private static final long serialVersionUID = 1L;
+ // The initial lookup context
+ private transient InitialContext initialContext;
+
+ /**
+ * Constructor
+ */
+ public DefaultNamingContext()
+ {
+ try
+ {
+ this.initialContext = new InitialContext();
+ }
+ catch (NamingException e)
+ {
+ throw new ExecutionException("Could not obtain InitialContext", e);
+ }
+ }
+
+ /**
+ * Gets the initial context
+ *
+ * @return The initial context
+ */
+ public InitialContext getContext()
+ {
+ return initialContext;
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultNamingContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultResourceLoader.java (from rev 1554, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/SimpleResourceLoader.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultResourceLoader.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultResourceLoader.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -0,0 +1,93 @@
+/*
+ * 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.resources;
+
+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;
+
+/**
+ * A simple resource loader.
+ *
+ * Uses {@link DefaultResourceLoader}'s classloader if the Thread Context
+ * Classloader isn't available
+ *
+ * @author Pete Muir
+ *
+ */
+public class DefaultResourceLoader implements ResourceLoader
+{
+
+ public Class<?> classForName(String name)
+ {
+
+ try
+ {
+ if (Thread.currentThread().getContextClassLoader() != null)
+ {
+ return Thread.currentThread().getContextClassLoader().loadClass(name);
+ }
+ else
+ {
+ return Class.forName(name);
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ catch (NoClassDefFoundError e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ }
+
+ public URL getResource(String name)
+ {
+ if (Thread.currentThread().getContextClassLoader() != null)
+ {
+ return Thread.currentThread().getContextClassLoader().getResource(name);
+ }
+ else
+ {
+ return getClass().getResource(name);
+ }
+ }
+
+ public Iterable<URL> getResources(String name)
+ {
+ try
+ {
+ if (Thread.currentThread().getContextClassLoader() != null)
+ {
+ return new EnumerationIterable<URL>(Thread.currentThread().getContextClassLoader().getResources(name));
+ }
+ else
+ {
+ return new EnumerationIterable<URL>(getClass().getClassLoader().getResources(name));
+ }
+ }
+ catch (IOException e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resources/DefaultResourceLoader.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: 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 2009-02-17 18:35:44 UTC (rev 1560)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletBootstrap.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -1,177 +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.servlet;
-
-import java.lang.reflect.Constructor;
-
-import javax.servlet.ServletContext;
-
-import org.jboss.webbeans.bootstrap.PropertiesBasedBootstrap;
-import org.jboss.webbeans.bootstrap.SimpleResourceLoader;
-import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
-import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
-import org.jboss.webbeans.context.ApplicationContext;
-import org.jboss.webbeans.context.ConversationContext;
-import org.jboss.webbeans.context.DependentContext;
-import org.jboss.webbeans.context.RequestContext;
-import org.jboss.webbeans.context.SessionContext;
-import org.jboss.webbeans.ejb.spi.EjbResolver;
-import org.jboss.webbeans.resource.DefaultNaming;
-import org.jboss.webbeans.resources.spi.NamingContext;
-import org.jboss.webbeans.resources.spi.ResourceLoader;
-import org.jboss.webbeans.util.DeploymentProperties;
-
-/**
- * Bootstrapper for usage within servlet environments
- *
- * @author Pete Muir
- */
-public class ServletBootstrap extends PropertiesBasedBootstrap
-{
-
- // The resource loader
- private final ResourceLoader resourceLoader;
- // The discover implementation
- private final WebBeanDiscovery webBeanDiscovery;
-
- private final EjbDiscovery ejbDiscovery;
-
- // The deployment properties
- private final DeploymentProperties deploymentProperties;
-
- public ServletBootstrap(ServletContext servletContext)
- {
-
- // Create a simpple resource loader based for initial loading
- ResourceLoader temporaryResourceLoader = new SimpleResourceLoader();
- this.deploymentProperties = new DeploymentProperties(temporaryResourceLoader);
-
- this.resourceLoader = createResourceLoader(servletContext, temporaryResourceLoader);
-
- // Now safe to initialize the manager
- initManager(servletContext);
-
- this.webBeanDiscovery = createWebBeanDiscovery(servletContext);
- this.ejbDiscovery = createEjbDiscovery(servletContext);
-
- // Register the contexts for the Servlet environment
- getManager().addContext(DependentContext.INSTANCE);
- getManager().addContext(RequestContext.INSTANCE);
- getManager().addContext(SessionContext.INSTANCE);
- getManager().addContext(ApplicationContext.INSTANCE);
- getManager().addContext(ConversationContext.INSTANCE);
- ApplicationContext.INSTANCE.setBeanMap(new ApplicationBeanMap(servletContext));
- }
-
- private void initManager(ServletContext servletContext)
- {
- initManager(createNaming(servletContext), createEjbResolver(servletContext), getResourceLoader());
- }
-
- protected NamingContext createNaming(ServletContext servletContext)
- {
- Constructor<? extends NamingContext> namingConstructor = getClassConstructor(getDeploymentProperties(), getResourceLoader(), NamingContext.PROPERTY_NAME, NamingContext.class, ServletContext.class);
- if (namingConstructor != null)
- {
- return newInstance(namingConstructor, servletContext);
- }
- else
- {
- return new DefaultNaming();
- }
- }
-
- protected EjbResolver createEjbResolver(ServletContext servletContext)
- {
- Constructor<? extends EjbResolver> constructor = getClassConstructor(getDeploymentProperties(), getResourceLoader(), EjbResolver.PROPERTY_NAME, EjbResolver.class, ServletContext.class);
- if (constructor != null)
- {
- return newInstance(constructor, servletContext);
- }
- else
- {
- throw new IllegalStateException("Unable to find a EjbResolver, check Web Beans is correctly installed in your container");
- }
- }
-
- protected EjbDiscovery createEjbDiscovery(ServletContext servletContext)
- {
- Constructor<? extends EjbDiscovery> constructor = getClassConstructor(getDeploymentProperties(), getResourceLoader(), EjbDiscovery.PROPERTY_NAME, EjbDiscovery.class, ServletContext.class);
- if (constructor != null)
- {
- return newInstance(constructor, servletContext);
- }
- else
- {
- throw new IllegalStateException("Unable to find a EjbDiscovery, check Web Beans is correctly installed in your container");
- }
- }
-
- protected WebBeanDiscovery createWebBeanDiscovery(ServletContext servletContext)
- {
- // 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
- {
- return newInstance(webBeanDiscoveryConstructor, servletContext);
- }
- }
-
- protected ResourceLoader createResourceLoader(ServletContext servletContext, ResourceLoader resourceLoader)
- {
- // Attempt to create a plugin resource loader
- Constructor<? extends ResourceLoader> resourceLoaderConstructor = getClassConstructor(deploymentProperties, resourceLoader, ResourceLoader.PROPERTY_NAME, ResourceLoader.class, ServletContext.class);
- if (resourceLoaderConstructor != null)
- {
- return newInstance(resourceLoaderConstructor, servletContext);
- }
- else
- {
- return resourceLoader;
- }
- }
-
- @Override
- protected DeploymentProperties getDeploymentProperties()
- {
- return deploymentProperties;
- }
-
- @Override
- public ResourceLoader getResourceLoader()
- {
- return resourceLoader;
- }
-
- @Override
- protected WebBeanDiscovery getWebBeanDiscovery()
- {
- return webBeanDiscovery;
- }
-
- @Override
- protected EjbDiscovery getEjbDiscovery()
- {
- return ejbDiscovery;
- }
-
-}
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletInitialization.java (from rev 1554, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletBootstrap.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletInitialization.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletInitialization.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -0,0 +1,155 @@
+/*
+ * 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.servlet;
+
+import java.lang.reflect.Constructor;
+
+import javax.servlet.ServletContext;
+
+import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.bootstrap.PropertiesBasedInitialization;
+import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
+import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
+import org.jboss.webbeans.context.ApplicationContext;
+import org.jboss.webbeans.context.ConversationContext;
+import org.jboss.webbeans.context.DependentContext;
+import org.jboss.webbeans.context.RequestContext;
+import org.jboss.webbeans.context.SessionContext;
+import org.jboss.webbeans.ejb.spi.EjbResolver;
+import org.jboss.webbeans.resources.DefaultNamingContext;
+import org.jboss.webbeans.resources.DefaultResourceLoader;
+import org.jboss.webbeans.resources.spi.NamingContext;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.util.DeploymentProperties;
+
+/**
+ * Bootstrapper for usage within servlet environments
+ *
+ * @author Pete Muir
+ */
+public class ServletInitialization extends PropertiesBasedInitialization
+{
+
+ // The deployment properties
+ private final DeploymentProperties deploymentProperties;
+ private final ResourceLoader resourceLoader;
+
+ private final WebBeansBootstrap bootstrap;
+
+ public ServletInitialization(ServletContext servletContext)
+ {
+ bootstrap = new WebBeansBootstrap();
+
+ // Create a simple resource loader based for initial loading
+ ResourceLoader temporaryResourceLoader = new DefaultResourceLoader();
+ this.deploymentProperties = new DeploymentProperties(temporaryResourceLoader);
+ this.resourceLoader = createResourceLoader(servletContext, temporaryResourceLoader);
+
+ bootstrap.setResourceLoader(resourceLoader);
+ bootstrap.setNamingContext(createNaming(servletContext));
+ bootstrap.setEjbResolver(createEjbResolver(servletContext));
+ bootstrap.setEjbDiscovery(createEjbDiscovery(servletContext));
+ bootstrap.setWebBeanDiscovery(createWebBeanDiscovery(servletContext));
+
+ bootstrap.initialize();
+
+ ManagerImpl manager = bootstrap.getManager();
+
+ // Register the contexts for the Servlet environment
+ manager.addContext(DependentContext.INSTANCE);
+ manager.addContext(RequestContext.INSTANCE);
+ manager.addContext(SessionContext.INSTANCE);
+ manager.addContext(ApplicationContext.INSTANCE);
+ manager.addContext(ConversationContext.INSTANCE);
+ ApplicationContext.INSTANCE.setBeanMap(new ApplicationBeanMap(servletContext));
+ }
+
+ protected NamingContext createNaming(ServletContext servletContext)
+ {
+ Constructor<? extends NamingContext> namingConstructor = getClassConstructor(deploymentProperties, resourceLoader, NamingContext.PROPERTY_NAME, NamingContext.class, ServletContext.class);
+ if (namingConstructor != null)
+ {
+ return newInstance(namingConstructor, servletContext);
+ }
+ else
+ {
+ return new DefaultNamingContext();
+ }
+ }
+
+ protected EjbResolver createEjbResolver(ServletContext servletContext)
+ {
+ Constructor<? extends EjbResolver> constructor = getClassConstructor(deploymentProperties, resourceLoader, EjbResolver.PROPERTY_NAME, EjbResolver.class, ServletContext.class);
+ if (constructor != null)
+ {
+ return newInstance(constructor, servletContext);
+ }
+ else
+ {
+ throw new IllegalStateException("Unable to find a EjbResolver, check Web Beans is correctly installed in your container");
+ }
+ }
+
+ protected EjbDiscovery createEjbDiscovery(ServletContext servletContext)
+ {
+ Constructor<? extends EjbDiscovery> constructor = getClassConstructor(deploymentProperties, resourceLoader, EjbDiscovery.PROPERTY_NAME, EjbDiscovery.class, ServletContext.class);
+ if (constructor != null)
+ {
+ return newInstance(constructor, servletContext);
+ }
+ else
+ {
+ throw new IllegalStateException("Unable to find a EjbDiscovery, check Web Beans is correctly installed in your container");
+ }
+ }
+
+ protected WebBeanDiscovery createWebBeanDiscovery(ServletContext servletContext)
+ {
+ // 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
+ {
+ return newInstance(webBeanDiscoveryConstructor, servletContext);
+ }
+ }
+
+ protected ResourceLoader createResourceLoader(ServletContext servletContext, ResourceLoader defaultResourceLoader)
+ {
+ // Attempt to create a plugin resource loader
+ Constructor<? extends ResourceLoader> resourceLoaderConstructor = getClassConstructor(deploymentProperties, defaultResourceLoader, ResourceLoader.PROPERTY_NAME, ResourceLoader.class, ServletContext.class);
+ if (resourceLoaderConstructor != null)
+ {
+ return newInstance(resourceLoaderConstructor, servletContext);
+ }
+ else
+ {
+ return defaultResourceLoader;
+ }
+ }
+
+ public void boot()
+ {
+ bootstrap.boot();
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletInitialization.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 2009-02-17 18:35:44 UTC (rev 1560)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -17,14 +17,12 @@
package org.jboss.webbeans.servlet;
-import javax.context.Conversation;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.context.ApplicationContext;
-import org.jboss.webbeans.context.ConversationContext;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.context.RequestContext;
import org.jboss.webbeans.context.SessionContext;
@@ -40,6 +38,14 @@
*/
public class ServletLifecycle
{
+
+ private static final ServletLifecycle lifecycle = new ServletLifecycle();
+
+ public static ServletLifecycle instance()
+ {
+ return lifecycle;
+ }
+
private static LogProvider log = Logging.getLogProvider(ServletLifecycle.class);
/**
@@ -49,16 +55,16 @@
*
* @param context The servlet context
*/
- public static void beginApplication(ServletContext servletContext)
+ public void beginApplication(ServletContext servletContext)
{
log.trace("Application is starting up");
- new ServletBootstrap(servletContext).boot();
+ new ServletInitialization(servletContext).boot();
}
/**
* Ends the application
*/
- public static void endApplication()
+ public void endApplication()
{
log.trace("Application is shutting down");
ApplicationContext.INSTANCE.destroy();
@@ -70,7 +76,7 @@
*
* @param session The HTTP session
*/
- public static void beginSession(HttpSession session)
+ public void beginSession(HttpSession session)
{
log.trace("Starting session " + session.getId());
}
@@ -80,7 +86,7 @@
*
* @param session The HTTP session
*/
- public static void endSession(HttpSession session)
+ public void endSession(HttpSession session)
{
log.trace("Ending session " + session.getId());
SessionContext.INSTANCE.setBeanMap(new HttpSessionBeanMap(session));
@@ -98,7 +104,7 @@
*
* @param request The request
*/
- public static void beginRequest(HttpServletRequest request)
+ public void beginRequest(HttpServletRequest request)
{
log.trace("Processing HTTP request " + request.getRequestURI() + " begins");
SessionContext.INSTANCE.setBeanMap(new HttpSessionBeanMap(request.getSession()));
@@ -110,7 +116,7 @@
*
* @param request The request
*/
- public static void endRequest(HttpServletRequest request)
+ public void endRequest(HttpServletRequest request)
{
log.trace("Processing HTTP request " + request.getRequestURI() + " ends");
DependentContext.INSTANCE.setActive(false);
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansListener.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansListener.java 2009-02-17 18:35:44 UTC (rev 1560)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansListener.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -45,7 +45,7 @@
*/
public void contextInitialized(ServletContextEvent event)
{
- ServletLifecycle.beginApplication(event.getServletContext());
+ ServletLifecycle.instance().beginApplication(event.getServletContext());
}
/**
@@ -55,7 +55,7 @@
*/
public void sessionCreated(HttpSessionEvent event)
{
- ServletLifecycle.beginSession(event.getSession());
+ ServletLifecycle.instance().beginSession(event.getSession());
}
/**
@@ -65,7 +65,7 @@
*/
public void sessionDestroyed(HttpSessionEvent event)
{
- ServletLifecycle.endSession(event.getSession());
+ ServletLifecycle.instance().endSession(event.getSession());
}
/**
@@ -75,7 +75,7 @@
*/
public void contextDestroyed(ServletContextEvent event)
{
- ServletLifecycle.endApplication();
+ ServletLifecycle.instance().endApplication();
}
/**
@@ -87,7 +87,7 @@
{
if (event.getServletRequest() instanceof HttpServletRequest)
{
- ServletLifecycle.endRequest((HttpServletRequest) event.getServletRequest());
+ ServletLifecycle.instance().endRequest((HttpServletRequest) event.getServletRequest());
}
else
{
@@ -104,7 +104,7 @@
{
if (event.getServletRequest() instanceof HttpServletRequest)
{
- ServletLifecycle.beginRequest((HttpServletRequest) event.getServletRequest());
+ ServletLifecycle.instance().beginRequest((HttpServletRequest) event.getServletRequest());
}
else
{
Deleted: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/AbstractEjbEmbeddableTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/AbstractEjbEmbeddableTest.java 2009-02-17 18:35:44 UTC (rev 1560)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/AbstractEjbEmbeddableTest.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -1,72 +0,0 @@
-package org.jboss.webbeans.test.unit;
-
-import java.net.URL;
-import java.util.Properties;
-
-import javax.ejb.EJBContainer;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.AfterSuite;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.BeforeSuite;
-
-
-
-public abstract class AbstractEjbEmbeddableTest extends AbstractTest
-{
-
- private EJBContainer ejbContainer;
-
- @AfterSuite
- public void afterClass() throws Exception
- {
- EJBContainer current = EJBContainer.getCurrentEJBContainer();
- if(current != null)
- {
- current.close();
- }
- }
-
- @BeforeSuite
- public void beforeClass() throws Exception
- {
- Properties properties = new Properties();
- String module = getURLToTestClasses(getTestClassesPath());
- properties.setProperty(EJBContainer.EMBEDDABLE_MODULES_PROPERTY, module);
- this.ejbContainer = EJBContainer.createEJBContainer(properties);
- }
-
- @BeforeMethod
- public void before() throws Exception
- {
- super.before();
- bootstrap.getNaming().setContext(new InitialContext());
- }
-
- @AfterMethod
- public void after() throws Exception
- {
- bootstrap.getNaming().setContext(null);
- }
-
-
- protected String getTestClassesPath()
- {
- return "org/jboss/webbeans/test";
- }
-
- private static String getURLToTestClasses(String path)
- {
- URL url = Thread.currentThread().getContextClassLoader().getResource(path);
- String s = url.toString();
- return s.substring(0, s.length() - path.length());
- }
-
- public Context getContext()
- {
- return bootstrap.getNaming().getContext();
- }
-
-}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/AbstractTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/AbstractTest.java 2009-02-17 18:35:44 UTC (rev 1560)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/AbstractTest.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -20,8 +20,8 @@
import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.context.DependentContext;
-import org.jboss.webbeans.mock.MockBootstrap;
import org.jboss.webbeans.mock.MockEjbDescriptor;
+import org.jboss.webbeans.mock.MockLifecycle;
import org.jboss.webbeans.mock.MockWebBeanDiscovery;
import org.jboss.webbeans.util.EnumerationIterable;
import org.testng.annotations.BeforeMethod;
@@ -62,7 +62,7 @@
protected static final int BUILT_IN_BEANS = 3;
protected ManagerImpl manager;
- protected MockBootstrap bootstrap;
+ protected MockLifecycle lifecycle;
protected MockWebBeanDiscovery discovery;
public static boolean visited = false;
@@ -70,10 +70,9 @@
@BeforeMethod
public void before() throws Exception
{
- bootstrap = new MockBootstrap();
- manager = bootstrap.getManager();
- this.discovery = new MockWebBeanDiscovery();
- bootstrap.setWebBeanDiscovery(discovery);
+ lifecycle = new MockLifecycle();
+ this.discovery = lifecycle.getWebBeanDiscovery();
+ this.manager = lifecycle.getBootstrap().getManager();
}
protected List<Class<? extends Annotation>> getEnabledDeploymentTypes()
@@ -132,8 +131,7 @@
protected void deployBeans(Class<?>... classes)
{
discovery.setWebBeanClasses(Arrays.asList(classes));
- bootstrap.boot();
- manager = bootstrap.getManager();
+ lifecycle.beginApplication();
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/bootstrap/BootstrapTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/bootstrap/BootstrapTest.java 2009-02-17 18:35:44 UTC (rev 1560)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/bootstrap/BootstrapTest.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -13,7 +13,7 @@
import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.RIBean;
import org.jboss.webbeans.bean.SimpleBean;
-import org.jboss.webbeans.mock.MockBootstrap;
+import org.jboss.webbeans.mock.MockLifecycle;
import org.jboss.webbeans.test.unit.AbstractTest;
import org.testng.annotations.Test;
@@ -218,9 +218,8 @@
@Test(groups="bootstrap", expectedExceptions=IllegalStateException.class)
public void testDiscoverFails()
{
- MockBootstrap bootstrap = new MockBootstrap();
- bootstrap.setWebBeanDiscovery(null);
- bootstrap.boot();
+ MockLifecycle lifecycle = new MockLifecycle(null);
+ lifecycle.beginApplication();
}
@Test(groups="bootstrap")
Added: ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java
===================================================================
--- ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java (rev 0)
+++ ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -0,0 +1,85 @@
+package org.jboss.webbeans.bootstrap.api;
+
+import javax.inject.manager.Manager;
+
+import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
+import org.jboss.webbeans.ejb.spi.EjbResolver;
+import org.jboss.webbeans.resources.spi.NamingContext;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+
+/**
+ * Bootstrap API for Web Beans.
+ *
+ * @author Pete Muir
+ *
+ */
+public interface Bootstrap
+{
+
+ /**
+ * Set the Web Bean Discovery to use
+ *
+ * @param webBeanDiscovery
+ */
+ public void setWebBeanDiscovery(WebBeanDiscovery webBeanDiscovery);
+
+ /**
+ * Set the EjbDiscovery to use
+ *
+ * @param ejbDiscovery
+ */
+ public void setEjbDiscovery(EjbDiscovery ejbDiscovery);
+
+ /**
+ * Set the EjbResolver to use
+ *
+ * @param ejbResolver
+ */
+ public void setEjbResolver(EjbResolver ejbResolver);
+
+ /**
+ * Set the NamingContext to use.
+ *
+ * By default @{link org.jboss.webbeans.resources.DefaultNamingContext} will
+ * be used
+ *
+ * @param namingContext
+ */
+ public void setNamingContext(NamingContext namingContext);
+
+ /**
+ * Set the ResourceLoader to use. By default @{link
+ * org.jboss.webbeans.resources.DefaultResourceLoader} will be used
+ *
+ * @param resourceLoader
+ */
+ public void setResourceLoader(ResourceLoader resourceLoader);
+
+ /**
+ * Initialize the bootstrap:
+ * <ul>
+ * <li>Create the manager and bind it to JNDI</li>
+ * </ul>
+ */
+ public void initialize();
+
+ /**
+ * Get the manager being used for bootstrap.
+ *
+ * @return the manager. Unless {@link #initialize()} has been called, this
+ * method will return null.
+ */
+ public Manager getManager();
+
+ /**
+ * Starts the boot process.
+ *
+ * Discovers the beans and registers them with the getManager(). Also
+ * resolves the injection points. Before running {@link #boot()} the contexts
+ * should be available
+ *
+ */
+ public void boot();
+
+}
Property changes on: ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java
===================================================================
--- ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java (rev 0)
+++ ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -0,0 +1,69 @@
+package org.jboss.webbeans.bootstrap.api.helpers;
+
+import org.jboss.webbeans.bootstrap.api.Bootstrap;
+import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
+import org.jboss.webbeans.ejb.spi.EjbResolver;
+import org.jboss.webbeans.resources.spi.NamingContext;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+
+public abstract class AbstractBootstrap implements Bootstrap
+{
+
+ private WebBeanDiscovery webBeanDiscovery;
+ private ResourceLoader resourceLoader;
+ private NamingContext namingContext;
+ private EjbResolver ejbResolver;
+ private EjbDiscovery ejbDiscovery;
+
+ public void setEjbDiscovery(EjbDiscovery ejbDiscovery)
+ {
+ this.ejbDiscovery = ejbDiscovery;
+ }
+
+ public void setEjbResolver(EjbResolver ejbResolver)
+ {
+ this.ejbResolver = ejbResolver;
+ }
+
+ public void setNamingContext(NamingContext namingContext)
+ {
+ this.namingContext = namingContext;
+ }
+
+ public void setResourceLoader(ResourceLoader resourceLoader)
+ {
+ this.resourceLoader = resourceLoader;
+ }
+
+ public void setWebBeanDiscovery(WebBeanDiscovery webBeanDiscovery)
+ {
+ this.webBeanDiscovery = webBeanDiscovery;
+ }
+
+ public WebBeanDiscovery getWebBeanDiscovery()
+ {
+ return webBeanDiscovery;
+ }
+
+ public ResourceLoader getResourceLoader()
+ {
+ return resourceLoader;
+ }
+
+ public NamingContext getNamingContext()
+ {
+ return namingContext;
+ }
+
+ public EjbResolver getEjbResolver()
+ {
+ return ejbResolver;
+ }
+
+ public EjbDiscovery getEjbDiscovery()
+ {
+ return ejbDiscovery;
+ }
+
+}
\ No newline at end of file
Property changes on: ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/helpers/AbstractNamingContext.java (from rev 1554, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resource/AbstractNamingContext.java)
===================================================================
--- ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/helpers/AbstractNamingContext.java (rev 0)
+++ ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/helpers/AbstractNamingContext.java 2009-02-17 18:58:25 UTC (rev 1561)
@@ -0,0 +1,102 @@
+/*
+ * 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.resources.spi.helpers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.ExecutionException;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.jboss.webbeans.resources.spi.NamingContext;
+
+/**
+ * Provides common functionality required by a NamingContext
+ *
+ * @author Pete Muir
+ *
+ */
+public abstract class AbstractNamingContext implements NamingContext
+{
+
+ public abstract Context getContext();
+
+ /**
+ * Binds in item to JNDI
+ *
+ * @param key The key to bind under
+ * @param value The value to bind
+ */
+ public void bind(String key, Object value)
+ {
+ try
+ {
+ List<String> parts = splitIntoContexts(key);
+ Context context = getContext();
+ for (int i = 0; i < parts.size() - 1; i++)
+ {
+ context = (Context) context.lookup(parts.get(i));
+ }
+ context.bind(parts.get(parts.size() - 1), value);
+ }
+ catch (NamingException e)
+ {
+ throw new ExecutionException("Cannot bind " + value + " to " + key, e);
+ }
+ }
+
+ /**
+ * Lookup an item from JNDI
+ *
+ * @param name The key
+ * @param expectedType The expected return type
+ * @return The found item
+ */
+ public <T> T lookup(String name, Class<? extends T> expectedType)
+ {
+ Object instance;
+ try
+ {
+ instance = getContext().lookup(name);
+ }
+ catch (NamingException e)
+ {
+ throw new ExecutionException("Cannot lookup " + name, e);
+ }
+ try
+ {
+ return expectedType.cast(instance);
+ }
+ catch (ClassCastException e)
+ {
+ throw new ExecutionException(instance + " not of expected type " + expectedType, e);
+ }
+ }
+
+ private static List<String> splitIntoContexts(String key)
+ {
+ List<String> parts = new ArrayList<String>();
+ for (String part : key.split("/"))
+ {
+ parts.add(part);
+ }
+ return parts;
+ }
+
+}
\ No newline at end of file
Property changes on: ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/resources/spi/helpers/AbstractNamingContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the weld-commits
mailing list