org.apache.camel.impl.converter.TypeConvertersPackageScanClassResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of camel-core Show documentation
Show all versions of camel-core Show documentation
The Core Camel Java DSL based router
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.camel.impl.converter;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.camel.spi.PackageScanClassResolver;
import org.apache.camel.spi.PackageScanFilter;
/**
* A {@link org.apache.camel.spi.ClassResolver} which loads type converters
* from an instance that implements {@link org.apache.camel.TypeConverters}.
*
* This is used when adding converters manually using the
* {@link org.apache.camel.impl.converter.BaseTypeConverterRegistry#addTypeConverters(org.apache.camel.TypeConverters)} method.
*/
public class TypeConvertersPackageScanClassResolver implements PackageScanClassResolver {
private final Set classLoaders = new LinkedHashSet();
private final Set> converters = new LinkedHashSet>();
public TypeConvertersPackageScanClassResolver(Class clazz) {
converters.add(clazz);
// use the classloader that loaded the class
classLoaders.add(clazz.getClassLoader());
}
@Override
public void setClassLoaders(Set classLoaders) {
// add all the class loaders
this.classLoaders.addAll(classLoaders);
}
@Override
public Set getClassLoaders() {
// return a new set to avoid any concurrency issues in other runtimes such as OSGi
return Collections.unmodifiableSet(new LinkedHashSet(classLoaders));
}
@Override
public void addClassLoader(ClassLoader classLoader) {
classLoaders.add(classLoader);
}
@Override
public Set> findAnnotated(Class annotation, String... packageNames) {
return converters;
}
@Override
public Set> findAnnotated(Set> annotations, String... packageNames) {
return converters;
}
@Override
public Set> findImplementations(Class parent, String... packageNames) {
// noop
return null;
}
@Override
public Set> findByFilter(PackageScanFilter filter, String... packageNames) {
// noop
return null;
}
@Override
public void addFilter(PackageScanFilter filter) {
// noop
}
@Override
public void removeFilter(PackageScanFilter filter) {
// noop
}
}