KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > workflow > notification > support > NotificationPublisherAwareProcessor


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.riot.workflow.notification.support;
25
26 import org.riotfamily.riot.workflow.notification.NotificationDao;
27 import org.riotfamily.riot.workflow.notification.NotificationFactory;
28 import org.riotfamily.riot.workflow.notification.NotificationPublisher;
29 import org.riotfamily.riot.workflow.notification.NotificationPublisherAware;
30 import org.springframework.beans.factory.InitializingBean;
31 import org.springframework.beans.factory.config.BeanPostProcessor;
32 import org.springframework.context.MessageSource;
33 import org.springframework.context.MessageSourceAware;
34 import org.springframework.util.Assert;
35
36 public class NotificationPublisherAwareProcessor implements BeanPostProcessor,
37         MessageSourceAware, InitializingBean {
38     
39     private NotificationPublisher notificationPublisher;
40
41     private NotificationFactory notificationFactory;
42     
43     private NotificationDao notificationDao;
44         
45     private MessageSource messageSource;
46     
47     public void setMessageSource(MessageSource messageSource) {
48         this.messageSource = messageSource;
49     }
50
51     public void setNotificationDao(NotificationDao notificationDao) {
52         this.notificationDao = notificationDao;
53     }
54
55     public void setNotificationFactory(NotificationFactory notificationFactory) {
56         this.notificationFactory = notificationFactory;
57     }
58
59     public void setNotificationPublisher(NotificationPublisher notificationPublisher) {
60         this.notificationPublisher = notificationPublisher;
61     }
62
63     public void afterPropertiesSet() throws Exception JavaDoc {
64         if (notificationPublisher == null) {
65             Assert.notNull(notificationFactory, "A NotificationFactory is required.");
66             Assert.notNull(notificationDao, "A NotificationDao is required.");
67             notificationPublisher = new NotificationPublisher(
68                     notificationFactory, notificationDao);
69             
70             notificationPublisher.setMessageSource(messageSource);
71         }
72     }
73     
74     public Object JavaDoc postProcessBeforeInitialization(Object JavaDoc bean, String JavaDoc beanName) {
75         if (bean instanceof NotificationPublisherAware) {
76             NotificationPublisherAware npa = (NotificationPublisherAware) bean;
77             npa.setNotificationPublisher(notificationPublisher);
78         }
79         return bean;
80     }
81
82     public Object JavaDoc postProcessAfterInitialization(Object JavaDoc bean, String JavaDoc beanName) {
83         return bean;
84     }
85 }
86
Popular Tags