[OFBiz] SVN: r5058 - trunk/framework/entity/src/org/ofbiz/entity

jonesde at svn.ofbiz.org jonesde at svn.ofbiz.org
Tue May 31 03:20:08 EDT 2005


Author: jonesde
Date: 2005-05-31 02:20:04 -0500 (Tue, 31 May 2005)
New Revision: 5058

Modified:
   trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java
Log:
Added code to getBytes to support both byte[] and ByteWrapper, and if it is not null and is anything else will throw an exception to that effect; based on question/request from Brett Palmer

Modified: trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java
===================================================================
--- trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java	2005-05-31 04:32:38 UTC (rev 5057)
+++ trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java	2005-05-31 07:20:04 UTC (rev 5058)
@@ -561,9 +561,20 @@
     }
 
     public byte[] getBytes(String name) {
-        ByteWrapper wrapper = (ByteWrapper) get(name);
-        if (wrapper == null) return null;
-        return wrapper.getBytes();
+        Object value = get(name);
+        if (value == null) {
+            return null;
+        }
+        if (value instanceof ByteWrapper) {
+            ByteWrapper wrapper = (ByteWrapper) value;
+            if (wrapper == null) return null;
+            return wrapper.getBytes();
+        }
+        if (value instanceof byte[]) {
+            return (byte[]) value;
+        }
+        // uh-oh, this shouldn't happen...
+        throw new IllegalArgumentException("In call to getBytes the value is not a supported type, should be byte[] or ByteWrapper, is: " + value.getClass().getName());
     }
 
     /** Checks a resource bundle for a value for this field using the entity name, the field name



More information about the Svn mailing list