mockProvider = configProvider.substring("java://".length());
}
try{
Class<?> providerClass = Class.forName(mockProvider);
if(!ComponentConfigProvider.class.isAssignableFrom(providerClass)){
throw new InvalidDefinitionException("Class specified as configProvider should implement ComponentConfigProvider", getLocation());
}
ComponentConfigProvider provider = (ComponentConfigProvider)providerClass.newInstance();
config = provider.provide();
}catch(ClassNotFoundException e){
throw new InvalidDefinitionException("Could not locate class specified as configProvider:"+configProvider, getLocation());
}catch(IllegalAccessException e){
throw new InvalidDefinitionException("Constructor is inaccessible for "+ configProvider, getLocation());
}catch (InstantiationException ie) {
throw new InvalidDefinitionException("Cannot instantiate " + configProvider, getLocation());
}
return (T)config;
}
};
}else{
return super.getAnswer(object, retClass);
}
}
throw new InvalidDefinitionException("Mock answer must specify either 'value' or 'error'", getLocation());
}