KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > wsm > axis > ControlProvider


1 /*
2  * ControlProvider.java
3  *
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *
20  * Original author: Jonathan Colwell
21  */

22 package org.apache.beehive.wsm.axis;
23
24 import java.lang.reflect.Field JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26
27 import org.apache.axis.MessageContext;
28 import org.apache.axis.providers.java.RPCProvider;
29 import org.apache.beehive.controls.api.bean.Control;
30 import org.apache.beehive.controls.api.context.ControlBeanContext;
31 import org.apache.beehive.controls.api.context.ControlContainerContext;
32 import org.apache.beehive.controls.api.context.ControlThreadContext;
33
34 /**
35  * ****************************************************************************
36  *
37  * @author Jonathan Colwell
38  */

39 public class ControlProvider extends RPCProvider {
40     
41     protected Object JavaDoc makeNewServiceObject(MessageContext msgContext, String JavaDoc clsName)
42             throws Exception JavaDoc
43     {
44         Object JavaDoc obj = super.makeNewServiceObject(msgContext, clsName);
45         initializeControls(obj);
46         return obj;
47     }
48
49     private void initializeControls(Object JavaDoc obj) throws Exception JavaDoc {
50     
51         Class JavaDoc cls = obj.getClass();
52
53         // search for fields with @Control annotations
54
for (Field JavaDoc field : cls.getFields()) {
55             if (null != field.getAnnotation(Control.class)) {
56         
57                 //attempt to load using client initializer.
58
ControlContainerContext ccc = ControlThreadContext.getContext();
59                 if (null == ccc) {
60                     throw new Exception JavaDoc("no control container context found");
61                 }
62                 Class JavaDoc clientInitializer = cls.getClassLoader().loadClass(cls.getName() + "ClientInitializer");
63                 Method JavaDoc init = clientInitializer.getMethod("initialize", ControlBeanContext.class, cls);
64                 init.invoke(null, ccc, obj);
65                 break;
66             }
67         }
68     }
69 }
70
Popular Tags