Search in sources :

Example 6 with XmlQName

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

the class SessionGetObjectStep method getXmlSchemaObject.

@Override
public XmlSchemaElement getXmlSchemaObject(XmlSchemaCollection collection, XmlSchema schema) {
    XmlSchemaElement element = XmlSchemaUtils.makeDynamic(this, new XmlSchemaElement());
    element.setName(getStepNodeName());
    if (!getXmlElementRefAffectation().isEmpty()) {
        XmlSchemaComplexType eType = XmlSchemaUtils.makeDynamic(this, new XmlSchemaComplexType(schema));
        element.setType(eType);
        XmlSchemaSequence eSequence = XmlSchemaUtils.makeDynamic(this, new XmlSchemaSequence());
        eType.setParticle(eSequence);
        SchemaMeta.setContainerXmlSchemaGroupBase(element, eSequence);
        XmlSchemaElement el = XmlSchemaUtils.makeDynamic(this, new XmlSchemaElement());
        eSequence.getItems().add(el);
        el.setRefName(getElementRefAffectation());
        el.setMinOccurs(0);
        el.setMaxOccurs(1);
    } else {
        XmlQName xmlQName = getXmlComplexTypeAffectation();
        if (xmlQName.isEmpty()) {
            xmlQName = getXmlSimpleTypeAffectation();
            if (xmlQName.isEmpty()) {
                xmlQName = new XmlQName(Constants.XSD_STRING);
            }
        }
        element.setSchemaTypeName(xmlQName.getQName());
    }
    return element;
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 7 with XmlQName

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

the class Migration7_0_0 method migrate.

public static void migrate(final String projectName) {
    try {
        Map<String, Reference> referenceMap = new HashMap<String, Reference>();
        XmlSchema projectSchema = null;
        Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName, false);
        // Copy all xsd files to project's xsd directory
        File destDir = new File(project.getXsdDirPath());
        copyXsdOfProject(projectName, destDir);
        String projectWsdlFilePath = Engine.PROJECTS_PATH + "/" + projectName + "/" + projectName + ".wsdl";
        File wsdlFile = new File(projectWsdlFilePath);
        String projectXsdFilePath = Engine.PROJECTS_PATH + "/" + projectName + "/" + projectName + ".xsd";
        File xsdFile = new File(projectXsdFilePath);
        if (xsdFile.exists()) {
            // Load project schema from old XSD file
            XmlSchemaCollection collection = new XmlSchemaCollection();
            collection.setSchemaResolver(new DefaultURIResolver() {

                public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
                    // Case of a c8o project location
                    if (schemaLocation.startsWith("../") && schemaLocation.endsWith(".xsd")) {
                        try {
                            String targetProjectName = schemaLocation.substring(3, schemaLocation.indexOf("/", 3));
                            File pDir = new File(Engine.projectDir(targetProjectName));
                            if (pDir.exists()) {
                                File pFile = new File(Engine.PROJECTS_PATH + schemaLocation.substring(2));
                                // Case c8o project is already migrated
                                if (!pFile.exists()) {
                                    Document doc = Engine.theApp.schemaManager.getSchemaForProject(targetProjectName).getSchemaDocument();
                                    DOMSource source = new DOMSource(doc);
                                    StringWriter writer = new StringWriter();
                                    StreamResult result = new StreamResult(writer);
                                    TransformerFactory.newInstance().newTransformer().transform(source, result);
                                    StringReader reader = new StringReader(writer.toString());
                                    return new InputSource(reader);
                                }
                            }
                            return null;
                        } catch (Exception e) {
                            Engine.logDatabaseObjectManager.warn("[Migration 7.0.0] Unable to find schema location \"" + schemaLocation + "\"", e);
                            return null;
                        }
                    } else if (schemaLocation.indexOf("://") == -1 && schemaLocation.endsWith(".xsd")) {
                        return super.resolveEntity(targetNamespace, schemaLocation, Engine.PROJECTS_PATH + "/" + projectName);
                    }
                    return super.resolveEntity(targetNamespace, schemaLocation, baseUri);
                }
            });
            projectSchema = SchemaUtils.loadSchema(new File(projectXsdFilePath), collection);
            ConvertigoError.updateXmlSchemaObjects(projectSchema);
            SchemaMeta.setCollection(projectSchema, collection);
            for (Connector connector : project.getConnectorsList()) {
                for (Transaction transaction : connector.getTransactionsList()) {
                    try {
                        // Migrate transaction in case of a Web Service consumption project
                        if (transaction instanceof XmlHttpTransaction) {
                            XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) transaction;
                            String reqn = xmlHttpTransaction.getResponseElementQName();
                            if (!reqn.equals("")) {
                                boolean useRef = reqn.indexOf(";") == -1;
                                // Doc/Literal case
                                if (useRef) {
                                    try {
                                        String[] qn = reqn.split(":");
                                        QName refName = new QName(projectSchema.getNamespaceContext().getNamespaceURI(qn[0]), qn[1]);
                                        xmlHttpTransaction.setXmlElementRefAffectation(new XmlQName(refName));
                                    } catch (Exception e) {
                                    }
                                } else // RPC case
                                {
                                    int index, index2;
                                    try {
                                        index = reqn.indexOf(";");
                                        String opName = reqn.substring(0, index);
                                        if ((index2 = reqn.indexOf(";", index + 1)) != -1) {
                                            String eltName = reqn.substring(index + 1, index2);
                                            String eltType = reqn.substring(index2 + 1);
                                            String[] qn = eltType.split(":");
                                            QName typeName = new QName(projectSchema.getNamespaceContext().getNamespaceURI(qn[0]), qn[1]);
                                            String responseElementQName = opName + ";" + eltName + ";" + "{" + typeName.getNamespaceURI() + "}" + typeName.getLocalPart();
                                            xmlHttpTransaction.setResponseElementQName(responseElementQName);
                                        }
                                    } catch (Exception e) {
                                    }
                                }
                            }
                        }
                        // Retrieve required XmlSchemaObjects for transaction
                        QName requestQName = new QName(project.getTargetNamespace(), transaction.getXsdRequestElementName());
                        QName responseQName = new QName(project.getTargetNamespace(), transaction.getXsdResponseElementName());
                        LinkedHashMap<QName, XmlSchemaObject> map = new LinkedHashMap<QName, XmlSchemaObject>();
                        XmlSchemaWalker dw = XmlSchemaWalker.newDependencyWalker(map, true, false);
                        dw.walkByElementRef(projectSchema, requestQName);
                        dw.walkByElementRef(projectSchema, responseQName);
                        // Create transaction schema
                        String targetNamespace = projectSchema.getTargetNamespace();
                        String prefix = projectSchema.getNamespaceContext().getPrefix(targetNamespace);
                        XmlSchema transactionSchema = SchemaUtils.createSchema(prefix, targetNamespace, XsdForm.unqualified.name(), XsdForm.unqualified.name());
                        // Add required prefix declarations
                        List<String> nsList = new LinkedList<String>();
                        for (QName qname : map.keySet()) {
                            String nsURI = qname.getNamespaceURI();
                            if (!nsURI.equals(Constants.URI_2001_SCHEMA_XSD)) {
                                if (!nsList.contains(nsURI)) {
                                    nsList.add(nsURI);
                                }
                            }
                            String nsPrefix = qname.getPrefix();
                            if (!nsURI.equals(targetNamespace)) {
                                NamespaceMap nsMap = SchemaUtils.getNamespaceMap(transactionSchema);
                                if (nsMap.getNamespaceURI(nsPrefix) == null) {
                                    nsMap.add(nsPrefix, nsURI);
                                    transactionSchema.setNamespaceContext(nsMap);
                                }
                            }
                        }
                        // Add required imports
                        for (String namespaceURI : nsList) {
                            XmlSchemaObjectCollection includes = projectSchema.getIncludes();
                            for (int i = 0; i < includes.getCount(); i++) {
                                XmlSchemaObject xmlSchemaObject = includes.getItem(i);
                                if (xmlSchemaObject instanceof XmlSchemaImport) {
                                    if (((XmlSchemaImport) xmlSchemaObject).getNamespace().equals(namespaceURI)) {
                                        // do not allow import with same ns !
                                        if (namespaceURI.equals(project.getTargetNamespace()))
                                            continue;
                                        String location = ((XmlSchemaImport) xmlSchemaObject).getSchemaLocation();
                                        // This is a convertigo project reference
                                        if (location.startsWith("../")) {
                                            // Copy all xsd files to xsd directory
                                            String targetProjectName = location.substring(3, location.indexOf("/", 3));
                                            copyXsdOfProject(targetProjectName, destDir);
                                        }
                                        // Add reference
                                        addReferenceToMap(referenceMap, namespaceURI, location);
                                        // Add import
                                        addImport(transactionSchema, namespaceURI, location);
                                    }
                                }
                            }
                        }
                        QName responseTypeQName = new QName(project.getTargetNamespace(), transaction.getXsdResponseTypeName());
                        // Add required schema objects
                        for (QName qname : map.keySet()) {
                            if (qname.getNamespaceURI().equals(targetNamespace)) {
                                XmlSchemaObject ob = map.get(qname);
                                if (qname.getLocalPart().startsWith("ConvertigoError"))
                                    continue;
                                transactionSchema.getItems().add(ob);
                                // Add missing response error element and attributes
                                if (qname.equals(responseTypeQName)) {
                                    Transaction.addSchemaResponseObjects(transactionSchema, (XmlSchemaComplexType) ob);
                                }
                            }
                        }
                        // Add missing ResponseType (with document)
                        if (map.containsKey(responseTypeQName)) {
                            Transaction.addSchemaResponseType(transactionSchema, transaction);
                        }
                        // Add everything
                        if (map.isEmpty()) {
                            Transaction.addSchemaObjects(transactionSchema, transaction);
                        }
                        // Add c8o error objects (for internal xsd edition only)
                        ConvertigoError.updateXmlSchemaObjects(transactionSchema);
                        // Save schema to file
                        String transactionXsdFilePath = transaction.getSchemaFilePath();
                        new File(transaction.getSchemaFileDirPath()).mkdirs();
                        SchemaUtils.saveSchema(transactionXsdFilePath, transactionSchema);
                    } catch (Exception e) {
                        Engine.logDatabaseObjectManager.error("[Migration 7.0.0] An error occured while migrating transaction \"" + transaction.getName() + "\"", e);
                    }
                    if (transaction instanceof TransactionWithVariables) {
                        TransactionWithVariables transactionVars = (TransactionWithVariables) transaction;
                        handleRequestableVariable(transactionVars.getVariablesList());
                        // Change SQLQuery variables : i.e. {id} --> {{id}}
                        if (transaction instanceof SqlTransaction) {
                            String sqlQuery = ((SqlTransaction) transaction).getSqlQuery();
                            sqlQuery = sqlQuery.replaceAll("\\{([a-zA-Z0-9_]+)\\}", "{{$1}}");
                            ((SqlTransaction) transaction).setSqlQuery(sqlQuery);
                        }
                    }
                }
            }
        } else {
            // Should only happen for projects which version <= 4.6.0
            XmlSchemaCollection collection = new XmlSchemaCollection();
            String prefix = project.getName() + "_ns";
            projectSchema = SchemaUtils.createSchema(prefix, project.getNamespaceUri(), XsdForm.unqualified.name(), XsdForm.unqualified.name());
            ConvertigoError.addXmlSchemaObjects(projectSchema);
            SchemaMeta.setCollection(projectSchema, collection);
            for (Connector connector : project.getConnectorsList()) {
                for (Transaction transaction : connector.getTransactionsList()) {
                    if (transaction instanceof TransactionWithVariables) {
                        TransactionWithVariables transactionVars = (TransactionWithVariables) transaction;
                        handleRequestableVariable(transactionVars.getVariablesList());
                    }
                }
            }
        }
        // Handle sequence objects
        for (Sequence sequence : project.getSequencesList()) {
            handleSteps(projectSchema, referenceMap, sequence.getSteps());
            handleRequestableVariable(sequence.getVariablesList());
        }
        // Add all references to project
        if (!referenceMap.isEmpty()) {
            for (Reference reference : referenceMap.values()) project.add(reference);
        }
        // Delete XSD file
        if (xsdFile.exists())
            xsdFile.delete();
        // Delete WSDL file
        if (wsdlFile.exists())
            wsdlFile.delete();
    } catch (Exception e) {
        Engine.logDatabaseObjectManager.error("[Migration 7.0.0] An error occured while migrating project \"" + projectName + "\"", e);
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Document(org.w3c.dom.Document) LinkedHashMap(java.util.LinkedHashMap) XmlSchemaWalker(com.twinsoft.convertigo.engine.util.XmlSchemaWalker) StringWriter(java.io.StringWriter) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) DefaultURIResolver(org.apache.ws.commons.schema.resolver.DefaultURIResolver) StringReader(java.io.StringReader) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection) StreamResult(javax.xml.transform.stream.StreamResult) Reference(com.twinsoft.convertigo.beans.core.Reference) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) ImportXsdSchemaReference(com.twinsoft.convertigo.beans.references.ImportXsdSchemaReference) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) QName(javax.xml.namespace.QName) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) Sequence(com.twinsoft.convertigo.beans.core.Sequence) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Project(com.twinsoft.convertigo.beans.core.Project) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) XmlSchema(org.apache.ws.commons.schema.XmlSchema) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap) TransactionWithVariables(com.twinsoft.convertigo.beans.core.TransactionWithVariables) File(java.io.File)

