[jboss-cvs] JBossAS SVN: r108657 - in trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration: deployer/env/bda and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Oct 19 11:35:34 EDT 2010
Author: alesj
Date: 2010-10-19 11:35:34 -0400 (Tue, 19 Oct 2010)
New Revision: 108657
Added:
trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/util/IdFactory.java
Modified:
trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WebContainterIntegrationDeployer.java
trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/Archive.java
trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/BeanDeploymentArchiveImpl.java
trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/DUTopLevelClassLoaderGetter.java
trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JBossBeanDeploymentArchiveLocator.java
Log:
Fix hack with CL::toString.
Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WebContainterIntegrationDeployer.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WebContainterIntegrationDeployer.java 2010-10-19 14:47:02 UTC (rev 108656)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WebContainterIntegrationDeployer.java 2010-10-19 15:35:34 UTC (rev 108657)
@@ -12,6 +12,7 @@
import org.jboss.weld.integration.deployer.DeployersUtils;
import org.jboss.weld.integration.deployer.env.helpers.BootstrapBean;
import org.jboss.weld.integration.injection.WeldInjector;
+import org.jboss.weld.integration.util.IdFactory;
/**
* Ensures that Weld is bootstrapped before the Web Application is started
@@ -39,7 +40,7 @@
BeanMetaDataBuilder weldInjector = BeanMetaDataBuilder.createBuilder(injectorName, WeldInjector.class.getName());
weldInjector.addConstructorParameter(BootstrapBean.class.getName(), weldInjector.createInject(bootstrapBeanName));
- weldInjector.addConstructorParameter(String.class.getName(), unit.getClassLoader().toString());
+ weldInjector.addConstructorParameter(String.class.getName(), IdFactory.getIdFromClassLoader(unit.getClassLoader()));
weldInjector.setDestroy("cleanup");
unit.addAttachment(injectorName + "_" + BeanMetaData.class.getSimpleName(), weldInjector.getBeanMetaData());
Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/Archive.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/Archive.java 2010-10-19 14:47:02 UTC (rev 108656)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/Archive.java 2010-10-19 15:35:34 UTC (rev 108657)
@@ -32,6 +32,7 @@
import org.jboss.weld.bootstrap.api.ServiceRegistry;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.weld.ejb.spi.EjbDescriptor;
+import org.jboss.weld.integration.util.IdFactory;
/**
* An archive is an abstract representation of one or more deployed archives.
@@ -113,7 +114,7 @@
// update instances map
synchronized (instances)
{
- instances.put(this.classLoader, new WeakReference(this));
+ instances.put(this.classLoader, new WeakReference<Archive>(this));
}
}
@@ -153,13 +154,14 @@
}
/**
- * Indicates whether {@code beanClass} is visible to this BDA
+ * Indicates whether {@code beanClass} is visible to this BDA.
+ *
* @param beanClass the beanClass
* @return {@code true} if {@code beanClass} is visible to this BDA
*/
public boolean isClassVisible(Class<?> beanClass)
{
- Class<?> loadedClass = null;
+ Class<?> loadedClass;
try
{
loadedClass = this.getClassLoader().loadClass(beanClass.getName());
@@ -170,8 +172,7 @@
}
return loadedClass == beanClass;
}
-
-
+
/**
* Adds a class to this archive.
*
@@ -241,6 +242,7 @@
* never returns duplicates.
*
* @param bootstrap the Weld boostrap
+ * @param services the services
* @return the BeanDeploymentArchive representing this archive. If this bda has not
* been created, it is created and returned
*/
@@ -248,7 +250,7 @@
{
if (bda == null)
{
- bda = new BeanDeploymentArchiveImpl(classLoader.toString(), bootstrap, services, this);
+ bda = new BeanDeploymentArchiveImpl(IdFactory.getIdFromClassLoader(classLoader), bootstrap, services, this);
for (ArchiveLifecycleListener listener: lifecycleListeners)
{
// notifies the listener that this archive became visible as a BDA
@@ -262,7 +264,8 @@
* Creates the BeanDeploymentArchive that corresponds to this archive. This method
* never returns duplicates.
* Use this method if you are sure that this Archive has no beans.xml file.
- *
+ *
+ * @param services the services
* @return the BeanDeploymentArchive representing this archive. If this bda has not
* been created, it is created and returned
*/
Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/BeanDeploymentArchiveImpl.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/BeanDeploymentArchiveImpl.java 2010-10-19 14:47:02 UTC (rev 108656)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/BeanDeploymentArchiveImpl.java 2010-10-19 15:35:34 UTC (rev 108657)
@@ -29,6 +29,7 @@
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.weld.bootstrap.spi.BeansXml;
import org.jboss.weld.ejb.spi.EjbDescriptor;
+import org.jboss.weld.xml.BeansXmlParser;
/**
* {@link BeanDeploymentArchive} implementation for JBoss AS.
@@ -38,6 +39,9 @@
*/
class BeanDeploymentArchiveImpl implements BeanDeploymentArchive
{
+ // the beans parser
+ private static final BeansXmlParser parser = new BeansXmlParser();
+
// identifies this BDA
private final String id;
@@ -60,6 +64,13 @@
*/
public BeanDeploymentArchiveImpl(String id, Bootstrap bootstrap, ServiceRegistry services, Archive archive)
{
+ if (id == null)
+ throw new IllegalArgumentException("Null id");
+ if (archive == null)
+ throw new IllegalArgumentException("Null archive");
+ if (services == null)
+ throw new IllegalArgumentException("Null services");
+
this.id = id;
this.bootstrap = bootstrap;
this.services = services;
@@ -79,11 +90,15 @@
public BeansXml getBeansXml()
{
Collection<URL> urls = archive.getXmlURLs();
- if (urls.isEmpty())
+ if (urls == null || urls.isEmpty())
{
return BeansXml.EMPTY_BEANS_XML;
}
- return bootstrap.parse(urls);
+
+ if (bootstrap != null)
+ return bootstrap.parse(urls);
+ else
+ return parser.parse(urls);
}
public Collection<EjbDescriptor<?>> getEjbs()
Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/DUTopLevelClassLoaderGetter.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/DUTopLevelClassLoaderGetter.java 2010-10-19 14:47:02 UTC (rev 108656)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/DUTopLevelClassLoaderGetter.java 2010-10-19 15:35:34 UTC (rev 108657)
@@ -22,7 +22,6 @@
package org.jboss.weld.integration.deployer.env.bda;
-import org.jboss.classloader.spi.base.BaseClassLoader;
import org.jboss.classloading.spi.RealClassLoader;
import org.jboss.classloading.spi.dependency.Module;
import org.jboss.deployers.plugins.classloading.AbstractDeploymentClassLoaderPolicyModule;
Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JBossBeanDeploymentArchiveLocator.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JBossBeanDeploymentArchiveLocator.java 2010-10-19 14:47:02 UTC (rev 108656)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JBossBeanDeploymentArchiveLocator.java 2010-10-19 15:35:34 UTC (rev 108657)
@@ -3,11 +3,13 @@
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.weld.integration.deployer.env.helpers.BootstrapBean;
+import org.jboss.weld.integration.util.IdFactory;
/**
* {@link BeanDeploymentArchiveLocator} implementation for non-flat (hierarchical) archives
*
* @author Marius Bogoevici
+ * @author Ales Justin
*/
public class JBossBeanDeploymentArchiveLocator implements BeanDeploymentArchiveLocator
{
@@ -15,7 +17,8 @@
{
for (BeanDeploymentArchive beanDeploymentArchive: bootstrap.getDeployment().getBeanDeploymentArchives())
{
- if (beanDeploymentArchive.getId().equals(deploymentUnit.getClassLoader().toString()))
+ String id = IdFactory.getIdFromClassLoader(deploymentUnit.getClassLoader());
+ if (beanDeploymentArchive.getId().equals(id))
{
return beanDeploymentArchive;
}
Added: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/util/IdFactory.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/util/IdFactory.java (rev 0)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/util/IdFactory.java 2010-10-19 15:35:34 UTC (rev 108657)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.weld.integration.util;
+
+import javax.management.ObjectName;
+
+import org.jboss.classloading.spi.RealClassLoader;
+
+/**
+ * Try creating id the best way we can.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public final class IdFactory
+{
+ private IdFactory()
+ {
+ }
+
+ /**
+ * Get the id from classloader -- let's try RealClassLoader's objectName.
+ *
+ * @param cl the classloader
+ * @return classloader's unique id
+ */
+ public static String getIdFromClassLoader(ClassLoader cl)
+ {
+ if (cl == null)
+ throw new IllegalArgumentException("Null classloader.");
+
+ ClassLoader current = cl;
+ while (current != null && (current instanceof RealClassLoader == false))
+ {
+ current = current.getParent();
+ }
+ if (current != null)
+ {
+ ObjectName on = ((RealClassLoader) current).getObjectName();
+ if (on != null)
+ return on.getCanonicalName();
+ }
+ return cl.toString(); // the best we can do :-(
+ }
+}
More information about the jboss-cvs-commits
mailing list