Skip to content
Permalink
Browse files
simplify MetadataSource initialization with default interface method
  • Loading branch information
mbenson committed Oct 18, 2018
1 parent 1d54c14 commit a52a3aa355e6c34edc9f12e5d886b2ecc7723963
Showing 3 changed files with 11 additions and 9 deletions.
@@ -370,9 +370,7 @@ private void loadAndVerifyUserCustomizations(ConfigurationState configuration) {
};
participantFactory.loadServices(MetadataSource.class)
.forEach(ms -> {
Optional.of(ms).filter(MetadataSource.FactoryDependent.class::isInstance)
.map(MetadataSource.FactoryDependent.class::cast).ifPresent(fd -> fd.setFactory(this));

ms.initialize(this);
ms.process(configuration, getConstraintsCache()::add, addBuilder);
});
}
@@ -20,15 +20,19 @@
import java.util.function.Consumer;

import javax.validation.ConstraintValidator;
import javax.validation.ValidatorFactory;
import javax.validation.spi.ConfigurationState;

import org.apache.bval.jsr.ApacheValidatorFactory;

/**
* Service interface for user metadata customizations.
*/
public interface MetadataSource {
interface FactoryDependent extends MetadataSource {
void setFactory(ValidatorFactory validatorFactory);
/**
* Initialize the {@link MetadataSource}.
* @param validatorFactory
*/
default void initialize(ApacheValidatorFactory validatorFactory) {
}

/**
@@ -51,7 +51,7 @@
* Uses JAXB to parse constraints.xml based on the validation-mapping XML schema.
*/
@Privilizing(@CallTo(Reflection.class))
public class ValidationMappingParser implements MetadataSource.FactoryDependent {
public class ValidationMappingParser implements MetadataSource {
private static final SchemaManager SCHEMA_MANAGER = new SchemaManager.Builder()
.add(XmlBuilder.Version.v10.getId(), "http://jboss.org/xml/ns/javax/validation/mapping",
"META-INF/validation-mapping-1.0.xsd")
@@ -64,8 +64,8 @@ public class ValidationMappingParser implements MetadataSource.FactoryDependent
private ApacheValidatorFactory validatorFactory;

@Override
public void setFactory(ValidatorFactory validatorFactory) {
this.validatorFactory = Validate.notNull(validatorFactory).unwrap(ApacheValidatorFactory.class);
public void initialize(ApacheValidatorFactory validatorFactory) {
this.validatorFactory = Validate.notNull(validatorFactory);
}

@Override

0 comments on commit a52a3aa

Please sign in to comment.