Search in sources :

Example 1 with MetadataTarget

use of jakarta.faces.view.facelets.MetadataTarget in project myfaces by apache.

the class CompositeMetaRulesetImpl method getMetaData.

private static Map<String, MetadataTarget> getMetaData() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Map<String, Object> applicationMap = facesContext.getExternalContext().getApplicationMap();
    Map<String, MetadataTarget> metadata = (Map<String, MetadataTarget>) applicationMap.computeIfAbsent(METADATA_KEY, k -> new HashMap<>());
    return metadata;
}
Also used : MetadataImpl(org.apache.myfaces.view.facelets.tag.MetadataImpl) MetaRule(jakarta.faces.view.facelets.MetaRule) MetaRuleset(jakarta.faces.view.facelets.MetaRuleset) TagException(jakarta.faces.view.facelets.TagException) Tag(jakarta.faces.view.facelets.Tag) HashMap(java.util.HashMap) FacesContext(jakarta.faces.context.FacesContext) Assert(org.apache.myfaces.core.api.shared.lang.Assert) BeanPropertyTagRule(org.apache.myfaces.view.facelets.tag.BeanPropertyTagRule) Logger(java.util.logging.Logger) NullMetadata(org.apache.myfaces.view.facelets.tag.NullMetadata) MetadataTargetImpl(org.apache.myfaces.view.facelets.tag.MetadataTargetImpl) TagAttribute(jakarta.faces.view.facelets.TagAttribute) IntrospectionException(java.beans.IntrospectionException) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) List(java.util.List) BeanInfo(java.beans.BeanInfo) Map(java.util.Map) PropertyDescriptorUtils(org.apache.myfaces.core.api.shared.lang.PropertyDescriptorUtils) Metadata(jakarta.faces.view.facelets.Metadata) LambdaMetadataTargetImpl(org.apache.myfaces.view.facelets.tag.LambdaMetadataTargetImpl) MetadataTarget(jakarta.faces.view.facelets.MetadataTarget) FacesContext(jakarta.faces.context.FacesContext) MetadataTarget(jakarta.faces.view.facelets.MetadataTarget) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with MetadataTarget

use of jakarta.faces.view.facelets.MetadataTarget in project myfaces by apache.

the class CompositeMetaRulesetImpl method finish.

@Override
public Metadata finish() {
    assert !_rules.isEmpty();
    if (!_attributes.isEmpty()) {
        MetadataTarget target = this._getMetadataTarget();
        int ruleEnd = _rules.size() - 1;
        // now iterate over attributes
        for (Map.Entry<String, TagAttribute> entry : _attributes.entrySet()) {
            Metadata data = null;
            int i = ruleEnd;
            // First loop is always safe
            do {
                MetaRule rule = _rules.get(i);
                data = rule.applyRule(entry.getKey(), entry.getValue(), target);
                i--;
            } while (data == null && i >= 0);
            if (data == null) {
                if (log.isLoggable(Level.SEVERE)) {
                    log.severe(entry.getValue() + " Unhandled by MetaTagHandler for type " + _type.getName());
                }
            } else {
                _mappers.add(data);
            }
        }
    }
    if (_mappers.isEmpty()) {
        return NullMetadata.INSTANCE;
    } else {
        return new MetadataImpl(_mappers.toArray(new Metadata[_mappers.size()]));
    }
}
Also used : MetadataImpl(org.apache.myfaces.view.facelets.tag.MetadataImpl) MetadataTarget(jakarta.faces.view.facelets.MetadataTarget) NullMetadata(org.apache.myfaces.view.facelets.tag.NullMetadata) Metadata(jakarta.faces.view.facelets.Metadata) TagAttribute(jakarta.faces.view.facelets.TagAttribute) HashMap(java.util.HashMap) Map(java.util.Map) MetaRule(jakarta.faces.view.facelets.MetaRule)

Example 3 with MetadataTarget

use of jakarta.faces.view.facelets.MetadataTarget in project myfaces by apache.

the class CompositeMetaRulesetImpl method _getBaseMetadataTarget.

private MetadataTarget _getBaseMetadataTarget() {
    Map<String, MetadataTarget> metadata = getMetaData();
    String key = _type.getName();
    MetadataTarget meta = metadata.get(key);
    if (meta == null) {
        try {
            if (PropertyDescriptorUtils.isUseLambdaMetafactory(FacesContext.getCurrentInstance().getExternalContext())) {
                meta = new LambdaMetadataTargetImpl(_type);
            } else {
                meta = new MetadataTargetImpl(_type);
            }
        } catch (IntrospectionException e) {
            throw new TagException(_tag, "Error Creating TargetMetadata", e);
        }
        metadata.put(key, meta);
    }
    return meta;
}
Also used : LambdaMetadataTargetImpl(org.apache.myfaces.view.facelets.tag.LambdaMetadataTargetImpl) MetadataTarget(jakarta.faces.view.facelets.MetadataTarget) TagException(jakarta.faces.view.facelets.TagException) IntrospectionException(java.beans.IntrospectionException) MetadataTargetImpl(org.apache.myfaces.view.facelets.tag.MetadataTargetImpl) LambdaMetadataTargetImpl(org.apache.myfaces.view.facelets.tag.LambdaMetadataTargetImpl)

