KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tutorial > DefaultGizmo


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 java.io.File JavaDoc;
20
21 import org.apache.avalon.framework.logger.Logger;
22 import org.apache.avalon.framework.context.Contextualizable;
23 import org.apache.avalon.framework.context.Context;
24 import org.apache.avalon.framework.context.ContextException;
25
26 /**
27  * A component that implements the Gizmo service.
28  *
29  * @avalon.component name="gizmo" lifestyle="singleton"
30  * @avalon.service type="tutorial.Gizmo"
31  */

32 public class DefaultGizmo implements Gizmo, Contextualizable
33 {
34    //---------------------------------------------------------
35
// immutable state
36
//---------------------------------------------------------
37

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

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

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

51    public DefaultGizmo( Logger logger )
52    {
53        m_logger = logger;
54        m_logger.info( "I've been created" );
55    }
56
57    //---------------------------------------------------------
58
// Contextualizable
59
//---------------------------------------------------------
60

61    /**
62     * Contextualization of the gizmo by the container.
63     * @param context the supplied runtime context
64     * @avalon.entry key="urn:avalon:home"
65     */

66     public void contextualize( Context context ) throws ContextException
67     {
68         File JavaDoc home = (File JavaDoc) context.get( "urn:avalon:home" );
69         m_logger.info( "home: " + home );
70     }
71
72    //---------------------------------------------------------
73
// Object
74
//---------------------------------------------------------
75

76    public String JavaDoc toString()
77    {
78        return "[gizmo:" + System.identityHashCode( this ) + "]";
79    }
80 }
81
Popular Tags