001package Torello.Browser;
002
003import java.util.*;
004import javax.json.*;
005import javax.json.stream.*;
006import java.io.*;
007
008import java.lang.reflect.Method;
009import java.lang.reflect.Parameter;
010import java.util.function.Function;
011
012import Torello.Java.Additional.*;
013import Torello.Java.JSON.*;
014
015import static Torello.Java.JSON.JFlag.*;
016
017import Torello.Java.StrCmpr;
018import Torello.JavaDoc.StaticFunctional;
019import Torello.JavaDoc.JDHeaderBackgroundImg;
020import Torello.JavaDoc.Excuse;
021
022/**
023 * <SPAN CLASS=COPIEDJDK><B><CODE>[No Description Provided by Google]</CODE></B></SPAN>
024 * 
025 * <EMBED CLASS='external-html' DATA-FILE-ID=CODE_GEN_NOTE>
026 */
027@StaticFunctional(Excused={"counter"}, Excuses={Excuse.CONFIGURATION})
028@JDHeaderBackgroundImg(EmbedTagFileID="WOOD_PLANK_NOTE")
029public class DeviceOrientation
030{
031    // ********************************************************************************************
032    // ********************************************************************************************
033    // Class Header Stuff
034    // ********************************************************************************************
035    // ********************************************************************************************
036
037
038    // No Pubic Constructors
039    private DeviceOrientation () { }
040
041    // These two Vector's are used by all the "Methods" exported by this class.  java.lang.reflect
042    // is used to generate the JSON String's.  It saves thousands of lines of Auto-Generated Code.
043    private static final Map<String, Vector<String>>    parameterNames = new HashMap<>();
044    private static final Map<String, Vector<Class<?>>>  parameterTypes = new HashMap<>();
045
046    // Some Methods do not take any parameters - for instance all the "enable()" and "disable()"
047    // I simply could not get ride of RAW-TYPES and UNCHECKED warnings... so there are now,
048    // offically, two empty-vectors.  One for String's, and the other for Classes.
049
050    private static final Vector<String>     EMPTY_VEC_STR = new Vector<>();
051    private static final Vector<Class<?>>   EMPTY_VEC_CLASS = new Vector<>();
052
053    static
054    {
055        for (Method m : DeviceOrientation.class.getMethods())
056        {
057            // This doesn't work!  The parameter names are all "arg0" ... "argN"
058            // It works for java.lang.reflect.Field, BUT NOT java.lang.reflect.Parameter!
059            //
060            // Vector<String> parameterNamesList = new Vector<>(); -- NOPE!
061
062            Vector<Class<?>> parameterTypesList = new Vector<>();
063        
064            for (Parameter p : m.getParameters()) parameterTypesList.add(p.getType());
065
066            parameterTypes.put(
067                m.getName(),
068                (parameterTypesList.size() > 0) ? parameterTypesList : EMPTY_VEC_CLASS
069            );
070        }
071    }
072
073    static
074    {
075        Vector<String> v = null;
076
077        parameterNames.put("clearDeviceOrientationOverride", EMPTY_VEC_STR);
078
079        v = new Vector<String>(3);
080        parameterNames.put("setDeviceOrientationOverride", v);
081        Collections.addAll(v, new String[]
082        { "alpha", "beta", "gamma", });
083    }
084
085
086    // ********************************************************************************************
087    // ********************************************************************************************
088    // Types - Static Inner Classes
089    // ********************************************************************************************
090    // ********************************************************************************************
091
092    
093    // Counter for keeping the WebSocket Request ID's distinct.
094    private static int counter = 1;
095    
096    /**
097     * Clears the overridden Device Orientation.
098     * 
099     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
100     * {@link Ret0}&gt;</CODE>
101     *
102     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
103     * browser receives the invocation-request.
104     *
105     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
106     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
107     * {@code >} to ensure the Browser Function has run to completion.
108     */
109    public static Script<String, JsonObject, Ret0> clearDeviceOrientationOverride()
110    {
111        final int          webSocketID = 20000000 + counter++;
112        final boolean[]    optionals   = new boolean[0];
113        
114        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
115        String requestJSON = WriteJSON.get(
116            parameterTypes.get("clearDeviceOrientationOverride"),
117            parameterNames.get("clearDeviceOrientationOverride"),
118            optionals, webSocketID,
119            "DeviceOrientation.clearDeviceOrientationOverride"
120        );
121        
122        // This Remote Command does not have a Return-Value.
123        return new Script<>
124            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
125    }
126    
127    /**
128     * Overrides the Device Orientation.
129     * 
130     * @param alpha Mock alpha
131     * 
132     * @param beta Mock beta
133     * 
134     * @param gamma Mock gamma
135     * 
136     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
137     * {@link Ret0}&gt;</CODE>
138     *
139     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
140     * browser receives the invocation-request.
141     *
142     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
143     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
144     * {@code >} to ensure the Browser Function has run to completion.
145     */
146    public static Script<String, JsonObject, Ret0> setDeviceOrientationOverride
147        (Number alpha, Number beta, Number gamma)
148    {
149        // Exception-Check(s) to ensure that if any parameters which are not declared as
150        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
151        
152        if (alpha == null) BRDPC.throwNPE("alpha");
153        if (beta == null)  BRDPC.throwNPE("beta");
154        if (gamma == null) BRDPC.throwNPE("gamma");
155        
156        final int       webSocketID = 20001000 + counter++;
157        final boolean[] optionals   = { false, false, false, };
158        
159        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
160        String requestJSON = WriteJSON.get(
161            parameterTypes.get("setDeviceOrientationOverride"),
162            parameterNames.get("setDeviceOrientationOverride"),
163            optionals, webSocketID,
164            "DeviceOrientation.setDeviceOrientationOverride",
165            alpha, beta, gamma
166        );
167        
168        // This Remote Command does not have a Return-Value.
169        return new Script<>
170            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
171    }
172    
173}