Package Torello.Browser
Class CDPTypes
- java.lang.Object
-
- Torello.Browser.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 ofTorello.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 ajava.lang.Stringinto abyteprimitive 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" onjava.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...)
Hi-Lited Source-Code:- View Here: Torello/Browser/CDPTypes.java
- Open New Browser-Tab: Torello/Browser/CDPTypes.java
File Size: 23,030 Bytes Line Count: 483 '\n' Characters Found
-
-
Field Summary
Conversion Map: Byte Constant into its Constant-Name, as a String Modifier and Type Field static ReadOnlyMap<Byte,String>namesConversion Map: Byte Constant into its Corresponding Java Type Class Name Modifier and Type Field static ReadOnlyMap<Byte,String>typesByte Constants: A CDP Class & an Array of CDP Classes Modifier and Type Field static byteCDP_TYPEstatic byteCDP_TYPE_ARRAY_1DByte Constants: Standard Java Types Modifier and Type Field static byteBOXED_BOOLEANstatic byteBOXED_INTEGERstatic byteNUMBERstatic bytePRIMITIVE_BOOLEANstatic bytePRIMITIVE_INTstatic byteSTRINGByte Constants: One-Dimensional Array Types Modifier and Type Field static byteBOOLEAN_ARRAY_1Dstatic byteINT_ARRAY_1Dstatic byteNUMBER_ARRAY_1Dstatic byteSTRING_ARRAY_1DByte Constants: Two-Dimeasional Array Types Modifier and Type Field static byteBOOLEAN_ARRAY_2Dstatic byteINT_ARRAY_2Dstatic byteNUMBER_ARRAY_2Dstatic byteSTRING_ARRAY_2DByte Constants: Unknown, Raw JSON Modifier and Type Field static byteRAW_JSON_VALUE
-
Method Summary
Methods, Primarily for Packge-Internal Use (but declared public) Modifier and Type Method static bytectasToByte(String CTAS)static bytectasToByte(String CTAS, boolean refNonNull, boolean refArrayNonNull)
-
-
-
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 JsonObjectJava 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 JsonArrayJava 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: JsonObjectNote: 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 JsonNumberJava 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 IntegerCDP In-Browser Type: Integer Web-Sockets Transmisson Layer: The Json-Type JsonNumberJava 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 booleanCDP In-Browser Type: Boolean Web-Sockets Transmisson Layer: Either JsonValue.TRUEorJsonValue.FALSEJava 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 booleanCDP In-Browser Type: Boolean Web-Sockets Transmisson Layer: Either JsonValue.TRUEorJsonValue.FALSEJava 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 CharactersCDP In-Browser Type: String Web-Sockets Transmisson Layer: The Json-Type JsonStringJava 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 TypeCDP In-Browser Type: Unspecified numeric type Web-Sockets Transmisson Layer: The Json-Type JsonNumberJava 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[]-ArrayCDP In-Browser Type: One dimensional integer array Web-Sockets Transmisson Layer: The Json-Type JsonArrayExpectation: It is expected that input JsonArrayinstances have only valid integers, and noJson Null'sJava 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[]-ArrayCDP In-Browser Type: One dimensional boolean array Web-Sockets Transmisson Layer: The Json-Type JsonArrayExpectation: It is expected that input JsonArrayinstances contain onlyJsonValue.TRUEorJsonValue.FALSE, without anyJson Null'sJava 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[]-ArrayCDP In-Browser Type: One dimensional string array Web-Sockets Transmisson Layer: The Json-Type JsonArrayExpectation: It is expected that the JsonArrayhave only validJsonStringinstancesJava 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[]-ArrayCDP In-Browser Type: One dimensional numeric array, of an unspecified numeric type Web-Sockets Transmisson Layer: The Json-Type JsonArrayJava Type: A Number[](may contain any concretejava.lang.Numbersubclass)- 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[][]-ArrayCDP In-Browser Type: Two-dimensional integer array Web-Sockets Transmisson Layer: The Json-Type JsonArrayExpectation: It is expected that the JsonArraybe 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[][]-ArrayCDP In-Browser Type: Two dimensional boolean array Web-Sockets Transmisson Layer: The Json-Type JsonArrayExpectation: It is expected that the JsonArraybe 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[][]-ArrayCDP In-Browser Type: Two dimensional string array Web-Sockets Transmisson Layer: The Json-Type JsonArrayExpectation: It is expected that the JsonArraybe 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[][] ArrayCDP In-Browser Type: Two dimensional numeric array, of an unspecified numeric type Web-Sockets Transmisson Layer: The Json-Type JsonArrayExpectation: It is expected that the JsonArraybe 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 ofjava.lang.StringBuilderto build strings.
TheString'swhich 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 asPRIMITIVE_INTorNUMBER_ARRAY_1Dto 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 abyteconstant to the Java-Type, as ajava.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'constantNote that there is one minor "exceptional case" that is handled inside of this method. Just look at the test forFilterEntry[], 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 classTypeNode). Click on theTypeNodelink, 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'constantsCDP_TYPEorCDP_TYPE_ARRAY_1Dare returned instead. - Throws:
UnrecognizedCTASError- Throws if parameter'CTAS'is passed a JavaStringthat is not among the recognized "Computed Type as String" values.Note that this class inheritsErrorbecause 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'constantThis 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 thePPR.reference()returns nullrefArrayNonNull- indicates whether thePPR.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'constantsCDP_TYPEorCDP_TYPE_ARRAY_1Dare returned instead. - Throws:
UnrecognizedCTASError- Throws if parameter'CTAS'is passed a JavaStringthat is not among the recognized "Computed Type as String" values.Note that this class inheritsErrorbecause 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);
-
-