All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cloud.sdk.frameworks.eclipselink.BeanValidationSessionCustomizer Maven / Gradle / Ivy

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