001/* 002 * Copyright 2002-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.beans.factory.parsing; 018 019import org.springframework.beans.BeanMetadataElement; 020import org.springframework.core.io.Resource; 021import org.springframework.lang.Nullable; 022import org.springframework.util.Assert; 023 024/** 025 * Representation of an import that has been processed during the parsing process. 026 * 027 * @author Juergen Hoeller 028 * @since 2.0 029 * @see ReaderEventListener#importProcessed(ImportDefinition) 030 */ 031public class ImportDefinition implements BeanMetadataElement { 032 033 private final String importedResource; 034 035 @Nullable 036 private final Resource[] actualResources; 037 038 @Nullable 039 private final Object source; 040 041 042 /** 043 * Create a new ImportDefinition. 044 * @param importedResource the location of the imported resource 045 */ 046 public ImportDefinition(String importedResource) { 047 this(importedResource, null, null); 048 } 049 050 /** 051 * Create a new ImportDefinition. 052 * @param importedResource the location of the imported resource 053 * @param source the source object (may be {@code null}) 054 */ 055 public ImportDefinition(String importedResource, @Nullable Object source) { 056 this(importedResource, null, source); 057 } 058 059 /** 060 * Create a new ImportDefinition. 061 * @param importedResource the location of the imported resource 062 * @param source the source object (may be {@code null}) 063 */ 064 public ImportDefinition(String importedResource, @Nullable Resource[] actualResources, @Nullable Object source) { 065 Assert.notNull(importedResource, "Imported resource must not be null"); 066 this.importedResource = importedResource; 067 this.actualResources = actualResources; 068 this.source = source; 069 } 070 071 072 /** 073 * Return the location of the imported resource. 074 */ 075 public final String getImportedResource() { 076 return this.importedResource; 077 } 078 079 @Nullable 080 public final Resource[] getActualResources() { 081 return this.actualResources; 082 } 083 084 @Override 085 @Nullable 086 public final Object getSource() { 087 return this.source; 088 } 089 090}