001package Torello.Browser.JsonAST; 002 003import javax.json.JsonValue; 004import javax.json.JsonArray; // JavaDoc Comment needs this 005 006/** 007 * Enumerates the limited set of values that the Chrome DevTools Protocol may assign to the 008 * {@code "type"} property of its schema definitions. While the protocol data itself is exchanged 009 * as JSON over WebSockets, these values are automatically bound into their corresponding Java 010 * types by this library, allowing end-users to work with ordinary Java objects rather than raw 011 * JSON. 012 */ 013public enum TypeProp 014{ 015 /** 016 * Denotes a protocol value that binds to a structured Java {@code Object}. When a CDP 017 * {@code Type} is declared to be {@code OBJECT}, a {@link JsonArray} whose property name is 018 * {@link PropName#PROPERTIES 'properties'} will be included that lists the type's various 019 * fields. 020 */ 021 OBJECT(JsonValue.class), 022 // This is usuallly a reference 023 024 /** 025 * Denotes a protocol value that binds to a sequential Java {@code List}-like array. 026 * Whenever a CDP {@code Type} or an {@code Event} is declared as an array, there will be a 027 * corresponding {@link PropName#ITEMS 'items'} property which declares the array's component 028 * type. (What the array's contents are going to be). 029 */ 030 ARRAY(), 031 // This must be a "reference" 032 033 /** Denotes a protocol value that binds to a Java {@code String}. */ 034 STRING(String.class, String.class, String[].class), 035 036 /** Denotes a protocol value that binds to a Java {@code int}-based numeric type. */ 037 INTEGER(int.class, Integer.class, int[].class), 038 039 /** Denotes a protocol value that binds to a Java {@code double}-based numeric type. */ 040 NUMBER(Number.class, Number.class, Number[].class), 041 042 /** Denotes a protocol value that binds to a Java {@code boolean}. */ 043 BOOLEAN(boolean.class, Boolean.class, boolean[].class), 044 045 /** 046 * API values described as {@code "Any"} are returned to the user as raw {@code JsonObject}. 047 * Whenever a {@link PPR} (property, parameter or return-value) is declared to be of type 048 * "Any", the corresponding method-parameter, class-field or return-value shall be declared to 049 * be of type {@link JsonValue}. 050 * 051 * <BR /><BR />In such cases, the actual raw JSON returned by the browser is passed on to the 052 * user. 053 */ 054 ANY(JsonValue.class); 055 056 057 // ******************************************************************************************** 058 // ******************************************************************************************** 059 // Constructors 060 // ******************************************************************************************** 061 // ******************************************************************************************** 062 063 064 // The various types used by the Type-Simplifier 065 066 /** 067 * The "Computed Type, as a String" that is used whenever a property, parameter or return-value 068 * is <B STYLE='color:red;'><I>NOT</I></B> declared <B STYLE='color:red;'><I>OPTIONAL</I></B>. 069 * 070 * <BR /><BR />Java's "Boxed Types" are used whenever the CDP API specifies that a 071 * method-parameter, class-field or return-value is "optional." In Java-HTML, in such cases, 072 * the the field, parameter or value is assigned null when Chrome or the Browser have elided 073 * or "left off" the value of a parameter, field or return-value. 074 */ 075 public final Class<?> primCTAS; 076 077 /** 078 * The "Computed Type as a String" which is required whenever the CDP API specifies that a 079 * method-parameter, class-field or return-value is "optional." This allows a 'null' to be 080 * assigned to such a field, parameter or return-value when the browser has left such 081 * information off. 082 */ 083 public final Class<?> boxedCTAS; 084 085 /** 086 * The "Computed Type as a String" when the CDP API has specified that an "array of" a 087 * certain type shall be used. Note that array's are already 'nullable', and as such, 088 * there is no need whatsoever to used a "Array of Boxed Types." 089 * 090 * <BR /><BR /> 091 * It is the case that the Browser could "elide" (leave off) the entire array when returning a 092 * value, or specifying an Event-Type's field-values. In that case, the array would simply be 093 * assigned 'null.' There is no need to actually allow the individual array element's to 094 * accept Boxed-Type 'null' values. 095 */ 096 public final Class<?> arrayCTAS; 097 098 private TypeProp() 099 { 100 this.primCTAS = null; 101 this.boxedCTAS = null; 102 this.arrayCTAS = null; 103 } 104 105 private TypeProp(final Class<JsonValue> _elided) 106 { this.primCTAS = this.boxedCTAS = this.arrayCTAS = JsonValue.class; } 107 108 private TypeProp( 109 final Class<?> primCTAS, 110 final Class<?> boxedCTAS, 111 final Class<?> arrayCTAS 112 ) 113 { 114 this.primCTAS = primCTAS; 115 this.boxedCTAS = boxedCTAS; 116 this.arrayCTAS = arrayCTAS; 117 } 118}