/** * Refreshes constraints defined by the DomainClassArtefactHandler. * * <p>TODO: Move this out of GrailsApplication */ public void refreshConstraints() { ArtefactInfo info = getArtefactInfo(DomainClassArtefactHandler.TYPE, true); GrailsClass[] domainClasses = info.getGrailsClasses(); for (GrailsClass domainClass : domainClasses) { ((GrailsDomainClass) domainClass).refreshConstraints(); } }
public GrailsClass getArtefactByLogicalPropertyName(String type, String logicalName) { ArtefactInfo info = getArtefactInfo(type); return info == null ? null : info.getGrailsClassByLogicalPropertyName(logicalName); }
protected GrailsClass getFirstArtefact(String artefactType) { ArtefactInfo info = getArtefactInfo(artefactType); // This will throw AIOB if we have none return info == null ? null : info.getGrailsClasses()[0]; }
/** * Retrieves an artefact for the given type and name. * * @param artefactType The artefact type as defined by a registered ArtefactHandler * @param name The name of the class * @return A GrailsClass instance or null if none could be found for the given artefactType and * name */ public GrailsClass getArtefact(String artefactType, String name) { ArtefactInfo info = getArtefactInfo(artefactType); return info == null ? null : info.getGrailsClass(name); }
/** * Retrieves the number of artefacts registered for the given artefactType as defined by the * ArtefactHandler. * * @param artefactType The type of the artefact as defined by the ArtefactHandler * @return The number of registered artefacts */ protected int getArtefactCount(String artefactType) { ArtefactInfo info = getArtefactInfo(artefactType); return info == null ? 0 : info.getClasses().length; }
@SuppressWarnings("rawtypes") @Override public GrailsClass getArtefactForFeature(Object featureId) { if (artefactInfo == null) { return null; } String uri; String pluginName = null; if (featureId instanceof Map) { Map featureIdMap = (Map) featureId; uri = (String) featureIdMap.get("uri"); pluginName = (String) featureIdMap.get("pluginName"); } else { uri = featureId.toString(); } GrailsClass controllerClass = uriToControllerClassCache.get(uri); if (controllerClass == null) { final ApplicationContext mainContext = grailsApplication.getMainContext(); GrailsPluginManager grailsPluginManager = null; if (mainContext.containsBean(GrailsPluginManager.BEAN_NAME)) { final Object pluginManagerBean = mainContext.getBean(GrailsPluginManager.BEAN_NAME); if (pluginManagerBean instanceof GrailsPluginManager) { grailsPluginManager = (GrailsPluginManager) pluginManagerBean; } } final GrailsClass[] controllerClasses = artefactInfo.getGrailsClasses(); // iterate in reverse in order to pick up application classes first for (int i = (controllerClasses.length - 1); i >= 0; i--) { GrailsClass c = controllerClasses[i]; if (((GrailsControllerClass) c).mapsToURI(uri)) { boolean foundController = false; if (pluginName != null && grailsPluginManager != null) { final GrailsPlugin pluginForClass = grailsPluginManager.getPluginForClass(c.getClazz()); if (pluginForClass != null && pluginName.equals(pluginForClass.getName())) { foundController = true; } } else { foundController = true; } if (foundController) { controllerClass = c; break; } } } if (controllerClass == null) { controllerClass = NO_CONTROLLER; } // don't cache for dev environment if (Environment.getCurrent() != Environment.DEVELOPMENT) { uriToControllerClassCache.put(uri, controllerClass); } } if (controllerClass == NO_CONTROLLER) { controllerClass = null; } return controllerClass; }