You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2013/07/15 20:56:03 UTC

svn commit: r1503421 - /cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java

Author: dkulp
Date: Mon Jul 15 18:56:02 2013
New Revision: 1503421

URL: http://svn.apache.org/r1503421
Log:
Fix compile failure

Modified:
    cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java

Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java?rev=1503421&r1=1503420&r2=1503421&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java (original)
+++ cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java Mon Jul 15 18:56:02 2013
@@ -43,6 +43,8 @@ public class Extension {
     protected Collection<String> namespaces = new ArrayList<String>();
     protected Object args[];
     protected Object obj;
+    protected boolean optional;
+    protected boolean notFound;
     
     public Extension() {
     }
@@ -70,6 +72,14 @@ public class Extension {
         intf = ext.intf;
         classloader = ext.classloader;
         args = ext.args;
+        optional = ext.optional;
+    }
+    
+    public void setOptional(boolean b) {
+        optional = b;
+    }
+    public boolean isOptional() {
+        return optional;
     }
     
     public String getName() {
@@ -114,6 +124,7 @@ public class Extension {
     
     public void setClassname(String i) {
         clazz = null;
+        notFound = false;
         className = i;
     }
        
@@ -123,6 +134,7 @@ public class Extension {
 
     public void setInterfaceName(String i) {
         interfaceName = i;
+        notFound = false;
     }
 
     public boolean isDeferred() {
@@ -141,40 +153,53 @@ public class Extension {
         args = a;
     }
     
-    public Class<?> getClassObject(ClassLoader cl) {
-        if (clazz == null) {
-            if (classloader != null) {
-                try {
-                    clazz = classloader.loadClass(className);
-                    return clazz;
-                } catch (ClassNotFoundException nex) {
-                    //ignore, fall into the stuff below
-                }
-            }                
+    private  Class<?> tryClass(String name, ClassLoader cl) {
+        if (classloader != null) {
+            try {
+                return classloader.loadClass(name);
+            } catch (Throwable nex) {
+                //ignore, fall into the stuff below
+            }
+        }                
+        try {
+            return cl.loadClass(name);
+        } catch (Throwable ex) {
             try {
-                clazz = cl.loadClass(className);
-            } catch (ClassNotFoundException ex) {
-                try {
-                    // using the extension classloader as a fallback
-                    clazz = this.getClass().getClassLoader().loadClass(className);
-                } catch (ClassNotFoundException nex) {
-                    throw new ExtensionException(new Message("PROBLEM_LOADING_EXTENSION_CLASS", LOG, className), nex);
+                // using the extension classloader as a fallback
+                return this.getClass().getClassLoader().loadClass(name);
+            } catch (Throwable nex) {
+                notFound = true;
+                if (!optional) {
+                    throw new ExtensionException(new Message("PROBLEM_LOADING_EXTENSION_CLASS", LOG, name), nex);
                 }
             }
         }
+        return null;
+    }
+    
+    public Class<?> getClassObject(ClassLoader cl) {
+        if (notFound) {
+            return null;
+        }
+        if (clazz == null) {
+            clazz = tryClass(className, cl);
+        }
         return clazz;
     }
     public Object load(ClassLoader cl, Bus b) {
         Class<?> cls = getClassObject(cl);
         try {
+            if (notFound) {
+                return null;
+            }
             try {
                 //if there is a Bus constructor, use it.
                 if (b != null && args == null) {
-                    Constructor con = cls.getConstructor(Bus.class);
+                    Constructor<?> con = cls.getConstructor(Bus.class);
                     obj = con.newInstance(b);
                     return obj;
                 } else if (b != null && args != null) {
-                    Constructor con;
+                    Constructor<?> con;
                     boolean noBus = false;
                     try {
                         con = cls.getConstructor(Bus.class, Object[].class);
@@ -189,7 +214,7 @@ public class Extension {
                     }
                     return obj;                    
                 } else if (args != null) {
-                    Constructor con = cls.getConstructor(Object[].class);
+                    Constructor<?> con = cls.getConstructor(Object[].class);
                     obj = con.newInstance(args);
                     return obj;                    
                 }
@@ -237,31 +262,11 @@ public class Extension {
         return obj;
     }
     
-    public Class loadInterface(ClassLoader cl) {
-        if (intf != null) {
+    public Class<?> loadInterface(ClassLoader cl) {
+        if (intf != null || notFound) {
             return intf;
         }
-        if (classloader != null) {
-            try {
-                intf = classloader.loadClass(interfaceName);
-                if (intf != null) {
-                    return intf;
-                }
-            } catch (ClassNotFoundException nex) {
-                //ignore, fall into the stuff below
-            }
-        }                
-
-        try {
-            intf = cl.loadClass(interfaceName);
-        } catch (ClassNotFoundException ex) {
-            try {
-                // using the extension classloader as a fallback
-                intf = this.getClass().getClassLoader().loadClass(interfaceName);
-            } catch (ClassNotFoundException nex) {
-                throw new ExtensionException(nex);
-            }
-        }
+        intf = tryClass(interfaceName, cl);
         return intf;
     }