1 16 17 package org.springframework.beans.factory.parsing; 18 19 import org.springframework.core.io.Resource; 20 21 29 public class ReaderContext { 30 31 private final Resource resource; 32 33 private final ProblemReporter problemReporter; 34 35 private final ReaderEventListener eventListener; 36 37 private final SourceExtractor sourceExtractor; 38 39 40 public ReaderContext(Resource resource, ProblemReporter problemReporter, 41 ReaderEventListener eventListener, SourceExtractor sourceExtractor) { 42 43 this.resource = resource; 44 this.problemReporter = problemReporter; 45 this.eventListener = eventListener; 46 this.sourceExtractor = sourceExtractor; 47 } 48 49 public final Resource getResource() { 50 return this.resource; 51 } 52 53 54 public void fatal(String message, Object source) { 55 fatal(message, source, null, null); 56 } 57 58 public void fatal(String message, Object source, Throwable ex) { 59 fatal(message, source, null, ex); 60 } 61 62 public void fatal(String message, Object source, ParseState parseState) { 63 fatal(message, source, parseState, null); 64 } 65 66 public void fatal(String message, Object source, ParseState parseState, Throwable cause) { 67 Location location = new Location(getResource(), source); 68 this.problemReporter.fatal(new Problem(message, location, parseState, cause)); 69 } 70 71 public void error(String message, Object source) { 72 error(message, source, null, null); 73 } 74 75 public void error(String message, Object source, Throwable ex) { 76 error(message, source, null, ex); 77 } 78 79 public void error(String message, Object source, ParseState parseState) { 80 error(message, source, parseState, null); 81 } 82 83 public void error(String message, Object source, ParseState parseState, Throwable cause) { 84 Location location = new Location(getResource(), source); 85 this.problemReporter.error(new Problem(message, location, parseState, cause)); 86 } 87 88 public void warning(String message, Object source) { 89 warning(message, source, null, null); 90 } 91 92 public void warning(String message, Object source, Throwable ex) { 93 warning(message, source, null, ex); 94 } 95 96 public void warning(String message, Object source, ParseState parseState) { 97 warning(message, source, parseState, null); 98 } 99 100 public void warning(String message, Object source, ParseState parseState, Throwable cause) { 101 Location location = new Location(getResource(), source); 102 this.problemReporter.warning(new Problem(message, location, parseState, cause)); 103 } 104 105 106 public void fireDefaultsRegistered(DefaultsDefinition defaultsDefinition) { 107 this.eventListener.defaultsRegistered(defaultsDefinition); 108 } 109 110 public void fireComponentRegistered(ComponentDefinition componentDefinition) { 111 this.eventListener.componentRegistered(componentDefinition); 112 } 113 114 public void fireAliasRegistered(String beanName, String alias, Object source) { 115 this.eventListener.aliasRegistered(new AliasDefinition(beanName, alias, source)); 116 } 117 118 public void fireImportProcessed(String importedResource, Object source) { 119 this.eventListener.importProcessed(new ImportDefinition(importedResource, source)); 120 } 121 122 123 public SourceExtractor getSourceExtractor() { 124 return this.sourceExtractor; 125 } 126 127 public Object extractSource(Object sourceCandidate) { 128 return this.sourceExtractor.extractSource(sourceCandidate, this.resource); 129 } 130 131 } 132 | Popular Tags |