KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log > output > AbstractWrappingTarget


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.log.output;
18
19 import org.apache.log.LogTarget;
20 import org.apache.log.util.Closeable;
21
22 /**
23  * Abstract base class for targets that wrap other targets. The class
24  * provides functionality for optionally closing a wrapped target that
25  * implements <code>org.apache.log.util.Closeable</code>.
26  *
27  * @see org.apache.log.util.Closeable
28  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
29  */

30 public abstract class AbstractWrappingTarget
31     extends AbstractTarget
32 {
33     private final boolean m_closeWrapped;
34     private final LogTarget m_wrappedLogTarget;
35
36     /**
37      * Creation of a new wrapping log target.
38      *
39      * @param logTarget the underlying target
40      * @param closeWrappedTarget boolean flag indicating whether the wrapped log target
41      * should be closed when this target is closed. Note: This flag has no
42      * effect unless the underlying target implements <code>org.apache.log.util.Closeable</code>.
43      * @see org.apache.log.util.Closeable
44      */

45     public AbstractWrappingTarget( final LogTarget logTarget, final boolean closeWrappedTarget )
46     {
47         m_wrappedLogTarget = logTarget;
48         m_closeWrapped = closeWrappedTarget;
49     }
50
51     /**
52      * Creation of a new wrapping log target. The underlying log target will
53      * <b>not</b> be closed when this target is closed.
54      *
55      * @param logTarget the underlying target
56      */

57     public AbstractWrappingTarget( final LogTarget logTarget )
58     {
59         this( logTarget, false );
60     }
61
62     public void close()
63     {
64         super.close();
65
66         if( m_closeWrapped && m_wrappedLogTarget instanceof Closeable )
67         {
68             ( (Closeable)m_wrappedLogTarget ).close();
69         }
70     }
71     
72     /**
73      * Return the target for subclasses
74      */

75     protected final LogTarget getLogTarget()
76     {
77         return m_wrappedLogTarget;
78     }
79 }
Popular Tags