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.util.blueprint.SSLContextParametersFactoryBean; 024import org.apache.camel.xml.jaxb.DefaultModelJAXBContextFactory; 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 @Override 040 protected String getPackages() { 041 // we nedd to have a class from each different package with jaxb models 042 // and we must use the .class for the classloader to work in OSGi 043 Set<Class<?>> classes = new LinkedHashSet<>(); 044 classes.add(CamelContextFactoryBean.class); 045 classes.add(AbstractCamelContextFactoryBean.class); 046 classes.add(SSLContextParametersFactoryBean.class); 047 classes.add(org.apache.camel.ExchangePattern.class); 048 classes.add(org.apache.camel.model.RouteDefinition.class); 049 classes.add(org.apache.camel.model.config.StreamResequencerConfig.class); 050 classes.add(org.apache.camel.model.dataformat.DataFormatsDefinition.class); 051 classes.add(org.apache.camel.model.language.ExpressionDefinition.class); 052 classes.add(org.apache.camel.model.loadbalancer.RoundRobinLoadBalancerDefinition.class); 053 classes.add(org.apache.camel.model.rest.RestDefinition.class); 054 classes.add(org.apache.camel.model.cloud.ServiceCallDefinition.class); 055 056 StringBuilder packages = new StringBuilder(); 057 for (Class<?> cl : classes) { 058 if (packages.length() > 0) { 059 packages.append(":"); 060 } 061 packages.append(cl.getName(), 0, cl.getName().lastIndexOf('.')); 062 } 063 return packages.toString(); 064 } 065 066}