diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileTargetAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileTargetAdapter.java new file mode 100644 index 0000000000..ef58538d5b --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileTargetAdapter.java @@ -0,0 +1,54 @@ +/* + * Copyright 2002-2007 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 + * + * 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.springframework.integration.adapter.file; + +import java.io.File; + +import org.springframework.integration.adapter.DefaultTargetAdapter; +import org.springframework.integration.adapter.Target; + +/** + * A convenience adapter for writing files. The actual file writing occurs in + * the message mapper ({@link TextFileMapper} or {@link ByteArrayFileMapper}). + * + * @author Mark Fisher + */ +public class FileTargetAdapter extends DefaultTargetAdapter { + + public FileTargetAdapter(File directory) { + this(directory, true); + } + + public FileTargetAdapter(File directory, boolean isTextBased) { + super(new FileTarget()); + if (isTextBased) { + this.setMessageMapper(new TextFileMapper(directory)); + } + else { + this.setMessageMapper(new ByteArrayFileMapper(directory)); + } + } + + + private static class FileTarget implements Target { + + public boolean send(File file) { + return file.exists(); + } + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/bus/MessageBus.java b/spring-integration-core/src/main/java/org/springframework/integration/bus/MessageBus.java index 5843764491..533bb1c541 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/bus/MessageBus.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/bus/MessageBus.java @@ -199,6 +199,9 @@ public class MessageBus implements ChannelRegistry, ApplicationContextAware, Lif UnicastMessageDispatcher dispatcher = new UnicastMessageDispatcher(retriever, policy); dispatcher.addExecutor(new MessageReceivingExecutor(adapter, policy.getConcurrency(), policy.getMaxConcurrency())); this.addDispatcherTask(new DispatcherTask(dispatcher, policy)); + if (logger.isInfoEnabled()) { + logger.info("registered target adapter '" + name + "'"); + } } }