nz.ac.auckland.lmz.widget.service.WidgetService.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lmzwidget Show documentation
Show all versions of lmzwidget Show documentation
LMZ Widget proof of concept frontend and bus module
package nz.ac.auckland.lmz.widget.service
import nz.ac.auckland.common.stereotypes.UniversityComponent
import nz.ac.auckland.lmz.widget.WidgetStencil
import nz.ac.auckland.lmzwidget.generator.annotations.Widget
import org.springframework.beans.factory.annotation.Autowired
import java.lang.annotation.Annotation
/**
* @author Marnix Cook
*
* A container for useful widget related functions
*/
@UniversityComponent
class WidgetService {
/**
* All widgets
*/
@Autowired(required = false)
List widgets;
/**
* @return the list of widgets
*/
public List getWidgets() {
return this.widgets
}
/**
* @return the widget stencil class for a widget called name. If it doesn't exist return null.
*/
public WidgetStencil getWidgetByName(String name) {
return this.widgets.find { WidgetStencil widgetStencil ->
Widget widgetAnn = getWidgetAnnotationFor(widgetStencil);
return (widgetAnn.name() == name);
}
}
/**
* Gets the annotation for the widget stencil class
*
* @param stencil
* @return
*/
public Widget getWidgetAnnotationFor(WidgetStencil stencil) {
return stencil.class.annotations.find { Annotation ann ->
return (ann instanceof Widget)
}
}
}