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