KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > ejb > config > AbstractJndiLocatingBeanDefinitionParser


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.ejb.config;
18
19 import org.w3c.dom.Element JavaDoc;
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 AbstractSimpleBeanDefinitionParser {
37
38     public static final String JavaDoc ENVIRONMENT = "environment";
39
40     public static final String JavaDoc ENVIRONMENT_REF = "environment-ref";
41
42     public static final String JavaDoc JNDI_ENVIRONMENT = "jndiEnvironment";
43
44
45     protected boolean isEligibleAttribute(String JavaDoc attributeName) {
46         return (super.isEligibleAttribute(attributeName) && !ENVIRONMENT_REF.equals(attributeName));
47     }
48
49     protected void postProcess(BeanDefinitionBuilder definitionBuilder, Element JavaDoc element) {
50         Object JavaDoc envValue = DomUtils.getChildElementValueByTagName(element, ENVIRONMENT);
51         if (envValue != null) {
52             // Specific environment settings defined, overriding any shared properties.
53
definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, envValue);
54         }
55         else {
56             // Check whether there is a reference to shared environment properties...
57
String JavaDoc envRef = element.getAttribute(ENVIRONMENT_REF);
58             if (StringUtils.hasLength(envRef)) {
59                 definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, new RuntimeBeanReference(envRef));
60             }
61         }
62     }
63
64 }
65
Popular Tags