Ignoring ClassLoader Roots
alrubinger Nov 20, 2008 1:24 AMIn doing some prototyping on AS Embedded, I've run into an issue where the bootstrap deployables in AS fail on definition of explicit roots:
<classloader name="aop-classloader" xmlns="urn:jboss:classloader:1.0" export-all="NON_EMPTY" import-all="true">
<root>${jboss.lib.url}jboss-aop-asintegration-core.jar</root>
...etc
</classloader>Ales kindly provided me with a NoopClassLoaderFactory:
http://anonsvn.jboss.org/repos/jbossas/projects/jboss-cl/trunk/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/metadata/xml/support/NoopClassLoaderFactory.java
...which has overridden:
@XmlTransient
public List<BeanMetaData> getBeans()
{
return Collections.emptyList();
}Though what's needed is an implementation that won't allow "roots" to be specified, so I've rewritten this in a (as of yet uncommitted) implementation in the new jboss-embedded-core project. This will be in SVN once I've got the proper JIRA rights to organize up and keep things documented.
Perhaps MC wants this code instead?
/*
* JBoss, Home of Professional Open Source.
* Copyright 2008, 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.embedded.classloading;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlRootElement;
import org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory;
import org.jboss.xb.annotations.JBossXmlSchema;
/**
* NoOpClassLoaderFactory
*
* ClassLoader Factory that will not allow roots to be added
*
* @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
* @version $Revision: $
*/
@JBossXmlSchema(namespace = "urn:jboss:classloader:1.0", elementFormDefault = XmlNsForm.QUALIFIED)
@XmlRootElement(name = "classloader")
public class NoOpClassLoaderFactory extends VFSClassLoaderFactory
{
//------------------------------------------------------------------||
// Class Members ---------------------------------------------------||
//------------------------------------------------------------------||
private static final long serialVersionUID = 1L;
//------------------------------------------------------------------||
// Instance Members ------------------------------------------------||
//------------------------------------------------------------------||
/**
* Empty list which may never have contents. Synchronization policy
* on "this".
*/
private volatile List<String> emptyList;
//------------------------------------------------------------------||
// Accessors / Mutators --------------------------------------------||
//------------------------------------------------------------------||
/**
* An overridden implementation to obtain the roots for
* this CL, which will always contain no elements
*/
@Override
public List<String> getRoots()
{
return this.getEmptyList();
}
//------------------------------------------------------------------||
// Internal Helper Methods -----------------------------------------||
//------------------------------------------------------------------||
/**
* Obtains an empty list (which may never become
* filled with any elements)
*
* @return
*/
private List<String> getEmptyList()
{
// Initialize
List<String> returnValue = this.emptyList;
// Check that underlying list is instanciated
if (returnValue == null)
{
// Sync up
synchronized (this)
{
// Double-check for instanciation
if (returnValue == null)
{
// Create the underlying list
this.emptyList = returnValue = new NoOpAdditiveList<String>();
}
}
}
// Return
return returnValue;
}
//------------------------------------------------------------------||
// Inner Classes ---------------------------------------------------||
//------------------------------------------------------------------||
/**
* NoOpAdditiveOperationsList
*
* An extension of ArrayList where the general contract
* of "Collection.add" is violated in favor of a NOOP
* implementation
*
* May be used in place of immutable lists when additions
* should silently not take place, instead of throwing
* UnsupportedOperationException
*
* @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
* @version $Revision: $
* @param <E>
*/
private static class NoOpAdditiveOperationsList<E> extends ArrayList<E>
{
private static final long serialVersionUID = 1L;
@Override
public boolean add(E o)
{
return true;
}
@Override
public void add(int index, E element)
{
return;
}
@Override
public boolean addAll(Collection<? extends E> c)
{
return true;
}
@Override
public boolean addAll(int index, Collection<? extends E> c)
{
return true;
}
}
}S,
ALR