@@ -0,0 +1,2920 @@
+/*%0A * JBoss, Home of Professional Open Source.%0A * Copyright 2010, Red Hat, Inc., and individual contributors%0A * as indicated by the @author tags. See the copyright.txt file in the%0A * distribution for a full listing of individual contributors.%0A *%0A * This is free software; you can redistribute it and/or modify it%0A * under the terms of the GNU Lesser General Public License as%0A * published by the Free Software Foundation; either version 2.1 of%0A * the License, or (at your option) any later version.%0A *%0A * This software is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU%0A * Lesser General Public License for more details.%0A *%0A * You should have received a copy of the GNU Lesser General Public%0A * License along with this software; if not, write to the Free%0A * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA%0A * 02110-1301 USA, or see the FSF site: http://www.fsf.org.%0A */%0A%0Apackage org.jboss.modules;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A/**%0A * A module loader which selects a delegate module loader based upon the prefix of the module name.  Longer%0A * names are matched first always.%0A *%0A * @author %3Ca href=%22mailto:david.lloyd@redhat.com%22%3EDavid M. Lloyd%3C/a%3E%0A */%0Apublic final class ClassifyingModuleLoader extends ModuleLoader %7B%0A    private volatile Map%3CString, ModuleLoader%3E delegates;%0A    private final ModuleLoader defaultLoader;%0A%0A    /**%0A     * Construct a new instance.  The given delegates map is copied.%0A     *%0A     * @param delegates the default delegates map to use%0A     * @param defaultLoader the default loader to use if no delegate mapping exists%0A     */%0A    public ClassifyingModuleLoader(final Map%3CString, ModuleLoader%3E delegates, final ModuleLoader defaultLoader) %7B%0A        this.defaultLoader = defaultLoader;%0A        this.delegates = new HashMap%3CString, ModuleLoader%3E(delegates);%0A    %7D%0A%0A    /** %7B@inheritDoc%7D */%0A    protected ModuleSpec findModule(final ModuleIdentifier moduleIdentifier) throws ModuleLoadException %7B%0A        String name = moduleIdentifier.getName();%0A        int idx;%0A        final Map%3CString, ModuleLoader%3E delegates = this.delegates;%0A        for (;;) %7B%0A            final ModuleLoader loader = delegates.get(name);%0A            if (loader != null) %7B%0A                return loader.findModule(moduleIdentifier);%0A            %7D%0A            idx = name.lastIndexOf('.');%0A            if (idx == -1) %7B%0A                return defaultLoader.findModule(moduleIdentifier);%0A            %7D%0A            name = name.substring(0, idx);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Change the delegates map.  A copy is made of the given map.%0A     *%0A     * @param delegates the new delegates map to use%0A     */%0A    public void setDelegates(Map%3CString, ModuleLoader%3E delegates) %7B%0A        this.delegates = new HashMap%3CString, ModuleLoader%3E(delegates);%0A    %7D%0A%7D%0A

Spell it out: add a classifying module loader implementation