1 /* 2 * Copyright 2010 The Meiyo Team 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.nnsoft.commons.meiyo.classpath; 17 18 import org.nnsoft.commons.meiyo.classpath.filter.Filter; 19 20 /** 21 * A classpath handler notifies {@link ClassPathEntry} found to {@link ClassPathEntryHandler} 22 * if and only if the {@link ClassPathEntry} satisfies the {@link Filter} requirements. 23 */ 24 final class ClassPathHandler { 25 26 /** 27 * The {@link Filter} reference. 28 */ 29 private final Filter filter; 30 31 /** 32 * The handlers list to witch {@link ClassPathEntry} will be notified if 33 * this last satisfies the {@link Filter} requirements. 34 */ 35 private final ClassPathEntryHandler[] classHandlers; 36 37 /** 38 * Creates a new classpath hanlder. 39 * 40 * @param filter the {@link Filter} reference. 41 * @param classHandlers the handlers list to witch {@link ClassPathEntry} will be notified. 42 */ 43 public ClassPathHandler(Filter filter, ClassPathEntryHandler...classHandlers) { 44 this.filter = filter; 45 this.classHandlers = classHandlers; 46 } 47 48 /** 49 * Notified the ClassPath entry if the {@link Filter} reference requirements 50 * are satisfied. 51 * 52 * @param path 53 * @param classPathEntry 54 */ 55 public void doHandle(String path, Class<?> classPathEntry) { 56 if (this.filter.matches(classPathEntry)) { 57 for (ClassPathEntryHandler classHandler : this.classHandlers) { 58 classHandler.doHandle(path, classPathEntry); 59 } 60 } 61 } 62 63 }