]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/ExecutionScopeDecorator.java
Docuementation
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / xml / ExecutionScopeDecorator.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.argeo.slc.core.execution.xml;
18
19 import org.springframework.aop.scope.ScopedProxyUtils;
20 import org.springframework.beans.factory.config.BeanDefinitionHolder;
21 import org.springframework.beans.factory.parsing.BeanComponentDefinition;
22 import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
23 import org.springframework.beans.factory.xml.ParserContext;
24 import org.w3c.dom.Element;
25 import org.w3c.dom.Node;
26
27 /**
28 * Inspired by org.springframework.aop.config.ScopedProxyBeanDefinitionDecorator
29 */
30 public class ExecutionScopeDecorator implements BeanDefinitionDecorator {
31 private static final String PROXY_TARGET_CLASS = "proxy-target-class";
32
33 public BeanDefinitionHolder decorate(Node node,
34 BeanDefinitionHolder definition, ParserContext parserContext) {
35
36 definition.getBeanDefinition().setScope("execution");
37
38 // Default: CGLib not used
39 boolean proxyTargetClass = false;
40 if (node instanceof Element) {
41 Element ele = (Element) node;
42 if (ele.hasAttribute(PROXY_TARGET_CLASS)) {
43 proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS)).booleanValue();
44 }
45 }
46
47 // Register the original bean definition as it will be referenced by the scoped proxy and is relevant for tooling (validation, navigation).
48 String targetBeanName = ScopedProxyUtils.getTargetBeanName(definition.getBeanName());
49 parserContext.getReaderContext().fireComponentRegistered(new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName));
50
51 return ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass);
52 }
53 }