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));
}
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));
}
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 + "!");
}
Aggregations