Skip to content

Commit

Permalink
Better error description on getExportedInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jan 23, 2013
1 parent 61b18bf commit 0227438
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.enterprise.inject.spi.BeanManager;
Expand All @@ -12,6 +11,7 @@
import org.jboss.forge.container.services.ExportedInstance;
import org.jboss.forge.container.services.ExportedInstanceImpl;
import org.jboss.forge.container.services.ServiceRegistry;
import org.jboss.forge.container.util.Assert;
import org.jboss.forge.container.util.Sets;

public class ServiceRegistryImpl implements ServiceRegistry
Expand Down Expand Up @@ -71,20 +71,43 @@ public <T> ExportedInstance<T> getExportedInstance(Class<T> clazz)
*/
private <T> ExportedInstance<T> getExportedInstance(Class<T> requestedType, Class<T> actualType)
{
Assert.notNull(requestedType, "Requested Class type may not be null");
Assert.notNull(actualType, "Actual Class type may not be null");

final Class<T> requestedLoadedType;
final Class<? extends T> actualLoadedType;
try
{
requestedLoadedType = loadAddonClass(requestedType);
}
catch (ClassNotFoundException cnfe)
{
log.fine("Class " + requestedType.getName() + " is not present in this addon classloader");
return null;
}
try
{
final Class<T> requestedLoadedType = loadAddonClass(requestedType);
final Class<? extends T> actualLoadedType = loadAddonClass(actualType);
actualLoadedType = loadAddonClass(actualType);
}
catch (ClassNotFoundException cnfe)
{
log.fine("Class " + actualType.getName() + " is not present in this addon classloader");
return null;
}

try
{
ExportedInstance<T> result = null;
if (!manager.getBeans(requestedLoadedType).isEmpty())
{
return new ExportedInstanceImpl<T>(addon.getClassLoader(), manager, requestedLoadedType, actualLoadedType);
result = new ExportedInstanceImpl<T>(addon.getClassLoader(), manager, requestedLoadedType, actualLoadedType);
}
return result;
}
catch (Exception e)
{
log.log(Level.FINE, "Error while fetching exported instances", e);
throw new ContainerException("Error while fetching exported instance", e);
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.sf.cglib.proxy.MethodProxy;

import org.jboss.forge.container.exception.ContainerException;
import org.jboss.forge.container.services.ExportedInstance;
import org.jboss.forge.container.util.ClassLoaders;

public class ExportedInstanceImpl<R> implements ExportedInstance<R>
Expand Down

0 comments on commit 0227438

Please sign in to comment.