Search in sources :

Example 1 with DomainClassArtefactHandler

use of org.grails.core.artefact.DomainClassArtefactHandler in project grails-core by grails.

the class CodecArtefactHandlerTests method testDomainClassWithNameEndingInCodecIsNotACodec.

public void testDomainClassWithNameEndingInCodecIsNotACodec() {
    GroovyClassLoader gcl = new GroovyClassLoader();
    Class<?> c = gcl.parseClass("class MySpecialCodec { Long id;Long version;}\n");
    ArtefactHandler domainClassHandler = new DomainClassArtefactHandler();
    assertTrue(domainClassHandler.isArtefact(c));
    ArtefactHandler codecHandler = new CodecArtefactHandler();
    assertFalse(codecHandler.isArtefact(c));
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) CodecArtefactHandler(org.grails.commons.CodecArtefactHandler) DomainClassArtefactHandler(org.grails.core.artefact.DomainClassArtefactHandler) ArtefactHandler(grails.core.ArtefactHandler) DomainClassArtefactHandler(org.grails.core.artefact.DomainClassArtefactHandler) CodecArtefactHandler(org.grails.commons.CodecArtefactHandler)

Example 2 with DomainClassArtefactHandler

use of org.grails.core.artefact.DomainClassArtefactHandler in project grails-core by grails.

the class DomainClassArtefactHandlerTests method testIsDomainClass.

public void testIsDomainClass() {
    GroovyClassLoader gcl = new GroovyClassLoader();
    Class<?> c = gcl.parseClass("class Test { Long id;Long version;}\n");
    ArtefactHandler handler = new DomainClassArtefactHandler();
    assertTrue(handler.isArtefact(c));
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) DomainClassArtefactHandler(org.grails.core.artefact.DomainClassArtefactHandler) ArtefactHandler(grails.core.ArtefactHandler) DomainClassArtefactHandler(org.grails.core.artefact.DomainClassArtefactHandler)

Example 3 with DomainClassArtefactHandler

use of org.grails.core.artefact.DomainClassArtefactHandler 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

DomainClassArtefactHandler (org.grails.core.artefact.DomainClassArtefactHandler)3 ArtefactHandler (grails.core.ArtefactHandler)2 GroovyClassLoader (groovy.lang.GroovyClassLoader)2 ArtefactAdditionEvent (grails.core.events.ArtefactAdditionEvent)1 CodecArtefactHandler (org.grails.commons.CodecArtefactHandler)1 GrailsConfigurationException (org.grails.core.exceptions.GrailsConfigurationException)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1