org.nuiton.jaxx.runtime.spi.init.ComponentInitializerManager Maven / Gradle / Ivy
package org.nuiton.jaxx.runtime.spi.init;
/*-
* #%L
* JAXX :: Runtime Spi
* %%
* Copyright (C) 2008 - 2020 Code Lutin, Ultreia.io
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import org.nuiton.jaxx.runtime.JAXXObject;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
/**
* Created by tchemit on 14/11/17.
*
* @author Tony Chemit - [email protected]
* @deprecated will be removed when 3.0 will be released.
*/
@Deprecated
public class ComponentInitializerManager {
public static final ComponentInitializerManager INSTANCE = new ComponentInitializerManager();
private final Set initializerSet;
private ComponentInitializerManager() {
initializerSet = new HashSet<>();
for (ComponentInitializer componentInitializer : ServiceLoader.load(ComponentInitializer.class)) {
initializerSet.add(componentInitializer);
}
}
public static ComponentInitializerManager get() {
return INSTANCE;
}
public Set apply(JAXXObject ui) {
Set done = new LinkedHashSet<>();
for (ComponentInitializer initializer : initializerSet) {
initializer.reset();
if (initializer.acceptUi(ui)) {
initializer.start(ui);
for (Map.Entry entry : ui.get$objectMap().entrySet()) {
Object component = entry.getValue();
if (component == null) {
continue;
}
if (initializer.acceptComponent(component)) {
initializer.init(ui, component);
}
}
}
if (initializer.isTouched()) {
done.add(initializer);
}
}
for (ComponentInitializer componentInitializer : done) {
componentInitializer.end(ui);
}
return done;
}
}