1 16 17 package org.springframework.beans.factory.xml; 18 19 import java.util.Stack ; 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 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 containingComponents = new Stack (); 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 extractSource(Object 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 |