01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
17: package org.springframework.beans.factory.parsing;
18:
19: import org.springframework.core.io.Resource;
20: import org.springframework.util.Assert;
21:
22: /**
23: * Class that models an arbitrary location in a {@link Resource resource}.
24: *
25: * <p>Typically used to track the location of problematic or erroneous
26: * metadata in XML configuration files. For example, a
27: * {@link #getSource() source} location might be 'The bean defined on
28: * line 76 of beans.properties has an invalid Class'; another source might
29: * be the actual DOM Element from a parsed XML {@link org.w3c.dom.Document};
30: * or the source object might simply be <code>null</code>.
31: *
32: * @author Rob Harrop
33: * @since 2.0
34: */
35: public class Location {
36:
37: private final Resource resource;
38:
39: private final Object source;
40:
41: /**
42: * Create a new instance of the {@link Location} class.
43: * @param resource the resource with which this location is associated
44: */
45: public Location(Resource resource) {
46: this (resource, null);
47: }
48:
49: /**
50: * Create a new instance of the {@link Location} class.
51: * @param resource the resource with which this location is associated
52: * @param source the actual location within the associated resource
53: * (may be <code>null</code>)
54: */
55: public Location(Resource resource, Object source) {
56: Assert.notNull(resource, "Resource must not be null");
57: this .resource = resource;
58: this .source = source;
59: }
60:
61: /**
62: * Get the resource with which this location is associated.
63: */
64: public Resource getResource() {
65: return this .resource;
66: }
67:
68: /**
69: * Get the actual location within the associated {@link #getResource() resource}
70: * (may be <code>null</code>).
71: * <p>See the {@link Location class level javadoc for this class} for examples
72: * of what the actual type of the returned object may be.
73: */
74: public Object getSource() {
75: return this.source;
76: }
77:
78: }
|