Class CDPTypes


  • public class CDPTypes
    extends java.lang.Object
    ⚠️ This class is designated as an "internal use only class." While there is nothing detrimental about using this class, it is actually only declared 'public' because it's methods & fields are indeed needed in packages outside of Torello.Browser. Classes which are declared 'public' are automatically documented by 'javadoc'. Therefore this page is included for viewing, even though Java-HTML Library users probably don't actually need to know about it!

    💡 Feel free to review it's contents. Perhaps there are explanations which might be of interest.
    💡 Primarily, this class is used by the Code Generator to produce the classes that comprise the Java Browser-Automation Library. Generating Java Code to interface with a "Google Compliant Browser" isn't exactly rocket science, but rather it is just very tedious and time consuming. When the Code Generator emits a class - that class is nothing more than a "wrapper" around a "Web Sockets Implementation" for Google Chromes CDP (Chrome DevTools Protocol).

    🧠 The reality is that the entire CDP library is based on nothing more than two JSON files that Google has left on a particular Git-Hub Page. You may search Google for the CDP JSON specification files, and it will produce a nice page for you. Those JSON files are converted piece by piece from "Json Strings" into actual Java Types. An "AST Tree" is built from the JSON file, and then that AST is passed to a Code Generator that "emits" Java Files.

    100% of the files in the BrowserAPI & JavaScriptAPI were produced, themselves, by a Code Generator package that is not actually part of the public Torello Java-HTML JAR Distribution Library.

    📌 This class does nothing more than map a java.lang.String into a byte primitive constant. Why? Implementing a Code Generator that contains quite a few switch statements which "switch" on a Java 'byte' is much nicer to look at & read than one which is repeatedly "switching" on java.lang.String's.

    🚫 It's quite simple really! Only downside (for you, the user) is that I don't actually expose or provide the Code Generator's Java source code. Sorry, it's just not a useful thing for anyone except me! (Trust me, you really wouldn't care...)


    • Method Summary

       
      Methods, Primarily for Packge-Internal Use (but declared public)
      Modifier and Type Method
      static byte ctasToByte​(String CTAS)
      static byte ctasToByte​(String CTAS, boolean refNonNull, boolean refArrayNonNull)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CDP_TYPE

        🡇     🗕  🗗  🗖
        public static final byte CDP_TYPE
        Indicates an In-Browser 'Data-Class'
        CDP In-Browser Type: An actual Data-Object, defined for use by the browser
        Web-Sockets Transmisson Layer: The Json-Type JsonObject
        Java Type: Any one of the scores of Data-Classes inside the Browser & Java-Script API packages. (These are always a 'nested class' of any domain-class)
        Note: A type that is a "CDP Type" *must* be one of type, event or command-return-types
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Indicates an In-Browser 'Data-Class'", background=BlueDither)
             public static final byte CDP_TYPE = 1;
        
      • CDP_TYPE_ARRAY_1D

        🡅  🡇     🗕  🗗  🗖
        public static final byte CDP_TYPE_ARRAY_1D
        An Array of any one In-Browser 'Data-Class'
        CDP In-Browser Type: An array of Browser Types / Objects
        Web-Sockets Transmisson Layer: The Json-Type JsonArray
        Java Type: An array of a 'nested-class' data-object
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="An Array of any one In-Browser 'Data-Class'", background=GreenDither)
             public static final byte CDP_TYPE_ARRAY_1D = CDP_TYPE + 1;
        
      • RAW_JSON_VALUE

        🡅  🡇     🗕  🗗  🗖
        public static final byte RAW_JSON_VALUE
        Unspecified Browser Type - Accepts Any Type!
        CDP In-Browser Type: Unknown, Any
        Web-Sockets Transmisson Layer: The Json-Type Raw-Json
        Java Type:  JsonObject
        Note: There are *VERY FEW* types which are defined as 'Any' or (unknown) 'Object' in Google's CDP Spec-Files. When it used, you (the user) get to receive the "Raw JSON Object" that was transmitted via Web-Socket.
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Unspecified Browser Type - Accepts Any Type!", background=BlueDither)
             public static final byte RAW_JSON_VALUE = CDP_TYPE_ARRAY_1D + 1;
        
      • PRIMITIVE_INT

        🡅  🡇     🗕  🗗  🗖
        public static final byte PRIMITIVE_INT
        Required, Non-Nullable 'int'
        CDP In-Browser Type: Integer
        Web-Sockets Transmisson Layer: The Json-Type JsonNumber
        Java Type: Primitive 'int'
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Required, Non-Nullable 'int'", background=GreenDither)
             public static final byte PRIMITIVE_INT = RAW_JSON_VALUE + 1;
        
      • BOXED_INTEGER

        🡅  🡇     🗕  🗗  🗖
        public static final byte BOXED_INTEGER
        Nullabele / Optional Integer
        CDP In-Browser Type: Integer
        Web-Sockets Transmisson Layer: The Json-Type JsonNumber
        Java Type: Boxed-Type java.lang.Integer
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Nullabele / Optional Integer", background=BlueDither)
             public static final byte BOXED_INTEGER = PRIMITIVE_INT + 1;
        
      • PRIMITIVE_BOOLEAN

        🡅  🡇     🗕  🗗  🗖
        public static final byte PRIMITIVE_BOOLEAN
        Required, Non-Nullable boolean
        CDP In-Browser Type: Boolean
        Web-Sockets Transmisson Layer: Either JsonValue.TRUE or JsonValue.FALSE
        Java Type: Primitive 'boolean'
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Required, Non-Nullable boolean", background=GreenDither)
             public static final byte PRIMITIVE_BOOLEAN = BOXED_INTEGER + 1;
        
      • BOXED_BOOLEAN

        🡅  🡇     🗕  🗗  🗖
        public static final byte BOXED_BOOLEAN
        Optional / Nullable boolean
        CDP In-Browser Type: Boolean
        Web-Sockets Transmisson Layer: Either JsonValue.TRUE or JsonValue.FALSE
        Java Type: Boxed-Type java.lang.Boolean
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Optional / Nullable boolean", background=BlueDither)
             public static final byte BOXED_BOOLEAN = PRIMITIVE_BOOLEAN + 1;
        
      • STRING

        🡅  🡇     🗕  🗗  🗖
        public static final byte STRING
        String of Characters
        CDP In-Browser Type: String
        Web-Sockets Transmisson Layer: The Json-Type JsonString
        Java Type: A java.lang.String
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="String of Characters", background=GreenDither)
             public static final byte STRING = BOXED_BOOLEAN + 1;
        
      • NUMBER

        🡅  🡇     🗕  🗗  🗖
        public static final byte NUMBER
        Unspecified Numeric Type
        CDP In-Browser Type: Unspecified numeric type
        Web-Sockets Transmisson Layer: The Json-Type JsonNumber
        Java Type: Any concrete sub-class of java.lang.Number
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Unspecified Numeric Type", background=BlueDither)
             public static final byte NUMBER = STRING + 1;
        
      • INT_ARRAY_1D

        🡅  🡇     🗕  🗗  🗖
        public static final byte INT_ARRAY_1D
        Type: int[]-Array
        CDP In-Browser Type: One dimensional integer array
        Web-Sockets Transmisson Layer: The Json-Type JsonArray
        Expectation: It is expected that input JsonArray instances have only valid integers, and no Json Null's
        Java Type: Primitive int[]-Array
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Type: int[]-Array", background=GreenDither)
             public static final byte INT_ARRAY_1D = NUMBER + 1;
        
      • BOOLEAN_ARRAY_1D

        🡅  🡇     🗕  🗗  🗖
        public static final byte BOOLEAN_ARRAY_1D
        Type: boolean[]-Array
        CDP In-Browser Type: One dimensional boolean array
        Web-Sockets Transmisson Layer: The Json-Type JsonArray
        Expectation: It is expected that input JsonArray instances contain only JsonValue.TRUE or JsonValue.FALSE, without any Json Null's
        Java Type: Primitive boolean[]-Array
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Type: boolean[]-Array", background=BlueDither)
             public static final byte BOOLEAN_ARRAY_1D = INT_ARRAY_1D + 1;
        
      • STRING_ARRAY_1D

        🡅  🡇     🗕  🗗  🗖
        public static final byte STRING_ARRAY_1D
        Type: String[]-Array
        CDP In-Browser Type: One dimensional string array
        Web-Sockets Transmisson Layer: The Json-Type JsonArray
        Expectation: It is expected that the JsonArray have only valid JsonString instances
        Java Type: A java.lang.String[]
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Type: String[]-Array", background=GreenDither)
             public static final byte STRING_ARRAY_1D = BOOLEAN_ARRAY_1D + 1;
        
      • NUMBER_ARRAY_1D

        🡅  🡇     🗕  🗗  🗖
        public static final byte NUMBER_ARRAY_1D
        Type: Number[]-Array
        CDP In-Browser Type: One dimensional numeric array, of an unspecified numeric type
        Web-Sockets Transmisson Layer: The Json-Type JsonArray
        Java Type: A Number[] (may contain any concrete java.lang.Number subclass)
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Type: Number[]-Array", background=BlueDither)
             public static final byte NUMBER_ARRAY_1D = STRING_ARRAY_1D + 1;
        
      • INT_ARRAY_2D

        🡅  🡇     🗕  🗗  🗖
        public static final byte INT_ARRAY_2D
        Type: 2-D int[][]-Array
        CDP In-Browser Type: Two-dimensional integer array
        Web-Sockets Transmisson Layer: The Json-Type JsonArray
        Expectation: It is expected that the JsonArray be a valid 2-D array of arrays.
        Java Type: Primitive, two-dimensioinal int[][]-Array
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Type: 2-D int[][]-Array", background=GreenDither)
             public static final byte INT_ARRAY_2D = NUMBER_ARRAY_1D + 1;
        
      • BOOLEAN_ARRAY_2D

        🡅  🡇     🗕  🗗  🗖
        public static final byte BOOLEAN_ARRAY_2D
        Type: 2-D boolean[][]-Array
        CDP In-Browser Type: Two dimensional boolean array
        Web-Sockets Transmisson Layer: The Json-Type JsonArray
        Expectation: It is expected that the JsonArray be a valid 2-D array of arrays.
        Java Type: Primitive, two-dimensioinal boolean[][]-Array
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Type: 2-D boolean[][]-Array", background=BlueDither)
             public static final byte BOOLEAN_ARRAY_2D = INT_ARRAY_2D + 1;
        
      • STRING_ARRAY_2D

        🡅  🡇     🗕  🗗  🗖
        public static final byte STRING_ARRAY_2D
        Type: 2-D String[][]-Array
        CDP In-Browser Type: Two dimensional string array
        Web-Sockets Transmisson Layer: The Json-Type JsonArray
        Expectation: It is expected that the JsonArray be a valid 2-D array of arrays.
        Java Type: Two-dimensional String[][]-Array
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Type: 2-D String[][]-Array", background=GreenDither)
             public static final byte STRING_ARRAY_2D = BOOLEAN_ARRAY_2D + 1;
        
      • NUMBER_ARRAY_2D

        🡅  🡇     🗕  🗗  🗖
        public static final byte NUMBER_ARRAY_2D
        Type: 2-D Number[][] Array
        CDP In-Browser Type: Two dimensional numeric array, of an unspecified numeric type
        Web-Sockets Transmisson Layer: The Json-Type JsonArray
        Expectation: It is expected that the JsonArray be a valid 2-D array of arrays.
        Java Type: Two-dimensional Number[][]-Array
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         @IntoHTMLTable(title="Type: 2-D Number[][] Array", background=BlueDither)
             public static final byte NUMBER_ARRAY_2D = STRING_ARRAY_2D + 1;
        
      • names

        🡅  🡇     🗕  🗗  🗖
        public static final ReadOnlyMap<java.lang.Byte,​java.lang.String> names
        The "switch" from a number to string is done using this map. When a Code Generator "emits" or "outputs" (when it does its thing, and generates Java Source Code), it literally just goes through the AST and using lots of java.lang.StringBuilder to build strings.

        The String's which are produced, are saved directly to '.java' files, and eventually those '.java' files are compiled using the standard 'javac' compiler stage of the Torello Build-Tool, and turned into the '.class' files offered by the Java-HTML JAR Library.

        Click on the "View Hilited Source" arrow-button '⮫' (directly above) to see how this map is loaded, using reflection.

        This particular field does nothing more than map one of the 'byte' constants, such as PRIMITIVE_INT or NUMBER_ARRAY_1D to the Java 'String' name of that constant - "PRIMITIVE_INT" or "NUMBER_ARRAY_1D".

        If you ask "Why?" - again, the classes inside 'BrowserAPI' and 'JavaScriptAPI' have source code that was emitted, automatically, and "emitting" Java Code such as "CDPTypes.PRIMTIVIE_INT" requires this little map field.

        It is that simple, but unfortunately, the Java Code Generator which produces the classes in this API is not part of the public-API, and therefore its source code cannot be viewed. It mostly "really boring" stuff. The code generator isn't included in the Java-HTML '.jar' because it doesn't serve any purpose, other than generating the '.java' files inside 'BrowserAPI' and 'JavaScriptAPI'.
        Code:
        Exact Field Declaration Expression:
         public static final ReadOnlyMap<Byte, String> names;
        
      • types

        🡅  🡇     🗕  🗗  🗖
        public static final ReadOnlyMap<java.lang.Byte,​java.lang.String> types
        Switches from a byte constant to the Java-Type, as a java.lang.String
        Code:
        Exact Field Declaration Expression:
         public static final ReadOnlyMap<Byte, String> types;
        
    • Method Detail

      • ctasToByte

        🡅  🡇     🗕  🗗  🗖
        public static byte ctasToByte​(java.lang.String CTAS)
        Converts the strings created inside the Json-AST package into a 'byte' constant

        Note that there is one minor "exceptional case" that is handled inside of this method. Just look at the test for FilterEntry[], below, to see how it is handled. It's a minor nuisance inside of the CDP specs.


        This class is used only once, throughout all of the Java-HTML '.jar'. It may be found inside the AST node for "types" (see class TypeNode). Click on the TypeNode link, and then click the "View Hilited Source" to see this method's use.

        It may found inside the package-private constructor for that class.
        Parameters:
        CTAS - The "Computed Type as a String"
        Returns:
        A 'byte' constant which represents that type. If the type is an actual and reified browser object type, then the 'byte' constants CDP_TYPE or CDP_TYPE_ARRAY_1D are returned instead.
        Throws:
        UnrecognizedCTASError - Throws if parameter 'CTAS' is passed a Java String that is not among the recognized "Computed Type as String" values.

        Note that this class inherits Error because this method is intended for internal use by the Java-HTML codebase, not for direct use by end-user code. When used by Java-HTML, this method should never receive an unrecognized 'CTAS' value, under normal operation.

        ⚠️ Generally, this throwable replaces & enforces a standard Java 'assert' statement.
        See Also:
        TypeNode
        Code:
        Exact Method Body:
         final Byte ret = bytes.get(CTAS);
        
         if (ret != null)                                return ret.byteValue();
         else if (CTAS.equals("FilterEntry[]"))          return CDP_TYPE_ARRAY_1D;
         else if (CDP_TYPE_NAME_PREDICATE.test(CTAS))    return CDP_TYPE;
         else                                            throw new UnrecognizedCTASError(CTAS);
        
      • ctasToByte

        🡅     🗕  🗗  🗖
        public static byte ctasToByte​(java.lang.String CTAS,
                                      boolean refNonNull,
                                      boolean refArrayNonNull)
        Converts the strings created inside the Json-AST package into a 'byte' constant

        This class is used only once throughout all of the Java-HTML '.jar'. It may be found inside the AST node for "Parameters, Properties & Return-Values" (PPR). Click the PPR link, and then click the "View Hilited Source" to see this method's use.

        It may be found inside the package-private method named "setCTAS(String)"
        Parameters:
        CTAS - The "Computed Type as a String"
        refNonNull - indicates whether the PPR.reference() returns null
        refArrayNonNull - indicates whether the PPR.referenceArray() returns null
        Returns:
        A 'byte' constant which represents that type. If the type is an actual and reified browser object type, then the 'byte' constants CDP_TYPE or CDP_TYPE_ARRAY_1D are returned instead.
        Throws:
        UnrecognizedCTASError - Throws if parameter 'CTAS' is passed a Java String that is not among the recognized "Computed Type as String" values.

        Note that this class inherits Error because this method is intended for internal use by the Java-HTML codebase, not for direct use by end-user code. When used by Java-HTML, this method should never receive an unrecognized 'CTAS' value, under normal operation.

        ⚠️ Generally, this throwable replaces & enforces a standard Java 'assert' statement.
        See Also:
        PPR
        Code:
        Exact Method Body:
         final Byte ret = bytes.get(CTAS);
        
         if (ret != null)            return ret.byteValue();
         else if (refNonNull)        return CDP_TYPE;
         else if (refArrayNonNull)   return CDP_TYPE_ARRAY_1D;
         else                        throw new UnrecognizedCTASError(CTAS);