cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1544947 - in /cayenne/main/trunk: cayenne-di/src/main/java/org/apache/cayenne/di/ cayenne-di/src/main/java/org/apache/cayenne/di/spi/ cayenne-server/src/main/java/org/apache/cayenne/map/ cayenne-server/src/main/java/org/apache/cayenne/util/
Date Sun, 24 Nov 2013 08:50:28 GMT
Author: aadamchik
Date: Sun Nov 24 08:50:28 2013
New Revision: 1544947

URL: http://svn.apache.org/r1544947
Log:
CAY-1887 Move class loading under Di, differentiate between Cayenne and application classes

(also supporting for 'void' primitive type)

Modified:
    cayenne/main/trunk/cayenne-di/src/main/java/org/apache/cayenne/di/AdhocObjectFactory.java
    cayenne/main/trunk/cayenne-di/src/main/java/org/apache/cayenne/di/spi/DefaultAdhocObjectFactory.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/map/ObjEntity.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/util/Util.java

Modified: cayenne/main/trunk/cayenne-di/src/main/java/org/apache/cayenne/di/AdhocObjectFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-di/src/main/java/org/apache/cayenne/di/AdhocObjectFactory.java?rev=1544947&r1=1544946&r2=1544947&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-di/src/main/java/org/apache/cayenne/di/AdhocObjectFactory.java
(original)
+++ cayenne/main/trunk/cayenne-di/src/main/java/org/apache/cayenne/di/AdhocObjectFactory.java
Sun Nov 24 08:50:28 2013
@@ -33,6 +33,14 @@ public interface AdhocObjectFactory {
     <T> T newInstance(Class<? super T> superType, String className);
 
     /**
+     * Returns a Java class loaded using ClassLoader returned from
+     * {@link #getClassLoader(String)} for a given class name.
+     * 
+     * @since 3.2
+     */
+    Class<?> getJavaClass(String className);
+
+    /**
      * Returns a ClassLoader appropriate for loading a given resource. Resource
      * path should be compatible with Class.getResource(..) and such, i.e. the
      * path component separator should be slash, not dot.

Modified: cayenne/main/trunk/cayenne-di/src/main/java/org/apache/cayenne/di/spi/DefaultAdhocObjectFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-di/src/main/java/org/apache/cayenne/di/spi/DefaultAdhocObjectFactory.java?rev=1544947&r1=1544946&r2=1544947&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-di/src/main/java/org/apache/cayenne/di/spi/DefaultAdhocObjectFactory.java
(original)
+++ cayenne/main/trunk/cayenne-di/src/main/java/org/apache/cayenne/di/spi/DefaultAdhocObjectFactory.java
Sun Nov 24 08:50:28 2013
@@ -48,12 +48,7 @@ public class DefaultAdhocObjectFactory i
             throw new NullPointerException("Null className");
         }
 
-        Class<T> type;
-        try {
-            type = (Class<T>) getJavaClass(className);
-        } catch (ClassNotFoundException e) {
-            throw new DIRuntimeException("Invalid class %s of type %s", e, className, superType.getName());
-        }
+        Class<T> type = (Class<T>) getJavaClass(className);
 
         if (!superType.isAssignableFrom(type)) {
             throw new DIRuntimeException("Class %s is not assignable to %s", className, superType.getName());
@@ -93,12 +88,13 @@ public class DefaultAdhocObjectFactory i
         return classLoader;
     }
 
-    public Class<?> getJavaClass(String className) throws ClassNotFoundException {
+    @Override
+    public Class<?> getJavaClass(String className) {
 
         // is there a better way to get array class from string name?
 
         if (className == null) {
-            throw new ClassNotFoundException("Null class name");
+            throw new NullPointerException("Null class name");
         }
 
         ClassLoader classLoader = getClassLoader(className.replace('.', '/'));
@@ -125,6 +121,8 @@ public class DefaultAdhocObjectFactory i
                     return Float.TYPE;
                 } else if ("boolean".equals(className)) {
                     return Boolean.TYPE;
+                } else if ("void".equals(className)) {
+                    return Void.TYPE;
                 }
                 // try inner class often specified with "." instead of $
                 else {
@@ -139,7 +137,7 @@ public class DefaultAdhocObjectFactory i
                     }
                 }
 
-                throw e;
+                throw new DIRuntimeException("Invalid class: %s", e, className);
             }
 
             if (className.length() < 3) {
@@ -167,7 +165,11 @@ public class DefaultAdhocObjectFactory i
                 return boolean[].class;
             }
 
-            return Class.forName("[L" + className + ";", true, classLoader);
+            try {
+                return Class.forName("[L" + className + ";", true, classLoader);
+            } catch (ClassNotFoundException e1) {
+                throw new DIRuntimeException("Invalid class: %s", e1, className);
+            }
         }
     }
 }

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/map/ObjEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/map/ObjEntity.java?rev=1544947&r1=1544946&r2=1544947&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/map/ObjEntity.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/map/ObjEntity.java
Sun Nov 24 08:50:28 2013
@@ -34,6 +34,7 @@ import org.apache.cayenne.CayenneRuntime
 import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.ConfigurationNodeVisitor;
 import org.apache.cayenne.dba.TypesMapping;
+import org.apache.cayenne.di.AdhocObjectFactory;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionException;
 import org.apache.cayenne.exp.ExpressionFactory;
@@ -281,8 +282,10 @@ public class ObjEntity extends Entity im
      * Returns a non-null class name. For generic entities with no class
      * specified explicitly, default DataMap superclass is used, and if it is
      * not set - CayenneDataObject is used.
+     * 
+     * @since 3.2
      */
-    String getJavaClassName() {
+   public  String getJavaClassName() {
         String name = getClassName();
 
         if (name == null && getDataMap() != null) {
@@ -303,7 +306,12 @@ public class ObjEntity extends Entity im
      * Casts any thrown exceptions into CayenneRuntimeException.
      * 
      * @since 1.2
+     * @deprecated since 3.2 this method based on statically defined class
+     *             loading algorithm is not going to work in environments like
+     *             OSGi. {@link AdhocObjectFactory} should be used as it can
+     *             provide the environment-specific class loading policy. 
      */
+    @Deprecated
     public Class<?> getJavaClass() {
         String name = getJavaClassName();
 

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/util/Util.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/util/Util.java?rev=1544947&r1=1544946&r2=1544947&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/util/Util.java (original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/util/Util.java Sun
Nov 24 08:50:28 2013
@@ -502,11 +502,16 @@ public class Util {
     }
 
     /**
-     * Creates a Java class, handling regular class names as well as single-dimensional
-     * arrays and primitive types.
-     *
+     * Creates a Java class, handling regular class names as well as
+     * single-dimensional arrays and primitive types.
+     * 
      * @since 1.2
+     * @deprecated since 3.2 this method based on statically defined class
+     *             loading algorithm is not going to work in environments like
+     *             OSGi. {@link AdhocObjectFactory} should be used as it can
+     *             provide the environment-specific class loading policy.
      */
+    @Deprecated
     public static Class<?> getJavaClass(String className) throws ClassNotFoundException
{
         return objectFactory.getJavaClass(className);
     }



Mime
View raw message