Search in sources :

Example 1 with Javelin

use of com.twinsoft.twinj.Javelin in project convertigo by convertigo.

the class JavelinTransaction method runCore.

public void runCore() throws EngineException {
    try {
        JavelinConnector connector = (JavelinConnector) parent;
        Javelin javelin = ((JavelinConnector) connector).javelin;
        vExtractionRulesInited = new ArrayList<String>(32);
        boolean bDocumentLogScreenDumps = (EnginePropertiesManager.getProperty(PropertyName.DOCUMENT_LOG_SCREEN_DUMPS).equals("true") ? true : false);
        if (handlerResult.equalsIgnoreCase(RETURN_CANCEL)) {
            // must detect screen class before exit
            String t = context.statistics.start(EngineStatistics.GET_CURRENT_SCREEN_CLASS);
            try {
                /*
					if ((Engine.objectsProvider == null) && !javelin.isConnected()) {
						throw new ConnectionException("The emulator has been disconnected! See the emulator logs for more details...");
					}
					*/
                screenClass = ((JavelinConnector) connector).getCurrentScreenClass();
                normalizedScreenClassName = StringUtils.normalize(screenClass.getName());
                context.lastDetectedObject = screenClass;
                score += 1;
                // for compatibility with older javelin projects, set the legacy lastDetectedScreenClass context property
                context.lastDetectedScreenClass = screenClass;
                Engine.logContext.info("Detected screen class: '" + screenClass.getName() + "'");
                if (bDocumentLogScreenDumps) {
                    StringBuffer screenDump = new StringBuffer("");
                    int sw = javelin.getScreenWidth();
                    int sh = javelin.getScreenHeight();
                    for (int i = 0; i < sh; i++) {
                        screenDump.append(javelin.getString(0, i, sw) + "\n");
                    }
                    Engine.logContext.info("Screen dump for screen class '" + screenClass.getName() + "':\n" + screenDump.toString());
                }
                // We fire engine events only in studio mode.
                if (Engine.isStudioMode()) {
                    Engine.theApp.fireObjectDetected(new EngineEvent(screenClass));
                }
                return;
            } finally {
                context.statistics.stop(t, bNotFirstLoop1);
            }
        }
        if (!handlerResult.equalsIgnoreCase(RETURN_BYPASS)) {
            applyUserRequest(javelin);
        }
        blocks = new ArrayList<Collection<Block>>(16);
        bNotFirstLoop1 = false;
        bNotFirstLoop2 = false;
        if (!runningThread.bContinue) {
            return;
        }
        do {
            do {
                String t = context.statistics.start(EngineStatistics.GET_CURRENT_SCREEN_CLASS);
                try {
                    /*
    					if ((Engine.objectsProvider == null) && !javelin.isConnected()) {
    						throw new ConnectionException("The emulator has been disconnected! See the emulator logs for more details...");
    					}
    					*/
                    screenClass = (JavelinScreenClass) ((JavelinConnector) connector).getCurrentScreenClass();
                    if (screenClass == null) {
                        throw new EngineException("(JavelinTransaction) The currentScreenClass is null, is the emulator connected ?");
                    }
                    normalizedScreenClassName = StringUtils.normalize(screenClass.getName());
                    context.lastDetectedObject = screenClass;
                    score += 1;
                    // for compatibility with older javelin projects, set the legacy lastDetectedScreenClass context property
                    context.lastDetectedScreenClass = screenClass;
                    Engine.logContext.info("Detected screen class: '" + screenClass.getName() + "'");
                    if (bDocumentLogScreenDumps) {
                        StringBuffer screenDump = new StringBuffer("");
                        int sw = javelin.getScreenWidth();
                        int sh = javelin.getScreenHeight();
                        for (int i = 0; i < sh; i++) {
                            screenDump.append(javelin.getString(0, i, sw) + "\n");
                        }
                        Engine.logContext.info("Screen dump for screen class '" + screenClass.getName() + "':\n" + screenDump.toString());
                    }
                    // We fire engine events only in studio mode.
                    if (Engine.isStudioMode()) {
                        Engine.theApp.fireObjectDetected(new EngineEvent(screenClass));
                    }
                } finally {
                    context.statistics.stop(t, bNotFirstLoop1);
                }
                // We execute the entry handler for the detected screen class
                executeHandler(EVENT_ENTRY_HANDLER, ((RequestableThread) Thread.currentThread()).javascriptContext);
                bNotFirstLoop1 = true;
            } while (runningThread.bContinue && (handlerResult.equalsIgnoreCase(RETURN_REDETECT)));
            if (!handlerResult.equalsIgnoreCase(RETURN_SKIP)) {
                BlockFactory blockFactory = screenClass.getBlockFactory();
                // We fire engine events only in studio mode.
                if (Engine.isStudioMode()) {
                    Engine.theApp.fireObjectDetected(new EngineEvent(blockFactory));
                }
                if (!runningThread.bContinue) {
                    return;
                }
                applyBlockFactory(screenClass, blockFactory, javelin, bNotFirstLoop2);
                Engine.logContext.debug("(JavelinTransaction) Block factory executed...");
                if (!runningThread.bContinue) {
                    return;
                }
                // first extraction rules execution on the block factory
                applyExtractionRules(screenClass, blockFactory, javelin, bNotFirstLoop2);
                if (executeExtractionRulesInPanels) {
                    // search panels and apply extraction rules on their content blocks
                    searchPanelsAndApplyExtractionRules(screenClass, blockFactory, javelin, bNotFirstLoop2);
                }
                Engine.logContext.debug("(JavelinTransaction) Extraction rules executed ...");
                blocks.add(blockFactory.getAllBlocks());
                Engine.logContext.debug("(JavelinTransaction) Blocks added to output");
            }
            if (!runningThread.bContinue) {
                return;
            }
            // We execute the exit handler for the current screen class
            executeHandler(EVENT_EXIT_HANDLER, ((RequestableThread) Thread.currentThread()).javascriptContext);
            bNotFirstLoop2 = true;
        } while (runningThread.bContinue && (handlerResult.equalsIgnoreCase(RETURN_ACCUMULATE)));
        if (!runningThread.bContinue) {
            return;
        }
        // Adding screen resolution information and cursor position information to the XML document
        Element documentElement = context.outputDocument.getDocumentElement();
        documentElement.setAttribute("screenWidth", Integer.toString(javelin.getScreenWidth()));
        documentElement.setAttribute("screenHeight", Integer.toString(javelin.getScreenHeight()));
        documentElement.setAttribute("cursorLine", Integer.toString(javelin.getCurrentLine()));
        documentElement.setAttribute("cursorColumn", Integer.toString(javelin.getCurrentColumn()));
        // Generating the blocks XML tags
        renderBlocksToXml(blocks);
        // and move all sub blocks node to the root element.
        if (isRemoveBlocksNode()) {
            NodeList childNodes = documentElement.getChildNodes();
            int len = childNodes.getLength();
            for (int i = 0; i < len; i++) {
                // Use index 0 because blocks node is removed at each loop round!
                Node node = childNodes.item(0);
                if (node.getNodeName().equalsIgnoreCase("blocks")) {
                    NodeList subNodesBlocks = node.getChildNodes();
                    int len2 = subNodesBlocks.getLength();
                    while (len2 > 0) {
                        documentElement.appendChild(subNodesBlocks.item(0));
                        subNodesBlocks = node.getChildNodes();
                        len2 = subNodesBlocks.getLength();
                    }
                    documentElement.removeChild(node);
                }
            }
        }
    } finally {
        if (sessionMustBeDestroyed) {
            Engine.logContext.debug("(JavelinTransaction) Destroying the current session");
            Engine.theApp.sessionManager.removeSession(context.contextID);
        }
        if ((runningThread == null) || (!runningThread.bContinue)) {
            Engine.logContext.warn("(JavelinTransaction) The transaction \"" + getName() + "\" has been successfully interrupted.");
        } else {
            Engine.logContext.debug("(JavelinTransaction) The transaction \"" + getName() + "\" has successfully finished.");
        }
    }
}
Also used : DefaultBlockFactory(com.twinsoft.convertigo.beans.common.DefaultBlockFactory) BlockFactory(com.twinsoft.convertigo.beans.core.BlockFactory) PanelBlockFactory(com.twinsoft.convertigo.beans.common.PanelBlockFactory) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) EngineException(com.twinsoft.convertigo.engine.EngineException) Javelin(com.twinsoft.twinj.Javelin) com.twinsoft.twinj.iJavelin(com.twinsoft.twinj.iJavelin) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) Collection(java.util.Collection)

