001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.blueprint;
018
019import java.util.LinkedHashSet;
020import java.util.Set;
021
022import org.apache.camel.core.xml.AbstractCamelContextFactoryBean;
023import org.apache.camel.impl.DefaultModelJAXBContextFactory;
024import org.apache.camel.util.blueprint.SSLContextParametersFactoryBean;
025
026public class BlueprintModelJAXBContextFactory extends DefaultModelJAXBContextFactory {
027
028    private final ClassLoader classLoader;
029
030    public BlueprintModelJAXBContextFactory(ClassLoader classLoader) {
031        this.classLoader = classLoader;
032    }
033
034    @Override
035    protected ClassLoader getClassLoader() {
036        return classLoader;
037    }
038
039    protected String getPackages() {
040        // we nedd to have a class from each different package with jaxb models
041        // and we must use the .class for the classloader to work in OSGi
042        Set<Class<?>> classes = new LinkedHashSet<>();
043        classes.add(CamelContextFactoryBean.class);
044        classes.add(AbstractCamelContextFactoryBean.class);
045        classes.add(SSLContextParametersFactoryBean.class);
046        classes.add(org.apache.camel.ExchangePattern.class);
047        classes.add(org.apache.camel.model.RouteDefinition.class);
048        classes.add(org.apache.camel.model.config.StreamResequencerConfig.class);
049        classes.add(org.apache.camel.model.dataformat.DataFormatsDefinition.class);
050        classes.add(org.apache.camel.model.language.ExpressionDefinition.class);
051        classes.add(org.apache.camel.model.loadbalancer.RoundRobinLoadBalancerDefinition.class);
052        classes.add(org.apache.camel.model.rest.RestDefinition.class);
053        classes.add(org.apache.camel.model.cloud.ServiceCallDefinition.class);
054
055        StringBuilder packages = new StringBuilder();
056        for (Class<?> cl : classes) {
057            if (packages.length() > 0) {
058                packages.append(":");
059            }
060            packages.append(cl.getName(), 0, cl.getName().lastIndexOf('.'));
061        }
062        return packages.toString();
063    }
064
065}