KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > MessageSendMacro


1 /*
2  * This file is part of "SnipSnap Radeox Rendering Engine".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://radeox.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  * --LICENSE NOTICE--
24  */

25
26 package examples;
27
28 import org.snipsnap.render.context.SnipRenderContext;
29 import org.snipsnap.render.macro.SnipMacro;
30 import org.snipsnap.render.macro.parameter.SnipMacroParameter;
31 import org.snipsnap.snip.Snip;
32 import org.snipsnap.notification.Message;
33 import org.snipsnap.notification.MessageService;
34 import org.picocontainer.PicoContainer;
35
36 import java.io.IOException JavaDoc;
37 import java.io.Writer JavaDoc;
38
39 /**
40  * Example which shows howto get some component from the backend
41  * and sending a message.
42  *
43  * @author Stephan J. Schmidt
44  * @version $Id: MessageSendMacro.java 1606 2004-05-17 10:56:18Z leo $
45  */

46
47 // cut:start-1
48
public class MessageSendMacro extends SnipMacro {
49
50   public void execute(Writer JavaDoc writer, SnipMacroParameter params)
51     throws IllegalArgumentException JavaDoc, IOException JavaDoc {
52
53     SnipRenderContext context = params.getSnipRenderContext();
54     Snip snip = (Snip)
55         context.getAttribute(SnipRenderContext.SNIP);
56     PicoContainer container = (PicoContainer)
57       context.getAttribute(SnipRenderContext.CONTAINER);
58
59     MessageService service = (MessageService)
60       container.getComponentInstance(MessageService.class);
61     Message message = new Message("SNIP_VIEWED",
62                                   snip.getName());
63     service.send(message);
64   }
65
66
67   public String JavaDoc getName() {
68     return "send-message";
69   }
70 }
71 // cut:end-1
72
Popular Tags