In this step the Customer bundle is updated to import an implementation of
the VendorService using an LDAP filter.
org.eclipse.soda.sat.tutorial.customer project.
package org.eclipse.soda.sat.tutorial.customer.bundle;
import org.eclipse.soda.sat.core.framework.BaseBundleActivator;
import org.eclipse.soda.sat.core.util.LogUtility;
import org.eclipse.soda.sat.tutorial.customer.Customer;
import org.eclipse.soda.sat.tutorial.vendor.service.VendorService;
public class Activator extends BaseBundleActivator {
private Customer customer;
protected void activate() {
LogUtility.logInfo("The Customer bundle has been activated"); //$NON-NLS-1$
VendorService vendor = getVendorService();
Customer customer = getCustomer();
customer.setVendor(vendor);
customer.eat();
}
protected void deactivate() {
Customer customer = getCustomer();
customer.setVendor(null);
LogUtility.logInfo("The Customer bundle has been deactivated"); //$NON-NLS-1$
}
private Customer getCustomer() {
return customer;
}
protected String[] getImportedServiceNames() {
return new String[] {
VendorService.SERVICE_NAME
};
}
private VendorService getVendorService() {
return (VendorService) getImportedService(VendorService.SERVICE_NAME);
}
private void setCustomer(Customer customer) {
this.customer = customer;
}
private String getVendorFilter() {
StringBuffer buffer = new StringBuffer(50);
buffer.append('(');
buffer.append(VendorService.SPICINESS_PROPERTY);
buffer.append("<="); //$NON-NLS-1$
buffer.append(8);
buffer.append(')');
String filter = buffer.toString();
return filter;
}
protected void start() throws Exception {
LogUtility.logInfo("The Customer bundle has been started"); //$NON-NLS-1$
Customer customer = new Customer();
setCustomer(customer);
String filter = getVendorFilter();
addImportedServiceFilter(VendorService.SERVICE_NAME, filter);
}
protected void stop() throws Exception {
setCustomer(null);
LogUtility.logInfo("The Customer bundle has been stopped"); //$NON-NLS-1$
}
}
start() methods has been updated to
create an LDAP filter that is passed to the
addImportedServiceFilter(String, String) method. This
causes the imported VendorService to have the LDAP filter
"(spiciness<=8)", which is created by the
getVendorFilter() method.
activate() method will only be called
when the Customer bundle has acquired an imported
VendorService that has a registered
VendorService.SPICINESS_PROPERTY that is less than or
equal to 8.
VendorService.SPICINESS_PROPERTY is greater than
8 then the deactivate() method will be called.
addImportedServiceFilter(String, String) method, or the
removeImportedServiceFilter(String) method. Changes to
the imported service filters will be immediately reflected in the
bundles' acquired imported services.
Copyright © 2001, 2007 IBM Corporation and others. All Rights Reserved.