*/
Object createProxy() {
if (log.isDebugEnabled())
log.debug("Creating a multi-value/collection proxy");
OsgiServiceCollection collection;
Collection delegate;
BundleContext bundleContext = getBundleContext();
ClassLoader classLoader = getAopClassLoader();
Filter filter = getUnifiedFilter();
if (CollectionType.LIST.equals(collectionType)) {
collection = (comparator == null ? new OsgiServiceList(filter, bundleContext, classLoader, proxyCreator)
: new OsgiServiceSortedList(filter, bundleContext, classLoader, comparator, proxyCreator));
delegate = Collections.unmodifiableList((List) collection);
}
else if (CollectionType.SET.equals(collectionType)) {
collection = (comparator == null ? new OsgiServiceSet(filter, bundleContext, classLoader, proxyCreator)
: new OsgiServiceSortedSet(filter, bundleContext, classLoader, comparator, proxyCreator));
delegate = Collections.unmodifiableSet((Set) collection);
}
else if (CollectionType.SORTED_LIST.equals(collectionType)) {
collection = new OsgiServiceSortedList(filter, bundleContext, classLoader, comparator, proxyCreator);
delegate = Collections.unmodifiableList((List) collection);
}
else if (CollectionType.SORTED_SET.equals(collectionType)) {
collection = new OsgiServiceSortedSet(filter, bundleContext, classLoader, comparator, proxyCreator);
delegate = Collections.unmodifiableSortedSet((SortedSet) collection);
}
else {
throw new IllegalArgumentException("Unknown collection type:" + collectionType);
}
collection.setRequiredAtStartup(getCardinality().isMandatory());
collection.setListeners(getListeners());
collection.setStateListeners(stateListeners);
collection.setServiceImporter(this);
collection.setServiceImporterName(getBeanName());
collection.afterPropertiesSet();
proxy = delegate;
exposedProxy = collection;
proxyDestructionCallback = new DisposableBeanRunnableAdapter(collection);