001: /*
002: * Danet GmbH
003: * Beratung und Software-Entwicklung
004: * Geschäftstelle AN
005: *
006: * $Id: EJBAppender.java,v 1.1.1.1 2003/06/30 20:05:12 drmlipp Exp $
007: *
008: * $Log: EJBAppender.java,v $
009: * Revision 1.1.1.1 2003/06/30 20:05:12 drmlipp
010: * Initial import
011: *
012: * Revision 1.4 2002/02/28 12:52:34 lipp
013: * Javadoc fix.
014: *
015: * Revision 1.3 2002/01/11 09:31:31 robert
016: * removes println
017: *
018: * Revision 1.2 2002/01/09 09:59:13 robert
019: * javadoc
020: *
021: * Revision 1.1 2002/01/09 09:39:58 robert
022: * new Appender
023: *
024: *
025: */
026:
027: package de.danet.an.util.log4j;
028:
029: import org.apache.log4j.AppenderSkeleton;
030: import org.apache.log4j.spi.LoggingEvent;
031:
032: import java.rmi.RemoteException;
033: import javax.ejb.RemoveException;
034: import javax.ejb.CreateException;
035: import javax.naming.NamingException;
036:
037: import de.danet.an.util.EJBUtil;
038:
039: /**
040: * This class implements the <code>Appender</code> interface.
041: * The EJBAppender forwards the log message to the <code>EJBSink</code> bean.
042: */
043: public class EJBAppender extends AppenderSkeleton {
044:
045: /**
046: * The name of the logging session bean.
047: */
048: private String beanName;
049:
050: /**
051: * The remote interface of the session bean.
052: */
053: private EJBSink ejbSink;
054:
055: /**
056: * Constructor for the EJBAppender object.
057: */
058: public EJBAppender() {
059: super ();
060: }
061:
062: /**
063: * Sets the JNDI name of the session bean.
064: *
065: *@param beanName the JNDI name of the session bean.
066: */
067: public void setEjbJNDIName(String beanName) {
068: this .beanName = beanName;
069: }
070:
071: /**
072: * Forwards the message to the EJBSink bean.
073: *
074: * @param event the event including the message to be logged.
075: */
076: public void append(LoggingEvent event) {
077: try {
078: ejbSink.append(event);
079: } catch (Exception e) {
080: try {
081: // create the EJBSink session bean
082: ejbSink = ((EJBSinkHome) EJBUtil.lookupEJBHome(
083: EJBSinkHome.class, beanName)).create();
084: ejbSink.append(event);
085: } catch (NamingException nex) {
086: nex.printStackTrace();
087: } catch (CreateException onf) {
088: onf.printStackTrace();
089: } catch (RemoteException rex) {
090: rex.printStackTrace();
091: }
092: }
093: }
094:
095: /**
096: * Internal method. Close the database connection and flush the buffer.
097: */
098: public void close() {
099: // destoy the session bean...
100: try {
101: ejbSink.remove();
102: } catch (RemoteException rex) {
103: rex.printStackTrace();
104: } catch (RemoveException rx) {
105: rx.printStackTrace();
106: }
107: }
108:
109: /**
110: * Internal method. Returns true, you may define your own layout...
111: *
112: *@return in this version allways <code>true</code>
113: */
114: public boolean requiresLayout() {
115: return true;
116: }
117: }
|