@@ -0,0 +1,3413 @@
+/*%0A * JBoss, Home of Professional Open Source%0A * Copyright 2008, JBoss Inc., and individual contributors as indicated%0A * by the @authors tag. See the copyright.txt in the distribution for a%0A * 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.marshalling;%0A%0Aimport java.util.Collection;%0Aimport java.util.Iterator;%0A%0A/**%0A * A class externalizer factory that tries each delegate externalizer factory in sequence, returning the first match.%0A */%0Apublic class ChainingClassExternalizerFactory implements ClassExternalizerFactory %7B%0A    private final ClassExternalizerFactory%5B%5D externalizerFactories;%0A%0A    /**%0A     * Construct a new instance.%0A     *%0A     * @param factories a collection of factories to use%0A     */%0A    public ChainingClassExternalizerFactory(final Collection%3CClassExternalizerFactory%3E factories) %7B%0A        externalizerFactories = factories.toArray(new ClassExternalizerFactory%5Bfactories.size()%5D);%0A    %7D%0A%0A    /**%0A     * Construct a new instance.%0A     *%0A     * @param factories a collection of factories to use%0A     */%0A    public ChainingClassExternalizerFactory(final Iterable%3CClassExternalizerFactory%3E factories) %7B%0A        this(factories.iterator());%0A    %7D%0A%0A    /**%0A     * Construct a new instance.%0A     *%0A     * @param factories a sequence of factories to use%0A     */%0A    public ChainingClassExternalizerFactory(final Iterator%3CClassExternalizerFactory%3E factories) %7B%0A        externalizerFactories = unroll(factories, 0);%0A    %7D%0A%0A    /**%0A     * Construct a new instance.%0A     *%0A     * @param factories an array of factories to use%0A     */%0A    public ChainingClassExternalizerFactory(final ClassExternalizerFactory%5B%5D factories) %7B%0A        externalizerFactories = factories.clone();%0A    %7D%0A%0A    private static ClassExternalizerFactory%5B%5D unroll(final Iterator%3CClassExternalizerFactory%3E iterator, final int i) %7B%0A        if (iterator.hasNext()) %7B%0A            final ClassExternalizerFactory factory = iterator.next();%0A            final ClassExternalizerFactory%5B%5D array = unroll(iterator, i + 1);%0A            array%5Bi%5D = factory;%0A            return array;%0A        %7D else %7B%0A            return new ClassExternalizerFactory%5Bi%5D;%0A        %7D%0A    %7D%0A%0A    /** %7B@inheritDoc%7D  This implementation tries each nested externalizer factory in order until a match is found. */%0A    public Externalizer getExternalizer(final Class%3C?%3E type) %7B%0A        for (ClassExternalizerFactory externalizerFactory : externalizerFactories) %7B%0A            final Externalizer externalizer = externalizerFactory.getExternalizer(type);%0A            if (externalizer != null) %7B%0A                return externalizer;%0A            %7D%0A        %7D%0A        return null;%0A    %7D%0A%7D%0A

Add chaining externalizer factory