diff --git a/spring-integration-core/src/main/java/org/springframework/integration/message/AbstractMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/message/AbstractMessageMapper.java new file mode 100644 index 0000000000..db48193a91 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/message/AbstractMessageMapper.java @@ -0,0 +1,43 @@ +/* + * 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.message; + +import org.springframework.integration.util.RandomGuidUidGenerator; +import org.springframework.integration.util.UidGenerator; +import org.springframework.util.Assert; + +/** + * Base class that provides the default {@link UidGenerator} as well as a setter + * for providing a custom id generator implementation. + * + * @author Mark Fisher + */ +public abstract class AbstractMessageMapper implements MessageMapper { + + private UidGenerator uidGenerator = new RandomGuidUidGenerator(); + + + public void setUidGenerator(UidGenerator uidGenerator) { + Assert.notNull(uidGenerator, "'uidGenerator' must not be null"); + this.uidGenerator = uidGenerator; + } + + public UidGenerator getUidGenerator() { + return this.uidGenerator; + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/message/SimplePayloadMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/message/SimplePayloadMessageMapper.java index 1884e7269d..cab790d70d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/message/SimplePayloadMessageMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/message/SimplePayloadMessageMapper.java @@ -16,40 +16,13 @@ package org.springframework.integration.message; -import org.springframework.integration.util.RandomGuidUidGenerator; -import org.springframework.integration.util.UidGenerator; -import org.springframework.util.Assert; - /** * A {@link MessageMapper} implementation that simply wraps and unwraps a * payload object in a {@link DocumentMessage}. * * @author Mark Fisher */ -public class SimplePayloadMessageMapper implements MessageMapper { - - private UidGenerator uidGenerator; - - - /** - * Create a mapper with the provided id generation strategy. - * - * @param uidGenerator the generator to use for message ids - */ - public SimplePayloadMessageMapper(UidGenerator uidGenerator) { - Assert.notNull(uidGenerator, "uidGenerator must not be null"); - this.uidGenerator = uidGenerator; - } - - /** - * Create a mapper with the default id generation strategy. - * - * @see RandomGuidUidGenerator - */ - public SimplePayloadMessageMapper() { - this.uidGenerator = new RandomGuidUidGenerator(); - } - +public class SimplePayloadMessageMapper extends AbstractMessageMapper { /** * Return the payload of the given Message. @@ -62,7 +35,7 @@ public class SimplePayloadMessageMapper implements MessageMapper { * Return a {@link DocumentMessage} with the given object as its payload. */ public Message toMessage(T source) { - return new GenericMessage(uidGenerator.generateUid(), source); + return new GenericMessage(this.getUidGenerator().generateUid(), source); } }