in myfaces-html5-core/src/main/java/org/apache/myfaces/html5/handler/MediaSourcesHandler.java [78:150]
public void apply(FaceletContext faceletContext, UIComponent parent) throws IOException
{
/*
* algo: if this is not disabled and parent is a MediaSourceHolder - get value of 'items' attr - convert the
* value to one of MediaInfo[] or Collection<Info> - add elements of array/collection into parent's MediaInfo
* set
*/
// if this is disabled, don't apply anything
if (this.disabled != null && this.disabled.getBoolean(faceletContext) == true)
{
if (log.isLoggable(Level.FINE))
log.fine("'disabled' is true. handler will not apply anything.");
return;
}
if (!(parent instanceof MediaSourceHolder))
{
if (log.isLoggable(Level.WARNING))
log.warning("parent component " + DebugUtils.getPathToComponent(parent) + " is not a MediaSourceHolder. handler will not apply anything.");
return;
}
MediaSourceHolder msh = (MediaSourceHolder) parent;
if (this.items.isLiteral())
throw new FacesException("'items' attribute of <fx:mediaSources> cannot be literal.");
Object objItems = this.items.getObject(faceletContext);
if (objItems == null)
{
if (log.isLoggable(Level.FINE))
log.fine("'items' is null. continue silently.");
return;
}
if (objItems instanceof MediaInfo[])
{
if (log.isLoggable(Level.FINE))
log.fine("type of 'items' is MediaInfo[]");
MediaInfo[] mediaInfoArr = (MediaInfo[]) objItems;
msh.addMediaInfo(mediaInfoArr);
}
else if (objItems instanceof Collection)
{
if (log.isLoggable(Level.FINE))
log.fine("type of 'items' is Collection<MediaInfo>");
Collection<MediaInfo> mediaInfoCollection = (Collection<MediaInfo>) objItems;
try
{
if (log.isLoggable(Level.FINE))
log.fine("Trying to convert Collection<MediaInfo> to MediaInfo[]");
MediaInfo[] mediaInfoArr = mediaInfoCollection.toArray(new MediaInfo[0]);
msh.addMediaInfo(mediaInfoArr);
}
catch (ArrayStoreException e)
{
// if there is one non-MediaInfo element in the collection,
// we'll fall in here during conversion to array.
throw new FacesException(
"All elements of 'items' attribute of <fx:mediaSources> must be an instance of MediaInfo class.",
e);
}
}
else
{
throw new FacesException(
"'items' attribute of <fx:mediaSources> must be an array or collection of MediaInfo instances. Type of the object provided : "
+ objItems.getClass());
}
}