Example usage for java.awt AWTException getClass

List of usage examples for java.awt AWTException getClass

Introduction

In this page you can find the example usage for java.awt AWTException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:edu.umd.cs.guitar.ripper.Ripper.java

/**
 * Rip a component//from   www  . j  av a  2 s  .c om
 *
 * As of now this method does not propagate exceptions.
 * It needs to be modified to progate exceptions. All callers
 * need to be modified to handle exceptions.
 *
 * <p>
 * 
 * @param component
 * @return
 */
public ComponentType ripComponent(GComponent component, GWindow window) {
    GUITARLog.log.info("");
    GUITARLog.log.info("----------------------------------");
    GUITARLog.log.info("Ripping component: ");
    GUITARLog.log.info("Signature: ");

    printComponentInfo(component, window);

    // 1. Rip special/customized components
    for (GComponentFilter cm : lComponentFilter) {
        if (cm.isProcess(component, window)) {
            GUITARLog.log.info("Filter " + cm.getClass().getSimpleName() + " is applied");

            return cm.ripComponent(component, window);
        }
    }

    // 2. Rip regular components
    ComponentType retComp = null;
    try {
        retComp = component.extractProperties();
        ComponentTypeWrapper compA = new ComponentTypeWrapper(retComp);

        if (useImage) {
            String sUUID = null;
            try {
                sUUID = captureImage(component);
            } catch (AWTException e) {
                // Ignore AWTException. sUUID is null.
            } catch (IOException e) {
                throw e;
            }

            if (sUUID != null) {
                compA.addProperty(GUITARConstants.UUID_TAG_NAME, sUUID);
            }
        }

        GUIType guiType = null;

        if (window != null) {
            guiType = window.extractGUIProperties();
        }

        retComp = compA.getDComponentType();

        // 2.1 Try to perform action on the component
        // to reveal more windows/components

        // clear window opened cache before performing actions
        monitor.resetWindowCache();

        if (monitor.isExpandable(component, window)) {
            monitor.expandGUI(component);
        } else {
            GUITARLog.log.info("Component is Unexpandable");
        }

        // Trigger terminal widget

        LinkedList<GWindow> lClosedWindows = monitor.getClosedWindowCache();

        String sTitle = window.getTitle();

        if (lClosedWindows.size() > 0) {

            GUITARLog.log.debug("!!!!! Window closed");

            for (GWindow closedWin : lClosedWindows) {
                String sClosedWinTitle = closedWin.getTitle();

                // Only consider widget closing the current window
                if (sTitle.equals(sClosedWinTitle)) {

                    GUITARLog.log.debug("\t" + sClosedWinTitle);

                    List<FullComponentType> lCloseComp = lCloseWindowComp.getFullComponent();

                    FullComponentType cCloseComp = factory.createFullComponentType();
                    cCloseComp.setWindow(closedWin.extractWindow().getWindow());
                    cCloseComp.setComponent(retComp);
                    lCloseComp.add(cCloseComp);
                    lCloseWindowComp.setFullComponent(lCloseComp);
                } // if
            } // for
        } // if

        if (monitor.isNewWindowOpened()) {

            List<FullComponentType> lOpenComp = lOpenWindowComps.getFullComponent();
            FullComponentType cOpenComp = factory.createFullComponentType();
            cOpenComp.setWindow(window.extractWindow().getWindow());
            cOpenComp.setComponent(retComp);
            lOpenComp.add(cOpenComp);
            lOpenWindowComps.setFullComponent(lOpenComp);

            LinkedList<GWindow> lNewWindows = monitor.getOpenedWindowCache();
            monitor.resetWindowCache();
            GUITARLog.log.info(lNewWindows.size() + " new window(s) opened!!!");
            for (GWindow newWins : lNewWindows) {
                GUITARLog.log.info("*\t Title:*" + newWins.getTitle() + "*");
            }

            // Process the opened windows in a FIFO order
            while (!lNewWindows.isEmpty()) {

                GWindow gNewWin = lNewWindows.getLast();
                lNewWindows.removeLast();

                GComponent gWinComp = gNewWin.getContainer();

                if (gWinComp != null) {

                    // Add invokelist property for the component
                    String sWindowTitle = gNewWin.getTitle();
                    compA = new ComponentTypeWrapper(retComp);
                    compA.addValueByName(GUITARConstants.INVOKELIST_TAG_NAME, sWindowTitle);

                    GUITARLog.log.debug(sWindowTitle + " recorded");

                    retComp = compA.getDComponentType();

                    // Check ignore window
                    if (!monitor.isIgnoredWindow(gNewWin)) {

                        if (!monitor.isRippedWindow(gNewWin)) {
                            gNewWin.setRoot(false);
                            monitor.addRippedList(gNewWin);

                            GUIType dWindow = ripWindow(gNewWin);

                            if (dWindow != null)
                                dGUIStructure.getGUI().add(dWindow);
                        } else {
                            GUITARLog.log.info("Window is ripped!!!");
                        }

                    } else {
                        GUITARLog.log.info("Window is ignored!!!");
                    }
                }

                monitor.closeWindow(gNewWin);
            }
        }

        // TODO: check if the component is still available after ripping
        // its child window
        List<GComponent> gChildrenList = component.getChildren();
        int nChildren = gChildrenList.size();
        int i = 0;

        // Debug

        String lChildren = "[";
        for (int j = 0; j < nChildren; j++) {
            lChildren += gChildrenList.get(j).getTitle() + " - " + gChildrenList.get(j).getClassVal() + "; ";
        }
        lChildren += "]";
        GUITARLog.log.debug("*" + component.getTitle() + "* in window *" + window.getTitle() + "* has "
                + nChildren + " children: " + lChildren);

        // End debug

        while (i < nChildren) {
            GComponent gChild = gChildrenList.get(i++);
            ComponentType guiChild = ripComponent(gChild, window);

            if (guiChild != null) {
                ((ContainerType) retComp).getContents().getWidgetOrContainer().add(guiChild);
            }

            if (nChildren < gChildrenList.size()) {
                nChildren = gChildrenList.size();
            }
        }

    } catch (Exception e) {
        if (e.getClass().getName().contains("StaleElementReferenceException")) {
            /**
             * This can happen when performing an action causes a page
             * navigation in the current window, for example, when
             * submitting a form.
             */
            GUITARLog.log.warn("Element went away: " + e.getMessage());
        } else {
            // TODO: Must throw exception
            GUITARLog.log.error("ripComponent exception", e);
        }

        /**
         * We'll return the component we calculated anyway so it
         * gets added to the GUI map. I'm not entirely sure this
         * is the right thing to do, but it gets us further anyway.
         */
        return retComp;
    }

    return retComp;
}