From 031aa372c0f12935cf54cd7cbd5e073c83e4fba2 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 4 Feb 2011 09:40:57 -0500 Subject: [PATCH] INT-1727 polishing --- .../DefaultScriptVariableGenerator.java | 40 ++++++++----------- .../groovy/ScriptVariableGenerator.java | 7 ++-- .../config/GroovyControlBusFactoryBean.java | 17 ++++---- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/DefaultScriptVariableGenerator.java b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/DefaultScriptVariableGenerator.java index 0d0bcb5c0a..5f73764419 100644 --- a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/DefaultScriptVariableGenerator.java +++ b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/DefaultScriptVariableGenerator.java @@ -13,54 +13,48 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.groovy; import java.util.HashMap; import java.util.Map; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.integration.Message; import org.springframework.util.CollectionUtils; /** * @author Oleg Zhurakousky + * @author Mark Fisher * @since 2.0.2 */ -class DefaultScriptVariableGenerator implements BeanFactoryAware, ScriptVariableGenerator { - - protected volatile ListableBeanFactory beanFactory; - - private volatile Map variableMap; - +class DefaultScriptVariableGenerator implements ScriptVariableGenerator { + + private final Map variableMap; + + public DefaultScriptVariableGenerator(){ this(null); } - - public DefaultScriptVariableGenerator(Map variableMap){ + + public DefaultScriptVariableGenerator(Map variableMap) { this.variableMap = variableMap; } - - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.beanFactory = (beanFactory instanceof ListableBeanFactory) ? (ListableBeanFactory) beanFactory : null; - } - - public Map generateScriptVariables(Message message){ + + + public Map generateScriptVariables(Message message) { Map scriptVariables = new HashMap(); - // Ad Message attributes + // Add Message content if (message != null) { scriptVariables.put("payload", message.getPayload()); scriptVariables.put("headers", message.getHeaders()); } // Add contents of 'variableMap' - if (!CollectionUtils.isEmpty(variableMap)){ - for (String variableName : variableMap.keySet()) { - Object variableValue = variableMap.get(variableName); - scriptVariables.put(variableName, variableValue); + if (!CollectionUtils.isEmpty(this.variableMap)) { + for (Map.Entry entry : this.variableMap.entrySet()) { + scriptVariables.put(entry.getKey(), entry.getValue()); } } return scriptVariables; } + } diff --git a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/ScriptVariableGenerator.java b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/ScriptVariableGenerator.java index 181dd3a356..d56268957e 100644 --- a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/ScriptVariableGenerator.java +++ b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/ScriptVariableGenerator.java @@ -13,18 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.groovy; import java.util.Map; import org.springframework.integration.Message; - /** * @author Oleg Zhurakousky - * + * @since 2.0.2 */ public interface ScriptVariableGenerator { - + Map generateScriptVariables(Message message); + } diff --git a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyControlBusFactoryBean.java b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyControlBusFactoryBean.java index 70c9206193..819d039cef 100644 --- a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyControlBusFactoryBean.java +++ b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyControlBusFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * 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 @@ -57,18 +57,20 @@ public class GroovyControlBusFactoryBean extends AbstractSimpleMessageHandlerFac } return handler; } - - private class ManagedBeansScriptVariableSource implements ScriptVariableGenerator { + + + private static class ManagedBeansScriptVariableSource implements ScriptVariableGenerator { + private final ListableBeanFactory beanFactory; - - public ManagedBeansScriptVariableSource(BeanFactory beanFactory){ + + public ManagedBeansScriptVariableSource(BeanFactory beanFactory) { this.beanFactory = (beanFactory instanceof ListableBeanFactory) ? (ListableBeanFactory) beanFactory : null; } - + public Map generateScriptVariables(Message message) { Map variables = new HashMap(); variables.put("headers", message.getHeaders()); - if (this.beanFactory != null){ + if (this.beanFactory != null) { for (String name : this.beanFactory.getBeanDefinitionNames()) { Object bean = this.beanFactory.getBean(name); if (bean instanceof Lifecycle || @@ -81,4 +83,5 @@ public class GroovyControlBusFactoryBean extends AbstractSimpleMessageHandlerFac return variables; } } + }