use of org.grails.core.exceptions.GrailsConfigurationException in project grails-core by grails.
the class DefaultGrailsApplication method addArtefact.
protected GrailsClass addArtefact(String artefactType, Class<?> artefactClass, boolean overrideable) {
ArtefactHandler handler = artefactHandlersByName.get(artefactType);
if (handler != null && handler.isArtefact(artefactClass)) {
GrailsClass artefactGrailsClass;
if (handler instanceof DomainClassArtefactHandler) {
artefactGrailsClass = ((DomainClassArtefactHandler) handler).newArtefactClass(artefactClass, proxyMappingContext);
} else {
artefactGrailsClass = handler.newArtefactClass(artefactClass);
}
artefactGrailsClass.setGrailsApplication(this);
// Store the GrailsClass in cache
DefaultArtefactInfo info = getArtefactInfo(artefactType, true);
if (overrideable) {
info.addOverridableGrailsClass(artefactGrailsClass);
} else {
info.addGrailsClass(artefactGrailsClass);
}
info.updateComplete();
addToLoaded(artefactClass);
if (isInitialised()) {
initializeArtefacts(artefactType);
ApplicationContext context = getMainContext();
if (context instanceof ConfigurableApplicationContext && contextInitialized && ((ConfigurableApplicationContext) context).isActive()) {
context.publishEvent(new ArtefactAdditionEvent(artefactGrailsClass));
}
}
return artefactGrailsClass;
}
throw new GrailsConfigurationException("Cannot add " + artefactType + " class [" + artefactClass + "]. It is not a " + artefactType + "!");
}
Aggregations