Search in sources :

Example 16 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class TableEditorComposite method createToolBar.

/**
 * This method initializes toolBar
 */
private void createToolBar() {
    GridData gridData = new org.eclipse.swt.layout.GridData();
    gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = false;
    gridData.verticalAlignment = org.eclipse.swt.layout.GridData.FILL;
    toolBar = new ToolBar(this, SWT.FLAT);
    toolBar.setLayoutData(gridData);
    ToolItem newLine = new ToolItem(toolBar, SWT.PUSH);
    newLine.setImage(new Image(Display.getCurrent(), getClass().getResourceAsStream("/com/twinsoft/convertigo/eclipse/property_editors/images/table_editor/new_line.png")));
    newLine.setDisabledImage(new Image(Display.getCurrent(), getClass().getResourceAsStream("/com/twinsoft/convertigo/eclipse/property_editors/images/table_editor/new_line.d.png")));
    newLine.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {

        @Override
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            XMLVector<Object> newLine = new XMLVector<Object>();
            int len = ((TableEditor) cellEditor).templateData.length;
            for (int i = 0; i < len; i++) newLine.add(((TableEditor) cellEditor).templateData[i]);
            rowList.addRow(new TableEditorRow(newLine));
        }
    });
    ToolItem deleteLine = new ToolItem(toolBar, SWT.PUSH);
    deleteLine.setImage(new Image(Display.getCurrent(), getClass().getResourceAsStream("/com/twinsoft/convertigo/eclipse/property_editors/images/table_editor/delete.png")));
    deleteLine.setDisabledImage(new Image(Display.getCurrent(), getClass().getResourceAsStream("/com/twinsoft/convertigo/eclipse/property_editors/images/table_editor/delete.d.png")));
    deleteLine.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {

        @Override
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            TableEditorRow row = (TableEditorRow) selection.getFirstElement();
            if (row != null) {
                TableEditorRow nextRow = null;
                int index = rowList.getRows().indexOf(row);
                int size = rowList.getRows().size();
                if (size == 1) {
                // only one row
                } else {
                    nextRow = rowList.getRows().get(index + ((size == index + 1) ? -1 : 1));
                }
                rowList.removeRow(row);
                if (nextRow != null) {
                    StructuredSelection newSelection = new StructuredSelection(nextRow);
                    tableViewer.setSelection(newSelection);
                }
            }
        }
    });
    ToolItem moveUp = new ToolItem(toolBar, SWT.PUSH);
    moveUp.setImage(new Image(Display.getCurrent(), getClass().getResourceAsStream("/com/twinsoft/convertigo/eclipse/property_editors/images/table_editor/move_up.png")));
    moveUp.setDisabledImage(new Image(Display.getCurrent(), getClass().getResourceAsStream("/com/twinsoft/convertigo/eclipse/property_editors/images/table_editor/move_up.d.png")));
    moveUp.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {

        @Override
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            TableEditorRow row = (TableEditorRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement();
            if (row != null) {
                List<TableEditorRow> v = rowList.getRows();
                if (v.contains(row)) {
                    int index = v.indexOf(row);
                    if (index > 0) {
                        TableEditorRow upRow = new TableEditorRow(row.getLine());
                        rowList.insertRow(upRow, ((index - 1 > 0) ? index - 1 : 0));
                        rowList.removeRow(row);
                        StructuredSelection newSelection = new StructuredSelection(upRow);
                        tableViewer.setSelection(newSelection);
                    }
                }
            }
        }
    });
    ToolItem moveDown = new ToolItem(toolBar, SWT.PUSH);
    moveDown.setImage(new Image(Display.getCurrent(), getClass().getResourceAsStream("/com/twinsoft/convertigo/eclipse/property_editors/images/table_editor/move_down.png")));
    moveDown.setDisabledImage(new Image(Display.getCurrent(), getClass().getResourceAsStream("/com/twinsoft/convertigo/eclipse/property_editors/images/table_editor/move_down.d.png")));
    moveDown.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {

        @Override
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            TableEditorRow row = (TableEditorRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement();
            if (row != null) {
                List<TableEditorRow> v = rowList.getRows();
                if (v.contains(row)) {
                    int len = v.size() - 1;
                    int index = v.indexOf(row);
                    if (index < len) {
                        TableEditorRow dowRow = new TableEditorRow(row.getLine());
                        rowList.insertRow(dowRow, ((index + 2 <= len) ? index + 2 : -1));
                        rowList.removeRow(row);
                        StructuredSelection newSelection = new StructuredSelection(dowRow);
                        tableViewer.setSelection(newSelection);
                    }
                }
            }
        }
    });
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) List(java.util.List) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 17 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class XMLTableWizardPage method fillXMLTableDescription.

private void fillXMLTableDescription() {
    NodeList tables;
    try {
        String theXPath = (xpath.indexOf("//TABLE") != -1) ? xpath : (xpath.startsWith("/") ? xpath : "/" + xpath);
        tables = XPathAPI.eval(dom.getDocumentElement(), theXPath).nodelist();
        if (tables.getLength() > 0) {
            // ------------------------------------------------------------- For Bean XMLTable
            xDescription = new XMLVector<XMLVector<Object>>();
            Element table = (Element) tables.item(0);
            int iHeaderRow = Integer.parseInt(headerRow.getText().trim(), 10);
            int iHeaderCol = Integer.parseInt(headerCol.getText().trim(), 10);
            boolean bHeadersFromRow = checkBoxHeadersFromRow.getSelection();
            boolean bHeadersFromCol = checkBoxHeadersFromCol.getSelection();
            boolean hasTableBody = XPathAPI.eval(table, "./TBODY").nodelist().getLength() > 0;
            int iTR = iHeaderRow + 1;
            int iTD = iHeaderCol + 1;
            if (!bHeadersFromCol && !bHeadersFromRow) {
                XMLTableRow xRow = XMLTableRow.create();
                xRow.setXpath(hasTableBody ? "./TBODY/TR" : "./TR");
                xRow.addColumn("column", "./TD", false);
                xDescription.add(xRow.toXMLVector());
            } else {
                boolean bSameRowHeaderNames = false, bSameColHeaderNames = false;
                String oldRowName = null, oldColName = null;
                Vector<String> colNames = new Vector<String>();
                String dataXPath = (hasTableBody ? (bHeadersFromRow ? "(./TBODY/TR)[position()>" + iHeaderRow + "]" : "./TBODY/TR") : (bHeadersFromRow ? "(./TR)[position()>" + iHeaderRow + "]" : "./TR"));
                NodeList nlTR = XPathAPI.eval(table, dataXPath).nodelist();
                for (int i = 0; i < nlTR.getLength(); i++) {
                    int iRow = iTR + i;
                    XMLTableRow xRow = XMLTableRow.create();
                    String rowXPath = (hasTableBody ? (bHeadersFromRow ? "(./TBODY/TR)[position()>" + iTR + "]" : "./TBODY/TR") : (bHeadersFromRow ? "(./TR)[position()>" + iTR + "]" : "./TR"));
                    xRow.setXpath(bHeadersFromCol ? (hasTableBody ? "(./TBODY/TR)[" + iRow + "]" : "(./TR)[" + iRow + "]") : rowXPath);
                    NodeList nlTD = XPathAPI.eval(nlTR.item(i), "(./TD)[position()>" + iHeaderCol + "] | (./TH)[position()>" + iHeaderCol + "]").nodelist();
                    for (int j = 0; j < nlTD.getLength(); j++) {
                        NodeList nltxt = XPathAPI.eval(nlTD.item(j), ".//text()").nodelist();
                        String tmpVal = "";
                        for (int k = 0; k < nltxt.getLength(); k++) {
                            tmpVal += StringUtils.normalize(nltxt.item(k).getNodeValue());
                        }
                        tmpVal.trim();
                        tmpVal = tmpVal.equals("") ? "X" : tmpVal;
                        int iCol = iTD + j;
                        if (bHeadersFromRow) {
                            if (i == 0) {
                                colNames.add(tmpVal);
                            } else {
                                if (bHeadersFromCol) {
                                    if (j == 0)
                                        xRow.setName(tmpVal);
                                    else {
                                        xRow.addColumn(colNames.get(j), "(./TD|./TH)[" + iCol + "]", true);
                                        if (oldColName == null)
                                            oldColName = colNames.get(j);
                                        else
                                            bSameColHeaderNames = oldColName.equals(colNames.get(j));
                                    }
                                } else {
                                    xRow.addColumn(colNames.get(j), "(./TD|./TH)[" + iCol + "]", true);
                                    if (oldColName == null)
                                        oldColName = colNames.get(j);
                                    else
                                        bSameColHeaderNames = oldColName.equals(colNames.get(j));
                                }
                            }
                        } else if (bHeadersFromCol) {
                            if (j == 0)
                                xRow.setName(tmpVal);
                            else
                                xRow.addColumn("column" + j, "(./TD|./TH)[" + iCol + "]", true);
                        }
                    }
                    if (((i == 1) && bHeadersFromRow && !bHeadersFromCol) || ((i >= 1) && bHeadersFromRow && bHeadersFromCol) || (!bHeadersFromRow && bHeadersFromCol)) {
                        if (bSameColHeaderNames) {
                            // optimization for table's columns with same names
                            int last;
                            xRow.setColumnXPath(0, "(./TD|./TH)[position()>" + (bHeadersFromCol ? iTD : iHeaderCol) + "]");
                            while ((last = xRow.getColumns().size()) > 1) xRow.getColumns().remove(last - 1);
                        }
                        xDescription.add(xRow.toXMLVector());
                        if (oldRowName == null)
                            oldRowName = xRow.getName();
                        else
                            bSameRowHeaderNames = oldRowName.equals(xRow.getName());
                    }
                }
                if (bSameRowHeaderNames) {
                    // optimization for table's rows with same names
                    XMLTableRow xRow = new XMLTableRow(xDescription.get(0));
                    xRow.setXpath(hasTableBody ? "(./TBODY/TR)[position()>" + (bHeadersFromRow ? iTR : iHeaderRow) + "]" : "(./TR)[position()>" + (bHeadersFromRow ? iTR : iHeaderRow) + "]");
                    xDescription = new XMLVector<XMLVector<Object>>();
                    xDescription.add(xRow.toXMLVector());
                }
            }
            // ------------------------------------------------------------ For SWT Table
            data = new Vector<Vector<String>>();
            NodeList nlCol = XPathAPI.eval(table, (hasTableBody ? "./TBODY/TR" : "./TR")).nodelist();
            for (int i = 0; i < nlCol.getLength(); i++) {
                if (i < iHeaderRow)
                    continue;
                NodeList nltd = XPathAPI.eval(nlCol.item(i), "./TD|./TH").nodelist();
                Vector<String> row = new Vector<String>();
                for (int j = 0; j < nltd.getLength(); j++) {
                    NodeList nltxt = XPathAPI.eval(nltd.item(j), ".//text()").nodelist();
                    String tmpVal = "";
                    for (int k = 0; k < nltxt.getLength(); k++) {
                        tmpVal += StringUtils.normalize(nltxt.item(k).getNodeValue());
                    }
                    if (j < iHeaderCol)
                        continue;
                    row.add(tmpVal.trim());
                }
                data.add(row);
            }
            if (table != null) {
                setTableData();
            }
        }
    } catch (Exception e) {
        ;
    }
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) XMLTableRow(com.twinsoft.convertigo.beans.common.XMLTableRow) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) Vector(java.util.Vector)

Example 18 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class Migration7_0_0 method handleSteps.

private static void handleSteps(XmlSchema projectSchema, Map<String, Reference> referenceMap, List<Step> stepList) {
    for (Step step : stepList) {
        if (step instanceof XMLActionStep) {
            XMLVector<XMLVector<Object>> sourcesDefinition = ((XMLActionStep) step).getSourcesDefinition();
            for (XMLVector<Object> row : sourcesDefinition) {
                if (row.size() > 1) {
                    XMLVector<String> definition = GenericUtils.cast(row.get(1));
                    handleSourceDefinition(definition);
                }
            }
        }
        if (step instanceof TransactionStep) {
            XMLVector<String> definition = ((TransactionStep) step).getConnectionStringDefinition();
            handleSourceDefinition(definition);
        }
        if (step instanceof IStepSourceContainer) {
            /**
             * Case step's xpath has not been migrated when project has been deployed
             ** on a 5.0 server from a Studio with an older version *
             */
            IStepSourceContainer stepSourceContainer = (IStepSourceContainer) step;
            XMLVector<String> definition = stepSourceContainer.getSourceDefinition();
            handleSourceDefinition(definition);
        }
        if (step instanceof IVariableContainer) {
            IVariableContainer variableContainer = (IVariableContainer) step;
            for (Variable variable : variableContainer.getVariables()) {
                if (variable instanceof IStepSourceContainer) {
                    IStepSourceContainer stepSourceContainer = (IStepSourceContainer) variable;
                    XMLVector<String> definition = stepSourceContainer.getSourceDefinition();
                    handleSourceDefinition(definition);
                }
            }
        }
        String targetProjectName = null;
        String typeLocalName = null;
        if (step instanceof TransactionStep) {
            targetProjectName = ((TransactionStep) step).getProjectName();
            typeLocalName = ((TransactionStep) step).getConnectorName() + "__" + ((TransactionStep) step).getTransactionName() + "ResponseType";
        } else if (step instanceof SequenceStep) {
            targetProjectName = ((SequenceStep) step).getProjectName();
            typeLocalName = ((SequenceStep) step).getSequenceName() + "ResponseType";
        }
        String namespaceURI = null;
        // Case of Requestable steps
        if (targetProjectName != null) {
            try {
                namespaceURI = Project.CONVERTIGO_PROJECTS_NAMESPACEURI + targetProjectName;
                if (!targetProjectName.equals(step.getProject().getName())) {
                    try {
                        namespaceURI = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(targetProjectName).getTargetNamespace();
                    } catch (Exception e) {
                    }
                    // Add reference
                    String location = "../" + targetProjectName + "/" + targetProjectName + ".xsd";
                    addReferenceToMap(referenceMap, namespaceURI, location);
                }
                // Set step's typeQName
                step.setXmlComplexTypeAffectation(new XmlQName(new QName(namespaceURI, typeLocalName)));
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else // Other steps
        {
            try {
                String targetNamespace = projectSchema.getTargetNamespace();
                String targetPrefix = projectSchema.getNamespaceContext().getPrefix(targetNamespace);
                String s = null;
                try {
                    if (step instanceof XMLCopyStep) {
                        XmlSchemaCollection collection = SchemaMeta.getCollection(projectSchema);
                        XmlSchemaObject ob = step.getXmlSchemaObject(collection, projectSchema);
                        if (ob != null) {
                            if (ob instanceof XmlSchemaSequence) {
                                ob = ((XmlSchemaSequence) ob).getItems().getItem(0);
                            }
                            if (ob instanceof XmlSchemaElement || ob instanceof XmlSchemaAttribute) {
                                QName schemaTypeName = ob instanceof XmlSchemaElement ? ((XmlSchemaElement) ob).getSchemaTypeName() : ((XmlSchemaAttribute) ob).getSchemaTypeName();
                                String schemaTypePrefix = projectSchema.getNamespaceContext().getPrefix(schemaTypeName.getNamespaceURI());
                                String schemaTypeLocalName = schemaTypeName.getLocalPart();
                                s = schemaTypePrefix + ":" + schemaTypeLocalName;
                            }
                        }
                    } else {
                        String schemaType = step.getSchemaDataType();
                        s = schemaType.equals("") ? "xsd:string" : schemaType;
                    }
                } catch (Exception e) {
                    s = "xsd:string";
                }
                if ((s != null) && (!s.equals("")) && (!s.startsWith("xsd:"))) {
                    String prefix = s.split(":")[0];
                    typeLocalName = s.split(":")[1];
                    if (prefix.equals(targetPrefix)) {
                    // ignore
                    } else {
                        // Retrieve namespace uri
                        namespaceURI = projectSchema.getNamespaceContext().getNamespaceURI(prefix);
                        // Set step's typeQName
                        QName qname = new QName(namespaceURI, typeLocalName);
                        XmlSchemaType schemaType = projectSchema.getTypeByName(qname);
                        if (schemaType instanceof XmlSchemaComplexType)
                            step.setXmlComplexTypeAffectation(new XmlQName(qname));
                        if (schemaType instanceof XmlSchemaSimpleType)
                            step.setXmlSimpleTypeAffectation(new XmlQName(qname));
                    }
                }
            } catch (Exception e) {
            }
        }
        if (step instanceof ISimpleTypeAffectation) {
            QName qName = XmlSchemaUtils.getSchemaDataTypeName(step.getSchemaDataType());
            step.setXmlSimpleTypeAffectation(new XmlQName(qName));
        }
        if (step instanceof StepWithExpressions) {
            handleSteps(projectSchema, referenceMap, ((StepWithExpressions) step).getSteps());
        }
    }
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) Step(com.twinsoft.convertigo.beans.core.Step) XMLActionStep(com.twinsoft.convertigo.beans.steps.XMLActionStep) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) XMLCopyStep(com.twinsoft.convertigo.beans.steps.XMLCopyStep) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) IStepSourceContainer(com.twinsoft.convertigo.beans.core.IStepSourceContainer) XMLCopyStep(com.twinsoft.convertigo.beans.steps.XMLCopyStep) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) ISimpleTypeAffectation(com.twinsoft.convertigo.beans.core.ISimpleTypeAffectation) XMLActionStep(com.twinsoft.convertigo.beans.steps.XMLActionStep) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) IVariableContainer(com.twinsoft.convertigo.beans.core.IVariableContainer) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 19 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class Migration5_0_0 method updateElement.

private static void updateElement(Element element) {
    String version = element.getAttribute("version");
    String elementClassName = element.getAttribute("classname");
    Class<?> beanClass;
    try {
        NodeList children = element.getChildNodes();
        Element nameElement = MigrationUtils.findChildElementByAttributeValue(children, "property", "name");
        Element nameElementNode = (Element) XMLUtils.findChildNode(nameElement, Node.ELEMENT_NODE);
        String elementName = (String) XMLUtils.readObjectFromXml(nameElementNode);
        beanClass = GenericUtils.cast(Class.forName(elementClassName));
        // Case of Transaction
        if (com.twinsoft.convertigo.beans.core.Transaction.class.isAssignableFrom(beanClass)) {
            if (VersionUtils.compare(version, "3.0.2") < 0) {
                Element responseTimeout = MigrationUtils.findChildElementByAttributeValue(children, "property", "responseTimeout");
                if (responseTimeout != null) {
                    Element responseTimeoutNode = (Element) XMLUtils.findChildNode(responseTimeout, Node.ELEMENT_NODE);
                    Long iResponseTimeout = (Long) XMLUtils.readObjectFromXml(responseTimeoutNode);
                    Element newNode = (Element) XMLUtils.writeObjectToXml(element.getOwnerDocument(), iResponseTimeout.intValue() / 1000);
                    responseTimeout.replaceChild(newNode, responseTimeoutNode);
                }
                element.setAttribute("version", "3.0.2");
                Engine.logDatabaseObjectManager.warn("[Migration 4.6.0] The object \"" + elementName + "\" has been updated to version 3.0.2");
            }
            // Case of TransactionWithVariables
            if (com.twinsoft.convertigo.beans.core.TransactionWithVariables.class.isAssignableFrom(beanClass)) {
                Element variablesDefinition = MigrationUtils.findChildElementByAttributeValue(children, "property", "variables");
                if (variablesDefinition == null) {
                    variablesDefinition = MigrationUtils.findChildElementByAttributeValue(children, "property", "variablesDefinition");
                }
                if (variablesDefinition != null) {
                    Element variablesDefinitionNode = (Element) XMLUtils.findChildNode(variablesDefinition, Node.ELEMENT_NODE);
                    XMLVector<XMLVector<Object>> xmlv = GenericUtils.cast(XMLUtils.readObjectFromXml(variablesDefinitionNode));
                    if (VersionUtils.compare(version, "3.1.8") < 0) {
                        // Case of HttpTransaction
                        if (AbstractHttpTransaction.class.isAssignableFrom(beanClass)) {
                            Element httpVariables = MigrationUtils.findChildElementByAttributeValue(children, "property", "httpVariables");
                            if (httpVariables != null) {
                                Element httpVariablesNode = (Element) XMLUtils.findChildNode(httpVariables, Node.ELEMENT_NODE);
                                XMLVector<XMLVector<Object>> xmlv1 = GenericUtils.cast(XMLUtils.readObjectFromXml(httpVariablesNode));
                                /*Node xmlNode = null;
									NodeList nl = propValue.getChildNodes();
									int len_nl = nl.getLength();
									for (int j = 0 ; j < len_nl ; j++) {
										xmlNode = nl.item(j);
										if (xmlNode.getNodeType() == Node.ELEMENT_NODE) {
											httpVariables = (XMLVector) XMLUtils.readObjectFromXml((Element) xmlNode);
											continue;
										}
									}*/
                                int len = xmlv.size();
                                for (int i = 0; i < len; i++) {
                                    XMLVector<Object> line = xmlv.get(i);
                                    if (xmlv1.size() > 0) {
                                        line.add(xmlv1.get(i).get(1));
                                        line.add(xmlv1.get(i).get(2));
                                    }
                                }
                            }
                        }
                        int len = xmlv.size();
                        for (int i = 0; i < len; i++) {
                            XMLVector<Object> line = xmlv.get(i);
                            if (line.size() > 0) {
                                // Include in WSDL by default
                                line.add(Boolean.TRUE);
                            }
                        }
                        element.setAttribute("version", "3.1.8");
                        Engine.logDatabaseObjectManager.warn("[Migration 4.6.0] The object \"" + elementName + "\" has been updated to version 3.1.8");
                    }
                    if (VersionUtils.compare(version, "3.2.4") < 0) {
                        int len = xmlv.size();
                        for (int i = 0; i < len; i++) {
                            XMLVector<Object> line = xmlv.get(i);
                            if (line.size() > 0) {
                                // Defaults to non multivalued variable
                                line.add(3, Boolean.FALSE);
                            }
                        }
                        element.setAttribute("version", "3.2.4");
                        Engine.logDatabaseObjectManager.warn("[Migration 4.6.0] The object \"" + elementName + "\" has been updated to version 3.2.4");
                    }
                    if (VersionUtils.compare(version, "4.1.5") < 0) {
                        // Case of JavelinTransaction
                        if (com.twinsoft.convertigo.beans.transactions.JavelinTransaction.class.isAssignableFrom(beanClass)) {
                            Element propValue = MigrationUtils.findChildElementByAttributeValue(children, "property", "executeExtractionRulesInPanels");
                            if (propValue == null) {
                                Document document = element.getOwnerDocument();
                                propValue = document.createElement("property");
                                propValue.setAttribute("name", "executeExtractionRulesInPanels");
                                propValue.appendChild((Element) XMLUtils.writeObjectToXml(document, "false"));
                            }
                            element.setAttribute("version", "4.1.5");
                            Engine.logDatabaseObjectManager.warn("[Migration 4.6.0] The object \"" + elementName + "\" has been updated to version 4.1.5");
                        }
                    }
                    if (VersionUtils.compare(version, "4.2.0") < 0) {
                        int len = xmlv.size();
                        for (int i = 0; i < len; i++) {
                            XMLVector<Object> line = xmlv.get(i);
                            if (line.size() > 0) {
                                // Do not set as Personalizable by default
                                line.add(4, Boolean.FALSE);
                                // Sets description to variable name by default
                                line.add(1, line.get(0));
                            }
                        }
                        element.setAttribute("version", "4.2.0");
                        Engine.logDatabaseObjectManager.warn("[Migration 4.6.0] The object \"" + elementName + "\" has been updated to version 4.2.0");
                    }
                    if (VersionUtils.compare(version, "4.3.0") < 0) {
                        int len = xmlv.size();
                        for (int i = 0; i < len; i++) {
                            XMLVector<Object> line = xmlv.get(i);
                            if (line.size() > 0) {
                                // Set cached key
                                line.add(6, Boolean.TRUE);
                            }
                        }
                        element.setAttribute("version", "4.3.0");
                        Engine.logDatabaseObjectManager.warn("[Migration 4.6.0] The object \"" + elementName + "\" has been updated to version 4.3.0");
                    }
                    Element newNode = (Element) XMLUtils.writeObjectToXml(element.getOwnerDocument(), xmlv);
                    variablesDefinition.replaceChild(newNode, variablesDefinitionNode);
                    variablesDefinition.setAttribute("name", "variablesDefinition");
                }
            }
        } else // Case of HTTPStatement
        if (com.twinsoft.convertigo.beans.statements.HTTPStatement.class.isAssignableFrom(beanClass)) {
            if (VersionUtils.compare(version, "4.2.0") < 0) {
                Element variablesDefinition = MigrationUtils.findChildElementByAttributeValue(children, "property", "data");
                if (variablesDefinition != null) {
                    Element variablesDefinitionNode = (Element) XMLUtils.findChildNode(variablesDefinition, Node.ELEMENT_NODE);
                    XMLVector<XMLVector<Object>> xmlv = GenericUtils.cast(XMLUtils.readObjectFromXml(variablesDefinitionNode));
                    int len = xmlv.size();
                    for (int i = 0; i < len; i++) {
                        XMLVector<String> line = GenericUtils.cast(xmlv.get(i));
                        if (line.size() > 0) {
                            // Sets empty description by default
                            line.add(1, "");
                        }
                    }
                    Element newNode = (Element) XMLUtils.writeObjectToXml(element.getOwnerDocument(), xmlv);
                    variablesDefinition.replaceChild(newNode, variablesDefinitionNode);
                    variablesDefinition.setAttribute("name", "variablesDefinition");
                }
                Element requestUri = MigrationUtils.findChildElementByAttributeValue(children, "property", "requestUri");
                if (requestUri != null) {
                    Element requestUriNode = (Element) XMLUtils.findChildNode(requestUri, Node.ELEMENT_NODE);
                    String requestUriValue = (String) XMLUtils.readObjectFromXml(requestUriNode);
                    Element newNode = (Element) XMLUtils.writeObjectToXml(element.getOwnerDocument(), "'" + requestUriValue + "'");
                    requestUri.replaceChild(newNode, requestUriNode);
                }
                element.setAttribute("version", "4.2.0");
                Engine.logDatabaseObjectManager.warn("[Migration 4.6.0] The object \"" + elementName + "\" has been updated to version 4.2.0");
            }
        }
    } catch (Exception e) {
        Engine.logDatabaseObjectManager.error("Unable to update element", e);
    }
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) EngineException(com.twinsoft.convertigo.engine.EngineException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 20 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class Migration5_0_0 method createVariables.

private static void createVariables(Document document, Element element) throws Exception {
    Element pName, pVariablesDef;
    // NodeList properties;
    XMLVector<XMLVector<?>> xmlv;
    XMLVector<?> row;
    XMLVector<Long> ordered;
    Node node, newChild, newNode;
    Variable variable;
    String elementName, elementClassName;
    // first update element (see preconfigure() and configure())
    updateElement(element);
    NodeList children = element.getChildNodes();
    elementClassName = element.getAttribute("classname");
    pName = MigrationUtils.findChildElementByAttributeValue(children, "property", "name");
    elementName = (String) XMLUtils.readObjectFromXml((Element) XMLUtils.findChildNode(pName, Node.ELEMENT_NODE));
    pVariablesDef = MigrationUtils.findChildElementByAttributeValue(children, "property", "variablesDefinition");
    if (pVariablesDef != null) {
        node = XMLUtils.findChildNode(pVariablesDef, Node.ELEMENT_NODE);
        xmlv = GenericUtils.cast(XMLUtils.readObjectFromXml((Element) node));
        ordered = new XMLVector<Long>();
        for (int j = 0; j < xmlv.size(); j++) {
            row = (XMLVector<?>) xmlv.get(j);
            if (!row.isEmpty()) {
                try {
                    variable = newVariable(elementClassName, row, j);
                    newChild = variable.toXml(document);
                    ordered.add(Long.valueOf(variable.priority));
                    element.appendChild(newChild);
                    Engine.logDatabaseObjectManager.info("[Migration 4.6.0] Added variable \"" + variable.getName() + "\" for object \"" + elementName + "\" (" + elementClassName + ")");
                } catch (EngineException e) {
                    Engine.logDatabaseObjectManager.error("[Migration 4.6.0] Unable to migrate variable defined at row" + j + " for object \"" + elementName + "\" (" + elementClassName + ")", e);
                }
            } else {
                Engine.logDatabaseObjectManager.info("[Migration 4.6.0] No variable defined for object \"" + elementName + "\" (" + elementClassName + ")");
            }
        }
        xmlv = new XMLVector<XMLVector<?>>();
        xmlv.add(ordered);
        newNode = XMLUtils.writeObjectToXml(document, xmlv);
        pVariablesDef.replaceChild(newNode, node);
    }
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) RequestableMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableMultiValuedVariable) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) HttpStatementVariable(com.twinsoft.convertigo.beans.variables.HttpStatementVariable) HttpStatementMultiValuedVariable(com.twinsoft.convertigo.beans.variables.HttpStatementMultiValuedVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) RequestableHttpMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) EngineException(com.twinsoft.convertigo.engine.EngineException)

Aggregations

XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)51 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)18 EngineException (com.twinsoft.convertigo.engine.EngineException)15 Element (org.w3c.dom.Element)15 IOException (java.io.IOException)10 NodeList (org.w3c.dom.NodeList)8 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)7 RequestableHttpVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpVariable)6 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)6 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)6 Shell (org.eclipse.swt.widgets.Shell)6 Step (com.twinsoft.convertigo.beans.core.Step)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ArrayList (java.util.ArrayList)5 Document (org.w3c.dom.Document)5 Block (com.twinsoft.convertigo.beans.core.Block)4 Sequence (com.twinsoft.convertigo.beans.core.Sequence)4 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)4 TestCase (com.twinsoft.convertigo.beans.core.TestCase)4 Variable (com.twinsoft.convertigo.beans.core.Variable)4