Example 2 with Javelin

use of com.twinsoft.twinj.Javelin in project convertigo by convertigo.

the class JavelinConnectorComposite method showBlocks.

private void showBlocks(BlockFactoryWithVector bf) {
    JavelinConnector javelinConnector = (JavelinConnector) connector;
    Javelin javelin = javelinConnector.javelin;
    if (javelin == null)
        return;
    Vector<Rectangle> vz = null;
    Vector<Color> vc = null;
    int len;
    if (bf != null) {
        vz = new Vector<Rectangle>(bf.list.size());
        vc = new Vector<Color>(bf.list.size());
        Rectangle rect;
        for (Block block : bf.list) {
            String size = block.getOptionalAttribute("size");
            try {
                len = Integer.parseInt(size);
            } catch (Exception e) {
                len = block.length;
            }
            rect = new Rectangle(block.column, block.line, len, 1);
            vz.add(rect);
            vc.add(Color.gray);
        }
    }
    javelin.showZones(vz, vc);
}
Also used : JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Color(java.awt.Color) Rectangle(java.awt.Rectangle) Block(com.twinsoft.convertigo.beans.core.Block) Javelin(com.twinsoft.twinj.Javelin) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException)

Example 3 with Javelin

use of com.twinsoft.twinj.Javelin in project convertigo by convertigo.

