X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2Fxml%2FExecutionScopeDecorator.java;h=dfca9d51260ca94029dde18d2a8f832c0fe6bdfa;hb=6de9c4036be9e318f59a0ffa187570f5999c53cb;hp=e5738b16878d30c9efb8956e77ac156c5cbc94a5;hpb=b9336fb77b251c886f7bc09ffafeb9818a50eb94;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/ExecutionScopeDecorator.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/ExecutionScopeDecorator.java index e5738b168..dfca9d512 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/ExecutionScopeDecorator.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/ExecutionScopeDecorator.java @@ -1,44 +1,52 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.argeo.slc.core.execution.xml; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.aop.scope.ScopedProxyUtils; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.xml.BeanDefinitionDecorator; import org.springframework.beans.factory.xml.ParserContext; +import org.w3c.dom.Element; import org.w3c.dom.Node; /** - * Inspired by org.springframework.aop.config.AopNamespaceHandler - * Conceived to replace Element "aop:scoped-proxy" by an attribute. - * Does not work correctly with other attribute decorators (e.g. - * p namespace) since this decorator needs to be called after all - * properties have been set on target bean. + * Inspired by org.springframework.aop.config.ScopedProxyBeanDefinitionDecorator */ -public class ExecutionScopeDecorator implements BeanDefinitionDecorator { - private Log log = LogFactory.getLog(ExecutionScopeDecorator.class); +public class ExecutionScopeDecorator implements BeanDefinitionDecorator { + private static final String PROXY_TARGET_CLASS = "proxy-target-class"; public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { - Boolean isVar = Boolean.valueOf(node.getNodeValue()); - - if(isVar) { - definition.getBeanDefinition().setScope("execution"); - - boolean proxyTargetClass = true; - - // Register the original bean definition as it will be referenced by the scoped proxy and is relevant for tooling (validation, navigation). - String targetBeanName = ScopedProxyUtils.getTargetBeanName(definition.getBeanName()); - parserContext.getReaderContext().fireComponentRegistered(new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName)); - - log.debug("Decorating bean " + definition.getBeanName()); - - return ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass); - } - else { - return definition; + definition.getBeanDefinition().setScope("execution"); + + // Default: CGLib not used + boolean proxyTargetClass = false; + if (node instanceof Element) { + Element ele = (Element) node; + if (ele.hasAttribute(PROXY_TARGET_CLASS)) { + proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS)).booleanValue(); + } } + + // Register the original bean definition as it will be referenced by the scoped proxy and is relevant for tooling (validation, navigation). + String targetBeanName = ScopedProxyUtils.getTargetBeanName(definition.getBeanName()); + parserContext.getReaderContext().fireComponentRegistered(new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName)); + + return ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass); } }