Search in sources :

Example 21 with WalkHelper

use of com.twinsoft.convertigo.engine.helpers.WalkHelper in project convertigo by convertigo.

the class ProjectUtils method getStatByProject.

public static Map<String, String> getStatByProject(Project project) throws Exception {
    final Map<String, String> result = new HashMap<String, String>();
    try {
        if (project != null) {
            try {
                new WalkHelper() {

                    String displayString = "";

                    @SuppressWarnings("unused")
                    int depth = 0;

                    int sequenceJavascriptLines;

                    int sequenceJavascriptFunction;

                    int connectorCount = 0;

                    int httpConnectorCount = 0;

                    int httpsConnectorCount = 0;

                    int htmlConnectorCount = 0;

                    int cicsConnectorCount = 0;

                    int siteClipperConnectorCount = 0;

                    int sqlConnectorCount = 0;

                    int javelinConnectorCount = 0;

                    int htmlScreenclassCount = 0;

                    int htmlCriteriaCount = 0;

                    int siteClipperScreenclassCount = 0;

                    int siteClipperCriteriaCount = 0;

                    int htmlExtractionRuleCount = 0;

                    int htmlTransactionVariableCount = 0;

                    int sqlTransactionVariableCount = 0;

                    int javelinTransactionVariableCount = 0;

                    int javelinScreenclassCount = 0;

                    int javelinCriteriaCount = 0;

                    int javelinExtractionRuleCount = 0;

                    int javelinEntryHandlerCount = 0;

                    int javelinExitHandlerCount = 0;

                    int javelinHandlerCount = 0;

                    int javelinJavascriptLines = 0;

                    int statementCount = 0;

                    int poolCount = 0;

                    int handlerstatementCount = 0;

                    @SuppressWarnings("unused")
                    int reqVariableCount = 0;

                    int sequenceVariableCount = 0;

                    @SuppressWarnings("unused")
                    int transactionVariableCount = 0;

                    int testcaseVariableCount = 0;

                    int testcaseCount = 0;

                    int sequenceCount = 0;

                    int stepCount = 0;

                    int sheetCount = 0;

                    int referenceCount = 0;

                    int selectInQueryCount = 0;

                    /*
    					 * transaction counters
    					 */
                    @SuppressWarnings("unused")
                    int transactionCount = 0;

                    @SuppressWarnings("unused")
                    int transactionWithVariablesCount = 0;

                    int htmltransactionCount = 0;

                    int httpTransactionCount = 0;

                    int httpsTransactionCount = 0;

                    int xmlHttpTransactionCount = 0;

                    int xmlHttpsTransactionCount = 0;

                    int jsonHttpTransactionCount = 0;

                    int jsonHttpsTransactionCount = 0;

                    int proxyTransactionCount = 0;

                    int siteClipperTransactionCount = 0;

                    int javelinTransactionCount = 0;

                    int sqlTransactionCount = 0;

                    int totalC8oObjects = 0;

                    public void go(DatabaseObject project) {
                        try {
                            String projectName = project.getName();
                            init(project);
                            connectorCount = htmlConnectorCount + httpConnectorCount + httpsConnectorCount + cicsConnectorCount + siteClipperConnectorCount + sqlConnectorCount + javelinConnectorCount;
                            totalC8oObjects = 1 + // connectors
                            connectorCount + htmlScreenclassCount + htmlCriteriaCount + htmlExtractionRuleCount + htmlTransactionVariableCount + handlerstatementCount + statementCount + javelinScreenclassCount + javelinCriteriaCount + javelinExtractionRuleCount + javelinTransactionCount + javelinEntryHandlerCount + javelinExitHandlerCount + javelinHandlerCount + javelinTransactionVariableCount + sqlTransactionCount + sqlTransactionVariableCount + sheetCount + jsonHttpTransactionCount + jsonHttpsTransactionCount + xmlHttpTransactionCount + xmlHttpsTransactionCount + httpTransactionCount + httpsTransactionCount + proxyTransactionCount + siteClipperTransactionCount + siteClipperScreenclassCount + siteClipperCriteriaCount + sequenceCount + stepCount + sequenceVariableCount + sequenceJavascriptFunction + poolCount + referenceCount + testcaseCount + testcaseVariableCount;
                            displayString = // ok
                            totalC8oObjects + " object(s)<br/>" + connectorCount + // ok
                            " connector(s)";
                            result.put(projectName, displayString);
                            if (htmltransactionCount > 0) {
                                displayString = // ok
                                (htmlScreenclassCount > 0 ? "&nbsp;screenclassCount = " + htmlScreenclassCount + "<br/>" : "") + (htmlCriteriaCount > 0 ? "&nbsp;criteriaCount = " + htmlCriteriaCount + "<br/>" : "") + (htmlExtractionRuleCount > 0 ? "&nbsp;extractionRuleCount = " + htmlExtractionRuleCount + "<br/>" : "") + "&nbsp;transactionCount = " + htmltransactionCount + // ok
                                "<br/>" + (htmlTransactionVariableCount > 0 ? "&nbsp;transactionVariableCount = " + htmlTransactionVariableCount + "<br/>" : "") + "&nbsp;statementCount (handlers=" + handlerstatementCount + ", statements=" + statementCount + ", total=" + (int) (handlerstatementCount + statementCount) + ")";
                                result.put("HTML connector", displayString);
                            }
                            /*
								 * javelin connector
								 */
                            if (javelinScreenclassCount > 0) {
                                displayString = // ok
                                "&nbsp;screenclassCount = " + javelinScreenclassCount + "<br/>" + (javelinCriteriaCount > 0 ? "&nbsp;criteriaCount = " + javelinCriteriaCount + "<br/>" : "") + (javelinExtractionRuleCount > 0 ? "&nbsp;extractionRuleCount = " + javelinExtractionRuleCount + "<br/>" : "") + // ok
                                (javelinTransactionCount > 0 ? "&nbsp;transactionCount = " + javelinTransactionCount + "<br/>" : "") + "&nbsp;handlerCount (Entry = " + javelinEntryHandlerCount + ", Exit = " + javelinExitHandlerCount + ", Screenclass = " + javelinHandlerCount + "), total = " + (int) (javelinEntryHandlerCount + javelinExitHandlerCount + javelinHandlerCount) + " in " + javelinJavascriptLines + " lines<br/>" + (javelinTransactionVariableCount > 0 ? "&nbsp;variableCount = " + javelinTransactionVariableCount : "");
                                result.put("Javelin connector", displayString);
                            }
                            /*
								 * SQL connector
								 */
                            if (sqlTransactionCount > 0) {
                                displayString = // ok
                                "&nbsp;sqltransactionCount = " + sqlTransactionCount + "<br/>" + // ok
                                (selectInQueryCount > 0 ? "&nbsp;selectInQueryCount = " + selectInQueryCount + "<br/>" : "") + (sqlTransactionVariableCount > 0 ? "&nbsp;transactionVariableCount = " + sqlTransactionVariableCount : "");
                                if (sheetCount > 0) {
                                    displayString += "<br/>Sheets<br/>" + "&nbsp;sheetCount = " + sheetCount;
                                }
                                result.put("SQL connector", displayString);
                            }
                            /*
								 * Http connector
								 */
                            if (httpConnectorCount > 0) {
                                displayString = "&nbsp;connectorCount = " + httpConnectorCount + "<br/>";
                            }
                            if (jsonHttpTransactionCount > 0) {
                                displayString += // ok
                                "&nbsp;JSONTransactionCount = " + jsonHttpTransactionCount + "<br/>" + // ok
                                (xmlHttpTransactionCount > 0 ? "&nbsp;XmlTransactionCount = " + xmlHttpTransactionCount + "<br/>" : "") + (httpTransactionCount > 0 ? "&nbsp;HTTPtransactionCount = " + httpTransactionCount : "");
                                result.put("HTTP connector", displayString);
                            }
                            /*
								 * Https connector
								 */
                            if (httpsConnectorCount > 0) {
                                displayString = "&nbsp;connectorCount = " + httpsConnectorCount + "<br/>" + // ok
                                (jsonHttpsTransactionCount > 0 ? "&nbsp;JSONTransactionCount = " + jsonHttpsTransactionCount + "<br/>" : "") + // ok
                                (xmlHttpsTransactionCount > 0 ? "&nbsp;XmlTransactionCount = " + xmlHttpsTransactionCount + "<br/>" : "") + // ok
                                (httpsTransactionCount > 0 ? "&nbsp;HTTPStransactionCount = " + httpsTransactionCount : "");
                                result.put("HTTPS connector", displayString);
                            }
                            /*
								 * Proxy connector
								 */
                            if (proxyTransactionCount > 0) {
                                displayString = "&nbsp;TransactionCount = " + proxyTransactionCount;
                                result.put("Proxy connector", displayString);
                            }
                            /*
								 * Siteclipper connector
								 */
                            if (siteClipperTransactionCount > 0) {
                                displayString = // ok
                                "&nbsp;TransactionCount = " + siteClipperTransactionCount + "<br/>" + // ok
                                (siteClipperScreenclassCount > 0 ? "&nbsp;screenclassCount = " + siteClipperScreenclassCount + "<br/>" : "") + (siteClipperCriteriaCount > 0 ? "&nbsp;criteriaCount = " + siteClipperCriteriaCount : "");
                                result.put("SiteClipper connector", displayString);
                            }
                            /*
								 * Sequencer
								 */
                            if (sequenceCount > 0) {
                                displayString = // ok
                                "&nbsp;sequenceCount = " + sequenceCount + "<br/>" + // ok
                                (stepCount > 0 ? "&nbsp;stepCount = " + stepCount + "<br/>" : "") + (sequenceVariableCount > 0 ? "&nbsp;variableCount = " + sequenceVariableCount + "<br/>" : "") + "&nbsp;javascriptCode = " + sequenceJavascriptFunction + " functions in " + sequenceJavascriptLines + " lines" + ((boolean) (sequenceJavascriptFunction == 0) ? " (declarations or so)" : "");
                                result.put("Sequencer", displayString);
                            }
                            if (poolCount > 0) {
                                displayString = "&nbsp;poolCount = " + poolCount;
                                result.put("Pools", displayString);
                            }
                            if (referenceCount > 0) {
                                displayString = "&nbsp;referenceCount = " + referenceCount;
                                result.put("References", displayString);
                            }
                            if (testcaseCount > 0) {
                                displayString = "&nbsp;testcaseCount = " + testcaseCount + "<br/>" + (testcaseVariableCount > 0 ? "&nbsp;testcaseVariableCount = " + testcaseVariableCount : "");
                                result.put("Test cases", displayString);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void walk(DatabaseObject databaseObject) throws Exception {
                        depth++;
                        // deal with connectors
                        if (databaseObject instanceof Connector) {
                            if (databaseObject instanceof HtmlConnector) {
                                htmlConnectorCount++;
                            } else if (databaseObject instanceof HttpConnector) {
                                if (((HttpConnector) databaseObject).isHttps())
                                    httpsConnectorCount++;
                                else
                                    httpConnectorCount++;
                            } else if (databaseObject instanceof CicsConnector) {
                                cicsConnectorCount++;
                            } else if (databaseObject instanceof SiteClipperConnector) {
                                siteClipperConnectorCount++;
                            } else if (databaseObject instanceof SqlConnector) {
                                sqlConnectorCount++;
                            } else if (databaseObject instanceof JavelinConnector) {
                                javelinConnectorCount++;
                            }
                        } else // deal with screenclasses
                        if (databaseObject instanceof ScreenClass) {
                            if (databaseObject instanceof JavelinScreenClass) {
                                // deal with javelinScreenClasses
                                javelinScreenclassCount++;
                            } else if (databaseObject instanceof SiteClipperScreenClass) {
                                // deal with siteClipperScreenClasses
                                siteClipperScreenclassCount++;
                            } else {
                                // deal with html ScreenClasses
                                htmlScreenclassCount++;
                            }
                        } else if (databaseObject instanceof Criteria) {
                            if (databaseObject.getParent() instanceof JavelinScreenClass) {
                                javelinCriteriaCount++;
                            } else if (databaseObject.getParent() instanceof SiteClipperScreenClass) {
                                siteClipperCriteriaCount++;
                            } else {
                                htmlCriteriaCount++;
                            }
                        } else if (databaseObject instanceof ExtractionRule) {
                            if (databaseObject.getParent() instanceof JavelinScreenClass) {
                                javelinExtractionRuleCount++;
                            } else {
                                htmlExtractionRuleCount++;
                            }
                        } else if (databaseObject instanceof Transaction) {
                            if (databaseObject instanceof TransactionWithVariables) {
                                if (databaseObject instanceof HtmlTransaction) {
                                    htmltransactionCount++;
                                } else if (databaseObject instanceof JsonHttpTransaction) {
                                    if (((HttpConnector) databaseObject.getParent()).isHttps())
                                        jsonHttpsTransactionCount++;
                                    else
                                        jsonHttpTransactionCount++;
                                } else if (databaseObject instanceof HttpTransaction) {
                                    if (((HttpConnector) databaseObject.getParent()).isHttps())
                                        httpsTransactionCount++;
                                    else
                                        httpTransactionCount++;
                                } else if (databaseObject instanceof XmlHttpTransaction) {
                                    if (((HttpConnector) databaseObject.getParent()).isHttps())
                                        xmlHttpsTransactionCount++;
                                    else
                                        xmlHttpTransactionCount++;
                                } else if (databaseObject instanceof ProxyTransaction) {
                                    proxyTransactionCount++;
                                } else if (databaseObject instanceof SiteClipperTransaction) {
                                    siteClipperTransactionCount++;
                                } else if (databaseObject instanceof JavelinTransaction) {
                                    JavelinTransaction javelinTransaction = (JavelinTransaction) databaseObject;
                                    // Functions
                                    String line;
                                    int lineNumber = 0;
                                    BufferedReader br = new BufferedReader(new StringReader(javelinTransaction.handlers));
                                    while ((line = br.readLine()) != null) {
                                        line = line.trim();
                                        lineNumber++;
                                        if (line.startsWith("function ")) {
                                            try {
                                                String functionName = line.substring(9, line.indexOf(')') + 1);
                                                if (functionName.endsWith(JavelinTransaction.EVENT_ENTRY_HANDLER + "()")) {
                                                    // TYPE_FUNCTION_SCREEN_CLASS_ENTRY
                                                    javelinEntryHandlerCount++;
                                                } else if (functionName.endsWith(JavelinTransaction.EVENT_EXIT_HANDLER + "()")) {
                                                    // TYPE_FUNCTION_SCREEN_CLASS_EXIT
                                                    javelinExitHandlerCount++;
                                                } else {
                                                    // TYPE_OTHER
                                                    javelinHandlerCount++;
                                                }
                                            } catch (StringIndexOutOfBoundsException e) {
                                            // Ignore
                                            }
                                        }
                                    }
                                    // compute total number of lines of javascript
                                    javelinJavascriptLines += lineNumber;
                                    javelinTransactionCount++;
                                } else if (databaseObject instanceof SqlTransaction) {
                                    SqlTransaction sqlTransaction = (SqlTransaction) databaseObject;
                                    /*
										 * count the number of SELECT
										 */
                                    String query = sqlTransaction.getSqlQuery();
                                    if (query != null) {
                                        query = query.toLowerCase();
                                        String pattern = "select";
                                        int lastIndex = 0;
                                        while (lastIndex != -1) {
                                            lastIndex = query.indexOf(pattern, lastIndex);
                                            if (lastIndex != -1) {
                                                selectInQueryCount++;
                                                lastIndex += pattern.length();
                                            }
                                        }
                                    }
                                    sqlTransactionCount++;
                                }
                                transactionWithVariablesCount++;
                            } else {
                                // transaction with no variables
                                transactionCount++;
                            }
                        } else // deal with statements
                        if (databaseObject instanceof Statement) {
                            // System.out.println(databaseObject.getClass().getName() + "\r\n");
                            if (databaseObject instanceof HandlerStatement) {
                                handlerstatementCount++;
                            } else {
                                statementCount++;
                            }
                        } else // deal with variables
                        if (databaseObject instanceof Variable) {
                            if (databaseObject.getParent() instanceof Transaction) {
                                if (databaseObject.getParent() instanceof JavelinTransaction) {
                                    javelinTransactionVariableCount++;
                                } else if (databaseObject.getParent() instanceof HtmlTransaction) {
                                    htmlTransactionVariableCount++;
                                } else if (databaseObject.getParent() instanceof SqlTransaction) {
                                    sqlTransactionVariableCount++;
                                } else {
                                    // should be zero
                                    transactionVariableCount++;
                                }
                            } else if (databaseObject.getParent() instanceof Sequence) {
                                sequenceVariableCount++;
                            } else if (databaseObject.getParent() instanceof TestCase) {
                                testcaseVariableCount++;
                            }
                        } else if (databaseObject instanceof TestCase) {
                            testcaseCount++;
                        } else if (databaseObject instanceof Sequence) {
                            sequenceCount++;
                        } else if (databaseObject instanceof Step) {
                            if (databaseObject instanceof SimpleStep) {
                                SimpleStep simpleStep = (SimpleStep) databaseObject;
                                // Functions
                                String line;
                                int lineNumber = 0;
                                BufferedReader br = new BufferedReader(new StringReader(simpleStep.getExpression()));
                                while ((line = br.readLine()) != null) {
                                    line = line.trim();
                                    lineNumber++;
                                    if (line.startsWith("function ")) {
                                        try {
                                            sequenceJavascriptFunction++;
                                        } catch (StringIndexOutOfBoundsException e) {
                                        // Ignore
                                        }
                                    }
                                }
                                sequenceJavascriptLines += lineNumber;
                                stepCount++;
                            } else
                                stepCount++;
                        } else if (databaseObject instanceof Sheet) {
                            sheetCount++;
                        } else if (databaseObject instanceof Pool) {
                            poolCount++;
                        }
                        super.walk(databaseObject);
                    }
                }.go(project);
            } catch (Exception e) {
            // Just ignore, should never happen
            }
        }
    } catch (Throwable e) {
        throw new Exception("Unable to compute statistics of the project!: \n" + e.getMessage());
    } finally {
    }
    return result;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) CicsConnector(com.twinsoft.convertigo.beans.connectors.CicsConnector) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) HttpTransaction(com.twinsoft.convertigo.beans.transactions.HttpTransaction) JsonHttpTransaction(com.twinsoft.convertigo.beans.transactions.JsonHttpTransaction) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) Variable(com.twinsoft.convertigo.beans.core.Variable) SimpleStep(com.twinsoft.convertigo.beans.steps.SimpleStep) HashMap(java.util.HashMap) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) SiteClipperScreenClass(com.twinsoft.convertigo.beans.screenclasses.SiteClipperScreenClass) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) SiteClipperScreenClass(com.twinsoft.convertigo.beans.screenclasses.SiteClipperScreenClass) ExtractionRule(com.twinsoft.convertigo.beans.core.ExtractionRule) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Criteria(com.twinsoft.convertigo.beans.core.Criteria) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) Step(com.twinsoft.convertigo.beans.core.Step) SimpleStep(com.twinsoft.convertigo.beans.steps.SimpleStep) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) JavelinTransaction(com.twinsoft.convertigo.beans.transactions.JavelinTransaction) ProxyTransaction(com.twinsoft.convertigo.engine.proxy.translated.ProxyTransaction) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) StringReader(java.io.StringReader) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Pool(com.twinsoft.convertigo.beans.core.Pool) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) Statement(com.twinsoft.convertigo.beans.core.Statement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) SiteClipperTransaction(com.twinsoft.convertigo.beans.transactions.SiteClipperTransaction) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) Sequence(com.twinsoft.convertigo.beans.core.Sequence) EngineException(com.twinsoft.convertigo.engine.EngineException) TransformerException(javax.xml.transform.TransformerException) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) ProxyTransaction(com.twinsoft.convertigo.engine.proxy.translated.ProxyTransaction) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) HttpTransaction(com.twinsoft.convertigo.beans.transactions.HttpTransaction) SiteClipperTransaction(com.twinsoft.convertigo.beans.transactions.SiteClipperTransaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) JavelinTransaction(com.twinsoft.convertigo.beans.transactions.JavelinTransaction) JsonHttpTransaction(com.twinsoft.convertigo.beans.transactions.JsonHttpTransaction) CicsConnector(com.twinsoft.convertigo.beans.connectors.CicsConnector) TestCase(com.twinsoft.convertigo.beans.core.TestCase) BufferedReader(java.io.BufferedReader) TransactionWithVariables(com.twinsoft.convertigo.beans.core.TransactionWithVariables) JsonHttpTransaction(com.twinsoft.convertigo.beans.transactions.JsonHttpTransaction) Sheet(com.twinsoft.convertigo.beans.core.Sheet)

