KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > xml > ParserContext


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.xml;
18
19 import java.util.Stack JavaDoc;
20
21 import org.springframework.beans.factory.config.BeanDefinition;
22 import org.springframework.beans.factory.parsing.ComponentDefinition;
23 import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
24 import org.springframework.beans.factory.support.BeanDefinitionRegistry;
25
26 /**
27  * Context that gets passed along a bean definition parsing process,
28  * encapsulating all relevant configuration as well as state.
29  * Nested inside an {@link XmlReaderContext}.
30  *
31  * @author Rob Harrop
32  * @author Juergen Hoeller
33  * @since 2.0
34  * @see XmlReaderContext
35  * @see BeanDefinitionParserDelegate
36  */

37 public final class ParserContext {
38
39     private final XmlReaderContext readerContext;
40
41     private final BeanDefinitionParserDelegate delegate;
42
43     private BeanDefinition containingBeanDefinition;
44
45     private final Stack JavaDoc containingComponents = new Stack JavaDoc();
46
47
48     public ParserContext(XmlReaderContext readerContext, BeanDefinitionParserDelegate delegate) {
49         this.readerContext = readerContext;
50         this.delegate = delegate;
51     }
52
53     public ParserContext(XmlReaderContext readerContext, BeanDefinitionParserDelegate delegate,
54             BeanDefinition containingBeanDefinition) {
55
56         this.readerContext = readerContext;
57         this.delegate = delegate;
58         this.containingBeanDefinition = containingBeanDefinition;
59     }
60
61
62     public final XmlReaderContext getReaderContext() {
63         return this.readerContext;
64     }
65
66     public final BeanDefinitionRegistry getRegistry() {
67         return this.readerContext.getRegistry();
68     }
69
70     public final BeanDefinitionParserDelegate getDelegate() {
71         return this.delegate;
72     }
73
74     public final BeanDefinition getContainingBeanDefinition() {
75         return this.containingBeanDefinition;
76     }
77
78     public final boolean isNested() {
79         return (this.containingBeanDefinition != null);
80     }
81
82     public boolean isDefaultLazyInit() {
83         return BeanDefinitionParserDelegate.TRUE_VALUE.equals(this.delegate.getDefaults().getLazyInit());
84     }
85
86     public Object JavaDoc extractSource(Object JavaDoc sourceCandidate) {
87         return this.readerContext.extractSource(sourceCandidate);
88     }
89
90     public CompositeComponentDefinition getContainingComponent() {
91         return (!this.containingComponents.isEmpty() ?
92                 (CompositeComponentDefinition) this.containingComponents.lastElement() : null);
93     }
94
95     public void pushContainingComponent(CompositeComponentDefinition containingComponent) {
96         this.containingComponents.push(containingComponent);
97     }
98
99     public CompositeComponentDefinition popContainingComponent() {
100         return (CompositeComponentDefinition) this.containingComponents.pop();
101     }
102
103     public void popAndRegisterContainingComponent() {
104         registerComponent(popContainingComponent());
105     }
106
107     public void registerComponent(ComponentDefinition component) {
108         CompositeComponentDefinition containingComponent = getContainingComponent();
109         if (containingComponent != null) {
110             containingComponent.addNestedComponent(component);
111         }
112         else {
113             this.readerContext.fireComponentRegistered(component);
114         }
115     }
116
117 }
118
Popular Tags