if (context != null) {
try {
if (context instanceof AtomicComponent || context instanceof Reference || context instanceof Service) {
return instanceInterface.cast(context.getServiceInstance());
} else {
IllegalTargetException e = new IllegalTargetException("Autowire target must be a system "
+ "service, atomic component, or reference");
e.setIdentifier(instanceInterface.getName());
e.addContextName(getName());
throw e;
}
} catch (CoreRuntimeException e) {
e.addContextName(getName());
throw e;
}
} else {
try {
if (CompositeComponent.class.isAssignableFrom(instanceInterface)) {
return instanceInterface.cast(this);
}
// resolve to parent
if (getParent() == null) {
return null;
}
return getParent().resolveInstance(instanceInterface);
} catch (AutowireResolutionException e) {
e.addContextName(getName());
throw e;
}
}
}