private static SSLSocketFactory createJava14SSLSocketFactory(SSLTrustManager[] tm)
            throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException,
            IllegalAccessException {
        /*
         * The code below does the following:
         * TrustManagerJava14Wrapper[] tmWrappers = TrustManagerJava14Wrapper.wrap(tm);
         * javax.net.ssl.SSLContext context = javax.net.ssl.SSLContext.getInstance("SSL");
         * context.init(null, tmWrappers, null);
         * SSLSocketFactory socketFactory = context.getSocketFactory();
         */

        Class<?> stringClass = String.class;
        Class<?> contextClass = Class.forName("javax.net.ssl.SSLContext");
        Class<?> keyManagerClass = Class.forName("javax.net.ssl.KeyManager");
        Class<?> keyManagerArrayClass = java.lang.reflect.Array.newInstance(keyManagerClass, 0).getClass();
        Class<?> trustManagerClass = Class.forName("javax.net.ssl.TrustManager");
        Class<?> trustManagerArrayClass = java.lang.reflect.Array.newInstance(trustManagerClass, 0)
                .getClass();
        Class<?> secureRandomClass = java.security.SecureRandom.class;

        Method getInstanceMethod = contextClass.getMethod("getInstance", new Class[] { stringClass });
        Method initMethod = contextClass.getMethod("init", new Class[] { keyManagerArrayClass,
                trustManagerArrayClass, secureRandomClass });
        Method getSocketFactoryMethod = contextClass.getMethod("getSocketFactory", (Class[]) null);

        Class.forName("javax.net.ssl.X509TrustManager"); // check for availability
        TrustManagerJava14Wrapper[] tmWrappers = TrustManagerJava14Wrapper.wrap(tm);

        String protocol = SSLIRCConnection.protocol;
        Object context = getInstanceMethod.invoke(null, new Object[] { protocol });
        initMethod.invoke(context, new Object[] { null, tmWrappers, null });
        Object socketFactory = getSocketFactoryMethod.invoke(context, (Object[]) null);

        return (SSLSocketFactory) socketFactory;
    }