Class JsUtils


  • public class JsUtils
    extends Object
    Utility class to provide generic methods used by all specific JSInterop classes
    • Method Detail

      • add

        public static <D> void add​(jsinterop.base.JsArrayLike<D> jsArrayLike,
                                   D element)
      • addAll

        public static <D,​E extends D> void addAll​(jsinterop.base.JsArrayLike<D> jsArrayLike,
                                                        E... elements)
      • remove

        public static <D> void remove​(jsinterop.base.JsArrayLike<D> jsArrayLike,
                                      int index)
      • toList

        public static <D> List<D> toList​(jsinterop.base.JsArrayLike<D> jsArrayLike)
      • toJsArrayLike

        public static <D> jsinterop.base.JsArrayLike<D> toJsArrayLike​(List<D> list)
      • toAttributesMap

        public static Map<QName,​String> toAttributesMap​(Object original)
        Extracts the otherAttributes property from a JavaScriptObject to a regular Java Map.
        Parameters:
        original - js object to transform.
        Returns:
        the populated Map<QName, String>
      • fromAttributesMap

        public static <D> D fromAttributesMap​(Map<QName,​String> original)
        Extracts the otherAttributes property from a regular Java Map to a JavaScriptObject.
        Parameters:
        original - the Map<QName, String> to transform.
        Returns:
        the populated JavaScriptObject
      • newWrappedInstance

        public static <D> D newWrappedInstance()
        Returns a stub object with name and value attributes
        Returns:
      • setNameOnWrapped

        public static <D> void setNameOnWrapped​(D wrappedObject,
                                                JSIName name)
        Set the name attribute of the given wrapped D with the json representation of the given JSIName
        Parameters:
        wrappedObject -
        name -
      • setValueOnWrapped

        public static <D,​E> void setValueOnWrapped​(D wrappedObject,
                                                         E value)
        Set the value attribute of the given wrapped D with the json representation of value E
        Parameters:
        wrappedObject -
        value -
      • getNativeElementsArray

        public static <D> jsinterop.base.JsArrayLike<D> getNativeElementsArray​(jsinterop.base.JsArrayLike<D> original)
        Returns the original JsArrayLike or, ift the original JsArrayLike is null, a new, empty one
        Type Parameters:
        D -
        Parameters:
        original -
        Returns:
      • getUnwrappedElementsArray

        public static <D> jsinterop.base.JsArrayLike<D> getUnwrappedElementsArray​(jsinterop.base.JsArrayLike<D> original)
        Returns a JsArrayLike where each element represents the unwrapped object (i.e. object.value) of the original one. It the original JsArrayLike is null, returns a new, empty one
        Type Parameters:
        D -
        Parameters:
        original -
        Returns:
      • getUnwrappedElement

        public static Object getUnwrappedElement​(Object original)
      • getWrappedElement

        public static <D> D getWrappedElement​(Object value)
      • getNativeArray

        public static <D> jsinterop.base.JsArrayLike<D> getNativeArray()
        Helper method to create a new, empty JsArrayLike
        Returns:
      • getTypeName

        public static String getTypeName​(Object instance)