cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r607231 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/
Date Fri, 28 Dec 2007 13:09:54 GMT
Author: aadamchik
Date: Fri Dec 28 05:09:53 2007
New Revision: 607231

URL: http://svn.apache.org/viewvc?rev=607231&view=rev
Log:
generics, other jdk 1.5 related refactoring

Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ConverterFactory15.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/BaseToManyProperty.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/CallbackOnEntity.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/CallbackOnListener.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ConverterFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/EnumConverter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/SingletonFaultFactory.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/BaseToManyProperty.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/BaseToManyProperty.java?rev=607231&r1=607230&r2=607231&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/BaseToManyProperty.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/BaseToManyProperty.java
Fri Dec 28 05:09:53 2007
@@ -71,7 +71,7 @@
 
         // Now do the rest of the normal handling (regardless of whether it was
         // flattened or not)
-        Collection collection = (Collection) readProperty(source);
+        Collection<Object> collection = (Collection<Object>) readProperty(source);
         collection.add(target);
 
         if (setReverse) {
@@ -87,7 +87,7 @@
 
         // Now do the rest of the normal handling (regardless of whether it was
         // flattened or not)
-        Collection collection = (Collection) readProperty(source);
+        Collection<Object> collection = (Collection<Object>) readProperty(source);
         collection.remove(target);
 
         if (target != null && setReverse) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/CallbackOnEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/CallbackOnEntity.java?rev=607231&r1=607230&r2=607231&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/CallbackOnEntity.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/CallbackOnEntity.java
Fri Dec 28 05:09:53 2007
@@ -36,14 +36,14 @@
 
     private Method callbackMethod;
 
-    CallbackOnEntity(Class objectClass, String methodName)
+    CallbackOnEntity(Class<?> objectClass, String methodName)
             throws IllegalArgumentException {
         this.callbackMethod = findMethod(objectClass, methodName);
     }
 
     public void performCallback(Object entity) {
         try {
-            callbackMethod.invoke(entity, null);
+            callbackMethod.invoke(entity, (Object[]) null);
         }
         catch (Exception e) {
             throw new CayenneRuntimeException("Error invoking entity callback method "
@@ -51,7 +51,7 @@
         }
     }
 
-    private Method findMethod(Class objectClass, String methodName)
+    private Method findMethod(Class<?> objectClass, String methodName)
             throws IllegalArgumentException {
         Method[] methods = objectClass.getDeclaredMethods();
         for (int i = 0; i < methods.length; i++) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/CallbackOnListener.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/CallbackOnListener.java?rev=607231&r1=607230&r2=607231&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/CallbackOnListener.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/CallbackOnListener.java
Fri Dec 28 05:09:53 2007
@@ -42,7 +42,7 @@
         this(listener, methodName, Object.class);
     }
 
-    CallbackOnListener(Object listener, String methodName, Class entityType)
+    CallbackOnListener(Object listener, String methodName, Class<?> entityType)
             throws IllegalArgumentException {
 
         if (listener == null) {
@@ -67,17 +67,17 @@
         }
     }
 
-    private Method findMethod(Class objectClass, String methodName, Class entityType)
+    private Method findMethod(Class<?> objectClass, String methodName, Class<?>
entityType)
             throws IllegalArgumentException {
 
         Method[] methods = objectClass.getDeclaredMethods();
         for (int i = 0; i < methods.length; i++) {
             if (methodName.equals(methods[i].getName())) {
 
-                // must be non-static, void, with a single arg assinable to entity type
+                // must be non-static, void, with a single arg assignable to entity type
                 // JPA spec also requires it to be non-final, but we don't care
                 int modifiers = methods[i].getModifiers();
-                Class[] parameters = methods[i].getParameterTypes();
+                Class<?>[] parameters = methods[i].getParameterTypes();
                 if (!Modifier.isStatic(modifiers)
                         && Void.TYPE.isAssignableFrom(methods[i].getReturnType())
                         && parameters.length == 1

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ConverterFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ConverterFactory.java?rev=607231&r1=607230&r2=607231&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ConverterFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ConverterFactory.java
Fri Dec 28 05:09:53 2007
@@ -24,8 +24,6 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.cayenne.util.Util;
-
 /**
  * A factory of property type converters.
  * 
@@ -34,30 +32,30 @@
  */
 class ConverterFactory {
 
-    private static final String FACTORY_CLASS_JDK15 = "org.apache.cayenne.reflect.ConverterFactory15";
+    static final ConverterFactory factory = new ConverterFactory();
 
-    static final ConverterFactory factory = createFactory();
-    static Map converters;
+    private Map<String, Converter> converters;
+    private EnumConverter enumConveter = new EnumConverter();
 
     static final Converter noopConverter = new Converter() {
 
-        Object convert(Object object, Class type) {
+        Object convert(Object object, Class<?> type) {
             return object;
         }
     };
 
-    static {
+    private ConverterFactory() {
 
         Converter stringConverter = new Converter() {
 
-            Object convert(Object object, Class type) {
+            Object convert(Object object, Class<?> type) {
                 return object != null ? object.toString() : null;
             }
         };
 
         Converter booleanConverter = new Converter() {
 
-            Object convert(Object object, Class type) {
+            Object convert(Object object, Class<?> type) {
                 if (object == null) {
                     return type.isPrimitive() ? Boolean.FALSE : null;
                 }
@@ -74,7 +72,7 @@
 
         Converter intConverter = new Converter() {
 
-            Object convert(Object object, Class type) {
+            Object convert(Object object, Class<?> type) {
                 if (object == null) {
                     return type.isPrimitive() ? Integer.valueOf(0) : null;
                 }
@@ -89,7 +87,7 @@
 
         Converter byteConverter = new Converter() {
 
-            Object convert(Object object, Class type) {
+            Object convert(Object object, Class<?> type) {
                 if (object == null) {
                     return type.isPrimitive() ? Byte.valueOf((byte) 0) : null;
                 }
@@ -104,7 +102,7 @@
 
         Converter shortConverter = new Converter() {
 
-            Object convert(Object object, Class type) {
+            Object convert(Object object, Class<?> type) {
                 if (object == null) {
                     return type.isPrimitive() ? Short.valueOf((short) 0) : null;
                 }
@@ -119,7 +117,7 @@
 
         Converter charConverter = new Converter() {
 
-            Object convert(Object object, Class type) {
+            Object convert(Object object, Class<?> type) {
                 if (object == null) {
                     return type.isPrimitive() ? Character.valueOf((char) 0) : null;
                 }
@@ -135,7 +133,7 @@
 
         Converter doubleConverter = new Converter() {
 
-            Object convert(Object object, Class type) {
+            Object convert(Object object, Class<?> type) {
                 if (object == null) {
                     return type.isPrimitive() ? new Double(0.0d) : null;
                 }
@@ -150,7 +148,7 @@
 
         Converter floatConverter = new Converter() {
 
-            Object convert(Object object, Class type) {
+            Object convert(Object object, Class<?> type) {
                 if (object == null) {
                     return type.isPrimitive() ? new Float(0.0f) : null;
                 }
@@ -165,7 +163,7 @@
 
         Converter bigDecimalConverter = new Converter() {
 
-            Object convert(Object object, Class type) {
+            Object convert(Object object, Class<?> type) {
                 if (object == null) {
                     return null;
                 }
@@ -180,7 +178,7 @@
 
         Converter bigIntegerConverter = new Converter() {
 
-            Object convert(Object object, Class type) {
+            Object convert(Object object, Class<?> type) {
                 if (object == null) {
                     return null;
                 }
@@ -195,7 +193,7 @@
 
         // TODO: byte[] converter...
 
-        converters = new HashMap();
+        converters = new HashMap<String, Converter>();
 
         converters.put(Boolean.class.getName(), booleanConverter);
         converters.put("boolean", booleanConverter);
@@ -224,26 +222,17 @@
         converters.put(String.class.getName(), stringConverter);
     }
 
-    static ConverterFactory createFactory() {
-        try {
-            // sniff JDK 1.5
-            Class.forName("java.lang.StringBuilder");
-
-            Class factoryClass = Util.getJavaClass(FACTORY_CLASS_JDK15);
-            return (ConverterFactory) factoryClass.newInstance();
-        }
-        catch (Throwable th) {
-            // .. jdk 1.4
-            return new ConverterFactory();
-        }
-    }
-
-    Converter getConverter(Class type) {
+    Converter getConverter(Class<?> type) {
         if (type == null) {
             throw new IllegalArgumentException("Null type");
         }
 
-        Converter c = (Converter) converters.get(type.getName());
+        // check for enum BEFORE super call, as it will return a noop converter
+        if (type.isEnum()) {
+            return enumConveter;
+        }
+
+        Converter c = converters.get(type.getName());
         return c != null ? c : noopConverter;
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/EnumConverter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/EnumConverter.java?rev=607231&r1=607230&r2=607231&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/EnumConverter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/EnumConverter.java
Fri Dec 28 05:09:53 2007
@@ -26,6 +26,7 @@
 class EnumConverter extends Converter {
 
     @Override
+    @SuppressWarnings("unchecked")
     Object convert(Object object, Class type) {
 
         if (object == null) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/SingletonFaultFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/SingletonFaultFactory.java?rev=607231&r1=607230&r2=607231&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/SingletonFaultFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/SingletonFaultFactory.java
Fri Dec 28 05:09:53 2007
@@ -36,7 +36,7 @@
     protected Fault toOneFault = new ToOneFault();
     protected Fault listFault = new ToManyListFault();
     protected Fault setFault = new ToManySetFault();
-    protected Map mapFaults = new HashMap();
+    protected Map<Accessor, Fault> mapFaults = new HashMap<Accessor, Fault>();
 
     public Fault getCollectionFault() {
         return listFault;
@@ -48,7 +48,7 @@
     
     public Fault getMapFault(Accessor mapKeyAccessor) {
         synchronized (mapFaults) {
-            Fault fault = (Fault) mapFaults.get(mapKeyAccessor);
+            Fault fault = mapFaults.get(mapKeyAccessor);
 
             if (fault == null) {
                 fault = new ToManyMapFault(mapKeyAccessor);



Mime
View raw message