cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r919314 - in /cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs: core/Response.java ext/RuntimeDelegate.java
Date Fri, 05 Mar 2010 06:49:09 GMT
Author: bluk
Date: Fri Mar  5 06:49:09 2010
New Revision: 919314

URL: http://svn.apache.org/viewvc?rev=919314&view=rev
Log:
Fix RuntimeDelegate

Modified:
    cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java
    cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java

Modified: cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java?rev=919314&r1=919313&r2=919314&view=diff
==============================================================================
--- cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java (original)
+++ cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java Fri Mar
 5 06:49:09 2010
@@ -89,12 +89,13 @@
             "Bad Request"), CONFLICT(Family.CLIENT_ERROR, 409, "Conflict"), CREATED(
             Family.SUCCESSFUL, 201, "Created"), FORBIDDEN(Family.CLIENT_ERROR, 403, "Forbidden"),
GONE(
             Family.CLIENT_ERROR, 410, "Gone"), INTERNAL_SERVER_ERROR(Family.SERVER_ERROR,
500,
-            "Internal Server Error"), MOVED_PERMANENTLY(Family.REDIRECTION, 303, "See Other"),
NO_CONTENT(
-            Family.SUCCESSFUL, 204, "No Content"), NOT_ACCEPTABLE(Family.CLIENT_ERROR, 406,
-            "Not Acceptable"), NOT_FOUND(Family.CLIENT_ERROR, 404, "Not Found"), NOT_MODIFIED(
-            Family.REDIRECTION, 304, "Not Modified"), OK(Family.SUCCESSFUL, 200, "OK"), PRECONDITION_FAILED(
-            Family.CLIENT_ERROR, 412, "Precondition Failed"), SEE_OTHER(Family.REDIRECTION,
303,
-            "See Other"), SERVICE_UNAVAILABLE(Family.SERVER_ERROR, 503, "Service Unavailable"),
TEMPORARY_REDIRECT(
+            "Internal Server Error"), MOVED_PERMANENTLY(Family.REDIRECTION, 301,
+            "Moved Permanently"), NO_CONTENT(Family.SUCCESSFUL, 204, "No Content"), NOT_ACCEPTABLE(
+            Family.CLIENT_ERROR, 406, "Not Acceptable"), NOT_FOUND(Family.CLIENT_ERROR, 404,
+            "Not Found"), NOT_MODIFIED(Family.REDIRECTION, 304, "Not Modified"), OK(
+            Family.SUCCESSFUL, 200, "OK"), PRECONDITION_FAILED(Family.CLIENT_ERROR, 412,
+            "Precondition Failed"), SEE_OTHER(Family.REDIRECTION, 303, "See Other"), SERVICE_UNAVAILABLE(
+            Family.SERVER_ERROR, 503, "Service Unavailable"), TEMPORARY_REDIRECT(
             Family.REDIRECTION, 307, "Temporary Redirect"), UNAUTHORIZED(Family.CLIENT_ERROR,
401,
             "Unauthorized"), UNSUPPORTED_MEDIA_TYPE(Family.CLIENT_ERROR, 415,
             "Unsupported Media Type"), ;

