01: /*
02: * Copyright 2002-2007 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.ejb.config;
18:
19: import org.w3c.dom.Element;
20:
21: import org.springframework.beans.factory.config.RuntimeBeanReference;
22: import org.springframework.beans.factory.support.BeanDefinitionBuilder;
23: import org.springframework.beans.factory.xml.ParserContext;
24: import org.springframework.jndi.JndiObjectFactoryBean;
25: import org.springframework.util.StringUtils;
26:
27: /**
28: * Simple {@link org.springframework.beans.factory.xml.BeanDefinitionParser} implementation that
29: * translates <code>jndi-lookup</code> tag into {@link JndiObjectFactoryBean} definitions.
30: *
31: * @author Rob Harrop
32: * @author Juergen Hoeller
33: * @since 2.0
34: * @see JndiObjectFactoryBean
35: */
36: class JndiLookupBeanDefinitionParser extends
37: AbstractJndiLocatingBeanDefinitionParser {
38:
39: public static final String DEFAULT_VALUE = "default-value";
40:
41: public static final String DEFAULT_REF = "default-ref";
42:
43: public static final String DEFAULT_OBJECT = "defaultObject";
44:
45: protected Class getBeanClass(Element element) {
46: return JndiObjectFactoryBean.class;
47: }
48:
49: protected boolean isEligibleAttribute(String attributeName) {
50: return (super .isEligibleAttribute(attributeName)
51: && !DEFAULT_VALUE.equals(attributeName) && !DEFAULT_REF
52: .equals(attributeName));
53: }
54:
55: protected void doParse(Element element,
56: ParserContext parserContext, BeanDefinitionBuilder builder) {
57: super .doParse(element, parserContext, builder);
58:
59: String defaultValue = element.getAttribute(DEFAULT_VALUE);
60: String defaultRef = element.getAttribute(DEFAULT_REF);
61: if (StringUtils.hasLength(defaultValue)) {
62: if (StringUtils.hasLength(defaultRef)) {
63: parserContext
64: .getReaderContext()
65: .error(
66: "<jndi-lookup> element is only allowed to contain either "
67: + "'default-value' attribute OR 'default-ref' attribute, not both",
68: element);
69: }
70: builder.addPropertyValue(DEFAULT_OBJECT, defaultValue);
71: } else if (StringUtils.hasLength(defaultRef)) {
72: builder.addPropertyValue(DEFAULT_OBJECT,
73: new RuntimeBeanReference(defaultRef));
74: }
75: }
76:
77: }
|