
com.almworks.jira.structure.api2g.attribute.SimpleAttributeProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of structure-api Show documentation
Show all versions of structure-api Show documentation
Public API for the Structure Plugin for JIRA
package com.almworks.jira.structure.api2g.attribute;
import com.almworks.jira.structure.api.column.AttributeContext;
import com.almworks.jira.structure.api.column.StructureColumnException;
import com.almworks.jira.structure.api2g.attribute.loader.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
// todo problem (STR-504): suppose we register loaders for foo:B, foo:C and we're asked for foo:A
// todo where C can be converted to A, but B can't
// todo we'll return loader foo:B, but should have returned foo:C
public abstract class SimpleAttributeProvider implements AttributeLoaderProvider {
private final Map, AttributeLoader>> myLoaders = new HashMap<>();
// If requested format is not found, we return the first registered loader for the spec ignoring the format
private final Map, AttributeLoader>> myLoadersNormalized = new HashMap<>();
// Call from constructor
protected final void registerLoader(AttributeLoader> loader) {
AttributeSpec> spec = loader.getAttributeSpec();
if (myLoaders.containsKey(spec)) {
throw new IllegalArgumentException("loader with spec " + spec + " is already registered");
}
myLoaders.put(spec, loader);
AttributeSpec> normalizedSpec = normalize(spec);
if (!myLoadersNormalized.containsKey(normalizedSpec)) {
myLoadersNormalized.put(normalizedSpec, loader);
}
}
private static AttributeSpec> normalize(AttributeSpec> attributeSpec) {
return attributeSpec.as(ValueFormat.HTML);
}
@SafeVarargs
protected final void registerCompositeLoader(AttributeSpec spec, AttributeLoader... loaders) {
registerLoader(CompositeAttributeLoader.create(spec, Arrays.asList(loaders)));
}
@Nullable
public synchronized AttributeLoader> createAttributeLoader(AttributeSpec> attributeSpec,
@NotNull AttributeContext context) throws StructureColumnException
{
AttributeLoader> r = myLoaders.get(attributeSpec);
if (r == null) {
attributeSpec = normalize(attributeSpec);
r = myLoadersNormalized.get(attributeSpec);
}
return r;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy