Search in sources :

Example 1 with PrivilegedGetSystemProperty

use of org.eclipse.persistence.internal.security.PrivilegedGetSystemProperty in project eclipselink by eclipse-ee4j.

the class PersistenceUnitProcessor method getArchiveFactory.

public static ArchiveFactory getArchiveFactory(ClassLoader loader, Map properties) {
    if (ARCHIVE_FACTORY != null) {
        return ARCHIVE_FACTORY;
    }
    ArchiveFactory factory = null;
    String factoryClassName = PrivilegedAccessHelper.shouldUsePrivilegedAccess() ? AccessController.doPrivileged(new PrivilegedGetSystemProperty(SystemProperties.ARCHIVE_FACTORY)) : System.getProperty(SystemProperties.ARCHIVE_FACTORY);
    if (factoryClassName == null && properties != null) {
        Object name = properties.get(SystemProperties.ARCHIVE_FACTORY);
        if (name instanceof String) {
            factoryClassName = (String) name;
        }
    }
    if (factoryClassName == null) {
        return new ArchiveFactoryImpl();
    } else {
        try {
            if (loader != null) {
                Class<?> archiveClass = loader.loadClass(factoryClassName);
                if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
                    try {
                        factory = (ArchiveFactory) AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(archiveClass));
                    } catch (PrivilegedActionException exception) {
                        throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(factoryClassName, exception);
                    }
                } else {
                    factory = (ArchiveFactory) PrivilegedAccessHelper.newInstanceFromClass(archiveClass);
                }
            }
        } catch (ClassNotFoundException cnfe) {
            throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(factoryClassName, cnfe);
        } catch (IllegalAccessException iae) {
            throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(factoryClassName, iae);
        } catch (InstantiationException ie) {
            throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(factoryClassName, ie);
        }
    }
    return factory;
}
Also used : ArchiveFactory(org.eclipse.persistence.jpa.ArchiveFactory) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedGetSystemProperty(org.eclipse.persistence.internal.security.PrivilegedGetSystemProperty)

Aggregations

PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedGetSystemProperty (org.eclipse.persistence.internal.security.PrivilegedGetSystemProperty)1 PrivilegedNewInstanceFromClass (org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass)1 ArchiveFactory (org.eclipse.persistence.jpa.ArchiveFactory)1