avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1156803 - in /avro/trunk: CHANGES.txt lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumReader.java
Date Thu, 11 Aug 2011 20:14:23 GMT
Author: cutting
Date: Thu Aug 11 20:14:22 2011
New Revision: 1156803

URL: http://svn.apache.org/viewvc?rev=1156803&view=rev
Log:
AVRO-873. Java: Permit passing classloader to SpecificDatumReader.  Contributed by Michael
Armbrust.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumReader.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1156803&r1=1156802&r2=1156803&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu Aug 11 20:14:22 2011
@@ -32,6 +32,9 @@ Avro 1.6.0 (unreleased)
     metadata.  Also link top-level pom.xml to lang/java.
     (Jan Prach via cutting)
 
+    AVRO-873. Java: Permit passing classloader to SpecificDatumReader.
+    (Michael Armbrust via cutting)
+
   BUG FIXES
 
     AVRO-824. Java: Fix usage message of BinaryFragmentToJsonTool.

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java?rev=1156803&r1=1156802&r2=1156803&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java Thu
Aug 11 20:14:22 2011
@@ -38,7 +38,15 @@ public class SpecificData extends Generi
 
   private static final SpecificData INSTANCE = new SpecificData();
 
-  protected SpecificData() {}
+  private final ClassLoader classLoader;
+
+  /** For subclasses.  Applications normally use {@link SpecificData#get()}. */
+  protected SpecificData() { this(SpecificData.class.getClassLoader()); }
+
+  /** Construct with a specific classloader. */
+  public SpecificData(ClassLoader classLoader) {
+    this.classLoader = classLoader;
+  }
   
   /** Return the singleton instance. */
   public static SpecificData get() { return INSTANCE; }
@@ -71,7 +79,7 @@ public class SpecificData extends Generi
       Class c = classCache.get(name);
       if (c == null) {
         try {
-          c = Class.forName(getClassName(schema));
+          c = classLoader.loadClass(getClassName(schema));
         } catch (ClassNotFoundException e) {
           c = NO_CLASS;
         }

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumReader.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumReader.java?rev=1156803&r1=1156802&r2=1156803&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumReader.java
(original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumReader.java
Thu Aug 11 20:14:22 2011
@@ -44,14 +44,19 @@ public class SpecificDatumReader<T> exte
     this(writer, reader, SpecificData.get());
   }
 
-  protected SpecificDatumReader(Schema writer, Schema reader,
-                                SpecificData data) {
+  /** Construct given writer's schema, reader's schema, and a {@link
+   * SpecificData}. */
+  public SpecificDatumReader(Schema writer, Schema reader,
+                             SpecificData data) {
     super(writer, reader, data);
   }
 
+  /** Return the contained {@link SpecificData}. */
+  public SpecificData getSpecificData() { return (SpecificData)getData(); }
+
   @Override
   protected Object newRecord(Object old, Schema schema) {
-    Class c = SpecificData.get().getClass(schema);
+    Class c = getSpecificData().getClass(schema);
     if (c == null) return super.newRecord(old, schema); // punt to generic
     return (c.isInstance(old) ? old : newInstance(c, schema));
   }
@@ -59,14 +64,14 @@ public class SpecificDatumReader<T> exte
   @Override
   @SuppressWarnings("unchecked")
   protected Object createEnum(String symbol, Schema schema) {
-    Class c = SpecificData.get().getClass(schema);
+    Class c = getSpecificData().getClass(schema);
     if (c == null) return super.createEnum(symbol, schema); // punt to generic
     return Enum.valueOf(c, symbol);
   }
 
   @Override
   protected Object createFixed(Object old, Schema schema) {
-    Class c = SpecificData.get().getClass(schema);
+    Class c = getSpecificData().getClass(schema);
     if (c == null) return super.createFixed(old, schema); // punt to generic
     return c.isInstance(old) ? old : newInstance(c, schema);
   }



Mime
View raw message