
com.sap.cloud.sdk.frameworks.eclipselink.BeanValidationSessionCustomizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eclipselink-javaee Show documentation
Show all versions of eclipselink-javaee Show documentation
Framework adaptation for EclipseLink and Java EE.
The newest version!
/*
* Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.
*/
package com.sap.cloud.sdk.frameworks.eclipselink;
import javax.validation.Validation;
import javax.validation.ValidatorFactory;
import org.eclipse.persistence.config.SessionCustomizer;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.sessions.Session;
/**
* Session customizer for bootstrapping bean validation.
*/
public class BeanValidationSessionCustomizer implements SessionCustomizer
{
@Override
public void customize( final Session session )
{
bootstrapBeanValidation(session);
}
/**
* Bootstraps bean validation independent of existing settings in persistence.xml.
*/
private void bootstrapBeanValidation( final Session session )
{
final ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
final BeanValidationListener listener = new BeanValidationListener(factory, null, null, null);
for( final ClassDescriptor descriptor : session.getProject().getOrderedDescriptors() ) {
if( descriptor.isDescriptorTypeNormal() ) {
descriptor.getEventManager().addInternalListener(listener);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy