| /** |
| * Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Florian Pirchner - Initial implementation |
| */ |
| |
| |
| package org.eclipse.osbp.runtime.web.vaadin.components.fields; |
| |
| import java.util.ArrayList; |
| import java.util.Collections; |
| import java.util.List; |
| |
| import org.eclipse.osbp.runtime.web.vaadin.common.data.IBeanSearchService; |
| import org.eclipse.osbp.runtime.web.vaadin.common.data.IBeanSearchServiceFactory; |
| import org.eclipse.osbp.runtime.web.vaadin.common.data.IBeanSearchServiceFactoryDelegate; |
| import org.eclipse.osbp.runtime.web.vaadin.common.data.StatefulInMemoryBeanSearchService; |
| import org.osgi.service.component.annotations.Component; |
| import org.osgi.service.component.annotations.Reference; |
| import org.osgi.service.component.annotations.ReferenceCardinality; |
| import org.osgi.service.component.annotations.ReferencePolicy; |
| |
| @Component(immediate = true, enabled = true) |
| public class BeanSearchServiceFactory implements IBeanSearchServiceFactory { |
| |
| private List<IBeanSearchServiceFactoryDelegate> delegates = Collections |
| .synchronizedList(new ArrayList<IBeanSearchServiceFactoryDelegate>()); |
| |
| @Override |
| public <BEAN> IBeanSearchService<BEAN> createService(Class<BEAN> bean) { |
| return createService(bean, false); |
| } |
| |
| @Override |
| public <BEAN> IBeanSearchService<BEAN> createService(Class<BEAN> bean, boolean ignoreHistorizedFilter) { |
| |
| synchronized (delegates) { |
| for (IBeanSearchServiceFactoryDelegate delegate : delegates) { |
| IBeanSearchService<BEAN> service = delegate.createService(bean, ignoreHistorizedFilter); |
| if (service != null) { |
| return service; |
| } |
| } |
| } |
| |
| return new StatefulInMemoryBeanSearchService<BEAN>(bean); |
| } |
| |
| @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, unbind = "removeDelegate") |
| protected void addDelegate(IBeanSearchServiceFactoryDelegate delegate) { |
| if (!delegates.contains(delegate)) { |
| delegates.add(delegate); |
| } |
| } |
| |
| protected void removeDelegate(IBeanSearchServiceFactoryDelegate delegate) { |
| delegates.remove(delegate); |
| } |
| |
| |
| } |