/**
 * Copyright (C) FuseSource, Inc.
 * http://fusesource.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.fusesource.fabric.jaxb.dynamic;

import javax.xml.bind.JAXBContext;

import org.apache.camel.converter.jaxb.JaxbDataFormat;
import org.apache.camel.util.ObjectHelper;

/**
 * An implementation of {@link JaxbDataFormat} which can deal with compiling XSD files on the fly
 * to create the JAXB context
 */
public class DynamicJaxbDataFormat extends JaxbDataFormat implements CompileResultsHandler {
    private DynamicCompiler compiler;

    public DynamicJaxbDataFormat() {
    }

    public DynamicJaxbDataFormat(JAXBContext context) {
        super(context);
    }

    public DynamicJaxbDataFormat(String contextPath) {
        super(contextPath);
    }

    public DynamicCompiler getCompiler() {
        return compiler;
    }

    public void setCompiler(DynamicCompiler compiler) throws Exception {
        this.compiler = compiler;
        if (compiler != null) {
            compiler.setHandler(this);
        }
    }

    public void init() throws Exception {
        ObjectHelper.notNull(getCompiler(), "compiler");
    }

    /**
     * Whenever any kind of compiler is performed this is the handler method to pass in the results
     */
    @Override
    public void onCompileResults(CompileResults compileResults) {
        setContext(compileResults.getJAXBContext());
    }
}

@@ -1063,16 +1063,59 @@
 ompiler;
+%0A    private CompileResults compileResults;
 %0A%0A    pu
@@ -1913,51 +1913,473 @@
     
-setContext(compileResults.getJAXBContext())
+this.compileResults = compileResults;%0A        setContext(compileResults.getJAXBContext());%0A    %7D%0A%0A    /**%0A     * Returns the class loader created by the dynamic compilation or null if none has been created yet%0A     */%0A    public ClassLoader getClassLoader() %7B%0A        if (compileResults != null) %7B%0A            return compileResults.getClassLoader();%0A        %7D%0A        return null;%0A    %7D%0A%0A    public CompileResults getCompileResults() %7B%0A        return compileResults
 ;%0A  

add an API so folks can find the class loader of the dynamic jaxb context