the class JavelinConnectorComposite method getJavelin.

public Javelin getJavelin() {
    JavelinConnector javelinConnector = (JavelinConnector) connector;
    Javelin javelin = javelinConnector.javelin;
    return javelin;
}
Also used : JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Javelin(com.twinsoft.twinj.Javelin)

Example 4 with Javelin

use of com.twinsoft.twinj.Javelin in project convertigo by convertigo.

the class JavelinConnectorComposite method createWaitAtFromSelectionZone.

public void createWaitAtFromSelectionZone() {
    JavelinConnector javelinConnector = (JavelinConnector) connector;
    if (javelinConnector.isLearning()) {
        long timeout = 1000;
        if (!bHandlerOpened)
            openScreenClassHandler(true);
        // If there was a pending doAction command, clear it
        if (bDoAction) {
            bDoAction = false;
            long rightNow = new java.util.Date().getTime();
            timeout = rightNow - doActionTime;
        }
        Javelin javelin = getJavelin();
        Rectangle zone = javelin.getSelectionZone();
        String strZone = javelin.getString(zone.x, zone.y, zone.width);
        writeLine("javelin.waitAt(\"" + strZone + "\", " + zone.x + ", " + zone.y + ", " + ((int) (timeout * 1.3)) + ");");
        bWaitForDataStable = false;
        javelin.setSelectionZone(new Rectangle(0, 0, 0, 0));
        javelin.requestFocus();
    }
}
Also used : JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Rectangle(java.awt.Rectangle) Javelin(com.twinsoft.twinj.Javelin)

Example 5 with Javelin

use of com.twinsoft.twinj.Javelin in project convertigo by convertigo.

the class TransactionShowVariableAction method run.

