Object provider = providerClass.newInstance();
return serviceClass.cast( provider );
} catch ( InstantiationException e ) {
final String msg = MessageFormat.format( ERR_NOT_CONCRETE,
providerClass.getName() );
throw new ProviderInitializationException( msg,
e );
} catch ( IllegalAccessException e ) {
final String msg = MessageFormat.format( ERR_NOT_ACCESSIBLE,
providerClass.getName() );
throw new ProviderInitializationException( msg,
e );
} catch ( ClassCastException e ) {
final String pattern = serviceClass.isInterface() ? ERR_IMPLEMENTS : ERR_EXTENDS;
final String msg = MessageFormat.format( pattern,
providerClass.getName(),
serviceClass.getName() );
throw new ProviderInitializationException( msg,
e );
}
}