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.AbstractSimpleBeanDefinitionParser;
24: import org.springframework.util.StringUtils;
25: import org.springframework.util.xml.DomUtils;
26:
27: /**
28: * Abstract base class for BeanDefinitionParsers which build
29: * JNDI-locating beans, supporting an optional "jndiEnvironment"
30: * bean property, populated from an "environment" XML sub-element.
31: *
32: * @author Rob Harrop
33: * @author Juergen Hoeller
34: * @since 2.0
35: */
36: abstract class AbstractJndiLocatingBeanDefinitionParser extends
37: AbstractSimpleBeanDefinitionParser {
38:
39: public static final String ENVIRONMENT = "environment";
40:
41: public static final String ENVIRONMENT_REF = "environment-ref";
42:
43: public static final String JNDI_ENVIRONMENT = "jndiEnvironment";
44:
45: protected boolean isEligibleAttribute(String attributeName) {
46: return (super .isEligibleAttribute(attributeName) && !ENVIRONMENT_REF
47: .equals(attributeName));
48: }
49:
50: protected void postProcess(BeanDefinitionBuilder definitionBuilder,
51: Element element) {
52: Object envValue = DomUtils.getChildElementValueByTagName(
53: element, ENVIRONMENT);
54: if (envValue != null) {
55: // Specific environment settings defined, overriding any shared properties.
56: definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT,
57: envValue);
58: } else {
59: // Check whether there is a reference to shared environment properties...
60: String envRef = element.getAttribute(ENVIRONMENT_REF);
61: if (StringUtils.hasLength(envRef)) {
62: definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT,
63: new RuntimeBeanReference(envRef));
64: }
65: }
66: }
67:
68: }
|