public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            String variable = (String) ((VariableTreeObject) treeObject).getObject();
            JavelinTransaction transaction = (JavelinTransaction) treeObject.getParent().getParent().getObject();
            JavelinConnector javelinConnector = (JavelinConnector) transaction.getParent();
            IEditorPart wpart = getConnectorEditor(javelinConnector);
            if ((wpart != null) && (wpart instanceof ConnectorEditor)) {
                getActivePage().activate(wpart);
                ConnectorEditor connectorEditor = (ConnectorEditor) wpart;
                ConnectorEditorPart connectorEditorPart = connectorEditor.getConnectorEditorPart();
                AbstractConnectorComposite connectorComposite = connectorEditorPart.getConnectorComposite();
                if ((connectorComposite != null) && (connectorComposite instanceof JavelinConnectorComposite)) {
                    Javelin javelin = ((JavelinConnectorComposite) connectorComposite).getJavelin();
                    ScreenClass currentScreenClass = ((JavelinConnector) connectorEditorPart.getConnector()).getCurrentScreenClass();
                    String normalizedScreenClassName = StringUtils.normalize(currentScreenClass.getName());
                    int i;
                    String handlerName = "on" + normalizedScreenClassName + JavelinTransaction.EVENT_ENTRY_HANDLER;
                    if ((i = transaction.handlers.indexOf(handlerName)) == -1) {
                        display.beep();
                        ConvertigoPlugin.logWarning("Unable to show the position of the variable \"" + variable + "\": no handler found for the current screen class!");
                    } else {
                        ConvertigoPlugin.logDebug("Found handler: " + handlerName);
                        // Delimit the function
                        int bof, eof;
                        bof = transaction.handlers.indexOf('{', i) + 2;
                        eof = transaction.handlers.indexOf("function", bof);
                        if (eof == -1) {
                            eof = transaction.handlers.lastIndexOf('}') - 1;
                        } else {
                            eof = transaction.handlers.lastIndexOf('}', eof) - 1;
                        }
                        String function = transaction.handlers.substring(bof, eof);
                        // Delimit the marker for generated input variables code
                        int idxMarker = function.indexOf("\t// begin-of-variables");
                        if (idxMarker == -1) {
                            // No variable marker, do nothing
                            display.beep();
                            ConvertigoPlugin.logWarning("Unable to show the position of the variable \"" + variable + "\": no variable marker found for the handler!");
                            return;
                        }
                        int idxMarker2 = function.indexOf("\t// end-of-variables", idxMarker);
                        String code = function.substring(idxMarker, idxMarker2);
                        String line = "\tjavelin.send(" + variable + ");\n";
                        int idxPosition = code.indexOf(line);
                        if (idxPosition == -1) {
                            ConvertigoPlugin.logDebug("No variable '" + variable + "' found into the handler!");
                            return;
                        }
                        idxPosition = code.lastIndexOf("moveCursor(", idxPosition) + 11;
                        int idxComa = code.indexOf(',', idxPosition);
                        int idxClosedParenthesis = code.indexOf(')', idxComa);
                        int x = Integer.parseInt(code.substring(idxPosition, idxComa).trim());
                        int y = Integer.parseInt(code.substring(idxComa + 1, idxClosedParenthesis).trim());
                        ConvertigoPlugin.logDebug("Variable position found: " + x + ", " + y);
                        javelin.moveCursor(x, y);
                    }
                    javelin.requestFocus();
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to show variable to Javelin!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) AbstractConnectorComposite(com.twinsoft.convertigo.eclipse.editors.connector.AbstractConnectorComposite) JavelinConnectorComposite(com.twinsoft.convertigo.eclipse.editors.connector.JavelinConnectorComposite) Javelin(com.twinsoft.twinj.Javelin) IEditorPart(org.eclipse.ui.IEditorPart) Cursor(org.eclipse.swt.graphics.Cursor) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) ConnectorEditorPart(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditorPart) JavelinTransaction(com.twinsoft.convertigo.beans.transactions.JavelinTransaction) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Shell(org.eclipse.swt.widgets.Shell) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) VariableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.VariableTreeObject) Display(org.eclipse.swt.widgets.Display)

Aggregations

Javelin (com.twinsoft.twinj.Javelin)13 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)12 Rectangle (java.awt.Rectangle)5 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)4 AbstractConnectorComposite (com.twinsoft.convertigo.eclipse.editors.connector.AbstractConnectorComposite)4 ConnectorEditor (com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor)4 ConnectorEditorPart (com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditorPart)4 JavelinConnectorComposite (com.twinsoft.convertigo.eclipse.editors.connector.JavelinConnectorComposite)4 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)4 Cursor (org.eclipse.swt.graphics.Cursor)4 Display (org.eclipse.swt.widgets.Display)4 Shell (org.eclipse.swt.widgets.Shell)4 JavelinTransaction (com.twinsoft.convertigo.beans.transactions.JavelinTransaction)3 EngineEvent (com.twinsoft.convertigo.engine.EngineEvent)3 EngineException (com.twinsoft.convertigo.engine.EngineException)3 ScreenClassTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject)2 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)2 VariableTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.VariableTreeObject)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2