configureClasses(application, dispenser, map);
}*/
protected FacesConfig createFacesConfig(Map< Class<? extends Annotation>, Set<Class<?>> > map)
{
FacesConfig facesConfig = new FacesConfig();
Set<Class<?>> classes = map.get(FacesComponent.class);
if (classes != null && !classes.isEmpty())
{
for (Class<?> clazz : classes)
{
FacesComponent comp = (FacesComponent) clazz
.getAnnotation(FacesComponent.class);
if (comp != null)
{
if (log.isLoggable(Level.FINEST))
{
log.finest("addComponent(" + comp.value() + ","
+ clazz.getName() + ")");
}
facesConfig.addComponent(comp.value(), clazz.getName());
}
}
}
classes = map.get(FacesConverter.class);
if (classes != null && !classes.isEmpty())
{
for (Class<?> clazz : classes)
{
FacesConverter conv = (FacesConverter) clazz
.getAnnotation(FacesConverter.class);
if (conv != null)
{
if (log.isLoggable(Level.FINEST))
{
log.finest("addConverter(" + conv.value() + ","
+ clazz.getName() + ")");
}
//If there is a previous entry on Application Configuration Resources,
//the entry there takes precedence
boolean hasForClass = !Object.class.equals(conv.forClass());
boolean hasValue = conv.value().length() > 0;
if (hasForClass || hasValue)
{
Converter converter = new Converter();
if (hasForClass)
{
converter.setForClass(conv.forClass().getName());
}
if (hasValue) {
converter.setConverterId(conv.value());
}
converter.setConverterClass(clazz.getName());
facesConfig.addConverter(converter);
}
else
{
// TODO MartinKoci MYFACES-3053
throw new FacesException("@FacesConverter must have value, forClass or both. Check annotation @FacesConverter on class: " + clazz.getName());
}
}
}
}
classes = map.get(FacesValidator.class);
if (classes != null && !classes.isEmpty())
{
for (Class<?> clazz : classes)
{
FacesValidator val = (FacesValidator) clazz
.getAnnotation(FacesValidator.class);
if (val != null)
{
if (log.isLoggable(Level.FINEST))
{
log.finest("addValidator(" + val.value() + "," + clazz.getName()
+ ")");
}
facesConfig.addValidator(val.value(), clazz.getName());
if (val.isDefault())
{
Application app = null;
if(facesConfig.getApplications().isEmpty())
{
app = new Application();
}
else
{
app = (Application) facesConfig.getApplications().get(0);
}
app.addDefaultValidatorId(val.value());
}
}
}
}
classes = map.get(FacesRenderer.class);
if (classes != null && !classes.isEmpty())
{
for (Class<?> clazz : classes)
{
FacesRenderer rend = (FacesRenderer) clazz
.getAnnotation(FacesRenderer.class);
if (rend != null)
{
String renderKitId = rend.renderKitId();
if (renderKitId == null)
{
renderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT;
}
if (log.isLoggable(Level.FINEST))
{
log.finest("addRenderer(" + renderKitId + ", "
+ rend.componentFamily() + ", " + rend.rendererType()
+ ", " + clazz.getName() + ")");
}
org.apache.myfaces.config.impl.digester.elements.RenderKit renderKit =
(org.apache.myfaces.config.impl.digester.elements.RenderKit) facesConfig.getRenderKit(renderKitId);
if (renderKit == null)
{
renderKit = new org.apache.myfaces.config.impl.digester.elements.RenderKit();
renderKit.setId(renderKitId);
facesConfig.addRenderKit(renderKit);
}
org.apache.myfaces.config.impl.digester.elements.Renderer renderer =
new org.apache.myfaces.config.impl.digester.elements.Renderer();
renderer.setComponentFamily(rend.componentFamily());
renderer.setRendererClass(clazz.getName());
renderer.setRendererType(rend.rendererType());
renderKit.addRenderer(renderer);
}
}
}
classes = map.get(ManagedBean.class);
if (classes != null && !classes.isEmpty())
{
for (Class<?> clazz : classes)
{
javax.faces.bean.ManagedBean bean =
(javax.faces.bean.ManagedBean) clazz.getAnnotation(javax.faces.bean.ManagedBean.class);
if (bean != null)
{
if (log.isLoggable(Level.FINE))
{
log.fine("Class '" + clazz.getName() + "' has an @ManagedBean annotation");
}
org.apache.myfaces.config.impl.digester.elements.ManagedBean mbc =
new org.apache.myfaces.config.impl.digester.elements.ManagedBean();
String beanName = bean.name();
if ((beanName == null) || beanName.equals ("")) {
int index;
// Missing name attribute algorithm: take the unqualified name and make the
// first character lowercase.
beanName = clazz.getName();
index = beanName.lastIndexOf (".");
if (index != -1) {
beanName = beanName.substring (index + 1);
}
beanName = Character.toLowerCase (beanName.charAt (0)) +
beanName.substring (1);
}
mbc.setName(beanName);
mbc.setEager(Boolean.toString(bean.eager()));
mbc.setBeanClass(clazz.getName());
ApplicationScoped appScoped = (ApplicationScoped) clazz.getAnnotation(ApplicationScoped.class);
if (appScoped != null)
{
mbc.setScope("application");
}
else
{
NoneScoped noneScoped = (NoneScoped) clazz.getAnnotation(NoneScoped.class);
if (noneScoped != null)
{
mbc.setScope("none");
}
else
{
RequestScoped requestScoped = (RequestScoped) clazz.getAnnotation(RequestScoped.class);
if (requestScoped != null)
{
mbc.setScope("request");
}
else
{
SessionScoped sessionScoped = (SessionScoped) clazz.getAnnotation(SessionScoped.class);
if (sessionScoped != null)
{
mbc.setScope("session");
}
else
{
ViewScoped viewScoped = (ViewScoped) clazz.getAnnotation(ViewScoped.class);
if (viewScoped != null)
{
mbc.setScope("view");
}
else {
CustomScoped customScoped = (CustomScoped) clazz.getAnnotation(CustomScoped.class);
if (customScoped != null)
{
mbc.setScope(customScoped.value());
}
else
{
// No scope annotation means default of "request".
mbc.setScope ("request");
}
}
}
}
}
}
Field[] fields = fields(clazz);
for (Field field : fields)
{
if (log.isLoggable(Level.FINEST))
{
log.finest(" Scanning field '" + field.getName() + "'");
}
javax.faces.bean.ManagedProperty property = (javax.faces.bean.ManagedProperty) field
.getAnnotation(javax.faces.bean.ManagedProperty.class);
if (property != null)
{
if (log.isLoggable(Level.FINE))
{
log.fine(" Field '" + field.getName()
+ "' has a @ManagedProperty annotation");
}
org.apache.myfaces.config.impl.digester.elements.ManagedProperty mpc =
new org.apache.myfaces.config.impl.digester.elements.ManagedProperty();
String name = property.name();
if ((name == null) || "".equals(name))
{
name = field.getName();
}
mpc.setPropertyName(name);
mpc.setPropertyClass(field.getType().getName()); // FIXME - primitives, arrays, etc.
mpc.setValue(property.value());
mbc.addProperty(mpc);
continue;
}
}
facesConfig.addManagedBean(mbc);
}
}
}
classes = map.get(NamedEvent.class);
if (classes != null && !classes.isEmpty())
{
for (Class<?> clazz : classes)
{
NamedEvent namedEvent = (NamedEvent) clazz.getAnnotation (NamedEvent.class);
if (namedEvent != null) {
// Can only apply @NamedEvent to ComponentSystemEvent subclasses.
if (!ComponentSystemEvent.class.isAssignableFrom (clazz)) {
// Just log this. We'll catch it later in the runtime.
if (log.isLoggable(Level.WARNING)) {
log.warning (clazz.getName() + " is annotated with @javax.faces.event.NamedEvent, but does " +
"not extend javax.faces.event.ComponentSystemEvent");
}
}
// Have to register @NamedEvent annotations with the NamedEventManager class since
// we need to get access to this info later and can't from the dispenser (it's not a
// singleton).
org.apache.myfaces.config.impl.digester.elements.NamedEvent namedEventConfig =
new org.apache.myfaces.config.impl.digester.elements.NamedEvent();
namedEventConfig.setEventClass(clazz.getName());
namedEventConfig.setShortName(namedEvent.shortName());
facesConfig.addNamedEvent(namedEventConfig);
}
}
}
classes = map.get(FacesBehavior.class);
if (classes != null && !classes.isEmpty())
{
for (Class<?> clazz : classes)
{
FacesBehavior facesBehavior = (FacesBehavior) clazz.getAnnotation (FacesBehavior.class);
if (facesBehavior != null) {
// Can only apply @FacesBehavior to Behavior implementors.
if (!javax.faces.component.behavior.Behavior.class.isAssignableFrom (clazz)) {
// Just log this. We'll catch it later in the runtime.
if (log.isLoggable(Level.WARNING)) {
log.warning (clazz.getName() + " is annotated with @javax.faces.component.behavior.FacesBehavior, " +
"but does not implement javax.faces.component.behavior.Behavior");
}
}
if (log.isLoggable(Level.FINEST)) {
log.finest ("addBehavior(" + facesBehavior.value() + ", " + clazz.getName() + ")");
}
Behavior behavior = new Behavior();
behavior.setBehaviorId(facesBehavior.value());
behavior.setBehaviorClass(clazz.getName());
facesConfig.addBehavior(behavior);
}
}
}
classes = map.get(FacesBehaviorRenderer.class);
if (classes != null && !classes.isEmpty())
{
for (Class<?> clazz : classes)
{
FacesBehaviorRenderer facesBehaviorRenderer = (FacesBehaviorRenderer) clazz.getAnnotation (FacesBehaviorRenderer.class);
if (facesBehaviorRenderer != null) {
String renderKitId = facesBehaviorRenderer.renderKitId();
//RenderKit renderKit;
if (log.isLoggable(Level.FINEST)) {
log.finest ("addClientBehaviorRenderer(" + renderKitId + ", " + facesBehaviorRenderer.rendererType() + ", " +
clazz.getName() + ")");
}
org.apache.myfaces.config.impl.digester.elements.RenderKit renderKit =
(org.apache.myfaces.config.impl.digester.elements.RenderKit) facesConfig.getRenderKit(renderKitId);
if (renderKit == null)
{
renderKit = new org.apache.myfaces.config.impl.digester.elements.RenderKit();
renderKit.setId(renderKitId);
facesConfig.addRenderKit(renderKit);
}
org.apache.myfaces.config.impl.digester.elements.ClientBehaviorRenderer cbr =
new org.apache.myfaces.config.impl.digester.elements.ClientBehaviorRenderer();
cbr.setRendererType(facesBehaviorRenderer.rendererType());