blob: 17c2c3a4afcab350518ba1f99e6a8f9589c4eb6b [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2008, 2010 Oracle Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Cameron Bateman - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.jsf.facelet.core.internal.registry;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.jst.jsf.common.dom.TagIdentifier;
import org.eclipse.jst.jsf.common.runtime.internal.view.model.common.ComponentPropertyHandler;
import org.eclipse.jst.jsf.common.runtime.internal.view.model.common.ITagAttribute;
import org.eclipse.jst.jsf.common.runtime.internal.view.model.common.ITagAttributeHandler;
import org.eclipse.jst.jsf.common.runtime.internal.view.model.common.TagAttributeHandler;
import org.eclipse.jst.jsf.designtime.internal.view.mapping.ViewMetadataLoader;
import org.eclipse.jst.jsf.designtime.internal.view.mapping.viewmapping.AttributeToPropertyMapping;
import org.eclipse.jst.jsf.designtime.internal.view.model.jsp.IAttributeAdvisor;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib.FaceletTaglibTagAttribute;
import org.eclipse.jst.jsf.facelet.core.internal.tagmodel.FaceletAttribute;
/**
* An attribute advisor that composes multiple strategies for deriving information
* about Facelet tags.
*
* @author cbateman
*
*/
/*package*/ class MetadataAttributeAdvisor implements IAttributeAdvisor
{
private final TagIdentifier _tagId;
private final ViewMetadataLoader _loader;
private List<FaceletTaglibTagAttribute> _attributes;
/**
* @param tagId
* @param loader
* @param attributes
*/
public MetadataAttributeAdvisor(final TagIdentifier tagId,
final ViewMetadataLoader loader, final List<FaceletTaglibTagAttribute> attributes)
{
_tagId = tagId;
_loader = loader;
_attributes = attributes;
}
public ITagAttributeHandler createAttributeHandler(final String name)
throws UnknownAttributeException
{
final AttributeToPropertyMapping mapping = _loader.getAttributeMapping(
_tagId, name);
if (mapping != null)
{
final String customHandler = mapping.getCustomConversionFactoryId();
final boolean isELAllowed = mapping.isElAllowed();
final String propertyName = mapping.getPropertyName();
if (propertyName != null)
{
return new ComponentPropertyHandler(customHandler, name,
isELAllowed, propertyName);
}
return new TagAttributeHandler(customHandler, name, isELAllowed);
}
return new TagAttributeHandler(null, name, false);
}
public Map<String, ? extends ITagAttribute> getAttributes()
{
final Map<String, ITagAttribute> attributes = new HashMap<String, ITagAttribute>();
for (final FaceletTaglibTagAttribute attribute : _attributes)
{
attributes.put(attribute.getName(), new FaceletAttribute(attribute));
}
return Collections.unmodifiableMap(attributes);
}
}