Example 4 with MetadataTarget

use of jakarta.faces.view.facelets.MetadataTarget in project myfaces by apache.

the class MetaRulesetImpl method finish.

@Override
public Metadata finish() {
    MetadataTarget target = null;
    assert !_rules.isEmpty();
    if (!_attributes.isEmpty()) {
        target = this._getMetadataTarget();
        int ruleEnd = _rules.size() - 1;
        // now iterate over attributes
        for (Map.Entry<String, TagAttribute> entry : _attributes.entrySet()) {
            Metadata data = null;
            int i = ruleEnd;
            // First loop is always safe
            do {
                MetaRule rule = _rules.get(i);
                data = rule.applyRule(entry.getKey(), entry.getValue(), target);
                i--;
            } while (data == null && i >= 0);
            if (data == null) {
                if (log.isLoggable(Level.SEVERE)) {
                    log.severe(entry.getValue() + " Unhandled by MetaTagHandler for type " + _type.getName());
                }
            } else {
                _mappers.add(data);
            }
        }
    }
    if (_passthroughAttributes.length > 0 && _passthroughRules.size() > 0) {
        if (target == null) {
            target = this._getMetadataTarget();
        }
        int ruleEnd = _passthroughRules.size() - 1;
        // now iterate over attributes
        for (TagAttribute passthroughAttribute : _passthroughAttributes) {
            Metadata data = null;
            int i = ruleEnd;
            // First loop is always safe
            do {
                MetaRule rule = _passthroughRules.get(i);
                data = rule.applyRule(passthroughAttribute.getLocalName(), passthroughAttribute, target);
                i--;
            } while (data == null && i >= 0);
            if (data == null) {
                if (log.isLoggable(Level.SEVERE)) {
                    log.severe(passthroughAttribute.getLocalName() + " Unhandled by MetaTagHandler for type " + _type.getName());
                }
            } else {
                _mappers.add(data);
            }
        }
    }
    if (_mappers.isEmpty()) {
        return NullMetadata.INSTANCE;
    } else {
        return new MetadataImpl(_mappers.toArray(new Metadata[_mappers.size()]));
    }
}
Also used : MetadataTarget(jakarta.faces.view.facelets.MetadataTarget) Metadata(jakarta.faces.view.facelets.Metadata) TagAttribute(jakarta.faces.view.facelets.TagAttribute) HashMap(java.util.HashMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) MetaRule(jakarta.faces.view.facelets.MetaRule)

Example 5 with MetadataTarget

use of jakarta.faces.view.facelets.MetadataTarget in project myfaces by apache.

the class MetaRulesetImpl method _getMetadataTarget.

private MetadataTarget _getMetadataTarget() {
    Map<String, MetadataTarget> metadata = getMetaData();
    String metaKey = _type.getName();
    MetadataTarget meta = metadata.get(metaKey);
    if (meta == null) {
        try {
            if (PropertyDescriptorUtils.isUseLambdaMetafactory(FacesContext.getCurrentInstance().getExternalContext())) {
                meta = new LambdaMetadataTargetImpl(_type);
            } else {
                meta = new MetadataTargetImpl(_type);
            }
        } catch (IntrospectionException e) {
            throw new TagException(_tag, "Error Creating TargetMetadata", e);
        }
        synchronized (metadata) {
            // Use a synchronized block to ensure proper operation on concurrent use cases.
            // This is a racy single check, because initialization over the same class could happen
            // multiple times, but the same result is always calculated. The synchronized block
            // just ensure thread-safety, because only one thread will modify the cache map
            // at the same time.
            metadata.put(metaKey, meta);
        }
    }
    return meta;
}
Also used : MetadataTarget(jakarta.faces.view.facelets.MetadataTarget) TagException(jakarta.faces.view.facelets.TagException) IntrospectionException(java.beans.IntrospectionException)

Aggregations

MetadataTarget (jakarta.faces.view.facelets.MetadataTarget)7 MetaRule (jakarta.faces.view.facelets.MetaRule)4 Metadata (jakarta.faces.view.facelets.Metadata)4 TagAttribute (jakarta.faces.view.facelets.TagAttribute)4 TagException (jakarta.faces.view.facelets.TagException)4 IntrospectionException (java.beans.IntrospectionException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 WeakHashMap (java.util.WeakHashMap)2 LambdaMetadataTargetImpl (org.apache.myfaces.view.facelets.tag.LambdaMetadataTargetImpl)2 MetadataImpl (org.apache.myfaces.view.facelets.tag.MetadataImpl)2 MetadataTargetImpl (org.apache.myfaces.view.facelets.tag.MetadataTargetImpl)2 NullMetadata (org.apache.myfaces.view.facelets.tag.NullMetadata)2 FacesContext (jakarta.faces.context.FacesContext)1 MetaRuleset (jakarta.faces.view.facelets.MetaRuleset)1 Tag (jakarta.faces.view.facelets.Tag)1 BeanInfo (java.beans.BeanInfo)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Level (java.util.logging.Level)1