org.oddjob.arooa.registry.ComponentsServiceFinder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of arooa Show documentation
Show all versions of arooa Show documentation
A Rip Off Of Ant - A drag and drop component framework.
package org.oddjob.arooa.registry;
import org.oddjob.arooa.ComponentTrinity;
/**
* A {@link ServiceFinder] for a {@link ComponentPool}.
*
* @author rob
*
*/
public class ComponentsServiceFinder implements ServiceFinder {
private final ComponentPool directory;
public ComponentsServiceFinder(ComponentPool directory) {
this.directory = directory;
}
public Object find(Class> cl, String flavour) {
for (ComponentTrinity trinity: directory.allTrinities()) {
ServiceProvider provider = null;
if (trinity.getTheProxy() instanceof ServiceProvider) {
provider = (ServiceProvider) trinity.getTheProxy();
}
else if (trinity.getTheComponent() instanceof ServiceProvider){
provider = (ServiceProvider) trinity.getTheComponent();
}
if (provider == null) {
continue;
}
Services lookup = provider.getServices();
if (lookup == null) {
continue;
}
String identifier = lookup.serviceNameFor(cl, flavour);
if (identifier != null) {
return lookup.getService(identifier);
}
}
return null;
}
}