use of grails.core.GrailsClass in project grails-core by grails.
the class TagLibArtefactHandler method initialize.
/**
* Creates a map of tags (keyed on "${namespace}:${tagName}") to tag libraries.
*/
@Override
public void initialize(ArtefactInfo artefacts) {
tag2libMap = new HashMap<String, GrailsTagLibClass>();
for (GrailsClass aClass : artefacts.getGrailsClasses()) {
GrailsTagLibClass taglibClass = (GrailsTagLibClass) aClass;
String namespace = taglibClass.getNamespace();
namespace2tagLibMap.put(namespace, taglibClass);
for (Object o : taglibClass.getTagNames()) {
String tagName = namespace + ":" + o;
if (!tag2libMap.containsKey(tagName)) {
tag2libMap.put(tagName, taglibClass);
} else {
GrailsTagLibClass current = tag2libMap.get(tagName);
if (!taglibClass.equals(current)) {
LogFactory.getLog(TagLibArtefactHandler.class).info("There are conflicting tags: " + taglibClass.getFullName() + "." + tagName + " vs. " + current.getFullName() + "." + tagName + ". The former will take precedence.");
tag2libMap.put(tagName, taglibClass);
}
}
}
}
}
use of grails.core.GrailsClass in project grails-core by grails.
the class GrailsDomainConfigurationUtil method configureDomainClassRelationships.
/**
* Configures the relationships between domain classes after they have been all loaded.
*
* @param domainClasses The domain classes to configure relationships for
* @param domainMap The domain class map
*/
public static void configureDomainClassRelationships(GrailsClass[] domainClasses, Map<?, ?> domainMap) {
// and configure how domain class properties reference each other
for (GrailsClass grailsClass : domainClasses) {
GrailsDomainClass domainClass = (GrailsDomainClass) grailsClass;
if (!domainClass.isRoot()) {
Class<?> superClass = grailsClass.getClazz().getSuperclass();
while (!superClass.equals(Object.class) && !superClass.equals(GroovyObject.class)) {
GrailsDomainClass gdc = (GrailsDomainClass) domainMap.get(superClass.getName());
if (gdc == null || gdc.getSubClasses() == null) {
break;
}
gdc.getSubClasses().add((GrailsDomainClass) grailsClass);
superClass = superClass.getSuperclass();
}
}
GrailsDomainClassProperty[] props = domainClass.getPersistentProperties();
for (GrailsDomainClassProperty prop : props) {
if (prop != null && prop.isAssociation()) {
GrailsDomainClass referencedGrailsDomainClass = (GrailsDomainClass) domainMap.get(prop.getReferencedPropertyType().getName());
prop.setReferencedDomainClass(referencedGrailsDomainClass);
}
}
}
// now configure so that the 'other side' of a property can be resolved by the property itself
for (GrailsClass domainClass1 : domainClasses) {
GrailsDomainClass domainClass = (GrailsDomainClass) domainClass1;
GrailsDomainClassProperty[] props = domainClass.getPersistentProperties();
for (GrailsDomainClassProperty prop : props) {
if (prop == null || !prop.isAssociation()) {
continue;
}
GrailsDomainClass referenced = prop.getReferencedDomainClass();
if (referenced == null) {
continue;
}
boolean isOwnedBy = referenced.isOwningClass(domainClass.getClazz());
prop.setOwningSide(isOwnedBy);
String refPropertyName = null;
try {
refPropertyName = prop.getReferencedPropertyName();
} catch (UnsupportedOperationException e) {
// ignore (to support Hibernate entities)
}
if (!StringUtils.hasText(refPropertyName)) {
GrailsDomainClassProperty[] referencedProperties = referenced.getPersistentProperties();
for (GrailsDomainClassProperty referencedProp : referencedProperties) {
// to be equal to self
if (prop.equals(referencedProp) && prop.isBidirectional()) {
continue;
}
if (isCandidateForOtherSide(domainClass, prop, referencedProp)) {
prop.setOtherSide(referencedProp);
break;
}
}
} else {
GrailsDomainClassProperty otherSide = referenced.getPropertyByName(refPropertyName);
prop.setOtherSide(otherSide);
otherSide.setOtherSide(prop);
}
}
}
}
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) {
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 GroovyPagesTemplateEngine method createDomainClassMap.
/**
* The domainClassMap is used in GSP binding to "auto-import" domain classes in packages without package prefix.
* real imports aren't used, instead each class is added to the binding
*
* This feature has existed earlier, the code has just been refactored and moved to GroovyPagesTemplateEngine
* to prevent using the static cache that was used previously.
*/
private Map<String, Class<?>> createDomainClassMap() {
Map<String, Class<?>> domainsWithoutPackage = new HashMap<String, Class<?>>();
if (grailsApplication != null) {
GrailsClass[] domainClasses = grailsApplication.getArtefacts(DomainClassArtefactHandler.TYPE);
for (GrailsClass domainClass : domainClasses) {
final Class<?> theClass = domainClass.getClazz();
domainsWithoutPackage.put(theClass.getName(), theClass);
}
}
return domainsWithoutPackage;
}
use of grails.core.GrailsClass in project grails-core by grails.
the class DefaultCodecLookup method registerCodecs.
protected void registerCodecs() {
List<GrailsClass> codecs = Arrays.asList(grailsApplication.getArtefacts(CodecArtefactHandler.TYPE));
Collections.sort(codecs, OrderComparator.INSTANCE);
Collections.reverse(codecs);
for (GrailsClass grailsClass : codecs) {
registerCodec((GrailsCodecClass) grailsClass);
}
}
Aggregations