use of grails.core.GrailsClass in project grails-core by grails.
the class GrailsClassTests method testAbstractGrailsClassNoPackage.
@Test
public void testAbstractGrailsClassNoPackage() throws Exception {
GroovyClassLoader cl = new GroovyClassLoader();
Class<?> clazz = cl.parseClass("class TestService { }");
GrailsClass grailsClass = new AbstractGrailsClass(clazz, "Service") {
};
assertEquals("TestService", clazz.getName());
assertEquals("Test", grailsClass.getName());
assertEquals("TestService", grailsClass.getFullName());
assertNotNull(grailsClass.newInstance());
}
use of grails.core.GrailsClass in project grails-core by grails.
the class GrailsClassTests method testAbstractGrailsClassPackage.
@Test
public void testAbstractGrailsClassPackage() throws Exception {
GroovyClassLoader cl = new GroovyClassLoader();
Class<?> clazz = cl.parseClass("package test.casey; class TestService { }");
GrailsClass grailsClass = new AbstractGrailsClass(clazz, "Service") {
};
assertEquals("test.casey.TestService", clazz.getName());
assertEquals("Test", grailsClass.getName());
assertEquals("test.casey.TestService", grailsClass.getFullName());
assertNotNull(grailsClass.newInstance());
}
use of grails.core.GrailsClass in project grails-core by grails.
the class GrailsConfigUtils method executeGrailsBootstraps.
/**
* Executes Grails bootstrap classes
*
* @param application The Grails ApplicationContext instance
* @param webContext The WebApplicationContext instance
* @param servletContext The ServletContext instance
*/
public static void executeGrailsBootstraps(GrailsApplication application, WebApplicationContext webContext, ServletContext servletContext, GrailsPluginManager grailsPluginManager) {
configureServletContextAttributes(servletContext, application, grailsPluginManager, webContext);
PersistenceContextInterceptor interceptor = null;
String[] beanNames = webContext.getBeanNamesForType(PersistenceContextInterceptor.class);
if (beanNames.length > 0) {
interceptor = (PersistenceContextInterceptor) webContext.getBean(beanNames[0]);
}
if (interceptor != null) {
interceptor.init();
}
// init the Grails application
try {
GrailsClass[] bootstraps = application.getArtefacts(BootstrapArtefactHandler.TYPE);
for (GrailsClass bootstrap : bootstraps) {
final GrailsBootstrapClass bootstrapClass = (GrailsBootstrapClass) bootstrap;
final Object instance = bootstrapClass.getReferenceInstance();
webContext.getAutowireCapableBeanFactory().autowireBeanProperties(instance, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
bootstrapClass.callInit(servletContext);
}
if (interceptor != null) {
interceptor.flush();
}
} finally {
if (interceptor != null) {
interceptor.destroy();
}
}
}
use of grails.core.GrailsClass in project grails-core by grails.
the class DefaultArtefactInfo method addGrailsClassInternal.
private void addGrailsClassInternal(GrailsClass artefactClass, boolean atStart) {
grailsClassesByName = new LinkedHashMap<String, GrailsClass>(grailsClassesByName);
classesByName = new LinkedHashMap<String, Class<?>>(classesByName);
Class<?> actualClass = artefactClass.getClazz();
boolean addToGrailsClasses = true;
if (artefactClass instanceof InjectableGrailsClass) {
addToGrailsClasses = ((InjectableGrailsClass) artefactClass).getAvailable();
}
if (addToGrailsClasses) {
GrailsClass oldVersion = grailsClassesByName.put(actualClass.getName(), artefactClass);
grailsClasses.remove(oldVersion);
}
classesByName.put(actualClass.getName(), actualClass);
logicalPropertyNameToClassMap.put(artefactClass.getLogicalPropertyName(), artefactClass);
if (!grailsClasses.contains(artefactClass)) {
if (atStart) {
grailsClasses.addFirst(artefactClass);
} else {
grailsClasses.addLast(artefactClass);
}
}
}
use of grails.core.GrailsClass in project grails-core by grails.
the class GrailsClassTests method testGrailsClassNonPublicConstructor.
@Test
public void testGrailsClassNonPublicConstructor() throws Exception {
GroovyClassLoader cl = new GroovyClassLoader();
Class<?> clazz = cl.parseClass("class ProtectedConstructor { protected ProtectedConstructor() {}}");
GrailsClass grailsClass = new AbstractGrailsClass(clazz, "ProtectedConstructor") {
};
assertNotNull(grailsClass.newInstance());
}
Aggregations