Example 8 with XmlQName

use of com.twinsoft.convertigo.beans.common.XmlQName 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 9 with XmlQName

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

the class UpdateXSDTypesAction method run.

public void run() {
    final 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();
            ProjectTreeObject projectTreeObject = treeObject.getProjectTreeObject();
            MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION | SWT.APPLICATION_MODAL);
            String message = "Do you really want to extract the schema?\nWarning: the previous one will be replaced.";
            messageBox.setMessage(message);
            if (messageBox.open() == SWT.YES) {
                RequestableObject requestable = (RequestableObject) treeObject.getObject();
                String requestableName = StringUtils.normalize(requestable.getName(), true);
                Document document = null;
                String result = null;
                if (!(requestableName.equals(requestable.getName()))) {
                    throw new Exception("Requestable name should be normalized");
                }
                if (requestable instanceof Transaction) {
                    Connector connector = (Connector) requestable.getParent();
                    String connectorName = StringUtils.normalize(connector.getName(), true);
                    if (!(connectorName.equals(connector.getName()))) {
                        throw new Exception("Connector name should be normalized");
                    }
                    if (connector.getDefaultTransaction() == null) {
                        throw new Exception("Connector must have a default transaction");
                    }
                    if (requestable instanceof HtmlTransaction) {
                        if (extract) {
                            ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
                            if (connectorEditor == null) {
                                ConvertigoPlugin.infoMessageBox("Please open connector first.");
                                return;
                            }
                            document = connectorEditor.getLastGeneratedDocument();
                            if (document == null) {
                                ConvertigoPlugin.infoMessageBox("You should first generate the XML document before trying to extract the XSD types.");
                                return;
                            }
                            result = requestable.generateXsdTypes(document, extract);
                        } else {
                            HtmlTransaction defaultTransaction = (HtmlTransaction) connector.getDefaultTransaction();
                            String defaultTransactionName = StringUtils.normalize(defaultTransaction.getName(), true);
                            if (!(defaultTransactionName.equals(defaultTransaction.getName()))) {
                                throw new Exception("Default transaction name should be normalized");
                            }
                            String defaultXsdTypes = defaultTransaction.generateXsdTypes(null, false);
                            if (requestable.equals(defaultTransaction))
                                result = defaultXsdTypes;
                            else {
                                TransactionXSDTypesDialog dlg = new TransactionXSDTypesDialog(shell, requestable);
                                if (dlg.open() == Window.OK) {
                                    result = dlg.result;
                                    result += defaultXsdTypes;
                                }
                            }
                        }
                    } else {
                        if (extract) {
                            ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
                            if (connectorEditor == null) {
                                ConvertigoPlugin.infoMessageBox("Please open connector first.");
                                return;
                            }
                            document = connectorEditor.getLastGeneratedDocument();
                            if (document == null) {
                                ConvertigoPlugin.infoMessageBox("You should first generate the XML document before trying to extract the XSD types.");
                                return;
                            }
                            String prefix = requestable.getXsdTypePrefix();
                            document.getDocumentElement().setAttribute("transaction", prefix + requestableName);
                        }
                        if (requestable instanceof XmlHttpTransaction) {
                            XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) requestable;
                            XmlQName xmlQName = xmlHttpTransaction.getXmlElementRefAffectation();
                            String reqn = xmlHttpTransaction.getResponseElementQName();
                            if (extract && ((!xmlQName.isEmpty()) || (!reqn.equals("")))) {
                                if (!xmlQName.isEmpty()) {
                                    ConvertigoPlugin.infoMessageBox("You should first unset 'Assigned element QName' property.");
                                    return;
                                }
                                if (!reqn.equals("")) {
                                    ConvertigoPlugin.infoMessageBox("You should first unset 'Schema of XML response root element' property.");
                                    return;
                                }
                            }
                        }
                        result = requestable.generateXsdTypes(document, extract);
                    }
                }
                if ((result != null) && (!result.equals(""))) {
                    String xsdTypes = result;
                    if (requestable instanceof Transaction) {
                        if (requestable instanceof XmlHttpTransaction) {
                            XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) requestable;
                            XmlQName xmlQName = xmlHttpTransaction.getXmlElementRefAffectation();
                            String reqn = xmlHttpTransaction.getResponseElementQName();
                            if (!extract && ((!xmlQName.isEmpty()) || (!reqn.equals("")))) {
                                // ignore
                                ;
                            } else
                                ((Transaction) requestable).writeSchemaToFile(xsdTypes);
                        } else
                            ((Transaction) requestable).writeSchemaToFile(xsdTypes);
                    }
                    requestable.hasChanged = true;
                    Engine.theApp.schemaManager.clearCache(requestable.getProject().getName());
                    explorerView.refreshFirstSelectedTreeObject();
                    explorerView.objectSelected(new CompositeEvent(requestable));
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to update schema!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) Cursor(org.eclipse.swt.graphics.Cursor) Document(org.w3c.dom.Document) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) MessageBox(org.eclipse.swt.widgets.MessageBox) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) Shell(org.eclipse.swt.widgets.Shell) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) TransactionXSDTypesDialog(com.twinsoft.convertigo.eclipse.dialogs.TransactionXSDTypesDialog) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Display(org.eclipse.swt.widgets.Display)

Example 10 with XmlQName

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

the class XmlQNameEditorComposite method getValue.

@Override
public XmlQName getValue() {
    String namespace = tNamespace.getText();
    String localName = tLocalName.getText();
    if (localName.length() == 0) {
        return new XmlQName();
    } else {
        return new XmlQName(new QName(namespace, localName));
    }
}
Also used : XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) QName(javax.xml.namespace.QName)

Aggregations

XmlQName (com.twinsoft.convertigo.beans.common.XmlQName)16 QName (javax.xml.namespace.QName)6 EngineException (com.twinsoft.convertigo.engine.EngineException)5 XmlSchema (org.apache.ws.commons.schema.XmlSchema)4 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)4 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)4 XmlHttpTransaction (com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction)3 File (java.io.File)3 IOException (java.io.IOException)3 XmlSchemaCollection (org.apache.ws.commons.schema.XmlSchemaCollection)3 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)3 Document (org.w3c.dom.Document)3 XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)2 Connector (com.twinsoft.convertigo.beans.core.Connector)2 Transaction (com.twinsoft.convertigo.beans.core.Transaction)2 RequestableHttpVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpVariable)2 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)2 StringReader (java.io.StringReader)2 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)2 InputSource (org.xml.sax.InputSource)2