INT-1471 formatting

This commit is contained in:
Mark Fisher
2010-10-27 21:21:46 -04:00
parent ed140f5948
commit a5c09ef557
6 changed files with 97 additions and 88 deletions

View File

@@ -13,32 +13,49 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.config;
import static org.springframework.integration.twitter.config.TwitterNamespaceHandler.BASE_PACKAGE;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.util.StringUtils;
import static org.springframework.integration.twitter.config.TwitterNamespaceHandler.BASE_PACKAGE;
/**
* Parser for 'twitter-connection' element
* Parser for the 'twitter-connection' element.
*
* @author Josh Long
* @author Mark Fisher
* @since 2.0
*/
public class ConnectionParser extends AbstractSingleBeanDefinitionParser {
@Override
protected String getBeanClassName(Element element) {
return BASE_PACKAGE + ".oauth.OAuthConfigurationFactoryBean";
}
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
TwitterNamespaceHandler.configureTwitterConnection(element, parserContext, builder);
}
@Override
protected String getBeanClassName(Element element) {
return BASE_PACKAGE + ".oauth.OAuthConfigurationFactoryBean";
}
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
}
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
String ref = element.getAttribute("twitter-connection");
if (StringUtils.hasText(ref)) {
builder.addPropertyReference("twitterConnection", ref);
}
else {
for (String attribute : new String[] { "consumer-key", "consumer-secret", "access-token", "access-token-secret" }) {
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, attribute);
}
}
}
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010 the original author or authors
* Copyright 2002-2010 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.
@@ -13,10 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.config;
import static org.springframework.integration.twitter.config.TwitterNamespaceHandler.BASE_PACKAGE;
import org.w3c.dom.Element;
import org.springframework.beans.BeanMetadataElement;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -24,10 +27,9 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.w3c.dom.Element;
/**
* A parser for InboundTimelineUpdateEndpoint endpoint.
* Parser for inbound Twitter Channel Adapters.
*
* @author Oleg Zhurakousky
* @since 2.0
@@ -35,24 +37,25 @@ import org.w3c.dom.Element;
public class InboundMessageSourceParser extends AbstractPollingInboundChannelAdapterParser {
@Override
protected BeanMetadataElement parseSource(Element element, ParserContext parserContext) {
protected BeanMetadataElement parseSource(Element element, ParserContext parserContext) {
String elementName = element.getLocalName().trim();
String className = null;
if ("inbound-update-channel-adapter".equals(elementName)){
className = BASE_PACKAGE +".inbound.TimelineUpdateMessageSource" ;
}
else if ("inbound-dm-channel-adapter".equals(elementName)){
className = BASE_PACKAGE + ".inbound.DirectMessageMessageSource";
}
else if ("inbound-mention-channel-adapter".equals(elementName)){
className = BASE_PACKAGE + ".inbound.MentionMessageSource";
}
else {
throw new IllegalArgumentException("Element '" + elementName + "' is not supported by this parser");
}
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(className);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "twitter-connection", "configuration");
String name = BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry());
if ("inbound-update-channel-adapter".equals(elementName)) {
className = BASE_PACKAGE + ".inbound.TimelineUpdateMessageSource";
}
else if ("inbound-dm-channel-adapter".equals(elementName)) {
className = BASE_PACKAGE + ".inbound.DirectMessageMessageSource";
}
else if ("inbound-mention-channel-adapter".equals(elementName)) {
className = BASE_PACKAGE + ".inbound.MentionMessageSource";
}
else {
parserContext.getReaderContext().error("element '" + elementName + "' is not supported by this parser.", element);
}
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(className);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "twitter-connection", "configuration");
String name = BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry());
return new RuntimeBeanReference(name);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010 the original author or authors
* Copyright 2002-2010 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.
@@ -13,31 +13,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.config;
import static org.springframework.integration.twitter.config.TwitterNamespaceHandler.BASE_PACKAGE;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.w3c.dom.Element;
import static org.springframework.integration.twitter.config.TwitterNamespaceHandler.BASE_PACKAGE;
/**
* Parser for 'outbound-dm-channel-adapter' element
*
*
* @author Josh Long
* @since 2.0
*
*/
public class OutboundDirectMessageMessageHandlerParser extends AbstractOutboundChannelAdapterParser {
@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
BASE_PACKAGE + ".outbound.OutboundDirectMessageMessageHandler" );
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "twitter-connection", "configuration");
return builder.getBeanDefinition();
}
@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
BASE_PACKAGE + ".outbound.OutboundDirectMessageMessageHandler");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "twitter-connection", "configuration");
return builder.getBeanDefinition();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010 the original author or authors
* Copyright 2002-2010 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.config;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
@@ -25,23 +26,19 @@ import org.w3c.dom.Element;
import static org.springframework.integration.twitter.config.TwitterNamespaceHandler.BASE_PACKAGE;
/**
*
* Parsers for 'outbound-update-channel-adapter' element
*
* Parser for the 'outbound-update-channel-adapter' element.
*
* @author Josh Long
* @since 2.0
*/
public class OutboundTimelineUpdateMessageHandlerParser extends AbstractOutboundChannelAdapterParser {
@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
BASE_PACKAGE + ".outbound.OutboundTimelineUpdateMessageHandler" );
@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
BASE_PACKAGE + ".outbound.OutboundTimelineUpdateMessageHandler");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "twitter-connection", "configuration");
return builder.getBeanDefinition();
}
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element,
"twitter-connection", "configuration");
return builder.getBeanDefinition();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010 the original author or authors
* Copyright 2002-2010 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.
@@ -13,26 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.config;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.w3c.dom.Element;
import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler;
/**
* Namespace handler for the Twitter adapters.
*
* @author Josh Long
* @author Oleg Zhurakousky
* @since 2.0
*/
public class TwitterNamespaceHandler extends org.springframework.beans.factory.xml.NamespaceHandlerSupport {
public class TwitterNamespaceHandler extends AbstractIntegrationNamespaceHandler {
public static String BASE_PACKAGE = "org.springframework.integration.twitter";
public static String BASE_PACKAGE = "org.springframework.integration.twitter";
public void init() {
// twitter connections
// twitter connection
registerBeanDefinitionParser("twitter-connection", new ConnectionParser());
// inbound
@@ -45,19 +44,4 @@ public class TwitterNamespaceHandler extends org.springframework.beans.factory.x
registerBeanDefinitionParser("outbound-dm-channel-adapter", new OutboundDirectMessageMessageHandlerParser());
}
public static void configureTwitterConnection(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
String ref = element.getAttribute("twitter-connection");
if (org.springframework.util.StringUtils.hasText(ref)) {
builder.addPropertyReference("twitterConnection", ref);
} else {
for (String attribute : new String[]{"consumer-key", "consumer-secret", "access-token", "access-token-secret"}) {
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, attribute);
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010 the original author or authors
* Copyright 2002-2010 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.
@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.core;
package org.springframework.integration.twitter.core;
/**
* An enum to allow users to express interest in particular kinds of tweets.
@@ -25,9 +25,15 @@ package org.springframework.integration.twitter.core;
* @since 2.0
*/
public class TwitterHeaders {
public static final String TWITTER_IN_REPLY_TO_STATUS_ID = "TWITTER_IN_REPLY_TO_STATUS_ID";
public static final String TWITTER_PLACE_ID = "TWITTER_PLACE_ID";
public static final String TWITTER_GEOLOCATION = "TWITTER_GEOLOCATION";
public static final String TWITTER_DISPLAY_COORDINATES = "TWITTER_DISPLAY_COORDINATES";
public static final String TWITTER_DM_TARGET_USER_ID = "TWITTER_DM_TARGET_USER_ID";
}