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;
}
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()]));
}
}
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;
}
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()]));
}
}
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;
}
Aggregations