2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.core
.execution
.xml
;
18 import org
.springframework
.aop
.scope
.ScopedProxyUtils
;
19 import org
.springframework
.beans
.factory
.config
.BeanDefinitionHolder
;
20 import org
.springframework
.beans
.factory
.parsing
.BeanComponentDefinition
;
21 import org
.springframework
.beans
.factory
.xml
.BeanDefinitionDecorator
;
22 import org
.springframework
.beans
.factory
.xml
.ParserContext
;
23 import org
.w3c
.dom
.Element
;
24 import org
.w3c
.dom
.Node
;
27 * Inspired by org.springframework.aop.config.ScopedProxyBeanDefinitionDecorator
29 public class ExecutionScopeDecorator
implements BeanDefinitionDecorator
{
30 private static final String PROXY_TARGET_CLASS
= "proxy-target-class";
32 public BeanDefinitionHolder
decorate(Node node
,
33 BeanDefinitionHolder definition
, ParserContext parserContext
) {
35 definition
.getBeanDefinition().setScope("execution");
37 // Default: CGLib not used
38 boolean proxyTargetClass
= false;
39 if (node
instanceof Element
) {
40 Element ele
= (Element
) node
;
41 if (ele
.hasAttribute(PROXY_TARGET_CLASS
)) {
42 proxyTargetClass
= Boolean
.valueOf(ele
.getAttribute(PROXY_TARGET_CLASS
)).booleanValue();
46 // Register the original bean definition as it will be referenced by the scoped proxy and is relevant for tooling (validation, navigation).
47 String targetBeanName
= ScopedProxyUtils
.getTargetBeanName(definition
.getBeanName());
48 parserContext
.getReaderContext().fireComponentRegistered(new BeanComponentDefinition(definition
.getBeanDefinition(), targetBeanName
));
50 return ScopedProxyUtils
.createScopedProxy(definition
, parserContext
.getRegistry(), proxyTargetClass
);