This repository has been archived by the owner on May 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 783
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract ItemBuilderFactory from ItemRegistry (#6556)
The ItemRegistry did offer `newItemBuilder` methods which depended on a list of ItemFactories. In the ItemRegisryImpl nothing else did depend on the ItemFactories. With ESH in the Felix OSGi runtime there are circumstances where a circular dependency is detected for an ItemProvider implementation which depends on the ItemRegistry for ItemBuilder access. This extracts the new `ItemBuilderFactory` service from the ItemRegistry and provides the same API. The now deprecated API from ItemRegistry provides a fallback implementation based on a single instance of CoreItemFactory. This of cause API breaking. Signed-off-by: Henning Treu <henning.treu@googlemail.com>
- Loading branch information
1 parent
c6c40b5
commit 4733152
Showing
9 changed files
with
186 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
....core/src/main/java/org/eclipse/smarthome/core/internal/items/ItemBuilderFactoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Copyright (c) 2014,2018 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.smarthome.core.internal.items; | ||
|
||
import java.util.Set; | ||
import java.util.concurrent.CopyOnWriteArraySet; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.smarthome.core.items.Item; | ||
import org.eclipse.smarthome.core.items.ItemBuilder; | ||
import org.eclipse.smarthome.core.items.ItemBuilderFactory; | ||
import org.eclipse.smarthome.core.items.ItemFactory; | ||
import org.eclipse.smarthome.core.library.CoreItemFactory; | ||
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; | ||
|
||
/** | ||
* Provides an {@link ItemBuilder} with all available {@link ItemFactory}s set. The {@link CoreItemFactory} will always | ||
* be present. | ||
* | ||
* @author Henning Treu - initial contribution and API | ||
* | ||
*/ | ||
@NonNullByDefault | ||
@Component | ||
public class ItemBuilderFactoryImpl implements ItemBuilderFactory { | ||
|
||
private final @NonNullByDefault({}) Set<ItemFactory> itemFactories = new CopyOnWriteArraySet<>(); | ||
|
||
@Override | ||
public ItemBuilder newItemBuilder(Item item) { | ||
return new ItemBuilderImpl(itemFactories, item); | ||
} | ||
|
||
@Override | ||
public ItemBuilder newItemBuilder(String itemType, String itemName) { | ||
return new ItemBuilderImpl(itemFactories, itemType, itemName); | ||
} | ||
|
||
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) | ||
protected void addItemFactory(ItemFactory itemFactory) { | ||
itemFactories.add(itemFactory); | ||
} | ||
|
||
protected void removeItemFactory(ItemFactory itemFactory) { | ||
itemFactories.remove(itemFactory); | ||
} | ||
|
||
@Reference(target = "(component.name=org.eclipse.smarthome.core.library.CoreItemFactory)") | ||
protected void setCoreItemFactory(ItemFactory coreItemFactory) { | ||
itemFactories.add(coreItemFactory); | ||
} | ||
|
||
protected void unsetCoreItemFactory(ItemFactory coreItemFactory) { | ||
itemFactories.remove(coreItemFactory); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...pse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/ItemBuilderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright (c) 2014,2018 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.smarthome.core.items; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
/** | ||
* Creates a new {@link ItemBuilder} which is based on all available {@link ItemFactory}s. | ||
* | ||
* @author Henning Treu - initial contribution and API | ||
* | ||
*/ | ||
@NonNullByDefault | ||
public interface ItemBuilderFactory { | ||
|
||
/** | ||
* Create a new {@link ItemBuilder}, which is initialized by the given item. | ||
* | ||
* @param item the template to initialize the builder with | ||
* | ||
* @return an ItemBuilder instance | ||
*/ | ||
ItemBuilder newItemBuilder(Item item); | ||
|
||
/** | ||
* Create a new {@link ItemBuilder}, which is initialized by the given item. | ||
* | ||
* @param itemType the item type to create | ||
* @param itemName the name of the item to create | ||
* | ||
* @return an ItemBuilder instance | ||
*/ | ||
ItemBuilder newItemBuilder(String itemType, String itemName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.