Skip to content

Commit

Permalink
Testing classloaders for class in parameter of getExportedInstances
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jan 22, 2013
1 parent 8622acf commit 8e09662
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public interface AddonRegistry

<T> Set<ExportedInstance<T>> getExportedInstances(String clazz);

<T> ExportedInstance<T> getExportedInstance(Class<T> type);

<T> ExportedInstance<T> getExportedInstance(String type);

Future<?> start(Addon addon);

void stop(Addon addon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,46 @@ public <T> Set<ExportedInstance<T>> getExportedInstances(String typeName)
return result;
}

@Override
public <T> ExportedInstance<T> getExportedInstance(Class<T> type)
{
// TODO This needs to block addon installation/removal;
ExportedInstance<T> result = null;
for (Addon addon : addons)
{
if (addon.getStatus().isStarted())
{
ServiceRegistry serviceRegistry = addon.getServiceRegistry();
result = serviceRegistry.getExportedInstance(type);
if (result != null)
{
break;
}
}
}
return result;
}

@Override
public <T> ExportedInstance<T> getExportedInstance(String type)
{
// TODO This needs to block addon installation/removal;
ExportedInstance<T> result = null;
for (Addon addon : addons)
{
if (addon.getStatus().isStarted())
{
ServiceRegistry serviceRegistry = addon.getServiceRegistry();
result = serviceRegistry.getExportedInstance(type);
if (result != null)
{
break;
}
}
}
return result;
}

@Override
public String toString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,28 @@ public String toString()
public <T> Set<ExportedInstance<T>> getExportedInstances(Class<T> clazz)
{
Set<ExportedInstance<T>> result = new HashSet<ExportedInstance<T>>();
final Class<T> addonLoadedType;
if (clazz.getClassLoader() == addon.getClassLoader())
{
addonLoadedType = clazz;
}
else
{
try
{
addonLoadedType = (Class<T>) Class.forName(clazz.getName(), true, addon.getClassLoader());
}
catch (Exception e)
{
log.log(Level.FINE, "Error while fetching exported instances", e);
return result;
}
}

for (Class<?> type : services)
{
if (clazz.isAssignableFrom(type))

if (addonLoadedType.isAssignableFrom(type))
{
result.add((ExportedInstance<T>) getExportedInstance(type));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,15 @@
import org.jboss.forge.ui.UICommandID;
import org.jboss.forge.ui.UIContext;
import org.jboss.forge.ui.UIValidationContext;
import org.jboss.forge.ui.base.SimpleUICommandID;

public class MockChooseFrameworkStep implements UICommand
{

@Override
public UICommandID getId()
{
return new UICommandID()
{
@Override
public String getName()
{
return "Choose Framework";
}

@Override
public String getDescription()
{
return "Pick the framework you wish to use for this command.";
}
};
return new SimpleUICommandID("Choose Framework", "Pick the framework you wish to use for this command.");
}

@Override
Expand Down

0 comments on commit 8e09662

Please sign in to comment.