KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tutorial > StandardContextImp


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.io.File JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.apache.avalon.framework.context.ContextException;
24 import org.apache.avalon.framework.context.DefaultContext;
25 import org.apache.avalon.framework.context.Context;
26
27 /**
28  * This is example of a custom context class. It is used in the demonsteation
29  * of a context management fraework to show how a context class can be
30  * supplied to a component declaring a context interface criteria.
31  *
32  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
33  */

34 public class StandardContextImp extends DefaultContext implements StandardContext
35 {
36
37     //-----------------------------------------------------------------
38
// constructor
39
//-----------------------------------------------------------------
40

41     /**
42      * Creation of a new custom context instance.
43      * @param map the context name/value map
44      * @param parent a possibly parent context
45      */

46     public StandardContextImp( Context context ) throws ContextException
47     {
48         super( context );
49     }
50
51     //-----------------------------------------------------------------
52
// StandardContext
53
//-----------------------------------------------------------------
54

55     /**
56      * Return the name assigned to the component
57      * @return the name
58      */

59     public String JavaDoc getName()
60     {
61         try
62         {
63             return (String JavaDoc)super.get( StandardContext.NAME_KEY );
64         }
65         catch( Throwable JavaDoc e )
66         {
67             throw new IllegalStateException JavaDoc( StandardContext.NAME_KEY );
68         }
69     }
70
71     /**
72      * Return the partition name assigned to the component
73      * @return the partition name
74      * @exception IllegalStateException if the partition name is undefined
75      */

76     public String JavaDoc getPartitionName()
77     {
78         try
79         {
80             return (String JavaDoc)super.get( StandardContext.PARTITION_KEY );
81         }
82         catch( Throwable JavaDoc e )
83         {
84             throw new IllegalStateException JavaDoc( StandardContext.PARTITION_KEY );
85         }
86     }
87
88     /**
89      * Returns the home directory for this component.
90      * @return the home directory
91      */

92     public File JavaDoc getHomeDirectory()
93     {
94         try
95         {
96             return (File JavaDoc)super.get( StandardContext.HOME_KEY );
97         }
98         catch( Throwable JavaDoc e )
99         {
100             throw new IllegalStateException JavaDoc( StandardContext.HOME_KEY );
101         }
102     }
103
104     /**
105      * @return the working directory
106      */

107     public File JavaDoc getWorkingDirectory()
108     {
109         try
110         {
111             return (File JavaDoc)super.get( StandardContext.WORKING_KEY );
112         }
113         catch( Throwable JavaDoc e )
114         {
115             throw new IllegalStateException JavaDoc( StandardContext.WORKING_KEY );
116         }
117     }
118 }
119
Popular Tags