Modified: cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java?rev=919314&r1=919313&r2=919314&view=diff
==============================================================================
--- cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java
(original)
+++ cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java
Fri Mar  5 06:49:09 2010
@@ -19,11 +19,22 @@
 
 package javax.ws.rs.ext;
 
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.util.Properties;
+
+import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.Variant;
 
 public abstract class RuntimeDelegate {
+    public static final String JAXRS_RUNTIME_DELEGATE_PROPERTY = "javax.ws.rs.ext.RuntimeDelegate";
 
     public static interface HeaderDelegate<T> {
         public T fromString(String str);
@@ -31,9 +42,7 @@
         public String toString(T obj);
     }
 
-    public static RuntimeDelegate getInstance() {
-        return null;
-    }
+    public abstract <T> T createEndpoint(Application app, java.lang.Class<T>
type);
 
     public abstract UriBuilder createUriBuilder();
 
@@ -43,4 +52,171 @@
 
     public abstract Response.ResponseBuilder createResponseBuilder();
 
+    private static volatile RuntimeDelegate delegate;
+
+    public static void setInstance(RuntimeDelegate delegate) throws SecurityException {
+        RuntimeDelegate.delegate = delegate;
+    }
+
+    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;
+            }
+
+            String className = null;
+            InputStream is = null;
+
+            // try META-INF/services/javax.ws.rs.ext.RuntimeDelegate
+            try {
+                is =
+                    Thread.currentThread().getContextClassLoader()
+                        .getResourceAsStream("META-INF/services/javax.ws.rs.ext.RuntimeDelegate");
+                if (is != null) {
+                    BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+                    try {
+                        className = br.readLine();
+                        if (className != null && !"".equals(className)) {
+                            Class<?> delegateClass = null;
+                            try {
+                                delegateClass =
+                                    Class.forName(className, true, Thread.currentThread()
+                                        .getContextClassLoader());
+                                delegate = (RuntimeDelegate)delegateClass.newInstance();
+                                return delegate;
+                            } catch (ClassNotFoundException e) {
+                                // try Class.forName
+                                try {
+                                    delegateClass = Class.forName(className);
+                                    delegate = (RuntimeDelegate)delegateClass.newInstance();
+                                    return delegate;
+                                } catch (ClassNotFoundException e1) {
+                                    // do nothing
+                                }
+                            }
+                        }
+                    } catch (IOException e) {
+                        // do nothing
+                    } catch (InstantiationException e) {
+                        // do nothing
+                    } catch (IllegalAccessException e) {
+                        // do nothing
+                    }
+                }
+            } catch (SecurityException e) {
+                // do nothing
+            } catch (UnsupportedEncodingException e) {
+                // do nothing
+            } finally {
+                if (is != null) {
+                    try {
+                        is.close();
+                    } catch (IOException e) {
+                        // do nothing
+                    }
+                    is = null;
+                }
+            }
+
+            // try ${java.home}/lib/jaxrs.properties
+            try {
+                is = new FileInputStream(System.getProperty("java.home") + "/lib/jaxrs.properties");
+                if (is != null) {
+                    Properties props = new Properties();
+                    try {
+                        props.load(is);
+                        className = props.getProperty("javax.ws.rs.ext.RuntimeDelegate");
+                        if (className != null && !"".equals(className)) {
+                            Class<?> delegateClass;
+                            try {
+                                delegateClass =
+                                    Class.forName(className, true, Thread.currentThread()
+                                        .getContextClassLoader());
+                                delegate = (RuntimeDelegate)delegateClass.newInstance();
+                                return delegate;
+                            } catch (ClassNotFoundException e) {
+                                // try Class.forName
+                                try {
+                                    delegateClass = Class.forName(className);
+                                    delegate = (RuntimeDelegate)delegateClass.newInstance();
+                                    return delegate;
+                                } catch (ClassNotFoundException e1) {
+                                    // do nothing
+                                }
+                            }
+                        }
+                    } catch (IOException e) {
+                        // do nothing
+                    } catch (InstantiationException e) {
+                        // do nothing
+                    } catch (IllegalAccessException e) {
+                        // do nothing
+                    }
+                }
+            } catch (SecurityException e) {
+                // do nothing
+            } catch (FileNotFoundException e) {
+                // do nothing
+            } finally {
+                if (is != null) {
+                    try {
+                        is.close();
+                    } catch (IOException e) {
+                        // do nothing
+                    }
+                    is = null;
+                }
+            }
+
+            // 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";
+            }
+            Class<?> delegateClass;
+            try {
+                try {
+                    delegateClass =
+                        Class.forName(className, true, Thread.currentThread()
+                            .getContextClassLoader());
+                    delegate = (RuntimeDelegate)delegateClass.newInstance();
+                    return delegate;
+                } catch (ClassNotFoundException e) {
+                    // try Class.forName
+                    try {
+                        delegateClass = Class.forName(className);
+                        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
+            }
+
+            return delegate;
+        }
+    }
 }



Mime
View raw message