KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tutorial > DemoContextualizationHandler


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.lang.reflect.Constructor JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.apache.avalon.composition.model.ContextualizationHandler;
24 import org.apache.avalon.framework.context.ContextException;
25 import org.apache.avalon.framework.context.Context;
26
27 /**
28  * Definition of an extension handler that handles the Expoitable
29  * extension stage interface.
30  *
31  * @avalon.component name="demo"
32  * @avalon.extension id="tutorial.Contextualizable"
33  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
34  */

35 public class DemoContextualizationHandler implements ContextualizationHandler
36 {
37     //=======================================================================
38
// Extension
39
//=======================================================================
40

41     /**
42      * Handle the contextualization stage of a component lifecycle.
43      * @param object the object to contextualize
44      * @param context the component context argument
45      * @exception ContextException if a contextualization error occurs
46      */

47     public void contextualize(
48       Object JavaDoc object, Context context )
49       throws ContextException
50     {
51
52         //
53
// based on the supplied context directives, the container supplied
54
// map of base context entries and a classloader, build and apply
55
// a context object to the supplied target object
56
//
57

58         if( object instanceof Contextualizable )
59         {
60             StandardContext standard = new StandardContextImp( context );
61             ( (Contextualizable)object ).contextualize( standard );
62         }
63         else
64         {
65             final String JavaDoc error =
66               "Target object does not implement the "
67               + Contextualizable.class.getName() + " interface.";
68             throw new ContextException( error );
69         }
70     }
71 }
72
Popular Tags