KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portlet > PortletOutputLogTarget


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

16 package org.apache.cocoon.portlet;
17
18 import org.apache.log.format.Formatter;
19 import org.apache.log.output.AbstractOutputTarget;
20
21 import javax.portlet.PortletContext;
22
23 /**
24  * Log output target for JSR-168 Portlet context
25  *
26  * @author <a HREF="mailto:alex.rudnev@dc.gov">Alex Rudnev</a>
27  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
28  * @version CVS $Id: PortletOutputLogTarget.java 30932 2004-07-29 17:35:38Z vgritsenko $
29  */

30 public class PortletOutputLogTarget extends AbstractOutputTarget {
31
32     private PortletContext context;
33
34     public PortletOutputLogTarget(PortletContext context) {
35         this.context = context;
36         open();
37     }
38
39     public PortletOutputLogTarget(PortletContext context, Formatter formatter) {
40         super(formatter);
41         this.context = context;
42         open();
43     }
44
45     protected void write(String JavaDoc message) {
46         PortletContext context = this.context;
47         if (context != null) {
48             synchronized (context) {
49                 context.log(message);
50             }
51         }
52     }
53
54     public synchronized void close() {
55         super.close();
56         this.context = null;
57     }
58 }
59
Popular Tags