/*=============================================================================*
* Copyright 2006 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.
*=============================================================================*/
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;
/**
*
* 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 {
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;
}
}
}