Package org.apache.beehive.wsm.axis

Source Code of org.apache.beehive.wsm.axis.ControlProvider

/*
* ControlProvider.java
*
* Copyright 2001-2004 The Apache Software Foundation.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* Original author: Jonathan Colwell
*/
package org.apache.beehive.wsm.axis;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import org.apache.axis.MessageContext;
import org.apache.axis.providers.java.RPCProvider;
import org.apache.beehive.controls.api.bean.Control;
import org.apache.beehive.controls.api.context.ControlBeanContext;
import org.apache.beehive.controls.api.context.ControlContainerContext;
import org.apache.beehive.controls.api.context.ControlThreadContext;

/**
* ****************************************************************************
*
* @author Jonathan Colwell
*/
public class ControlProvider extends RPCProvider {
   
    protected Object makeNewServiceObject(MessageContext msgContext, String clsName)
            throws Exception
    {
        Object obj = super.makeNewServiceObject(msgContext, clsName);
        initializeControls(obj);
        return obj;
    }

    private void initializeControls(Object obj) throws Exception {
   
        Class cls = obj.getClass();

        // search for fields with @Control annotations
        for (Field field : cls.getFields()) {
            if (null != field.getAnnotation(Control.class)) {
       
                //attempt to load using client initializer.
                ControlContainerContext ccc = ControlThreadContext.getContext();
                if (null == ccc) {
                    throw new Exception("no control container context found");
                }
                Class clientInitializer = cls.getClassLoader().loadClass(cls.getName() + "ClientInitializer");
                Method init = clientInitializer.getMethod("initialize", ControlBeanContext.class, cls);
                init.invoke(null, ccc, obj);
                break;
            }
        }
    }
}
TOP

Related Classes of org.apache.beehive.wsm.axis.ControlProvider

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.