* @param map
* @return
*/
protected FacesConfigImpl createFacesConfig(Map<Class<? extends Annotation>, Set<Class<?>>> map)
{
FacesConfigImpl facesConfig = new FacesConfigImpl();
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() + ")");
}
String value = comp.value();
if ( value == null ||
(value != null && value.length() <= 0))
{
String simpleName = clazz.getSimpleName();
value = Character.toLowerCase(simpleName.charAt(0)) + simpleName.substring(1);
}
facesConfig.addComponent(value, clazz.getName());
if (comp.createTag())
{
facesConfig.addComponentTagDeclaration(value,
new ComponentTagDeclarationImpl(value,
comp.namespace(), comp.tagName()));
}
}
}
}
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)
{
ConverterImpl converter = new ConverterImpl();
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()
+ ")");
}
String value = val.value();
if ( value == null ||
(value != null && value.length() <= 0))
{
String simpleName = clazz.getSimpleName();
value = Character.toLowerCase(simpleName.charAt(0)) + simpleName.substring(1);
}
facesConfig.addValidator(value, clazz.getName());
if (val.isDefault())
{
ApplicationImpl app = null;
if (facesConfig.getApplications().isEmpty())
{
app = new ApplicationImpl();
}
else
{
app = (ApplicationImpl) facesConfig.getApplications().get(0);
}
app.addDefaultValidatorId(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.RenderKitImpl renderKit =
(org.apache.myfaces.config.impl.digester.elements.RenderKitImpl)
facesConfig.getRenderKit(renderKitId);
if (renderKit == null)
{
renderKit = new org.apache.myfaces.config.impl.digester.elements.RenderKitImpl();
renderKit.setId(renderKitId);
facesConfig.addRenderKit(renderKit);
}
org.apache.myfaces.config.impl.digester.elements.RendererImpl renderer =
new org.apache.myfaces.config.impl.digester.elements.RendererImpl();
renderer.setComponentFamily(rend.componentFamily());