Issue #2778 fix bug in JUtilHandler.py where size was None. Also made the registrations an OrderedDict for falling back so we can order how we fall back

Change-Id: I31120de5d206ddcade83e2c5455742deb1d6598a

Former-commit-id: dccb819738 [formerly 4252e58992] [formerly dccb819738 [formerly 4252e58992] [formerly 1ecc4541cf [formerly a1ca74f1b2ad0176ab38e4a41bb7df62e06cc0c1]]]
Former-commit-id: 1ecc4541cf
Former-commit-id: 5ce022cc1e [formerly f300282a22]
Former-commit-id: 053615e387
This commit is contained in:
Matt Nash 2014-02-07 12:05:41 -06:00
parent ad3939140c
commit 5ad02eb0e3

View file

@ -34,9 +34,12 @@ import JUtil
# Date Ticket# Engineer Description # Date Ticket# Engineer Description
# ------------ ---------- ----------- -------------------------- # ------------ ---------- ----------- --------------------------
# 10/14/13 2250 mnash Initial creation of JUtil handler # 10/14/13 2250 mnash Initial creation of JUtil handler
# 02/06/14 mnash Fixed fallbacks by using OrderedDict,
# fixed exception by declaring a size
# #
# #
from collections import OrderedDict
from java.lang import Integer, Float, Long, Boolean, String, Double, Number from java.lang import Integer, Float, Long, Boolean, String, Double, Number
from java.util import Date from java.util import Date
@ -160,10 +163,10 @@ def _toJavaDate(val):
return Date(long(delta.total_seconds()) * 1000) return Date(long(delta.total_seconds()) * 1000)
# the dict that registers the Python data type to the method for conversion # the dict that registers the Python data type to the method for conversion
pythonBasics = {int:_toJavaInt, float:_toJavaFloat, long:_toJavaLong, bool:_toJavaBoolean, str:_toJavaString, unicode:_toJavaString, datetime.datetime:_toJavaDate} pythonBasics = OrderedDict({int:_toJavaInt, float:_toJavaFloat, long:_toJavaLong, bool:_toJavaBoolean, str:_toJavaString, unicode:_toJavaString, datetime.datetime:_toJavaDate})
# the dict that registers the Java String of type to the method for conversion # the dict that registers the Java String of type to the method for conversion
javaBasics = {'java.lang.Integer':_toPythonInt, 'java.lang.Float':_toPythonFloat, 'java.lang.Double':_toPythonDouble, 'java.lang.Long':_toPythonLong, 'java.lang.Boolean':_toPythonBool, 'java.lang.String':_toPythonString, 'java.util.Date':_toPythonDatetime} javaBasics = OrderedDict({'java.lang.Integer':_toPythonInt, 'java.lang.Float':_toPythonFloat, 'java.lang.Double':_toPythonDouble, 'java.lang.Long':_toPythonLong, 'java.lang.Boolean':_toPythonBool, 'java.lang.String':_toPythonString, 'java.util.Date':_toPythonDatetime})
fallbackBasics = {Number:_toPythonFloat} fallbackBasics = OrderedDict({Number:_toPythonFloat})
''' '''
The following methods will handle Python and Java collection conversion. The following methods will handle Python and Java collection conversion.
''' '''
@ -173,7 +176,6 @@ from java.util import Date
from java.lang.reflect import Array from java.lang.reflect import Array
from java.util import List, Set, Map from java.util import List, Set, Map
from collections import OrderedDict
import jep import jep
# make a jarray to find out if we have that # make a jarray to find out if we have that
@ -247,6 +249,7 @@ def _fromJavaArray(obj, customConverter=None):
Converts from a Java array to a Python list. Converts from a Java array to a Python list.
''' '''
retVal = [] retVal = []
size = Array.getLength(obj)
for i in range(size): for i in range(size):
retVal.append(JUtil.javaObjToPyVal(Array.get(obj, i), customConverter)) retVal.append(JUtil.javaObjToPyVal(Array.get(obj, i), customConverter))
return retVal return retVal
@ -324,9 +327,9 @@ def __toJavaMap(pyDict, jmap):
jmap.put(JUtil.pyValToJavaObj(key), JUtil.pyValToJavaObj(pyDict[key])) jmap.put(JUtil.pyValToJavaObj(key), JUtil.pyValToJavaObj(pyDict[key]))
return jmap return jmap
javaCollections = {'java.util.ArrayList':_toPythonList, 'java.util.Arrays$ArrayList':_toPythonList, 'java.util.Collections$UnmodifiableRandomAccessList':_toPythonTuple, 'java.util.HashMap':_toPythonDict, 'java.util.LinkedHashMap':_toPythonOrderedDict} javaCollections = OrderedDict({'java.util.ArrayList':_toPythonList, 'java.util.Arrays$ArrayList':_toPythonList, 'java.util.Collections$UnmodifiableRandomAccessList':_toPythonTuple, 'java.util.HashMap':_toPythonDict, 'java.util.LinkedHashMap':_toPythonOrderedDict})
pythonCollections = { list:_toJavaList, tuple:_toJavaUnmodifiableList, OrderedDict:_toJavaLinkedMap, dict:_toJavaMap } pythonCollections = OrderedDict({ list:_toJavaList, tuple:_toJavaUnmodifiableList, OrderedDict:_toJavaLinkedMap, dict:_toJavaMap })
fallbackCollections = { List:_toPythonList, Map:_toPythonDict, Set:_toPythonSet } fallbackCollections = OrderedDict({ List:_toPythonList, Map:_toPythonDict, Set:_toPythonSet })
''' '''
Handles other types of Java to Python conversion and back. Handles other types of Java to Python conversion and back.
@ -359,4 +362,4 @@ def _toJavaClass(val):
return val.toJavaObj() return val.toJavaObj()
# registers the data type for conversion to a Java class. # registers the data type for conversion to a Java class.
pythonClasses = {JUtil.JavaWrapperClass:_toJavaClass} pythonClasses = OrderedDict({JUtil.JavaWrapperClass:_toJavaClass})