org.eclipse.persistence.jaxb.ValidationXMLReader Maven / Gradle / Ivy
Show all versions of eclipselink Show documentation
/*******************************************************************************
* Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Marcel Valovy - initial API and implementation
* Dmitry Kornilov - BeanValidationHelper refactoring
* Miroslav Kos - BeanValidationHelper refactoring
******************************************************************************/
package org.eclipse.persistence.jaxb;
import java.io.IOException;
import java.io.InputStream;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.eclipse.persistence.exceptions.BeanValidationException;
import org.eclipse.persistence.internal.helper.XMLHelper;
import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
import org.eclipse.persistence.internal.security.PrivilegedGetContextClassLoader;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
* Detects external Bean Validation configuration.
*
* Strategy:
* 1. Parse validation.xml, looking for a constraints-file reference.
* 2. For each reference, if file is found, parses the constraints file and puts all classes declared under
* {@literal } into
* {@link org.eclipse.persistence.jaxb.BeanValidationHelper#constraintsOnClasses}
* with value {@link Boolean#TRUE}.
*
* This class contains resources-burdening instance fields (e.g. SAXParser) and as such was designed to be instantiated
* once (make the instance BOUNDED) and have {@link #call()} method called on that instance once.
*
* Not suitable for singleton (memory burden). The method #parse() will be invoked only once per class load of this
* class. After that the instance and all its fields should be made collectible by GC.
*
* @author Marcel Valovy
* @author Dmitry Kornilov
* @author Miroslav Kos
* @since 2.6
*/
public class ValidationXMLReader implements Callable