KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > exception > CatchPushExceptionImpl


1 /**
2  * Dream
3  * Copyright (C) 2003-2004 INRIA Rhone-Alpes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: dream@objectweb.org
20  *
21  * Initial developer(s): Matthieu Leclercq
22  * Contributor(s):
23  */

24
25 package org.objectweb.dream.exception;
26
27 import java.util.HashMap JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import org.objectweb.dream.AbstractComponent;
31 import org.objectweb.dream.Push;
32 import org.objectweb.dream.PushException;
33 import org.objectweb.dream.message.Message;
34 import org.objectweb.fractal.api.NoSuchInterfaceException;
35 import org.objectweb.fractal.api.control.IllegalBindingException;
36 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
37 import org.objectweb.util.monolog.api.BasicLevel;
38
39 /**
40  * Try to push incomming messages on the output (<code>"out-push"</code>
41  * client interface). If a {@link PushException }is catched, the exception is
42  * added to the context, and the message is pushed on the
43  * <code>"exception-push"</code> client interface.
44  */

45 public class CatchPushExceptionImpl extends AbstractComponent implements Push
46 {
47   // ---------------------------------------------------------------------------
48
// Client interfaces
49
// ---------------------------------------------------------------------------
50
/**
51    * The default name of the out push interface used if a {@link PushException}
52    * has been catched while a message was pushed on the normal out push.
53    */

54   public static final String JavaDoc EXCEPTION_PUSH_ITF_NAME = "exception-push";
55   protected Push outPushItf;
56   protected Push exceptionPushItf;
57
58   // ---------------------------------------------------------------------------
59
// Implementation of the Push interface
60
// ---------------------------------------------------------------------------
61

62   /**
63    * @see Push#push(Message, Map)
64    */

65   public void push(Message message, Map JavaDoc context) throws PushException
66   {
67     try
68     {
69       outPushItf.push(message, context);
70     }
71     catch (PushException e)
72     {
73       logger.log(BasicLevel.INFO,
74           "Catched Push Exception push message on exception-push. ", e);
75       if (context == null)
76       {
77         context = new HashMap JavaDoc();
78       }
79       context.put("exception", e);
80       exceptionPushItf.push(message, context);
81     }
82   }
83
84   // ---------------------------------------------------------------------------
85
// Implementation of the BindingController interface
86
// ---------------------------------------------------------------------------
87

88   /**
89    * @see org.objectweb.fractal.api.control.BindingController#listFc()
90    */

91   public String JavaDoc[] listFc()
92   {
93     return new String JavaDoc[]{Push.OUT_PUSH_ITF_NAME, EXCEPTION_PUSH_ITF_NAME};
94   }
95
96   /**
97    * @see org.objectweb.fractal.api.control.BindingController#bindFc(String,
98    * Object)
99    */

100   public void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
101       throws NoSuchInterfaceException, IllegalBindingException,
102       IllegalLifeCycleException
103   {
104     super.bindFc(clientItfName, serverItf);
105     if (clientItfName.equals(Push.OUT_PUSH_ITF_NAME))
106     {
107       outPushItf = (Push) serverItf;
108     }
109     else if (clientItfName.equals(EXCEPTION_PUSH_ITF_NAME))
110     {
111       exceptionPushItf = (Push) serverItf;
112     }
113   }
114 }
Popular Tags