1717from java .lang import RuntimeException
1818from java .lang import String
1919from java .util import Properties
20+ from javax .management import ObjectName
2021
2122from oracle .weblogic .deploy .aliases import TypeUtils
2223from oracle .weblogic .deploy .aliases import VersionException
3031from wlsdeploy .aliases .alias_constants import ATTRIBUTES
3132from wlsdeploy .aliases .alias_constants import COMMA_DELIMITED_STRING
3233from wlsdeploy .aliases .alias_constants import DELIMITED_STRING
34+ from wlsdeploy .aliases .alias_constants import DICTIONARY
3335from wlsdeploy .aliases .alias_constants import JARRAY
3436from wlsdeploy .aliases .alias_constants import JAVA_LANG_BOOLEAN
3537from wlsdeploy .aliases .alias_constants import LIST
3638from wlsdeploy .aliases .alias_constants import LONG
3739from wlsdeploy .aliases .alias_constants import PATH_SEPARATOR_DELIMITED_STRING
40+ from wlsdeploy .aliases .alias_constants import PROPERTIES
3841from wlsdeploy .aliases .alias_constants import PREFERRED_MODEL_TYPE
3942from wlsdeploy .aliases .alias_constants import SECURITY_PROVIDER_FOLDER_PATHS
4043from wlsdeploy .aliases .alias_constants import SECURITY_PROVIDER_MBEAN_NAME_MAP
@@ -626,6 +629,67 @@ def get_number_of_directories_to_strip(desired_path_type, actual_path_type):
626629 return result
627630
628631
632+ def convert_from_type (data_type , value , preferred = None , delimiter = None ):
633+ """
634+ Convert from wlst type
635+ :param data_type: type of data
636+ :param value: value of data
637+ :param preferred: how it should be represented
638+ :param delimiter: for representation
639+ :return: converted type
640+ """
641+
642+ _method_name = 'convert_from_type'
643+ if value is not None and data_type == 'password' :
644+ # The password is an array of bytes coming back from the WLST get() method and only
645+ # java.lang.String() is able to properly convert it to the cipher text string. However,
646+ # we don't really want to return a java.lang.String to the caller so convert that Java
647+ # String back to a Python string...ugly but effective.
648+ new_value = str (String (value ))
649+ elif value is not None and isinstance (value , ObjectName ):
650+ new_value = value .getKeyProperty ('Name' )
651+ else :
652+ try :
653+ new_value = TypeUtils .convertToType (data_type , value , delimiter )
654+ except NumberFormatException , nfe :
655+ ex = exception_helper .create_alias_exception ('WLSDPLY-08021' , value , data_type , delimiter ,
656+ nfe .getLocalizedMessage (), error = nfe )
657+ _logger .throwing (ex , class_name = _class_name , method_name = _method_name )
658+ raise ex
659+
660+ if preferred :
661+ delimiter = compute_delimiter_from_data_type (preferred , value )
662+ try :
663+ if data_type == LONG :
664+ new_value = Long (new_value )
665+ elif data_type == JAVA_LANG_BOOLEAN :
666+ new_value = Boolean (new_value )
667+ elif data_type == JARRAY :
668+ new_value = _create_array (new_value , delimiter )
669+ elif data_type == PROPERTIES :
670+ if preferred == DICTIONARY :
671+ new_value =
672+ elif data_type == LIST :
673+ new_value = list (new_value )
674+ elif data_type in (COMMA_DELIMITED_STRING , DELIMITED_STRING , SEMI_COLON_DELIMITED_STRING ,
675+ SPACE_DELIMITED_STRING , PATH_SEPARATOR_DELIMITED_STRING ):
676+ #
677+ # This code intentionally ignores the delimiter value passed in and computes it from the data type.
678+ # This is required to handle the special case where the value we read from WLST might have a
679+ # different delimiter than the model value. In this use case, the value passed into the method
680+ # is the WLST value delimiter and the data_type is the preferred_model_type, so we compute the
681+ # model delimiter from the data_type directly.
682+ #
683+ delimiter = compute_delimiter_from_data_type (data_type , new_value )
684+ new_value = delimiter .join (new_value )
685+ except TypeError , te :
686+ ex = exception_helper .create_alias_exception ('WLSDPLY-08021' , value , data_type , delimiter , te )
687+ _logger .throwing (ex , class_name = _class_name , method_name = _method_name )
688+ raise ex
689+
690+ return new_value
691+
692+
629693def convert_to_type (data_type , value , subtype = None , delimiter = None ):
630694 """
631695 Convert the value to the specified type.
@@ -661,7 +725,7 @@ def convert_to_type(data_type, value, subtype=None, delimiter=None):
661725 new_value = Boolean (new_value )
662726 elif data_type == JARRAY :
663727 if subtype is None or subtype == 'java.lang.String' :
664- new_value = _create_string_array (new_value )
728+ new_value = _create_string_jarray (new_value )
665729 else :
666730 new_value = _create_mbean_array (new_value , subtype )
667731 elif data_type == LIST :
@@ -951,7 +1015,7 @@ def _get_value_for_path_type(path_type):
9511015 return result
9521016
9531017
954- def _create_string_array (iterable ):
1018+ def _create_string_jarray (iterable ):
9551019 """
9561020 Create a jarray of java.lang.String suitable for WLST attributes that take list objects.
9571021 This is mostly used for WLST online.
@@ -962,11 +1026,38 @@ def _create_string_array(iterable):
9621026 myarray = jarray .zeros (array_len , String )
9631027 idx = 0
9641028 for element in iterable :
965- myarray [idx ] = element
1029+ if isinstance (element , String ):
1030+ myarray [idx ] = element
1031+ elif isinstance (element , ObjectName ):
1032+ myarray [idx ] = ObjectName .unquote (element .getKeyProperty ('Name' ))
1033+ else :
1034+ myarray [idx ] = str (element )
9661035 idx += 1
9671036 return myarray
9681037
9691038
1039+ def _create_array (iterable , delimiter ):
1040+ """
1041+ Create an array from the jarray objects. If the delimiter is present, convert it to
1042+ a string with the delimiter.
1043+ :param iterable: a List object or other iterable type
1044+ :param delimiter: to create a string from the array
1045+ :return: an array or a string containing the same contents as the provided iterable
1046+ """
1047+ myarray = []
1048+ for element in iterable :
1049+ if isinstance (element , ObjectName ):
1050+ myarray .append (element .getKeyProperty ('Name' ))
1051+ elif not delimiter or isinstance (element , String ):
1052+ myarray .append (str (element ))
1053+ else :
1054+ myarray .append (element )
1055+ if delimiter :
1056+ # make it to a string
1057+ myarray = delimiter .join (myarray )
1058+ return myarray
1059+
1060+
9701061def _create_mbean_array (iterable , subtype ):
9711062 """
9721063 Create a jarray of the subtype suitable for WLST attributes that take list objects.
0 commit comments