本文整理匯總了Java中org.springframework.beans.factory.xml.ParserContext類的典型用法代碼示例。如果您正苦於以下問題:Java ParserContext類的具體用法?Java ParserContext怎麽用?Java ParserContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ParserContext類屬於org.springframework.beans.factory.xml包,在下文中一共展示了ParserContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseChildElements
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
private void parseChildElements(Element element, String parentId, String redissonRef, BeanDefinitionBuilder redissonDef, ParserContext parserContext) {
if (element.hasChildNodes()) {
CompositeComponentDefinition compositeDef
= new CompositeComponentDefinition(parentId,
parserContext.extractSource(element));
parserContext.pushContainingComponent(compositeDef);
List<Element> childElts = DomUtils.getChildElements(element);
for (Element elt : childElts) {
if(BeanDefinitionParserDelegate
.QUALIFIER_ELEMENT.equals(elt.getLocalName())) {
continue;//parsed elsewhere
}
String localName = parserContext.getDelegate().getLocalName(elt);
localName = Conventions.attributeNameToPropertyName(localName);
if (ConfigType.contains(localName)) {
parseConfigTypes(elt, localName, redissonDef, parserContext);
} else if (AddressType.contains(localName)) {
parseAddressTypes(elt, localName, redissonDef, parserContext);
} else if (helper.isRedissonNS(elt)) {
elt.setAttribute(REDISSON_REF, redissonRef);
parserContext.getDelegate().parseCustomElement(elt);
}
}
parserContext.popContainingComponent();
}
}
示例2: decorateIfRequired
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
public static BeanDefinitionHolder decorateIfRequired(Node node, BeanDefinitionHolder originalDef,
ParserContext parserContext) {
String namespaceUri = node.getNamespaceURI();
if (!parserContext.getDelegate().isDefaultNamespace(namespaceUri) && !isRFC124Namespace(namespaceUri)) {
NamespaceHandler handler =
parserContext.getReaderContext().getNamespaceHandlerResolver().resolve(namespaceUri);
if (handler != null) {
return handler.decorate(node, originalDef, new ParserContext(parserContext.getReaderContext(),
parserContext.getDelegate()));
} else if (namespaceUri.startsWith("http://www.springframework.org/")) {
parserContext.getReaderContext().error(
"Unable to locate Spring NamespaceHandler for XML schema namespace [" + namespaceUri + "]",
node);
} else {
// A custom namespace, not to be handled by Spring - maybe "xml:...".
}
}
return originalDef;
}
示例3: parse
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
public BeanDefinition parse(Element element, ParserContext parserContext)
{
BeanDefinitionBuilder dwrController = BeanDefinitionBuilder.rootBeanDefinition(DwrController.class);
List configurators = new ManagedList();
configurators.add(new RuntimeBeanReference(DEFAULT_SPRING_CONFIGURATOR_ID));
dwrController.addPropertyValue("configurators", configurators);
String debug = element.getAttribute("debug");
if (StringUtils.hasText(debug))
{
dwrController.addPropertyValue("debug", debug);
}
String beanName = element.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE);
String nameAttr = element.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE);
String[] aliases = null;
if (!StringUtils.hasText(beanName))
{
beanName = element.getAttribute("name");
}
else
{
String aliasName = element.getAttribute("name");
if (StringUtils.hasText(aliasName))
{
aliases = StringUtils.tokenizeToStringArray(nameAttr, BeanDefinitionParserDelegate.BEAN_NAME_DELIMITERS);
}
}
parseControllerParameters(dwrController, element);
BeanDefinitionHolder holder = new BeanDefinitionHolder(dwrController.getBeanDefinition(), beanName, aliases);
BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
return dwrController.getBeanDefinition();
}
示例4: parseNested
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
private static void parseNested(Element element, ParserContext parserContext, Class<?> beanClass, boolean required, String tag, String property, String ref, BeanDefinition beanDefinition) {
NodeList nodeList = element.getChildNodes();
if (nodeList != null && nodeList.getLength() > 0) {
boolean first = true;
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node instanceof Element) {
if (tag.equals(node.getNodeName())
|| tag.equals(node.getLocalName())) {
if (first) {
first = false;
String isDefault = element.getAttribute("default");
if (isDefault == null || isDefault.length() == 0) {
beanDefinition.getPropertyValues().addPropertyValue("default", "false");
}
}
BeanDefinition subDefinition = parse((Element) node, parserContext, beanClass, required);
if (subDefinition != null && ref != null && ref.length() > 0) {
subDefinition.getPropertyValues().addPropertyValue(property, new RuntimeBeanReference(ref));
}
}
}
}
}
}
示例5: parseNested
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
Class<?> apiClass;
try {
apiClass = Class.forName(helper.getAttribute(element,
RedissonNamespaceParserSupport.API_CLASS_ATTRIBUTE));
} catch (ClassNotFoundException ex) {
throw new IllegalArgumentException(
"The class [" + helper.getAttribute(element,
RedissonNamespaceParserSupport.API_CLASS_ATTRIBUTE)
+ "] specified in \""
+ RedissonNamespaceParserSupport.API_CLASS_ATTRIBUTE
+ "\" attribute has not "
+ "found. Please check the class path.", ex);
}
builder.addPropertyValue("targetObject", new RuntimeBeanReference(
helper.getAttribute(element,
RedissonNamespaceParserSupport.REMOTE_SERVICE_REF_ATTRIBUTE)));
builder.addPropertyValue("targetMethod", "get");
builder.addPropertyValue("arguments", new Object[] {apiClass});
}
示例6: parseNested
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
bd.setFactoryBeanName(element.getAttribute(
RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE));
String typeName
= Conventions.attributeNameToPropertyName(element.getLocalName());
bd.setFactoryMethodName("get" + StringUtils.capitalize(typeName));
helper.addConstructorArgs(element, KEY_ATTRIBUTE,
String.class, builder);
helper.addConstructorArgs(element, TOPIC_ATTRIBUTE,
String.class, builder);
helper.addConstructorArgs(element, PATTERN_ATTRIBUTE,
String.class, builder);
helper.addConstructorArgs(element, SERVICE_ATTRIBUTE,
String.class, builder);
helper.addConstructorArgs(element, CODEC_REF_ATTRIBUTE,
Codec.class, builder);
if (RDestroyable.class.isAssignableFrom(getBeanClass(element))) {
((AbstractBeanDefinition) bd).setDestroyMethodName("destroy");
}
}
示例7: doParse
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
super.doParse(element, parserContext, builder);
String defaultValue = element.getAttribute(DEFAULT_VALUE);
String defaultRef = element.getAttribute(DEFAULT_REF);
if (StringUtils.hasLength(defaultValue)) {
if (StringUtils.hasLength(defaultRef)) {
parserContext.getReaderContext().error("<jndi-lookup> element is only allowed to contain either " +
"'default-value' attribute OR 'default-ref' attribute, not both", element);
}
builder.addPropertyValue(DEFAULT_OBJECT, defaultValue);
}
else if (StringUtils.hasLength(defaultRef)) {
builder.addPropertyValue(DEFAULT_OBJECT, new RuntimeBeanReference(defaultRef));
}
}
示例8: doParse
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
builder.addPropertyReference("transactionManager", TxNamespaceHandler.getTransactionManagerName(element));
List<Element> txAttributes = DomUtils.getChildElementsByTagName(element, ATTRIBUTES_ELEMENT);
if (txAttributes.size() > 1) {
parserContext.getReaderContext().error(
"Element <attributes> is allowed at most once inside element <advice>", element);
}
else if (txAttributes.size() == 1) {
// Using attributes source.
Element attributeSourceElement = txAttributes.get(0);
RootBeanDefinition attributeSourceDefinition = parseAttributeSource(attributeSourceElement, parserContext);
builder.addPropertyValue("transactionAttributeSource", attributeSourceDefinition);
}
else {
// Assume annotations source.
builder.addPropertyValue("transactionAttributeSource",
new RootBeanDefinition("org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"));
}
}
示例9: doParse
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
@Override
protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
Assert.state(helper.isRedissonNS(element),
"Illegal state. "
+ this.getClass().getName()
+ " can only parse "
+ RedissonNamespaceParserSupport.REDISSON_NAMESPACE
+ " namespace elements");
Assert.state(element.hasAttribute(parentRefAttribute),
"Illegal state. property \"" + parentRefAttribute
+ "\" is required in the \""
+ helper.getName(element)
+ "\" element.");
helper.populateIdAttribute(element, builder, parserContext);
AbstractBeanDefinition bd = builder.getRawBeanDefinition();
parseNested(element, parserContext, builder, bd);
decorator.decorate(element, parserContext, builder, helper);
parserContext.getDelegate().parseQualifierElements(element, bd);
if (parserContext.isNested()) {
helper.registerBeanDefinition(builder, element, parserContext);
}
}
示例10: checkAvailabilityAndCardinalityDuplication
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
public static void checkAvailabilityAndCardinalityDuplication(Element element, String availabilityName,
String cardinalityName, ParserContext context) {
String avail = element.getAttribute(availabilityName);
String cardinality = element.getAttribute(cardinalityName);
if (StringUtils.hasText(avail) && StringUtils.hasText(cardinality)) {
boolean availStatus = avail.startsWith(ONE);
boolean cardStatus = cardinality.startsWith(M);
if (availStatus != cardStatus) {
context.getReaderContext().error(
"Both '" + availabilityName + "' and '" + cardinalityName
+ "' attributes have been specified but with contradictory values.", element);
}
}
}
示例11: parseAttributes
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
public void parseAttributes(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
NamedNodeMap attributes = element.getAttributes();
for (int x = 0; x < attributes.getLength(); x++) {
Attr attribute = (Attr) attributes.item(x);
if (isEligibleAttribute(attribute)) {
String propertyName
= attribute.getLocalName().endsWith(REF_SUFFIX)
? attribute.getLocalName()
.substring(0, attribute.getLocalName()
.length() - REF_SUFFIX.length())
: attribute.getLocalName();
propertyName = Conventions
.attributeNameToPropertyName(propertyName);
Assert.state(StringUtils.hasText(propertyName),
"Illegal property name returned from"
+ " 'extractPropertyName(String)': cannot be"
+ " null or empty.");
if (attribute.getLocalName().endsWith(REF_SUFFIX)) {
builder.addPropertyReference(propertyName,
attribute.getValue());
} else {
builder.addPropertyValue(propertyName, attribute.getValue());
}
}
}
}
示例12: doParse
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
// first check the attributes
if (element.hasAttribute(AUTOEXPORT) && !DISABLED.equals(element.getAttribute(AUTOEXPORT).trim())) {
if (element.hasAttribute(INTERFACE)) {
parserContext.getReaderContext().error(
"either 'auto-export' or 'interface' attribute has be specified but not both", element);
}
if (DomUtils.getChildElementByTagName(element, INTERFACES) != null) {
parserContext.getReaderContext().error(
"either 'auto-export' attribute or <intefaces> sub-element has be specified but not both",
element);
}
}
builder.addPropertyValue(CACHE_TARGET, true);
super.doParse(element, parserContext, builder);
}
示例13: parse
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
Object source = parserContext.extractSource(element);
// Obtain bean definitions for all relevant BeanPostProcessors.
Set<BeanDefinitionHolder> processorDefinitions =
AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source);
// Register component for the surrounding <context:annotation-config> element.
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
parserContext.pushContainingComponent(compDefinition);
// Nest the concrete beans in the surrounding component.
for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
parserContext.registerComponent(new BeanComponentDefinition(processorDefinition));
}
// Finally register the composite component.
parserContext.popAndRegisterContainingComponent();
return null;
}
示例14: BlueprintDefaultsDefinition
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
/**
* Constructs a new <code>BlueprintDefaultsDefinition</code> instance.
* @param parserContext
*
* @param root
*/
public BlueprintDefaultsDefinition(Document doc, ParserContext parserContext) {
super(doc, parserContext);
Element root = doc.getDocumentElement();
String timeout = getAttribute(root, BLUEPRINT_NS, DEFAULT_TIMEOUT);
setTimeout(StringUtils.hasText(timeout) ? timeout.trim() : TIMEOUT_DEFAULT);
String availability = getAttribute(root, BLUEPRINT_NS, DEFAULT_AVAILABILITY);
if (StringUtils.hasText(availability)) {
Availability avail = ReferenceParsingUtil.determineAvailability(availability);
setAvailability(avail);
}
// default initialization
String initialization = getAttribute(root, BLUEPRINT_NS, DEFAULT_INITIALIZATION);
defaultInitialization =
(StringUtils.hasText(initialization) ? initialization.trim().equalsIgnoreCase(LAZY_INITIALIZATION)
: INITIALIZATION_DEFAULT);
}
示例15: preInvoke
import org.springframework.beans.factory.xml.ParserContext; //導入依賴的package包/類
private BeanDefinitionBuilder preInvoke(Element element, Object obj, String method, Object[] args, ParserContext parserContext, boolean factory) {
BeanDefinitionBuilder builder
= createBeanDefinitionBuilder(element, parserContext,
factory
? MethodInvokingFactoryBean.class
: BeanMethodInvoker.class);
if (obj instanceof Class) {
builder.addPropertyValue("staticMethod",
((Class) obj).getName() + "." + method);
} else {
builder.addPropertyValue("targetMethod", method);
}
builder.addPropertyValue("arguments", args);
if (element != null) {
parserContext.getDelegate().parseQualifierElements(element,
builder.getRawBeanDefinition());
}
return builder;
}