public static RuntimeDelegate getInstance()

in geronimo-jaxrs_1.1_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java [67:151]


    public static RuntimeDelegate getInstance() {
        if (delegate != null) {
            return delegate;
        }

        // cannot synchronize on any instance so synchronize on class
        synchronized (RuntimeDelegate.class) {
            if (delegate != null) {
                return delegate;
            }

            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

            // try META-INF/services/javax.ws.rs.ext.RuntimeDelegate
            try {
                // check the META-INF/services definitions, and return it if
                // we find something.
                Object service = ProviderLocator.getService(RuntimeDelegate.class.getName(), RuntimeDelegate.class, classLoader);
                if (service != null) {
                    delegate = (RuntimeDelegate)service;
                    return delegate;
                }
            } catch (Exception ex) {
                // ignore any errors, try additional creation methods
            } catch (Error ex) {
                // ignore any errors, try additional creation methods
            }

            String className = null;

            try {
                // try to read from $java.home/lib/jaxrpc.properties
                className =  ProviderLocator.lookupByJREPropertyFile("lib" + File.separator + "jaxrpc.properties", RuntimeDelegate.class.getName());
                if (className != null) {
                    Class<?> delegateClass = ProviderLocator.loadClass(className,
                        RuntimeDelegate.class, classLoader);
                    delegate = (RuntimeDelegate)delegateClass.newInstance();
                    return delegate;
                }
            } catch (IOException e) {
                // do nothing
            } catch (ClassNotFoundException e) {
                // do nothing
            } catch (InstantiationException e) {
                // do nothing
            } catch (IllegalAccessException e) {
                // do nothing
            }

            // try system property
            try {
                className = System.getProperty("javax.ws.rs.ext.RuntimeDelegate");
            } catch (SecurityException e) {
                // do nothing
            }

            // if the system property is null or empty go ahead and use the
            // default implementation class name

            if (className == null || "".equals(className)) {
                // dunno which should be the default. this might be interesting
                // for OSGi purposes later to somehow set the
                // "current implementation" to be the current default. dunno if
                // spec allows for that
                className = "org.apache.wink.common.internal.runtime.RuntimeDelegateImpl";
            }

            try {
                Class<?> delegateClass = ProviderLocator.loadClass(className,
                    RuntimeDelegate.class, classLoader);
                delegate = (RuntimeDelegate)delegateClass.newInstance();
                return delegate;
            } catch (ClassNotFoundException e1) {
                // do nothing
            } catch (SecurityException e) {
                // do nothing
            } catch (InstantiationException e) {
                // do nothing
            } catch (IllegalAccessException e) {
                // do nothing
            }

            throw new RuntimeException("Unable to create jax-rs RuntimeDelegate");
        }
    }