cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r595829 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/
Date Fri, 16 Nov 2007 21:17:58 GMT
Author: aadamchik
Date: Fri Nov 16 13:17:57 2007
New Revision: 595829

URL: http://svn.apache.org/viewvc?rev=595829&view=rev
Log:
java5 cleanup

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ByteOrCharArrayFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/CalendarType.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/DefaultType.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/EnumType.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/EnumTypeFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ExtendedTypeFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ExtendedTypeMap.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/SubclassTypeFactory.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ByteOrCharArrayFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ByteOrCharArrayFactory.java?rev=595829&r1=595828&r2=595829&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ByteOrCharArrayFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ByteOrCharArrayFactory.java
Fri Nov 16 13:17:57 2007
@@ -33,11 +33,11 @@
         this.map = map;
     }
 
-    public ExtendedType getType(Class objectClass) {
+    public ExtendedType getType(Class<?> objectClass) {
 
         if (objectClass.isArray()) {
 
-            Class elementType = objectClass.getComponentType();
+            Class<?> elementType = objectClass.getComponentType();
 
             if (Character.class.isAssignableFrom(elementType)) {
                 // can't use "getRegisteredType" as it causes infinite recursion

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/CalendarType.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/CalendarType.java?rev=595829&r1=595828&r2=595829&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/CalendarType.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/CalendarType.java
Fri Nov 16 13:17:57 2007
@@ -37,11 +37,11 @@
  * @since 3.0
  * @author Andrus Adamchik
  */
-public class CalendarType implements ExtendedType {
+public class CalendarType<T extends Calendar> implements ExtendedType {
 
-    protected Class calendarClass;
+    protected Class<T> calendarClass;
 
-    public CalendarType(Class calendarClass) {
+    public CalendarType(Class<T> calendarClass) {
         if (calendarClass == null) {
             throw new IllegalArgumentException("Null calendar class");
         }
@@ -113,7 +113,7 @@
                 val = rs.getTime(index);
                 break;
             default:
-                // here the driver can "surpirse" us
+                // here the driver can "surprise" us
                 // check the type of returned value...
                 Object object = rs.getObject(index);
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/DefaultType.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/DefaultType.java?rev=595829&r1=595828&r2=595829&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/DefaultType.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/DefaultType.java
Fri Nov 16 13:17:57 2007
@@ -37,15 +37,15 @@
  */
 public class DefaultType extends AbstractType {
 
-    private static final Map readMethods = new HashMap();
-    private static final Map procReadMethods = new HashMap();
+    private static final Map<String, Method> readMethods = new HashMap<String, Method>();
+    private static final Map<String, Method> procReadMethods = new HashMap<String,
Method>();
     private static Method readObjectMethod;
     private static Method procReadObjectMethod;
 
     static {
         try {
-            Class rsClass = ResultSet.class;
-            Class[] paramTypes = new Class[] {
+            Class<?> rsClass = ResultSet.class;
+            Class<?>[] paramTypes = new Class[] {
                 Integer.TYPE
             };
             readMethods.put(TypesMapping.JAVA_LONG, rsClass.getMethod(
@@ -94,7 +94,7 @@
             readObjectMethod = rsClass.getMethod("getObject", paramTypes);
 
             // init procedure read methods
-            Class csClass = CallableStatement.class;
+            Class<?> csClass = CallableStatement.class;
             procReadMethods.put(TypesMapping.JAVA_LONG, csClass.getMethod(
                     "getLong",
                     paramTypes));
@@ -145,8 +145,10 @@
         }
     }
 
-    /** Returns an Iterator of supported default Java classes (as Strings) */
-    public static Iterator defaultTypes() {
+    /** 
+     * Returns an Iterator over the names of supported default Java classes.
+     */
+    public static Iterator<String> defaultTypes() {
         return readMethods.keySet().iterator();
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/EnumType.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/EnumType.java?rev=595829&r1=595828&r2=595829&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/EnumType.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/EnumType.java
Fri Nov 16 13:17:57 2007
@@ -39,12 +39,12 @@
  * @since 1.2
  * @author Andrus Adamchik
  */
-public class EnumType implements ExtendedType {
+public class EnumType<T extends Enum<T>> implements ExtendedType {
 
-    protected Class enumClass;
+    protected Class<T> enumClass;
     protected Object[] values;
 
-    public EnumType(Class enumClass) {
+    public EnumType(Class<T> enumClass) {
         if (enumClass == null) {
             throw new IllegalArgumentException("Null enum class");
         }
@@ -93,7 +93,7 @@
 
         if (value instanceof Enum) {
 
-            Enum e = (Enum) value;
+            Enum<?> e = (Enum<?>) value;
 
             if (TypesMapping.isNumeric(type)) {
                 statement.setInt(pos, e.ordinal());

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/EnumTypeFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/EnumTypeFactory.java?rev=595829&r1=595828&r2=595829&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/EnumTypeFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/EnumTypeFactory.java
Fri Nov 16 13:17:57 2007
@@ -18,51 +18,21 @@
  ****************************************************************/
 package org.apache.cayenne.access.types;
 
-import java.lang.reflect.Constructor;
-
-import org.apache.cayenne.util.Util;
-
 /**
- * ExtendedTypeFactory for handling JDK 1.5 Enums. Gracefully handles JDK 1.4 environment.
+ * ExtendedTypeFactory for handling JDK 1.5 Enums.
  * 
  * @since 3.0
  * @author Andrus Adamchik
  */
 class EnumTypeFactory implements ExtendedTypeFactory {
 
-    private Constructor enumTypeConstructor;
-
-    EnumTypeFactory() {
-
-        // see if we can support enums
-        try {
-            Class enumTypeClass = Util
-                    .getJavaClass("org.apache.cayenne.access.types.EnumType");
-            enumTypeConstructor = enumTypeClass.getConstructor(new Class[] {
-                Class.class
-            });
-        }
-        catch (Throwable th) {
-            // no enums support... either Java 1.4 or Cayenne 1.5 extensions are absent
-        }
-    }
-
-    public ExtendedType getType(Class objectClass) {
-        if (enumTypeConstructor == null) {
-            return null;
-        }
-
-        try {
-            // load EnumType via reflection as the source has to stay JDK 1.4 compliant
-            ExtendedType type = (ExtendedType) enumTypeConstructor
-                    .newInstance(new Object[] {
-                        objectClass
-                    });
-
-            return type;
+    @SuppressWarnings("all")
+    public ExtendedType getType(Class<?> objectClass) {
+        
+        if(objectClass.isEnum()) {
+            return new EnumType(objectClass);
         }
-        catch (Throwable th) {
-            // ignore exceptions...
+        else {
             return null;
         }
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ExtendedTypeFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ExtendedTypeFactory.java?rev=595829&r1=595828&r2=595829&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ExtendedTypeFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ExtendedTypeFactory.java
Fri Nov 16 13:17:57 2007
@@ -31,5 +31,5 @@
      * Returns ExtendedType instance that can handle a given object class. May return null
      * indicating that the class can not be handled.
      */
-    ExtendedType getType(Class objectClass);
+    ExtendedType getType(Class<?> objectClass);
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ExtendedTypeMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ExtendedTypeMap.java?rev=595829&r1=595828&r2=595829&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ExtendedTypeMap.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/ExtendedTypeMap.java
Fri Nov 16 13:17:57 2007
@@ -40,10 +40,10 @@
 // and 1% write, so probably should use ConcurrentHashMap once we switch to Java 5.
 public class ExtendedTypeMap {
 
-    static final Map classesForPrimitives;
+    static final Map<String, String> classesForPrimitives;
 
     static {
-        classesForPrimitives = new HashMap();
+        classesForPrimitives = new HashMap<String, String>();
         classesForPrimitives.put("long", Long.class.getName());
         classesForPrimitives.put("double", Double.class.getName());
         classesForPrimitives.put("byte", Byte.class.getName());
@@ -53,21 +53,21 @@
         classesForPrimitives.put("int", Integer.class.getName());
     }
 
-    protected final Map typeMap;
+    protected final Map<String, ExtendedType> typeMap;
     protected DefaultType defaultType;
 
-    Collection extendedTypeFactories;
+    Collection<ExtendedTypeFactory> extendedTypeFactories;
 
     // standard type factories registered by Cayenne that are consulted after the user
     // factories.
-    Collection internalTypeFactories;
+    Collection<ExtendedTypeFactory> internalTypeFactories;
 
     /**
      * Creates new ExtendedTypeMap, populating it with default JDBC-compatible types. If
      * JDK version is at least 1.5, also loads support for enumerated types.
      */
     public ExtendedTypeMap() {
-        this.typeMap = new HashMap();
+        this.typeMap = new HashMap<String, ExtendedType>();
         this.defaultType = new DefaultType();
 
         initDefaultTypes();
@@ -82,9 +82,9 @@
         registerType(new VoidType());
 
         // register default types
-        Iterator it = DefaultType.defaultTypes();
+        Iterator<String> it = DefaultType.defaultTypes();
         while (it.hasNext()) {
-            registerType(new DefaultType((String) it.next()));
+            registerType(new DefaultType(it.next()));
         }
     }
 
@@ -95,7 +95,7 @@
      * @since 3.0
      */
     protected void initDefaultFactories() {
-        internalTypeFactories = new ArrayList(3);
+        internalTypeFactories = new ArrayList<ExtendedTypeFactory>(3);
         internalTypeFactories.add(new EnumTypeFactory());
         internalTypeFactories.add(new ByteOrCharArrayFactory(this));
 
@@ -109,7 +109,7 @@
      * 
      * @since 1.2
      */
-    public Collection getFactories() {
+    public Collection<ExtendedTypeFactory> getFactories() {
         return extendedTypeFactories != null ? Collections
                 .unmodifiableCollection(extendedTypeFactories) : Collections.EMPTY_SET;
     }
@@ -131,7 +131,7 @@
         }
 
         if (extendedTypeFactories == null) {
-            extendedTypeFactories = new ArrayList();
+            extendedTypeFactories = new ArrayList<ExtendedTypeFactory>();
         }
 
         extendedTypeFactories.add(factory);
@@ -192,7 +192,7 @@
      */
     public ExtendedType getRegisteredType(String javaClassName) {
 
-        String nonPrimitive = (String) classesForPrimitives.get(javaClassName);
+        String nonPrimitive = classesForPrimitives.get(javaClassName);
         if (nonPrimitive != null) {
             javaClassName = nonPrimitive;
         }
@@ -215,7 +215,7 @@
     }
 
     ExtendedType getExplictlyRegisteredType(String className) {
-        return (ExtendedType) typeMap.get(className);
+        return typeMap.get(className);
     }
 
     /**
@@ -223,7 +223,7 @@
      * default type. It is guaranteed that this method returns a non-null ExtendedType
      * instance.
      */
-    public ExtendedType getRegisteredType(Class javaClass) {
+    public ExtendedType getRegisteredType(Class<?> javaClass) {
         String name = null;
 
         if (javaClass.isArray()) {
@@ -249,13 +249,13 @@
      * Returns array of Java class names supported by Cayenne for JDBC mapping.
      */
     public String[] getRegisteredTypeNames() {
-        Set keys = typeMap.keySet();
+        Set<String> keys = typeMap.keySet();
         int len = keys.size();
         String[] types = new String[len];
 
-        Iterator it = keys.iterator();
+        Iterator<String> it = keys.iterator();
         for (int i = 0; i < len; i++) {
-            types[i] = (String) it.next();
+            types[i] = it.next();
         }
 
         return types;
@@ -285,7 +285,7 @@
             return null;
         }
 
-        Class typeClass;
+        Class<?> typeClass;
         try {
             typeClass = Util.getJavaClass(className);
         }
@@ -296,10 +296,7 @@
 
         // lookup in user factories first
         if (extendedTypeFactories != null) {
-
-            Iterator it = extendedTypeFactories.iterator();
-            while (it.hasNext()) {
-                ExtendedTypeFactory factory = (ExtendedTypeFactory) it.next();
+            for (ExtendedTypeFactory factory : extendedTypeFactories) {
 
                 ExtendedType type = factory.getType(typeClass);
                 if (type != null) {
@@ -310,10 +307,7 @@
 
         // lookup in internal factories
 
-        Iterator it = internalTypeFactories.iterator();
-        while (it.hasNext()) {
-            ExtendedTypeFactory factory = (ExtendedTypeFactory) it.next();
-
+        for (ExtendedTypeFactory factory : internalTypeFactories) {
             ExtendedType type = factory.getType(typeClass);
             if (type != null) {
                 return type;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java?rev=595829&r1=595828&r2=595829&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java
Fri Nov 16 13:17:57 2007
@@ -41,7 +41,7 @@
         this.map = map;
     }
 
-    public ExtendedType getType(Class objectClass) {
+    public ExtendedType getType(Class<?> objectClass) {
 
         if (Serializable.class.isAssignableFrom(objectClass)) {
 
@@ -71,9 +71,9 @@
      */
     final class SerializableType extends ExtendedTypeDecorator {
 
-        private Class javaClass;
+        private Class<?> javaClass;
 
-        SerializableType(Class javaClass, ExtendedType bytesType) {
+        SerializableType(Class<?> javaClass, ExtendedType bytesType) {
             super(bytesType);
             this.javaClass = javaClass;
         }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/SubclassTypeFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/SubclassTypeFactory.java?rev=595829&r1=595828&r2=595829&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/SubclassTypeFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/types/SubclassTypeFactory.java
Fri Nov 16 13:17:57 2007
@@ -30,7 +30,7 @@
 class SubclassTypeFactory implements ExtendedTypeFactory {
 
     private ExtendedType type;
-    private Class javaClass;
+    private Class<?> javaClass;
 
     SubclassTypeFactory(ExtendedType type) {
         this.type = type;
@@ -50,7 +50,7 @@
         }
     }
 
-    public ExtendedType getType(Class objectClass) {
+    public ExtendedType getType(Class<?> objectClass) {
 
         if ((javaClass != null) && javaClass.isAssignableFrom(objectClass)) {
             return type;



Mime
View raw message