Example 22 with WalkHelper

use of com.twinsoft.convertigo.engine.helpers.WalkHelper in project convertigo by convertigo.

the class DatabaseObject method getDatabaseObjectChildren.

public List<DatabaseObject> getDatabaseObjectChildren(boolean deep) throws Exception {
    final List<DatabaseObject> children = new LinkedList<>();
    new WalkHelper() {

        @Override
        protected void walk(DatabaseObject databaseObject) throws Exception {
            if (databaseObject == DatabaseObject.this) {
                super.walk(databaseObject);
            } else {
                children.add(databaseObject);
                if (deep) {
                    super.walk(databaseObject);
                }
            }
        }
    }.init(this);
    return children;
}
Also used : WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) LinkedList(java.util.LinkedList) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EngineException(com.twinsoft.convertigo.engine.EngineException) DatabaseObjectNotFoundException(com.twinsoft.convertigo.engine.DatabaseObjectNotFoundException) VersionException(com.twinsoft.convertigo.engine.VersionException) UndefinedSymbolsException(com.twinsoft.convertigo.engine.UndefinedSymbolsException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException)

Example 23 with WalkHelper

use of com.twinsoft.convertigo.engine.helpers.WalkHelper in project convertigo by convertigo.

the class XmlSchemaBuilder method preBuildSchema.

private void preBuildSchema() throws EngineException {
    try {
        schema.setElementFormDefault(new XmlSchemaForm(project.getSchemaElementForm().name()));
        schema.setAttributeFormDefault(new XmlSchemaForm(project.getSchemaElementForm().name()));
        ConvertigoError.addXmlSchemaObjects(schema);
        EngineStatistics.addXmlSchemaObjects(schema);
        // static and read-only generation : references, transactions, sequences declaration
        new WalkHelper() {

            @Override
            protected void walk(DatabaseObject databaseObject) throws Exception {
                if (databaseObject instanceof ISchemaGenerator) {
                    // generate itself and add to the caller list
                    if (databaseObject instanceof ISchemaImportGenerator) {
                        // Import case
                        if (databaseObject instanceof ProjectSchemaReference) {
                        // done further in buildSchema
                        } else {
                            XmlSchemaImport schemaImport = ((ISchemaImportGenerator) databaseObject).getXmlSchemaObject(collection, schema);
                            if (schemaImport != null) {
                                SchemaMeta.setXmlSchemaObject(schema, databaseObject, schemaImport);
                                XmlSchemaUtils.add(schema, schemaImport);
                            }
                        }
                    } else if (databaseObject instanceof ISchemaIncludeGenerator) {
                        // Include case
                        if (databaseObject instanceof Transaction) {
                            XmlSchemaInclude schemaInclude = ((ISchemaIncludeGenerator) databaseObject).getXmlSchemaObject(collection, schema);
                            addSchemaIncludeObjects(databaseObject, schemaInclude.getSchema());
                        } else {
                            XmlSchemaInclude schemaInclude = ((ISchemaIncludeGenerator) databaseObject).getXmlSchemaObject(collection, schema);
                            SchemaMeta.setXmlSchemaObject(schema, databaseObject, schemaInclude);
                            XmlSchemaUtils.add(schema, schemaInclude);
                        }
                    } else if (databaseObject instanceof Sequence) {
                        // Sequence case
                        XmlSchemaElement element = ((Sequence) databaseObject).getXmlSchemaObject(collection, schema);
                        SchemaMeta.setXmlSchemaObject(schema, databaseObject, element);
                        XmlSchemaUtils.add(schema, element);
                    }
                } else {
                    // doesn't generate schema, just deep walk
                    super.walk(databaseObject);
                }
            }

            @Override
            protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
                // just walk references, transactions, sequences declaration
                return Step.class.isAssignableFrom(dboClass) || Transaction.class.isAssignableFrom(dboClass) || Sequence.class.isAssignableFrom(dboClass) || Reference.class.isAssignableFrom(dboClass) || Connector.class.isAssignableFrom(dboClass);
            }

            protected void addSchemaIncludeObjects(DatabaseObject databaseObject, XmlSchema xmlSchema) {
                if (xmlSchema != null) {
                    XmlSchemaObjectCollection c = xmlSchema.getItems();
                    Iterator<XmlSchemaObject> it = GenericUtils.cast(c.getIterator());
                    while (it.hasNext()) {
                        XmlSchemaObject xmlSchemaObject = it.next();
                        SchemaMeta.getReferencedDatabaseObjects(xmlSchemaObject).add(databaseObject);
                        if (xmlSchemaObject instanceof XmlSchemaImport) {
                        // ignore
                        } else if (xmlSchemaObject instanceof XmlSchemaInclude) {
                            XmlSchemaInclude schemaInclude = (XmlSchemaInclude) xmlSchemaObject;
                            addSchemaIncludeObjects(databaseObject, schemaInclude.getSchema());
                        } else if (xmlSchemaObject instanceof XmlSchemaAttribute) {
                            XmlSchemaAttribute attribute = (XmlSchemaAttribute) xmlSchemaObject;
                            if (schema.getAttributes().getItem(attribute.getQName()) == null) {
                                schema.getAttributes().add(attribute.getQName(), attribute);
                                schema.getItems().add(attribute);
                            }
                        } else if (xmlSchemaObject instanceof XmlSchemaAttributeGroup) {
                            XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup) xmlSchemaObject;
                            if (schema.getAttributeGroups().getItem(attributeGroup.getName()) == null) {
                                schema.getAttributeGroups().add(attributeGroup.getName(), attributeGroup);
                                schema.getItems().add(attributeGroup);
                            }
                        } else if (xmlSchemaObject instanceof XmlSchemaGroup) {
                            XmlSchemaGroup group = (XmlSchemaGroup) xmlSchemaObject;
                            if (schema.getGroups().getItem(group.getName()) == null) {
                                schema.getGroups().add(group.getName(), group);
                                schema.getItems().add(group);
                            }
                        } else if (xmlSchemaObject instanceof XmlSchemaElement) {
                            XmlSchemaElement element = (XmlSchemaElement) xmlSchemaObject;
                            if (collection.getElementByQName(element.getQName()) == null && schema.getElementByName(element.getQName()) == null) {
                                schema.getElements().add(element.getQName(), element);
                                schema.getItems().add(element);
                            }
                        } else if (xmlSchemaObject instanceof XmlSchemaType) {
                            XmlSchemaType schemaType = (XmlSchemaType) xmlSchemaObject;
                            if (collection.getTypeByQName(schemaType.getQName()) == null && schema.getTypeByName(schemaType.getQName()) == null) {
                                schema.addType(schemaType);
                                schema.getItems().add(schemaType);
                            }
                        } else {
                            schema.getItems().add(xmlSchemaObject);
                        }
                    }
                }
            }
        }.init(project);
    } catch (Exception e) {
        throw new EngineException("preBuildSchema failed", e);
    }
}
Also used : ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Step(com.twinsoft.convertigo.beans.core.Step) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) XMLCopyStep(com.twinsoft.convertigo.beans.steps.XMLCopyStep) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) Iterator(java.util.Iterator) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection) ISchemaIncludeGenerator(com.twinsoft.convertigo.beans.core.ISchemaIncludeGenerator) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Reference(com.twinsoft.convertigo.beans.core.Reference) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) XmlSchemaAttributeGroup(org.apache.ws.commons.schema.XmlSchemaAttributeGroup) XmlSchemaForm(org.apache.ws.commons.schema.XmlSchemaForm) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) Sequence(com.twinsoft.convertigo.beans.core.Sequence) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) XmlSchemaGroup(org.apache.ws.commons.schema.XmlSchemaGroup) Transaction(com.twinsoft.convertigo.beans.core.Transaction) XmlSchema(org.apache.ws.commons.schema.XmlSchema) ISchemaImportGenerator(com.twinsoft.convertigo.beans.core.ISchemaImportGenerator) XmlSchemaInclude(org.apache.ws.commons.schema.XmlSchemaInclude) ISchemaGenerator(com.twinsoft.convertigo.beans.core.ISchemaGenerator)

Example 24 with WalkHelper

use of com.twinsoft.convertigo.engine.helpers.WalkHelper in project convertigo by convertigo.

the class CarUtils method exportProject.

private static Document exportProject(Project project, final boolean includeTestCases) throws EngineException {
    try {
        final Document document = XMLUtils.getDefaultDocumentBuilder().newDocument();
        // ProcessingInstruction pi = document.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
        // document.appendChild(pi);
        final Element rootElement = document.createElement("convertigo");
        rootElement.setAttribute("version", com.twinsoft.convertigo.engine.Version.fullProductVersion);
        rootElement.setAttribute("engine", com.twinsoft.convertigo.engine.Version.version);
        rootElement.setAttribute("beans", com.twinsoft.convertigo.beans.Version.version);
        String studioVersion = "";
        try {
            Class<?> c = Class.forName("com.twinsoft.convertigo.eclipse.Version");
            studioVersion = (String) c.getDeclaredField("version").get(null);
        } catch (Exception e) {
        } catch (Throwable th) {
        }
        rootElement.setAttribute("studio", studioVersion);
        document.appendChild(rootElement);
        new WalkHelper() {

            protected Element parentElement = rootElement;

            @Override
            protected void walk(DatabaseObject databaseObject) throws Exception {
                Element parentElement = this.parentElement;
                Element element = parentElement;
                element = databaseObject.toXml(document);
                String name = " : " + databaseObject.getName();
                try {
                    name = CachedIntrospector.getBeanInfo(databaseObject.getClass()).getBeanDescriptor().getDisplayName() + name;
                } catch (IntrospectionException e) {
                    name = databaseObject.getClass().getSimpleName() + name;
                }
                Integer depth = (Integer) document.getUserData("depth");
                if (depth == null) {
                    depth = 0;
                }
                String openpad = StringUtils.repeat("   ", depth);
                String closepad = StringUtils.repeat("   ", depth);
                parentElement.appendChild(document.createTextNode("\n"));
                parentElement.appendChild(document.createComment(StringUtils.rightPad(openpad + "<" + name + ">", 150)));
                if (databaseObject instanceof TestCase) {
                    if (includeTestCases) {
                        parentElement.appendChild(element);
                    }
                } else {
                    parentElement.appendChild(element);
                }
                document.setUserData("depth", depth + 1, null);
                this.parentElement = element;
                super.walk(databaseObject);
                element.appendChild(document.createTextNode("\n"));
                element.appendChild(document.createComment(StringUtils.rightPad(closepad + "</" + name + ">", 150)));
                document.setUserData("depth", depth, null);
                databaseObject.hasChanged = false;
                databaseObject.bNew = false;
                this.parentElement = parentElement;
            }
        }.init(project);
        return document;
    } catch (Exception e) {
        throw new EngineException("Unable to export the project \"" + project.getName() + "\".", e);
    }
}
Also used : Element(org.w3c.dom.Element) IntrospectionException(java.beans.IntrospectionException) EngineException(com.twinsoft.convertigo.engine.EngineException) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Document(org.w3c.dom.Document) IOException(java.io.IOException) IntrospectionException(java.beans.IntrospectionException) EngineException(com.twinsoft.convertigo.engine.EngineException) TestCase(com.twinsoft.convertigo.beans.core.TestCase) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 25 with WalkHelper

use of com.twinsoft.convertigo.engine.helpers.WalkHelper in project convertigo by convertigo.

the class DatabaseObjectsManager method symbolsGetUndefined.

public Set<String> symbolsGetUndefined(String projectName) throws Exception {
    Project project = getOriginalProjectByName(projectName, false);
    final Set<String> allUndefinedSymbols = new HashSet<String>();
    if (project.undefinedGlobalSymbols) {
        new WalkHelper() {

            @Override
            protected void walk(DatabaseObject databaseObject) throws Exception {
                if (databaseObject.isSymbolError()) {
                    for (Set<String> undefinedSymbols : databaseObject.getSymbolsErrors().values()) {
                        allUndefinedSymbols.addAll(undefinedSymbols);
                    }
                }
                super.walk(databaseObject);
            }
        }.init(project);
    }
    return Collections.unmodifiableSet(allUndefinedSymbols);
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) SortedSet(java.util.SortedSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashSet(java.util.HashSet)

Aggregations

WalkHelper (com.twinsoft.convertigo.engine.helpers.WalkHelper)26 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)25 Project (com.twinsoft.convertigo.beans.core.Project)14 EngineException (com.twinsoft.convertigo.engine.EngineException)10 IOException (java.io.IOException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 CoreException (org.eclipse.core.runtime.CoreException)9 ArrayList (java.util.ArrayList)8 Transaction (com.twinsoft.convertigo.beans.core.Transaction)7 Step (com.twinsoft.convertigo.beans.core.Step)6 JSONException (org.codehaus.jettison.json.JSONException)6 Connector (com.twinsoft.convertigo.beans.core.Connector)5 Criteria (com.twinsoft.convertigo.beans.core.Criteria)5 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)5 Sequence (com.twinsoft.convertigo.beans.core.Sequence)5 Sheet (com.twinsoft.convertigo.beans.core.Sheet)5 Statement (com.twinsoft.convertigo.beans.core.Statement)5 TestCase (com.twinsoft.convertigo.beans.core.TestCase)5 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)5 HashMap (java.util.HashMap)5