17
17
from java .lang import RuntimeException
18
18
from java .lang import String
19
19
from java .util import Properties
20
+ from javax .management import ObjectName
20
21
21
22
from oracle .weblogic .deploy .aliases import TypeUtils
22
23
from oracle .weblogic .deploy .aliases import VersionException
30
31
from wlsdeploy .aliases .alias_constants import ATTRIBUTES
31
32
from wlsdeploy .aliases .alias_constants import COMMA_DELIMITED_STRING
32
33
from wlsdeploy .aliases .alias_constants import DELIMITED_STRING
34
+ from wlsdeploy .aliases .alias_constants import DICTIONARY
33
35
from wlsdeploy .aliases .alias_constants import JARRAY
34
36
from wlsdeploy .aliases .alias_constants import JAVA_LANG_BOOLEAN
35
37
from wlsdeploy .aliases .alias_constants import LIST
36
38
from wlsdeploy .aliases .alias_constants import LONG
37
39
from wlsdeploy .aliases .alias_constants import PATH_SEPARATOR_DELIMITED_STRING
40
+ from wlsdeploy .aliases .alias_constants import PROPERTIES
38
41
from wlsdeploy .aliases .alias_constants import PREFERRED_MODEL_TYPE
39
42
from wlsdeploy .aliases .alias_constants import SECURITY_PROVIDER_FOLDER_PATHS
40
43
from 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):
626
629
return result
627
630
628
631
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
+
629
693
def convert_to_type (data_type , value , subtype = None , delimiter = None ):
630
694
"""
631
695
Convert the value to the specified type.
@@ -661,7 +725,7 @@ def convert_to_type(data_type, value, subtype=None, delimiter=None):
661
725
new_value = Boolean (new_value )
662
726
elif data_type == JARRAY :
663
727
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 )
665
729
else :
666
730
new_value = _create_mbean_array (new_value , subtype )
667
731
elif data_type == LIST :
@@ -951,7 +1015,7 @@ def _get_value_for_path_type(path_type):
951
1015
return result
952
1016
953
1017
954
- def _create_string_array (iterable ):
1018
+ def _create_string_jarray (iterable ):
955
1019
"""
956
1020
Create a jarray of java.lang.String suitable for WLST attributes that take list objects.
957
1021
This is mostly used for WLST online.
@@ -962,11 +1026,38 @@ def _create_string_array(iterable):
962
1026
myarray = jarray .zeros (array_len , String )
963
1027
idx = 0
964
1028
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 )
966
1035
idx += 1
967
1036
return myarray
968
1037
969
1038
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
+
970
1061
def _create_mbean_array (iterable , subtype ):
971
1062
"""
972
1063
Create a jarray of the subtype suitable for WLST attributes that take list objects.
0 commit comments