Author: shane.bryzak(a)jboss.com
Date: 2008-07-21 10:48:42 -0400 (Mon, 21 Jul 2008)
New Revision: 58
Added:
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/deployment/
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/deployment/DeploymentStrategy.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/init/
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/init/Initialization.java
Modified:
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ContainerImpl.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/servlet/WebBeansListener.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Strings.java
Log:
deployment stuff
Modified: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ContainerImpl.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ContainerImpl.java 2008-07-21
10:56:44 UTC (rev 57)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ContainerImpl.java 2008-07-21
14:48:42 UTC (rev 58)
@@ -76,6 +76,8 @@
{
// TODO Auto-generated method stub
return null;
+
+
}
public Object getInstanceByName(String name)
Added:
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/deployment/DeploymentStrategy.java
===================================================================
---
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/deployment/DeploymentStrategy.java
(rev 0)
+++
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/deployment/DeploymentStrategy.java 2008-07-21
14:48:42 UTC (rev 58)
@@ -0,0 +1,79 @@
+package org.jboss.webbeans.deployment;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import javax.webbeans.Container;
+import javax.webbeans.DeploymentType;
+
+import org.jboss.webbeans.ComponentInstanceImpl;
+import org.jboss.webbeans.ContainerImpl;
+import org.jboss.webbeans.model.SimpleComponentModel;
+import org.jboss.webbeans.util.ClassAnnotatedItem;
+import org.jboss.webbeans.util.LoggerUtil;
+import org.jboss.webbeans.util.MutableAnnotatedItem;
+import org.jboss.webbeans.util.Reflections;
+import org.scannotation.AnnotationDB;
+import org.scannotation.ClasspathUrlFinder;
+
+/**
+ * @author Pete Muir
+ * @author Shane Bryzak
+ *
+ */
+public class DeploymentStrategy
+{
+ private static final Logger log =
LoggerUtil.getLogger(DeploymentStrategy.class.getName());
+
+ private ClassLoader classLoader;
+ private ContainerImpl container;
+
+ public DeploymentStrategy(ClassLoader classLoader, Container container)
+ {
+ this.classLoader = classLoader;
+
+ if (!(container instanceof ContainerImpl))
+ {
+ throw new IllegalArgumentException("Container must be an instance of
ContainerImpl");
+ }
+
+ this.container = (ContainerImpl) container;
+ }
+
+ public void scan()
+ throws ClassNotFoundException
+ {
+ URL[] urls =
ClasspathUrlFinder.findResourceBases("META-INF/web-beans.xml");
+
+ AnnotationDB db = new AnnotationDB();
+ try
+ {
+ db.scanArchives(urls);
+ db.crossReferenceMetaAnnotations();
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException("Epic fail", ex);
+ }
+
+ Map<String,Set<String>> index = db.getAnnotationIndex();
+
+ Set<String> classNames = index.get(DeploymentType.class.getName());
+
+ for (String className : classNames)
+ {
+ SimpleComponentModel componentModel = new SimpleComponentModel(
+ new ClassAnnotatedItem(Reflections.classForName(className)),
+ new MutableAnnotatedItem(null, new HashMap()), container);
+ container.addComponent(new ComponentInstanceImpl(componentModel));
+ }
+ }
+
+ public ClassLoader getClassLoader()
+ {
+ return classLoader;
+ }
+}
\ No newline at end of file
Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/init/Initialization.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/init/Initialization.java
(rev 0)
+++
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/init/Initialization.java 2008-07-21
14:48:42 UTC (rev 58)
@@ -0,0 +1,39 @@
+package org.jboss.webbeans.init;
+
+import javax.servlet.ServletContext;
+import javax.webbeans.Container;
+
+import org.jboss.webbeans.ContainerImpl;
+import org.jboss.webbeans.deployment.DeploymentStrategy;
+
+/**
+ * Initializes the WebBeans metadata
+ *
+ * @author Shane Bryzak
+ *
+ */
+public class Initialization
+{
+ private ServletContext servletContext;
+
+ DeploymentStrategy deploymentStrategy;
+
+ private static Container container;
+
+ public Initialization(ServletContext servletContext)
+ {
+ this.servletContext = servletContext;
+ }
+
+ public Initialization create()
+ {
+ container = new ContainerImpl(null);
+ deploymentStrategy = new
DeploymentStrategy(Thread.currentThread().getContextClassLoader(), container);
+ return this;
+ }
+
+ public void init()
+ {
+
+ }
+}
Modified:
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/servlet/WebBeansListener.java
===================================================================
---
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/servlet/WebBeansListener.java 2008-07-21
10:56:44 UTC (rev 57)
+++
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/servlet/WebBeansListener.java 2008-07-21
14:48:42 UTC (rev 58)
@@ -5,6 +5,8 @@
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
+import org.jboss.webbeans.init.Initialization;
+
/**
*
* @author Shane Bryzak
@@ -13,10 +15,10 @@
public class WebBeansListener implements ServletContextListener, HttpSessionListener
{
-
public void contextInitialized(ServletContextEvent event)
{
- ServletLifecycle.beginApplication( event.getServletContext() );
+ ServletLifecycle.beginApplication( event.getServletContext() );
+ new Initialization( event.getServletContext() ).create().init();
}
public void sessionCreated(HttpSessionEvent event)
Modified: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Strings.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Strings.java 2008-07-21
10:56:44 UTC (rev 57)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Strings.java 2008-07-21
14:48:42 UTC (rev 58)
@@ -1,6 +1,7 @@
package org.jboss.webbeans.util;
import java.beans.Introspector;
+import java.util.StringTokenizer;
public class Strings
{
@@ -9,5 +10,23 @@
{
return Introspector.decapitalize(camelCase);
}
-
+
+ public static String[] split(String strings, String delims)
+ {
+ if (strings==null)
+ {
+ return new String[0];
+ }
+ else
+ {
+ StringTokenizer tokens = new StringTokenizer(strings, delims);
+ String[] result = new String[ tokens.countTokens() ];
+ int i=0;
+ while ( tokens.hasMoreTokens() )
+ {
+ result[i++] = tokens.nextToken();
+ }
+ return result;
+ }
+ }
}