Multiple user referentials working with IPA.
[lgpl/argeo-commons.git] / org.argeo.util / src / org / argeo / util / register / ComponentRegister.java
index eb8acba02bcaeb97314b7f8872b43c2a20e63419..d78b6badbeb2dea14b6ea9103dc1760b71a0ea50 100644 (file)
@@ -1,14 +1,38 @@
 package org.argeo.util.register;
 
 import java.util.Map;
-import java.util.function.Consumer;
+import java.util.SortedSet;
 import java.util.function.Predicate;
 
-public interface ComponentRegister extends Consumer<Component<?>> {
-       <T> Component<? extends T> find(Class<T> clss, Predicate<Map<String, Object>> filter);
+/** A register of components which can coordinate their activation. */
+public interface ComponentRegister {
+       long register(Component<?> component);
+
+       <T> SortedSet<Component<? extends T>> find(Class<T> clss, Predicate<Map<String, Object>> filter);
+
+       default <T> Component.PublishedType<T> getSingleton(Class<T> type) {
+               SortedSet<Component<? extends T>> found = find(type, null);
+               if (found.size() == 0)
+                       throw new IllegalStateException("No component found for " + type);
+               return found.first().getType(type);
+       }
+
+       default <T> T getObject(Class<T> clss) {
+               SortedSet<Component<? extends T>> found = find(clss, null);
+               if (found.size() == 0)
+                       return null;
+               return found.first().get();
+       }
 
        Component<?> get(Object instance);
 
+//     default <T> PublishedType<T> getType(Class<T> clss) {
+//             SortedSet<Component<? extends T>> components = find(clss, null);
+//             if (components.size() == 0)
+//                     return null;
+//             return components.first().getType(clss);
+//     }
+
        void activate();
 
        void deactivate();