001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020package org.apache.commons.weaver.model; 021 022import java.util.ArrayList; 023import java.util.Collections; 024import java.util.LinkedHashSet; 025import java.util.List; 026import java.util.Set; 027 028import org.apache.commons.lang3.Validate; 029import org.apache.commons.weaver.spi.Cleaner; 030import org.apache.commons.weaver.spi.Weaver; 031 032/** 033 * Scan request object describing the types of elements in which a given {@link Weaver} or {@link Cleaner} is 034 * interested. 035 */ 036public class ScanRequest { 037 038 private final List<WeaveInterest> interests = new ArrayList<WeaveInterest>(); 039 private final Set<Class<?>> supertypes = new LinkedHashSet<Class<?>>(); 040 041 /** 042 * Register a {@link WeaveInterest}. 043 * @param interest {@link WeaveInterest} to add 044 * @return {@code this}, fluently 045 */ 046 public ScanRequest add(final WeaveInterest interest) { 047 if (interest == null) { 048 throw new NullPointerException(); 049 } 050 interests.add(interest); 051 return this; 052 } 053 054 /** 055 * Register one or more types whose subtypes you are looking for. 056 * @param types {@link Class}es to add 057 * @return {@code this}, fluently 058 */ 059 public ScanRequest addSupertypes(final Class<?>... types) { 060 Collections.addAll(supertypes, Validate.noNullElements(types, "null element at [%s]")); 061 return this; 062 } 063 064 /** 065 * Get registered {@link WeaveInterest}s. 066 * @return {@link Iterable} 067 */ 068 public Iterable<WeaveInterest> getInterests() { 069 return Collections.unmodifiableList(interests); 070 } 071 072 /** 073 * Get registered {@link Class}es whose subtypes will be returned. 074 * @return {@link Set} 075 */ 076 public Set<Class<?>> getSupertypes() { 077 return Collections.unmodifiableSet(supertypes); 078 } 079 080}