Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: de/danet/an/util/log4j/EJBAppender.java


1   /*
2    * Danet GmbH
3    * Beratung und Software-Entwicklung
4    * Geschäftstelle AN
5    *
6    * $Id: EJBAppender.java,v 1.4 2002/02/28 12:52:34 lipp Exp $
7    *
8    * $Log: EJBAppender.java,v $
9    * Revision 1.4  2002/02/28 12:52:34  lipp
10   * Javadoc fix.
11   *
12   * Revision 1.3  2002/01/11 09:31:31  robert
13   * removes println
14   *
15   * Revision 1.2  2002/01/09 09:59:13  robert
16   * javadoc
17   *
18   * Revision 1.1  2002/01/09 09:39:58  robert
19   * new Appender
20   *
21   *
22   */
23  
24  package de.danet.an.util.log4j;
25  
26  import org.apache.log4j.AppenderSkeleton;
27  import org.apache.log4j.spi.LoggingEvent;
28  
29  import java.rmi.RemoteException;
30  import javax.ejb.RemoveException;
31  import javax.ejb.CreateException;
32  import javax.naming.NamingException;
33  
34  import de.danet.an.util.EJBUtil;
35  
36  /**
37   * This class implements the <code>Appender</code> interface.
38   * The EJBAppender forwards the log message to the <code>EJBSink</code> bean.
39   */
40  public class EJBAppender extends AppenderSkeleton {
41  
42      /**
43       * The name of the logging session bean.
44       */
45      private String beanName;
46  
47      /**
48       * The remote interface of the session bean.
49       */
50      private EJBSink ejbSink;
51  
52      /**
53       * Constructor for the EJBAppender object.
54       */
55      public EJBAppender() {
56    super();
57      }
58      
59      /**
60       * Sets the JNDI name of the session bean.
61       *
62       *@param beanName the JNDI name of the session bean.
63       */
64      public void setEjbJNDIName(String beanName) {
65    this.beanName = beanName;
66      }
67  
68  
69      /**
70       * Forwards the message to the EJBSink bean.
71       *
72       * @param  event the event including the message to be logged.
73       */
74      public void append(LoggingEvent event) {
75    try {
76        ejbSink.append(event);
77    } catch (Exception e) {
78        try {
79      // create the EJBSink session bean
80      ejbSink = ((EJBSinkHome)EJBUtil.lookupEJBHome
81          (EJBSinkHome.class, beanName)).create();
82      ejbSink.append(event);
83        } catch (NamingException nex) {
84      nex.printStackTrace();
85        } catch (CreateException onf) {
86      onf.printStackTrace();
87        } catch (RemoteException rex) {
88      rex.printStackTrace();
89        }
90    }
91      }
92  
93      /**
94       *  Internal method. Close the database connection and flush the buffer.
95       */
96      public void close() {
97    // destoy the session bean...
98    try {
99        ejbSink.remove();
100   } catch (RemoteException rex) {
101       rex.printStackTrace();
102   } catch (RemoveException rx) {
103       rx.printStackTrace();
104   }
105     }
106     
107     /**
108      *  Internal method. Returns true, you may define your own layout...
109      *
110      *@return in this version allways <code>true</code>
111      */
112     public boolean requiresLayout() {
113   return true;
114     }
115 }
116