abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r441226 - /incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java
Date Thu, 07 Sep 2006 20:58:00 GMT
Author: jmsnell
Date: Thu Sep  7 13:57:59 2006
New Revision: 441226

URL: http://svn.apache.org/viewvc?view=rev&rev=441226
Log:
Some API improvements for Java 1.5 to reduce the number of explicit casts necessary. 
No effect for Java 1.4.2 users

Modified:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java?view=diff&rev=441226&r1=441225&r2=441226
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java
Thu Sep  7 13:57:59 2006
@@ -50,7 +50,7 @@
    * no instance is configured, the default class name will be used.  Returns
    * null if no instance can be created.
    */
-  public static Object newInstance(String id, String _default, Abdera abdera) {
+  public static <T>T newInstance(String id, String _default, Abdera abdera) {
     return locate(id, _default, abdera);
   }
 
@@ -112,11 +112,11 @@
     return Thread.currentThread().getContextClassLoader();
   }
   
-  public static Object locate(
+  public static <T>T locate(
     String id, 
     String _default, 
     Abdera abdera) {
-      Object object = locate(id, abdera);
+      T object = locate(id, abdera);
       if (object == null && _default != null) {
         object = locateInstance(getClassLoader(), _default, abdera);
       }
@@ -126,9 +126,10 @@
   /**
    * Locate a class instance for the given id
    */
-  public static Object locate(String id, Abdera abdera) {
-    Object service = checkAbderaConfiguration(id, abdera);
-    return ((service != null) ? service : checkMetaInfServices(id, abdera));
+  @SuppressWarnings("unchecked")
+  public static <T>T locate(String id, Abdera abdera) {
+    T service = checkAbderaConfiguration(id, abdera);
+    return ((service != null) ? service : (T)checkMetaInfServices(id, abdera));
   }
   
   @SuppressWarnings("unchecked")
@@ -186,13 +187,14 @@
     return null;
   }
   
-  private static Object checkAbderaConfiguration(String id, Abdera abdera) {
+  @SuppressWarnings("unchecked")
+  private static <T>T checkAbderaConfiguration(String id, Abdera abdera) {
     String s = abdera.getConfiguration().getConfigurationOption(id);
-    return (s != null) ? locateInstance(getClassLoader(), id, abdera) : null;
+    return (s != null) ? (T)locateInstance(getClassLoader(), id, abdera) : null;
   }
   
-  private static Object checkMetaInfServices(String id, Abdera abdera) {
-    Object object = null;
+  private static <T>T checkMetaInfServices(String id, Abdera abdera) {
+    T object = null;
     String sid = "META-INF/services/" + id;
     ClassLoader loader = getClassLoader();
     BufferedReader buf = null;



Mime
View raw message