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.spi; 018 019import java.lang.annotation.Annotation; 020import java.util.Set; 021 022import org.apache.camel.StaticService; 023 024/** 025 * A resolver that can find resources based on package scanning. 026 */ 027public interface PackageScanClassResolver extends StaticService { 028 029 /** 030 * Gets the ClassLoader instances that should be used when scanning for classes. 031 * <p/> 032 * This implementation will return a new unmodifiable set containing the classloaders. 033 * Use the {@link #addClassLoader(ClassLoader)} method if you want to add new classloaders 034 * to the class loaders list. 035 * 036 * @return the class loaders to use 037 */ 038 Set<ClassLoader> getClassLoaders(); 039 040 /** 041 * Adds the class loader to the existing loaders 042 * 043 * @param classLoader the loader to add 044 */ 045 void addClassLoader(ClassLoader classLoader); 046 047 /** 048 * Attempts to discover classes that are annotated with to the annotation. 049 * 050 * @param annotation the annotation that should be present on matching classes 051 * @param packageNames one or more package names to scan (including subpackages) for classes 052 * @return the classes found, returns an empty set if none found 053 */ 054 Set<Class<?>> findAnnotated(Class<? extends Annotation> annotation, String... packageNames); 055 056 /** 057 * Attempts to discover classes that are annotated with to the annotation. 058 * 059 * @param annotations the annotations that should be present (any of them) on matching classes 060 * @param packageNames one or more package names to scan (including subpackages) for classes 061 * @return the classes found, returns an empty set if none found 062 */ 063 Set<Class<?>> findAnnotated(Set<Class<? extends Annotation>> annotations, String... packageNames); 064 065 /** 066 * Attempts to discover classes that are assignable to the type provided. In 067 * the case that an interface is provided this method will collect 068 * implementations. In the case of a non-interface class, subclasses will be 069 * collected. 070 * 071 * @param parent the class of interface to find subclasses or implementations of 072 * @param packageNames one or more package names to scan (including subpackages) for classes 073 * @return the classes found, returns an empty set if none found 074 */ 075 Set<Class<?>> findImplementations(Class<?> parent, String... packageNames); 076 077 /** 078 * Attempts to discover classes filter by the provided filter 079 * 080 * @param filter filter to filter desired classes. 081 * @param packageNames one or more package names to scan (including subpackages) for classes 082 * @return the classes found, returns an empty set if none found 083 */ 084 Set<Class<?>> findByFilter(PackageScanFilter filter, String... packageNames); 085 086 /** 087 * Add a filter that will be applied to all scan operations 088 * 089 * @param filter filter to filter desired classes in all scan operations 090 */ 091 void addFilter(PackageScanFilter filter); 092 093 /** 094 * Removes the filter 095 * 096 * @param filter filter to filter desired classes in all scan operations 097 */ 098 void removeFilter(PackageScanFilter filter); 099}