Search in sources :

Example 6 with GrailsConfigurationException

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 + "!");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) GrailsConfigurationException(org.grails.core.exceptions.GrailsConfigurationException) DomainClassArtefactHandler(org.grails.core.artefact.DomainClassArtefactHandler) DomainClassArtefactHandler(org.grails.core.artefact.DomainClassArtefactHandler) ArtefactAdditionEvent(grails.core.events.ArtefactAdditionEvent)

Aggregations

GrailsConfigurationException (org.grails.core.exceptions.GrailsConfigurationException)6 MetaClassRegistry (groovy.lang.MetaClassRegistry)2 DomainClassArtefactHandler (org.grails.core.artefact.DomainClassArtefactHandler)2 ArtefactAdditionEvent (grails.core.events.ArtefactAdditionEvent)1 GrailsPlugin (grails.plugins.GrailsPlugin)1 Environment (grails.util.Environment)1 InputStream (java.io.InputStream)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParser (javax.xml.parsers.SAXParser)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 Resource (org.springframework.core.io.Resource)1 UrlResource (org.springframework.core.io.UrlResource)1 SAXException (org.xml.sax.SAXException)1