
io.protostuff.compiler.parser.AbstractExtensionRegistry Maven / Gradle / Ivy
package io.protostuff.compiler.parser;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import io.protostuff.compiler.model.Extension;
import io.protostuff.compiler.model.Field;
import io.protostuff.compiler.model.Message;
/**
* @author Kostiantyn Shchepanovskyi
*/
public abstract class AbstractExtensionRegistry implements ExtensionRegistry {
private final ConcurrentMap> fieldCache;
protected AbstractExtensionRegistry() {
fieldCache = new ConcurrentHashMap<>();
}
@Override
public void registerExtension(Extension extension) {
String fullyQualifiedName = extension.getExtendee().getFullyQualifiedName();
fieldCache.remove(fullyQualifiedName);
}
@Override
public Collection getExtensions(Message message) {
String fullyQualifiedName = message.getFullyQualifiedName();
return getExtensions(fullyQualifiedName);
}
@Override
public Map getExtensionFields(String fullMessageName) {
return fieldCache.computeIfAbsent(fullMessageName, messageName -> {
Map map = new HashMap<>();
Collection extensions = getExtensions(messageName);
for (Extension extension : extensions) {
for (Field field : extension.getFields()) {
String key = extension.getNamespace() + field.getName();
map.put(key, field);
}
}
return map;
});
}
@Override
public Map getExtensionFields(Message message) {
String fullyQualifiedName = message.getFullyQualifiedName();
return getExtensionFields(fullyQualifiedName);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy