Author: julien(a)jboss.com
Date: 2007-09-09 17:15:03 -0400 (Sun, 09 Sep 2007)
New Revision: 8202
Added:
modules/common/trunk/mc/src/main/org/jboss/portal/common/mc/bootstrap/ActualBootstrap.java
Modified:
modules/common/trunk/build/ide/intellij/idea60/modules/portal/portal.iml
modules/common/trunk/mc/src/main/org/jboss/portal/common/mc/bootstrap/WebBootstrap.java
Log:
improved MC web bootstrap
Modified: modules/common/trunk/build/ide/intellij/idea60/modules/portal/portal.iml
===================================================================
--- modules/common/trunk/build/ide/intellij/idea60/modules/portal/portal.iml 2007-09-07
18:42:36 UTC (rev 8201)
+++ modules/common/trunk/build/ide/intellij/idea60/modules/portal/portal.iml 2007-09-09
21:15:03 UTC (rev 8202)
@@ -10,5 +10,9 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntryProperties />
</component>
+ <component name="VcsManagerConfiguration">
+ <option name="ACTIVE_VCS_NAME" value="svn" />
+ <option name="USE_PROJECT_VCS" value="false" />
+ </component>
</module>
Added:
modules/common/trunk/mc/src/main/org/jboss/portal/common/mc/bootstrap/ActualBootstrap.java
===================================================================
---
modules/common/trunk/mc/src/main/org/jboss/portal/common/mc/bootstrap/ActualBootstrap.java
(rev 0)
+++
modules/common/trunk/mc/src/main/org/jboss/portal/common/mc/bootstrap/ActualBootstrap.java 2007-09-09
21:15:03 UTC (rev 8202)
@@ -0,0 +1,54 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.mc.bootstrap;
+
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ActualBootstrap extends BasicBootstrap
+{
+
+ /** . */
+ private final WebBootstrap callback;
+
+ // I don't know why we need to declare it since super() does not declare it
+ public ActualBootstrap(WebBootstrap callback) throws Exception
+ {
+ super();
+
+ //
+ this.callback = callback;
+ }
+
+ protected void bootstrap() throws Throwable
+ {
+ super.bootstrap();
+
+ //
+ callback.boostrap();
+ }
+
+}
Modified:
modules/common/trunk/mc/src/main/org/jboss/portal/common/mc/bootstrap/WebBootstrap.java
===================================================================
---
modules/common/trunk/mc/src/main/org/jboss/portal/common/mc/bootstrap/WebBootstrap.java 2007-09-07
18:42:36 UTC (rev 8201)
+++
modules/common/trunk/mc/src/main/org/jboss/portal/common/mc/bootstrap/WebBootstrap.java 2007-09-09
21:15:03 UTC (rev 8202)
@@ -23,19 +23,18 @@
package org.jboss.portal.common.mc.bootstrap;
import org.jboss.kernel.plugins.deployment.xml.BeanXMLDeployer;
-import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
import org.jboss.kernel.spi.deployment.KernelDeployment;
import org.jboss.kernel.spi.event.KernelEventListener;
import org.jboss.kernel.spi.event.KernelEvent;
import org.jboss.kernel.spi.registry.KernelRegistry;
import org.jboss.kernel.spi.registry.KernelRegistryEntry;
-import org.jboss.kernel.spi.config.KernelConfig;
import org.apache.log4j.Logger;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;
import java.net.URL;
+import java.net.MalformedURLException;
/**
* A kernel bootstrap with a life cycle triggered by the
<code>ServletContextListener</code> interface.
@@ -51,6 +50,31 @@
public class WebBootstrap implements ServletContextListener, KernelEventListener
{
+ /**
+ * The servlet context init parameter name for the bean resource location. For
instance for a web application
+ * resource it could be <i>/WEB-INF/my-beans.xml</i>, for the web
application classloader resource it could be
+ * <i>org/jboss/portal/my-beans.xml</i>. If no init parameter is declared
then the litteral value
+ * <i>/WEB-INF/jboss-beans.xml</i> is used and the lookup is done in the
servlet context resourcees.
+ */
+ public static final String BEANS_RESOURCE_LOCATION_KEY =
"jboss.portal.mc.beans_resource_location";
+
+ /**
+ * The servlet context init parameter name for the bean resource type which can be the
servlet context
+ * or the web application classloader. If no value is specified the servlet context
will be used for
+ * resource lookup. The legal values are <i>context</i> for the servlet
context and <i>classloader</i>
+ * for the web application classloader.
+ */
+ public static final String BEANS_RESOURCE_TYPE_KEY =
"jboss.portal.mc.beans_resource_type";
+
+ /** Default value for the bean resource location. */
+ public static final String DEFAULT_JBOSS_BEANS_RESOURCE_LOCATION =
"/WEB-INF/jboss-beans.xml";
+
+ /** Servlet context resource type. */
+ public static final String CONTEXT_RESOURCE_TYPE = "context";
+
+ /** Classloader resource type. */
+ public static final String CLASSLOADER_RESOURCE_TYPE = "classloader";
+
/** . */
private final static Logger log = Logger.getLogger(WebBootstrap.class);
@@ -67,19 +91,16 @@
private boolean registered;
/** . */
- private BootstrapExt bootstrap;
+ private ActualBootstrap bootstrap;
public void contextInitialized(ServletContextEvent event)
{
servletContext = event.getServletContext();
- // For now we do it here
- System.setProperty("org.jboss.logging.Logger.pluginClass",
"org.jboss.logging.log4j.Log4jLoggerPlugin");
-
//
try
{
- bootstrap = new BootstrapExt();
+ bootstrap = new ActualBootstrap(this);
//
bootstrap.run();
@@ -145,7 +166,7 @@
}
}
- private void boostrap() throws Throwable
+ void boostrap() throws Throwable
{
//
bootstrap.getKernel().getRegistry().registerListener(WebBootstrap.this, null,
"ABC");
@@ -155,25 +176,70 @@
deployer = new BeanXMLDeployer(bootstrap.getKernel());
//
- URL url = servletContext.getResource("/WEB-INF/jboss-beans.xml");
- deployment = deployer.deploy(url);
+ URL url = getBeansURL();
+
+ //
+ if (url != null)
+ {
+ log.debug("About to deploy beans url=" + url);
+ deployment = deployer.deploy(url);
+ }
+ else
+ {
+ log.error("No valid beans URL was determined");
+ }
}
- private class BootstrapExt extends BasicBootstrap
+ protected URL getBeansURL()
{
+ String location = servletContext.getInitParameter(BEANS_RESOURCE_LOCATION_KEY);
+ String type = servletContext.getInitParameter(BEANS_RESOURCE_TYPE_KEY);
- // I don't know why we need to declare it since super() does not declare it
- public BootstrapExt() throws Exception
+ //
+ if (location == null)
{
- super();
+ location = DEFAULT_JBOSS_BEANS_RESOURCE_LOCATION;
+ type = CONTEXT_RESOURCE_TYPE;
}
+ else if (type == null)
+ {
+ type = CONTEXT_RESOURCE_TYPE;
+ }
- protected void bootstrap() throws Throwable
+ //
+ if (CONTEXT_RESOURCE_TYPE.equals(type))
{
- super.bootstrap();
+ try
+ {
+ return servletContext.getResource(location);
+ }
+ catch (MalformedURLException e)
+ {
+ log.error("Cannot obtain beans definition file from servlet context with
location=" + location, e);
+ //
+ return null;
+ }
+ }
+ else if (CLASSLOADER_RESOURCE_TYPE.equals(type))
+ {
+ URL resource =
Thread.currentThread().getContextClassLoader().getResource(location);
+
//
- boostrap();
+ if (resource == null)
+ {
+ log.error("Cannot obtain bean definition file from thread context
classloader with location=" + location);
+ }
+
+ //
+ return resource;
}
+ else
+ {
+ log.error("Cannot obtain bean definition file since the context type cannot
be determined type=" + type);
+
+ //
+ return null;
+ }
}
}