KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tutorial > DefaultWidget


1 /*
2  * Copyright 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
17 package tutorial;
18
19 import org.apache.avalon.framework.logger.Logger;
20 import org.apache.avalon.framework.configuration.Configurable;
21 import org.apache.avalon.framework.configuration.Configuration;
22 import org.apache.avalon.framework.configuration.ConfigurationException;
23 import org.apache.avalon.framework.activity.Disposable;
24
25 /**
26  * A component that implements the Widget service.
27  *
28  * @avalon.component name="widget" lifestyle="singleton"
29  * @avalon.service type="tutorial.Widget"
30  */

31 public class DefaultWidget implements Widget, Configurable, Disposable
32 {
33    //---------------------------------------------------------
34
// immutable state
35
//---------------------------------------------------------
36

37   /**
38    * The logging channel supplied by the container.
39    */

40    private final Logger m_logger;
41
42    //---------------------------------------------------------
43
// constructor
44
//---------------------------------------------------------
45

46   /**
47    * Creation of a new hello facility.
48    * @param logger a logging channel
49    */

50    public DefaultWidget( Logger logger )
51    {
52        m_logger = logger;
53        m_logger.info( "hello" );
54    }
55
56    //---------------------------------------------------------
57
// Configurable
58
//---------------------------------------------------------
59

60    /**
61     * Configuration of the gizmo by the container.
62     * @param config the supplied configuration
63     */

64     public void configure( Configuration config ) throws ConfigurationException
65     {
66         final String JavaDoc message = config.getChild( "message" ).getValue( null );
67         if( null != message )
68         {
69             m_logger.info( message );
70         }
71     }
72
73    //---------------------------------------------------------
74
// Disposable
75
//---------------------------------------------------------
76

77   /**
78    * End-of-life processing initiated by the container.
79    */

80    public void dispose()
81    {
82         m_logger.info( "time to die" );
83    }
84
85    //---------------------------------------------------------
86
// Object
87
//---------------------------------------------------------
88

89    public String JavaDoc toString()
90    {
91        return "[widget:" + System.identityHashCode( this ) + "]";
92    }
93 }
94
95
Popular Tags