package com.dtikhonov.publishers.impl;
import com.dtikhonov.messages.MyMessageEvent;
import com.dtikhonov.publishers.MyPublisherInterface;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
/**
* Created by dtikhonov on 26/05/14.
*/
public class ApplicationEventAwarePublisher implements ApplicationEventPublisherAware, BeanNameAware,
MyPublisherInterface {
private String beanName = "Unknown Bean";
private ApplicationEventPublisher eventPublisher;
/**
* Implementation of the BeanNameAware interface
*/
public void setBeanName(String name) {
this.beanName = name;
}
/**
* This is the implementation of the MyPublisherInterface
*/
public void publish(String messageToPublish) {
eventPublisher.publishEvent(new MyMessageEvent(this, messageToPublish));
}
/**
* @see org.springframework.context.ApplicationEventPublisherAware#setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
*/
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
this.eventPublisher = publisher;
}
}