KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tutorial > DemoContextProvider


1 /*
2  * Copyright 2004 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
18 package tutorial;
19
20 import java.util.Map JavaDoc;
21 import java.io.File JavaDoc;
22
23 import org.apache.avalon.framework.context.Context;
24 import org.apache.avalon.framework.context.DefaultContext;
25 import org.apache.avalon.framework.context.ContextException;
26
27
28 /**
29  * A demonstration class that that we will instantiate via
30  * context directives within the component declaration.
31  */

32 public class DemoContextProvider extends DefaultContext implements DemoContext
33 {
34
35    /**
36     * A custom context type implementation must provide
37     * the following constructor.
38     * @param entries a map of context entries
39     */

40     public DemoContextProvider( Context context )
41     {
42         super( context );
43     }
44  
45    /**
46     * Return the component name.
47     * @return the component name
48     */

49     public String JavaDoc getName()
50     {
51         try
52         {
53             return (String JavaDoc) super.get( "urn:avalon:name" );
54         }
55         catch( ContextException ce )
56         {
57             // should not happen
58
throw new RuntimeException JavaDoc( ce.toString() );
59         }
60     }
61
62    /**
63     * Return the name of the partition assigned to the component.
64     * @return the partition name
65     */

66     public String JavaDoc getPartition()
67     {
68         try
69         {
70             return (String JavaDoc) super.get( "urn:avalon:partition" );
71         }
72         catch( ContextException ce )
73         {
74             // should not happen
75
throw new RuntimeException JavaDoc( ce.toString() );
76         }
77     }
78
79    /**
80     * Return the home directory.
81     * @return the home directory
82     */

83     public File JavaDoc getHomeDirectory()
84     {
85         try
86         {
87             return (File JavaDoc) super.get( "urn:avalon:home" );
88         }
89         catch( ContextException ce )
90         {
91             // should not happen
92
throw new RuntimeException JavaDoc( ce.toString() );
93         }
94     }
95
96
97    /**
98     * Return the temporary working directory.
99     * @return the temp directory
100     */

101     public File JavaDoc getWorkingDirectory()
102     {
103         try
104         {
105             return (File JavaDoc) super.get( "urn:avalon:temp" );
106         }
107         catch( ContextException ce )
108         {
109             // should not happen
110
throw new RuntimeException JavaDoc( ce.toString() );
111         }
112     }
113 }
114
Popular Tags