org.infinispan.protostream.config.AnnotationConfig Maven / Gradle / Ivy
package org.infinispan.protostream.config;
import org.infinispan.protostream.AnnotationMetadataCreator;
import org.infinispan.protostream.descriptors.AnnotatedDescriptor;
import org.infinispan.protostream.descriptors.Descriptor;
import org.infinispan.protostream.descriptors.EnumDescriptor;
import org.infinispan.protostream.descriptors.FieldDescriptor;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* @author [email protected]
* @since 2.0
*/
public final class AnnotationConfig {
private final String name;
private final Map attributes;
private final AnnotationMetadataCreator, DescriptorType> annotationMetadataCreator;
private AnnotationConfig(String name, Map attributes, AnnotationMetadataCreator, DescriptorType> annotationMetadataCreator) {
this.name = name;
this.attributes = Collections.unmodifiableMap(attributes);
this.annotationMetadataCreator = annotationMetadataCreator;
}
public String name() {
return name;
}
public Map attributes() {
return attributes;
}
public AnnotationMetadataCreator, DescriptorType> annotationMetadataCreator() {
return annotationMetadataCreator;
}
public static final class Builder {
private final Configuration.Builder parentBuilder;
private String name;
private final Map> attributeBuilders = new HashMap>();
private AnnotationMetadataCreator, DescriptorType> annotationMetadataCreator;
Builder(Configuration.Builder parentBuilder, String name) {
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException("annotation name must not be null or empty");
}
this.name = name;
this.parentBuilder = parentBuilder;
}
public AnnotationAttributeConfig.Builder attribute(String name) {
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException("attribute name must not be null or empty");
}
AnnotationAttributeConfig.Builder annotationAttributeConfigBuilder = new AnnotationAttributeConfig.Builder(this, name);
attributeBuilders.put(name, annotationAttributeConfigBuilder);
return annotationAttributeConfigBuilder;
}
public Builder annotationMetadataCreator(AnnotationMetadataCreator, DescriptorType> annotationMetadataCreator) {
this.annotationMetadataCreator = annotationMetadataCreator;
return this;
}
public AnnotationConfig.Builder messageAnnotation(String annotationName) {
return parentBuilder.messageAnnotation(annotationName);
}
public AnnotationConfig.Builder enumAnnotation(String annotationName) {
return parentBuilder.enumAnnotation(annotationName);
}
public AnnotationConfig.Builder fieldAnnotation(String annotationName) {
return parentBuilder.fieldAnnotation(annotationName);
}
AnnotationConfig buildAnnotationConfig() {
Map attributes = new HashMap(attributeBuilders.size());
for (AnnotationAttributeConfig.Builder attributeBuilder : attributeBuilders.values()) {
AnnotationAttributeConfig annotationAttributeConfig = attributeBuilder.buildAnnotationAttributeConfig();
attributes.put(annotationAttributeConfig.name(), annotationAttributeConfig);
}
return new AnnotationConfig(name, attributes, annotationMetadataCreator);
}
public Configuration build() {
return parentBuilder.build();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy