001: /*
002: * Copyright 2002-2007 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: * http://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:
017: package org.springframework.beans.factory.parsing;
018:
019: import org.springframework.core.io.Resource;
020:
021: /**
022: * Context that gets passed along a bean definition reading process,
023: * encapsulating all relevant configuration as well as state.
024: *
025: * @author Rob Harrop
026: * @author Juergen Hoeller
027: * @since 2.0
028: */
029: public class ReaderContext {
030:
031: private final Resource resource;
032:
033: private final ProblemReporter problemReporter;
034:
035: private final ReaderEventListener eventListener;
036:
037: private final SourceExtractor sourceExtractor;
038:
039: public ReaderContext(Resource resource,
040: ProblemReporter problemReporter,
041: ReaderEventListener eventListener,
042: SourceExtractor sourceExtractor) {
043:
044: this .resource = resource;
045: this .problemReporter = problemReporter;
046: this .eventListener = eventListener;
047: this .sourceExtractor = sourceExtractor;
048: }
049:
050: public final Resource getResource() {
051: return this .resource;
052: }
053:
054: public void fatal(String message, Object source) {
055: fatal(message, source, null, null);
056: }
057:
058: public void fatal(String message, Object source, Throwable ex) {
059: fatal(message, source, null, ex);
060: }
061:
062: public void fatal(String message, Object source,
063: ParseState parseState) {
064: fatal(message, source, parseState, null);
065: }
066:
067: public void fatal(String message, Object source,
068: ParseState parseState, Throwable cause) {
069: Location location = new Location(getResource(), source);
070: this .problemReporter.fatal(new Problem(message, location,
071: parseState, cause));
072: }
073:
074: public void error(String message, Object source) {
075: error(message, source, null, null);
076: }
077:
078: public void error(String message, Object source, Throwable ex) {
079: error(message, source, null, ex);
080: }
081:
082: public void error(String message, Object source,
083: ParseState parseState) {
084: error(message, source, parseState, null);
085: }
086:
087: public void error(String message, Object source,
088: ParseState parseState, Throwable cause) {
089: Location location = new Location(getResource(), source);
090: this .problemReporter.error(new Problem(message, location,
091: parseState, cause));
092: }
093:
094: public void warning(String message, Object source) {
095: warning(message, source, null, null);
096: }
097:
098: public void warning(String message, Object source, Throwable ex) {
099: warning(message, source, null, ex);
100: }
101:
102: public void warning(String message, Object source,
103: ParseState parseState) {
104: warning(message, source, parseState, null);
105: }
106:
107: public void warning(String message, Object source,
108: ParseState parseState, Throwable cause) {
109: Location location = new Location(getResource(), source);
110: this .problemReporter.warning(new Problem(message, location,
111: parseState, cause));
112: }
113:
114: public void fireDefaultsRegistered(
115: DefaultsDefinition defaultsDefinition) {
116: this .eventListener.defaultsRegistered(defaultsDefinition);
117: }
118:
119: public void fireComponentRegistered(
120: ComponentDefinition componentDefinition) {
121: this .eventListener.componentRegistered(componentDefinition);
122: }
123:
124: public void fireAliasRegistered(String beanName, String alias,
125: Object source) {
126: this .eventListener.aliasRegistered(new AliasDefinition(
127: beanName, alias, source));
128: }
129:
130: public void fireImportProcessed(String importedResource,
131: Object source) {
132: this .eventListener.importProcessed(new ImportDefinition(
133: importedResource, source));
134: }
135:
136: public SourceExtractor getSourceExtractor() {
137: return this .sourceExtractor;
138: }
139:
140: public Object extractSource(Object sourceCandidate) {
141: return this.sourceExtractor.extractSource(sourceCandidate,
142: this.resource);
143: }
144:
145: }
|