Package org.apache.muse.core.platform.osgi.axis2

Source Code of org.apache.muse.core.platform.osgi.axis2.Activator

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you 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.
*
*/

package org.apache.muse.core.platform.osgi.axis2;

import java.util.Hashtable;

import org.apache.muse.core.platform.osgi.ResourceManagementProvider;
import org.apache.muse.core.platform.osgi.axis2.internal.ResourceManagementAdminServiceImpl;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.apache.muse.osgi.soa.core.SOAPProvider;
import org.apache.muse.util.xml.XmlUtils;

/**
*
* Activator is ...
*
* @author Joel Hawkins (joelh)
*
*/

public class Activator implements BundleActivator, ServiceListener {

  private ResourceManagementProvider adminService;

  private BundleContext context;

  private ServiceReference soapProviderReference = null;

  private boolean enabled = false;

  private static final String SOAP_SERVICE_FILTER = "(objectclass=org.apache.muse.osgi.soa.core.SOAPProvider)";

  public void start(BundleContext context) throws Exception {
    this.context = context;
    try {
     
      //Intialize XMLUtils with this bundle's services.
      ClassLoader prev = Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader(Activator.class.getClassLoader());
      XmlUtils.createDocument();
      Thread.currentThread().setContextClassLoader(prev);
     
      if ((soapProviderReference = context
          .getServiceReference("org.apache.muse.osgi.soa.core.SOAPProvider")) != null) {
        SOAPProvider soapProvider = (SOAPProvider)context.getService(soapProviderReference);
        ResourceManagementAdminServiceImpl adminImpl = new ResourceManagementAdminServiceImpl(context, soapProvider);
        Axis2Environment.setBundleContext(context);
        adminService = adminImpl;
        context.registerService(
            "org.apache.muse.core.platform.osgi.ResourceManagementProvider",
            adminService, new Hashtable());
        enabled = true;
      }
      context.addServiceListener(this, SOAP_SERVICE_FILTER);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BundleException("Failed to start server");
    }
  }

  public void stop(BundleContext context) throws Exception {
    if(soapProviderReference != null){
      context.ungetService(soapProviderReference);
      soapProviderReference = null;
    }
  }

  public void serviceChanged(ServiceEvent event) {
    ServiceReference ref = event.getServiceReference();
    switch (event.getType()) {
    case ServiceEvent.REGISTERED:
      if (!enabled) {
        try {
          if ((soapProviderReference = context
              .getServiceReference("org.apache.muse.osgi.soa.core.SOAPProvider")) != null) {
            SOAPProvider soapProvider = (SOAPProvider)context.getService(soapProviderReference);
            ResourceManagementAdminServiceImpl adminImpl = new ResourceManagementAdminServiceImpl(context, soapProvider);
            Axis2Environment.setBundleContext(context);
            adminService = adminImpl;
            context.registerService(
                    "org.apache.muse.core.platform.osgi.ResourceManagementProvider",
                    adminService, new Hashtable());
            enabled = true;
          }
        } catch (Throwable e) {
          e.printStackTrace();
        }
      }
      break;
    case ServiceEvent.MODIFIED:
      break;
    case ServiceEvent.UNREGISTERING:
      if (ref == soapProviderReference) {
        enabled = false;
      }
      break;
    }
  }
}
TOP

Related Classes of org.apache.muse.core.platform.osgi.axis2.Activator

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.