You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2003/02/06 22:15:49 UTC
cvs commit: avalon-logkit/src/test/org/apache/log/test LoggerListenerTestCase.java RecordingLoggerListener.java
bloritsch 2003/02/06 13:15:49
Modified: src/java/org/apache/log Hierarchy.java
src/test/org/apache/log/test LoggerListenerTestCase.java
RecordingLoggerListener.java
Log:
complete listener code
Revision Changes Path
1.24 +35 -1 avalon-logkit/src/java/org/apache/log/Hierarchy.java
Index: Hierarchy.java
===================================================================
RCS file: /home/cvs/avalon-logkit/src/java/org/apache/log/Hierarchy.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- Hierarchy.java 6 Feb 2003 16:39:58 -0000 1.23
+++ Hierarchy.java 6 Feb 2003 21:15:49 -0000 1.24
@@ -70,7 +70,7 @@
{
///Format of default formatter
private static final String FORMAT =
- "%7.7{priority} %23.23{time:yyyy-MM-dd' 'HH:mm:ss.SSS} [%8.8{category}] (%{context}): "
+ "%7.7{priority} %23.23{time:yyyy-MM-dd' 'HH:mm:ss.SSS} [%8.8{category}] (%{context}): "
+ "%{message}\n%{throwable}";
///The instance of default hierarchy
@@ -205,6 +205,8 @@
*/
public synchronized void addLoggerListener( final LoggerListener loggerListener )
{
+ if ( null == loggerListener ) throw new NullPointerException( "loggerListener" );
+
if ( null == m_loggerListener )
{
m_loggerListener = loggerListener;
@@ -212,6 +214,38 @@
else
{
throw new UnsupportedOperationException( "LoggerListener already set on a unicast event notifier" );
+ }
+ }
+
+ public synchronized LoggerListener[] getLoggerListeners()
+ {
+ LoggerListener[] listeners = null;
+
+ if ( null == m_loggerListener )
+ {
+ listeners = new LoggerListener[] {};
+ }
+ else
+ {
+ listeners = new LoggerListener[] {m_loggerListener};
+ }
+
+ return listeners;
+ }
+
+ /**
+ * Remove the LoggerListener associated with hierarchy. Perform this
+ * step before adding a new one if you want to change it.
+ *
+ * @param loggerListener the LoggerListener
+ */
+ public synchronized void removeLoggerListener( final LoggerListener loggerListener )
+ {
+ if ( null == loggerListener ) throw new NullPointerException( "loggerListener" );
+
+ if ( null != m_loggerListener && m_loggerListener.equals( loggerListener ) );
+ {
+ m_loggerListener = null;
}
}
1.3 +70 -5 avalon-logkit/src/test/org/apache/log/test/LoggerListenerTestCase.java
Index: LoggerListenerTestCase.java
===================================================================
RCS file: /home/cvs/avalon-logkit/src/test/org/apache/log/test/LoggerListenerTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LoggerListenerTestCase.java 6 Feb 2003 16:39:58 -0000 1.2
+++ LoggerListenerTestCase.java 6 Feb 2003 21:15:49 -0000 1.3
@@ -1,9 +1,56 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
+/* ====================================================================
+ * The Apache Software License, Version 1.1
*
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE file.
+ * Copyright (c) 1997-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software
+ * itself, if and wherever such third-party acknowledgments
+ * normally appear.
+ *
+ * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation"
+ * must not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
*/
package org.apache.log.test;
@@ -40,6 +87,24 @@
{
// It passed, yay!
}
+ }
+
+ public void testRemoveLoggerListener()
+ {
+ final Hierarchy hierarchy = new Hierarchy();
+ final RecordingLoggerListener listener = new RecordingLoggerListener();
+
+ hierarchy.addLoggerListener( listener );
+
+ assertEquals( 1, hierarchy.getLoggerListeners().length );
+
+ hierarchy.removeLoggerListener( listener );
+
+ assertEquals( 0, hierarchy.getLoggerListeners().length );
+
+ hierarchy.addLoggerListener( listener );
+
+ assertEquals( 1, hierarchy.getLoggerListeners().length );
}
public void testPriorityInheritance()
1.2 +53 -6 avalon-logkit/src/test/org/apache/log/test/RecordingLoggerListener.java
Index: RecordingLoggerListener.java
===================================================================
RCS file: /home/cvs/avalon-logkit/src/test/org/apache/log/test/RecordingLoggerListener.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RecordingLoggerListener.java 3 Feb 2003 19:39:39 -0000 1.1
+++ RecordingLoggerListener.java 6 Feb 2003 21:15:49 -0000 1.2
@@ -1,9 +1,56 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
+/* ====================================================================
+ * The Apache Software License, Version 1.1
*
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
+ * Copyright (c) 1997-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software
+ * itself, if and wherever such third-party acknowledgments
+ * normally appear.
+ *
+ * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation"
+ * must not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
*/
package org.apache.log.test;
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-cvs-help@jakarta.apache.org
Re: cvs commit: avalon-logkit/src/test/org/apache/log/test LoggerListenerTestCase.java RecordingLoggerListener.java
Posted by Peter Donald <pe...@realityforge.org>.
On Fri, 7 Feb 2003 08:15, bloritsch@apache.org wrote:
> + public synchronized LoggerListener[] getLoggerListeners()
> + {
> + LoggerListener[] listeners = null;
> +
> + if ( null == m_loggerListener )
> + {
> + listeners = new LoggerListener[] {};
> + }
> + else
> + {
> + listeners = new LoggerListener[] {m_loggerListener};
> + }
> +
> + return listeners;
> + }
We dont want users being able to access thess objects.
On Fri, 7 Feb 2003 08:15, bloritsch@apache.org wrote:
+ public synchronized void removeLoggerListener( final LoggerListener loggerListener )
+ {
+ if ( null == loggerListener ) throw new NullPointerException("loggerListener" );
+
+ if ( null != m_loggerListener && m_loggerListener.equals( loggerListener ) );
And nor do we want to do deep compares as a dodgy loggerlistener could throw an exception in
equals. It would be better to replace this with an identity equality test.
--
Cheers,
Peter Donald
*------------------------------------------------------*
| An expert is someone who knows everything about the |
| topic except for its place in the world. |
*------------------------------------------------------*
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org