Search in sources :

Example 31 with Sequence

use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.

the class MobileComponentImportVariablesAction method run.

public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            Object databaseObject = treeObject.getObject();
            if (databaseObject != null) {
                if (databaseObject instanceof UIDynamicAction) {
                    UIDynamicAction dynAction = (UIDynamicAction) databaseObject;
                    IonBean ionBean = ((UIDynamicAction) dynAction).getIonBean();
                    if (ionBean != null) {
                        // Case of CallSequenceAction
                        if (ionBean.getName().equals("CallSequenceAction")) {
                            Object value = ionBean.getProperty("requestable").getValue();
                            if (!value.equals(false)) {
                                String target = value.toString();
                                if (!target.isEmpty()) {
                                    try {
                                        String projectName = target.substring(0, target.indexOf('.'));
                                        String sequenceName = target.substring(target.indexOf('.') + 1);
                                        Project p = Engine.theApp.databaseObjectsManager.getProjectByName(projectName);
                                        Sequence sequence = p.getSequenceByName(sequenceName);
                                        int size = sequence.numberOfVariables();
                                        for (int i = 0; i < size; i++) {
                                            RequestableVariable variable = (RequestableVariable) sequence.getVariable(i);
                                            if (variable != null) {
                                                String variableName = variable.getName();
                                                if (dynAction.getVariable(variableName) == null) {
                                                    if (!StringUtils.isNormalized(variableName))
                                                        throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
                                                    UIControlVariable uiVariable = new UIControlVariable();
                                                    uiVariable.setName(variableName);
                                                    uiVariable.setComment(variable.getDescription());
                                                    uiVariable.setVarSmartType(new MobileSmartSourceType(variable.getDefaultValue().toString()));
                                                    dynAction.addUIComponent(uiVariable);
                                                    uiVariable.bNew = true;
                                                    uiVariable.hasChanged = true;
                                                    dynAction.hasChanged = true;
                                                }
                                            }
                                        }
                                    } catch (Exception e) {
                                    }
                                }
                            }
                        } else // Case of InvokeAction
                        if (ionBean.getName().equals("InvokeAction")) {
                            UIDynamicInvoke dynInvoke = (UIDynamicInvoke) databaseObject;
                            UIActionStack stack = dynInvoke.getTargetSharedAction();
                            if (stack != null) {
                                for (UIStackVariable variable : stack.getVariables()) {
                                    String variableName = variable.getName();
                                    if (dynAction.getVariable(variableName) == null) {
                                        if (!StringUtils.isNormalized(variableName))
                                            throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
                                        UIControlVariable uiVariable = new UIControlVariable();
                                        uiVariable.setName(variableName);
                                        uiVariable.setComment(variable.getComment());
                                        MobileSmartSourceType msst = new MobileSmartSourceType();
                                        msst.setMode(MobileSmartSourceType.Mode.SCRIPT);
                                        msst.setSmartValue(variable.getVariableValue());
                                        uiVariable.setVarSmartType(msst);
                                        dynAction.addUIComponent(uiVariable);
                                        uiVariable.bNew = true;
                                        uiVariable.hasChanged = true;
                                        dynAction.hasChanged = true;
                                    }
                                }
                            }
                        }
                        if (dynAction.hasChanged) {
                            IScriptComponent main = dynAction.getMainScriptComponent();
                            if (main != null) {
                                if (main instanceof ApplicationComponent) {
                                    ((ApplicationComponent) main).markApplicationAsDirty();
                                }
                                if (main instanceof PageComponent) {
                                    ((PageComponent) main).markPageAsDirty();
                                }
                            }
                            explorerView.reloadTreeObject(treeObject);
                            StructuredSelection structuredSelection = new StructuredSelection(treeObject);
                            ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged((IWorkbenchPart) explorerView, structuredSelection);
                        }
                    }
                } else if (databaseObject instanceof UIUseShared) {
                    UIUseShared useShared = (UIUseShared) databaseObject;
                    UISharedComponent sharedComp = useShared.getTargetSharedComponent();
                    if (sharedComp != null) {
                        for (UICompVariable variable : sharedComp.getVariables()) {
                            String variableName = variable.getName();
                            if (useShared.getVariable(variableName) == null) {
                                if (!StringUtils.isNormalized(variableName))
                                    throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
                                UIControlVariable uiVariable = new UIControlVariable();
                                uiVariable.setName(variableName);
                                uiVariable.setComment(variable.getComment());
                                MobileSmartSourceType msst = new MobileSmartSourceType();
                                msst.setMode(MobileSmartSourceType.Mode.SCRIPT);
                                msst.setSmartValue(variable.getVariableValue());
                                uiVariable.setVarSmartType(msst);
                                useShared.addUIComponent(uiVariable);
                                uiVariable.bNew = true;
                                uiVariable.hasChanged = true;
                                useShared.hasChanged = true;
                            }
                        }
                        if (useShared.hasChanged) {
                            IScriptComponent main = useShared.getMainScriptComponent();
                            if (main != null) {
                                if (main instanceof ApplicationComponent) {
                                    ((ApplicationComponent) main).markApplicationAsDirty();
                                }
                                if (main instanceof PageComponent) {
                                    ((PageComponent) main).markPageAsDirty();
                                }
                            }
                            explorerView.reloadTreeObject(treeObject);
                            StructuredSelection structuredSelection = new StructuredSelection(treeObject);
                            ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged((IWorkbenchPart) explorerView, structuredSelection);
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to add variables to action !");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) MobileSmartSourceType(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType) UIUseShared(com.twinsoft.convertigo.beans.mobile.components.UIUseShared) EngineException(com.twinsoft.convertigo.engine.EngineException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) UIControlVariable(com.twinsoft.convertigo.beans.mobile.components.UIControlVariable) Cursor(org.eclipse.swt.graphics.Cursor) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) UICompVariable(com.twinsoft.convertigo.beans.mobile.components.UICompVariable) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) IScriptComponent(com.twinsoft.convertigo.beans.mobile.components.IScriptComponent) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) UIStackVariable(com.twinsoft.convertigo.beans.mobile.components.UIStackVariable) Sequence(com.twinsoft.convertigo.beans.core.Sequence) EngineException(com.twinsoft.convertigo.engine.EngineException) Project(com.twinsoft.convertigo.beans.core.Project) UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) UIDynamicAction(com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction) UIDynamicInvoke(com.twinsoft.convertigo.beans.mobile.components.UIDynamicInvoke) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) Display(org.eclipse.swt.widgets.Display)

Example 32 with Sequence

use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.

the class SequenceExecuteSelectedAction method openEditors.

private void openEditors(ProjectExplorerView explorerView, List<Step> steps, Set<SequenceStep> alreadyOpened) {
    for (Step step : steps) {
        if (step.isEnabled()) {
            if (step instanceof SequenceStep) {
                SequenceStep sequenceStep = (SequenceStep) step;
                String projectName = sequenceStep.getProjectName();
                // load project if necessary
                if (!step.getSequence().getProject().getName().equals(projectName))
                    loadProject(explorerView, projectName);
                if (alreadyOpened.contains(sequenceStep)) {
                    // avoid sequence recursion
                    return;
                }
                alreadyOpened.add(sequenceStep);
                try {
                    ProjectTreeObject projectTreeObject = (ProjectTreeObject) explorerView.getProjectRootObject(projectName);
                    Sequence subSequence = projectTreeObject.getObject().getSequenceByName(sequenceStep.getSequenceName());
                    SequenceTreeObject subSequenceTreeObject = (SequenceTreeObject) explorerView.findTreeObjectByUserObject(subSequence);
                    // recurse on sequence
                    openEditors(explorerView, subSequenceTreeObject, alreadyOpened);
                } catch (EngineException e) {
                    e.printStackTrace();
                }
            } else if (step instanceof TransactionStep) {
                TransactionStep transactionStep = (TransactionStep) step;
                String projectName = transactionStep.getProjectName();
                if (!step.getSequence().getProject().getName().equals(projectName))
                    // load project if necessary
                    loadProject(explorerView, projectName);
                try {
                    ProjectTreeObject projectTreeObject = (ProjectTreeObject) explorerView.getProjectRootObject(projectName);
                    Connector connector = projectTreeObject.getObject().getConnectorByName(transactionStep.getConnectorName());
                    ConnectorTreeObject connectorTreeObject = (ConnectorTreeObject) explorerView.findTreeObjectByUserObject(connector);
                    // open connector editor
                    connectorTreeObject.openConnectorEditor();
                } catch (EngineException e) {
                    e.printStackTrace();
                }
            } else if (step instanceof StepWithExpressions) {
                openEditors(explorerView, ((StepWithExpressions) step).getSteps(), alreadyOpened);
            }
        }
    }
}
Also used : TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) Connector(com.twinsoft.convertigo.beans.core.Connector) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) EngineException(com.twinsoft.convertigo.engine.EngineException) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) UnloadedProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) Step(com.twinsoft.convertigo.beans.core.Step) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) Sequence(com.twinsoft.convertigo.beans.core.Sequence)

Example 33 with Sequence

use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.

the class SequenceExecuteSelectedAction method run.

@Override
public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            if ((treeObject != null) && (treeObject instanceof SequenceTreeObject)) {
                SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) treeObject;
                openEditors(explorerView, sequenceTreeObject);
                Sequence sequence = sequenceTreeObject.getObject();
                ProjectTreeObject projectTreeObject = sequenceTreeObject.getProjectTreeObject();
                SequenceEditor sequenceEditor = projectTreeObject.getSequenceEditor(sequence);
                if (sequenceEditor != null) {
                    getActivePage().activate(sequenceEditor);
                    boolean fromStub = action.getId().contains("FromStub");
                    sequenceEditor.getSequenceEditorPart().getDocument(sequence.getName(), null, fromStub);
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to execute the selected sequence!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) UnloadedProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) UnloadedProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) Sequence(com.twinsoft.convertigo.beans.core.Sequence) SequenceEditor(com.twinsoft.convertigo.eclipse.editors.sequence.SequenceEditor) Cursor(org.eclipse.swt.graphics.Cursor) Display(org.eclipse.swt.widgets.Display)

Example 34 with Sequence

use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.

the class SequenceImportFromXsdAction method run.

public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
            DatabaseObject databaseObject = databaseObjectTreeObject.getObject();
            SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) ((databaseObject instanceof Sequence) ? databaseObjectTreeObject : databaseObjectTreeObject.getParentDatabaseObjectTreeObject());
            Sequence sequence = (databaseObject instanceof Sequence) ? (Sequence) databaseObject : ((StepWithExpressions) databaseObject).getSequence();
            FileDialog fileDialog = new FileDialog(shell, SWT.PRIMARY_MODAL | SWT.SAVE);
            fileDialog.setText("Import schema file");
            fileDialog.setFilterExtensions(new String[] { "*.xsd" });
            fileDialog.setFilterNames(new String[] { "Schema files" });
            fileDialog.setFilterPath(Engine.PROJECTS_PATH);
            String filePath = fileDialog.open();
            if (filePath != null) {
                filePath = filePath.replaceAll("\\\\", "/");
                XmlSchemaCollection collection = new XmlSchemaCollection();
                collection.setBaseUri(filePath);
                XmlSchema xmlSchema = SchemaUtils.loadSchema(new File(filePath), collection);
                SchemaMeta.setCollection(xmlSchema, collection);
                SchemaObjectsDialog dlg = new SchemaObjectsDialog(shell, sequence, xmlSchema);
                if (dlg.open() == Window.OK) {
                    if (dlg.result instanceof Throwable) {
                        throw (Throwable) dlg.result;
                    } else {
                        Step step = (Step) dlg.result;
                        if (step != null) {
                            if (databaseObject instanceof Sequence) {
                                sequence.addStep(step);
                                sequence.hasChanged = true;
                            } else {
                                StepWithExpressions swe = (StepWithExpressions) databaseObject;
                                swe.addStep(step);
                                swe.hasChanged = true;
                            }
                            sequence.hasChanged = true;
                            // Reload sequence in tree without updating its schema for faster reload
                            ConvertigoPlugin.logDebug("Reload sequence: start");
                            explorerView.reloadTreeObject(sequenceTreeObject);
                            ConvertigoPlugin.logDebug("Reload sequence: end");
                            // Select target dbo in tree
                            explorerView.objectSelected(new CompositeEvent(databaseObject));
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to import step from xsd!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) SchemaObjectsDialog(com.twinsoft.convertigo.eclipse.dialogs.SchemaObjectsDialog) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Step(com.twinsoft.convertigo.beans.core.Step) Cursor(org.eclipse.swt.graphics.Cursor) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) Shell(org.eclipse.swt.widgets.Shell) XmlSchema(org.apache.ws.commons.schema.XmlSchema) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Display(org.eclipse.swt.widgets.Display)

Example 35 with Sequence

use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.

the class SchemaManager method makeResponse.

public synchronized Document makeResponse(Document document) {
    try {
        Element documentElement = document.getDocumentElement();
        if (documentElement != null) {
            String project = documentElement.getAttribute("project");
            String sequence = documentElement.getAttribute("sequence");
            String connector = documentElement.getAttribute("connector");
            String transaction = documentElement.getAttribute("transaction");
            XmlSchema schema = getSchemaForProject(project);
            XmlSchemaCollection collection = SchemaMeta.getCollection(schema);
            String targetNamespace = schema.getTargetNamespace();
            String prefix = collection.getNamespaceContext().getPrefix(targetNamespace);
            String requestableName = sequence != null && sequence.length() > 0 ? sequence : connector + "__" + transaction;
            String tagname = prefix + ":" + requestableName + "Response";
            QName qname = new QName(targetNamespace, requestableName + "Response");
            Project p = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(project);
            boolean isIncludeResponseElement = true;
            if (!"".equals(sequence)) {
                try {
                    Sequence seqObj = p.getSequenceByName(sequence);
                    isIncludeResponseElement = seqObj.isIncludeResponseElement();
                } catch (Exception e) {
                }
            }
            Document responseDoc = XMLUtils.getDefaultDocumentBuilder().newDocument();
            Element requestableResponse = responseDoc.createElementNS(targetNamespace, tagname);
            if (isIncludeResponseElement) {
                Node renamed = responseDoc.renameNode(responseDoc.importNode(documentElement, true), "", "response");
                requestableResponse.appendChild(renamed);
            } else {
                NodeList children = documentElement.getChildNodes();
                for (int i = 0; i < children.getLength(); i++) {
                    requestableResponse.appendChild(responseDoc.importNode(children.item(i), true));
                }
            }
            final Map<XmlSchemaObject, List<List<XmlSchemaObject>>> map = new LinkedHashMap<XmlSchemaObject, List<List<XmlSchemaObject>>>();
            new XmlSchemaWalker(true, true) {

                List<XmlSchemaObject> elist = null;

                List<XmlSchemaObject> alist = null;

                Map<QName, XmlSchemaObject> mso = new HashMap<QName, XmlSchemaObject>();

                Map<QName, XmlSchemaObject> mto = new HashMap<QName, XmlSchemaObject>();

                public void init(XmlSchema xmlSchema, QName qname, Element element) {
                    XmlSchemaElement rxe = SchemaMeta.getCollection(xmlSchema).getElementByQName(qname);
                    if (rxe != null) {
                        List<List<XmlSchemaObject>> list = new ArrayList<List<XmlSchemaObject>>();
                        list.add(new ArrayList<XmlSchemaObject>());
                        list.add(new ArrayList<XmlSchemaObject>());
                        map.put(rxe, list);
                        mso.put(qname, rxe);
                        elist = list.get(0);
                        alist = list.get(1);
                        walkElement(xmlSchema, rxe);
                        /*for (XmlSchemaObject xso: map.keySet()) {
								System.out.println(((XmlSchemaElement)xso).getName());
								System.out.print("\t[");
								for (XmlSchemaObject child: map.get(xso).get(1)) {
									System.out.print(((XmlSchemaAttribute)child).getName()+",");
								}
								System.out.println("]");
								for (XmlSchemaObject child: map.get(xso).get(0)) {
									System.out.println("\t"+((XmlSchemaElement)child).getName());
								}
							}*/
                        makeCompliant(rxe, element);
                    }
                }

                protected boolean makeCompliant(XmlSchemaObject xso, Node node) {
                    String tns = node.getNamespaceURI();
                    String nodeName = node.getNodeName();
                    String localName = nodeName.substring(nodeName.indexOf(":") + 1);
                    String xsoName = xso instanceof XmlSchemaElement ? ((XmlSchemaElement) xso).getName() : ((XmlSchemaAttribute) xso).getName();
                    if (xsoName.equals(localName)) {
                        Document doc = node.getOwnerDocument();
                        QName xsoQName = xso instanceof XmlSchemaElement ? ((XmlSchemaElement) xso).getQName() : ((XmlSchemaAttribute) xso).getQName();
                        boolean elementQualified = SchemaMeta.getSchema(xso).getElementFormDefault().getValue().equals("qualified");
                        boolean attributeQualified = SchemaMeta.getSchema(xso).getAttributeFormDefault().getValue().equals("qualified");
                        boolean isQualified = (xsoQName != null && !xsoQName.getNamespaceURI().equals("")) || (xso instanceof XmlSchemaElement ? elementQualified : attributeQualified);
                        // String targetNamespace = SchemaMeta.getSchema(xso).getTargetNamespace();
                        // String prefix = SchemaMeta.getCollection(xso).getNamespaceContext().getPrefix(targetNamespace);
                        String targetNamespace = xsoQName != null && !xsoQName.getNamespaceURI().equals("") ? xsoQName.getNamespaceURI() : SchemaMeta.getSchema(xso).getTargetNamespace();
                        String prefix = SchemaMeta.getCollection(xso).getNamespaceContext().getPrefix(targetNamespace);
                        prefix = prefix == null ? (xsoQName != null && !xsoQName.getNamespaceURI().equals("") ? xsoQName.getPrefix() : "") : prefix;
                        if (isQualified)
                            node = doc.renameNode(node, targetNamespace, prefix + ":" + localName);
                        else
                            node = doc.renameNode(node, "", localName);
                        if (node.getNodeType() == Node.ELEMENT_NODE) {
                            Element element = (Element) node;
                            if (element.hasAttributes()) {
                                NamedNodeMap attributes = element.getAttributes();
                                List<Node> list = new ArrayList<Node>();
                                for (int i = 0; i < attributes.getLength(); i++) {
                                    Node attr = attributes.item(i);
                                    String attrNodeName = attr.getNodeName();
                                    boolean found = false;
                                    for (XmlSchemaObject a : map.get(xso).get(1)) {
                                        if (makeCompliant(a, attr)) {
                                            found = true;
                                            break;
                                        }
                                    }
                                    if (!found) {
                                        if (attrNodeName.equals("xsi:type") || attrNodeName.startsWith("xmlns:") || attrNodeName.endsWith(":encodingStyle")) {
                                            list.add(attr);
                                        }
                                    } else {
                                        if (attrNodeName.startsWith("xsi:")) {
                                            attr = doc.renameNode(attr, Constants.URI_2001_SCHEMA_XSI, attrNodeName);
                                            String attrNodeValue = attr.getNodeValue();
                                            int index = attrNodeValue.indexOf(":");
                                            if (index != -1) {
                                                String pref = attrNodeValue.substring(0, index);
                                                if (attributes.getNamedItem("xmlns:" + pref) == null) {
                                                    String ns = SchemaMeta.getCollection(xso).getNamespaceContext().getNamespaceURI(pref);
                                                    if ("".equals(ns) || ns == null)
                                                        ns = SchemaMeta.getSchema(xso).getTargetNamespace();
                                                    element.setAttributeNS(Constants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + pref, ns);
                                                }
                                            }
                                        }
                                        if (attrNodeName.startsWith("xmlns:")) {
                                            attr = doc.renameNode(attr, Constants.XMLNS_ATTRIBUTE_NS_URI, attrNodeName);
                                        }
                                    }
                                }
                                for (Node attr : list) {
                                    element.removeAttributeNode((Attr) attr);
                                }
                            }
                            if (element.hasChildNodes()) {
                                NodeList children = element.getChildNodes();
                                for (int i = 0; i < children.getLength(); i++) {
                                    if (children.item(i).getNodeType() == Node.TEXT_NODE)
                                        continue;
                                    // System.out.println("element: "+children.item(i).getNodeName());
                                    for (XmlSchemaObject e : map.get(xso).get(0)) {
                                        // System.out.println(" test "+((XmlSchemaElement)e).getName());
                                        if (makeCompliant(e, children.item(i))) {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        return true;
                    } else {
                        // System.out.println(nodeName);
                        if ((tns != null) && !tns.equals("")) {
                            Document doc = node.getOwnerDocument();
                            String prefix = SchemaMeta.getCollection(xso).getNamespaceContext().getPrefix(tns);
                            if ((prefix != null) && !prefix.equals("")) {
                                node = doc.renameNode(node, tns, prefix + ":" + localName);
                            }
                        }
                    }
                    return false;
                }

                @Override
                public void walkByTypeName(XmlSchema xmlSchema, QName qname) {
                    XmlSchemaType obj = SchemaMeta.getCollection(xmlSchema).getTypeByQName(qname);
                    if (obj != null) {
                        if (!mso.containsKey(qname)) {
                            mso.put(qname, obj);
                            super.walkByTypeName(xmlSchema, qname);
                        } else {
                            if (mto.containsKey(qname)) {
                                // System.out.println("\nWalk type "+ qname);
                                elist.addAll(map.get(mto.get(qname)).get(0));
                            }
                        }
                    }
                }

                @Override
                public void walkByElementRef(XmlSchema xmlSchema, QName qname) {
                    XmlSchemaElement obj = SchemaMeta.getCollection(xmlSchema).getElementByQName(qname);
                    if (obj != null) {
                        if (!mso.containsKey(qname)) {
                            mso.put(qname, obj);
                            super.walkByElementRef(xmlSchema, qname);
                        } else {
                            if (mto.containsKey(qname)) {
                                // System.out.println("\nWalk elem ref "+ qname);
                                elist.add(mto.get(qname));
                            }
                        }
                    }
                }

                @Override
                public void walkByAttributeGroupRef(XmlSchema xmlSchema, QName qname) {
                    XmlSchema schema = SchemaMeta.getCollection(xmlSchema).schemaForNamespace(qname.getNamespaceURI());
                    XmlSchemaAttributeGroup obj = (XmlSchemaAttributeGroup) schema.getAttributeGroups().getItem(qname);
                    if (obj != null) {
                        if (!mso.containsKey(qname)) {
                            mso.put(qname, obj);
                            super.walkByAttributeGroupRef(xmlSchema, qname);
                        }
                    }
                }

                @Override
                public void walkByAttributeRef(XmlSchema xmlSchema, QName qname) {
                    XmlSchemaAttribute obj = SchemaMeta.getCollection(xmlSchema).getAttributeByQName(qname);
                    if (obj != null) {
                        if (!mso.containsKey(qname)) {
                            mso.put(qname, obj);
                            super.walkByAttributeRef(xmlSchema, qname);
                        } else {
                            if (mto.containsKey(qname)) {
                                // System.out.println("\nWalk attr ref "+ qname);
                                alist.add(mto.get(qname));
                            }
                        }
                    }
                }

                @Override
                public void walkByGroupRef(XmlSchema xmlSchema, QName qname) {
                    XmlSchema schema = SchemaMeta.getCollection(xmlSchema).schemaForNamespace(qname.getNamespaceURI());
                    XmlSchemaGroup obj = (XmlSchemaGroup) schema.getGroups().getItem(qname);
                    if (obj != null) {
                        if (!mso.containsKey(qname)) {
                            mso.put(qname, obj);
                            super.walkByGroupRef(xmlSchema, qname);
                        }
                    }
                }

                @Override
                protected void walkElement(XmlSchema xmlSchema, XmlSchemaElement obj) {
                    List<XmlSchemaObject> el = elist;
                    List<XmlSchemaObject> al = alist;
                    QName qname = obj.getQName();
                    QName refName = obj.getRefName();
                    QName typeName = obj.getSchemaTypeName();
                    if (refName == null) {
                        el.add(obj);
                        List<List<XmlSchemaObject>> list = new ArrayList<List<XmlSchemaObject>>();
                        list.add(new ArrayList<XmlSchemaObject>());
                        list.add(new ArrayList<XmlSchemaObject>());
                        map.put(obj, list);
                        // System.out.print("\nname="+obj.getName());
                        String ns = SchemaMeta.getSchema(obj).getTargetNamespace();
                        if (typeName != null) {
                            if (!mto.containsKey(typeName)) {
                                if (typeName.getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
                                    typeName = new QName(ns, obj.getName());
                                }
                                mto.put(typeName, obj);
                            // System.out.print("; typeN="+typeName);
                            } else {
                                map.put(obj, map.get(mto.get(typeName)));
                                // type already done
                                return;
                            }
                        } else {
                            if (qname != null) {
                                if (qname.getNamespaceURI().equals("")) {
                                    qname = new QName(ns, obj.getName());
                                }
                            } else
                                qname = new QName(ns, obj.getName());
                            if (!mto.containsKey(qname)) {
                                mto.put(qname, obj);
                            // System.out.print("; qname="+qname);
                            }
                        }
                        elist = list.get(0);
                        alist = list.get(1);
                        super.walkElement(xmlSchema, obj);
                        elist = el;
                        alist = al;
                    } else {
                        super.walkElement(xmlSchema, obj);
                        elist = el;
                        alist = al;
                    }
                }

                @Override
                protected void walkAttribute(XmlSchema xmlSchema, XmlSchemaAttribute obj) {
                    if (obj.getRefName() == null) {
                        alist.add(obj);
                    }
                    super.walkAttribute(xmlSchema, obj);
                }
            }.init(schema, qname, requestableResponse);
            responseDoc.appendChild(requestableResponse);
            // System.out.println(XMLUtils.prettyPrintDOM(responseDoc));
            return responseDoc;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return document;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr) LinkedHashMap(java.util.LinkedHashMap) XmlSchemaWalker(com.twinsoft.convertigo.engine.util.XmlSchemaWalker) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) NamedNodeMap(org.w3c.dom.NamedNodeMap) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) NodeList(org.w3c.dom.NodeList) XmlSchemaAttributeGroup(org.apache.ws.commons.schema.XmlSchemaAttributeGroup) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) Sequence(com.twinsoft.convertigo.beans.core.Sequence) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) SAXException(org.xml.sax.SAXException) Project(com.twinsoft.convertigo.beans.core.Project) XmlSchemaGroup(org.apache.ws.commons.schema.XmlSchemaGroup) XmlSchema(org.apache.ws.commons.schema.XmlSchema)

Aggregations

Sequence (com.twinsoft.convertigo.beans.core.Sequence)94 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)47 EngineException (com.twinsoft.convertigo.engine.EngineException)42 Step (com.twinsoft.convertigo.beans.core.Step)38 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)37 Project (com.twinsoft.convertigo.beans.core.Project)34 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)34 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)32 Transaction (com.twinsoft.convertigo.beans.core.Transaction)29 Cursor (org.eclipse.swt.graphics.Cursor)29 Display (org.eclipse.swt.widgets.Display)29 Shell (org.eclipse.swt.widgets.Shell)29 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)27 Connector (com.twinsoft.convertigo.beans.core.Connector)21 StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)20 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)19 TransactionStep (com.twinsoft.convertigo.beans.steps.TransactionStep)18 SequenceStep (com.twinsoft.convertigo.beans.steps.SequenceStep)17 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)17 RequestableStep (com.twinsoft.convertigo.beans.core.RequestableStep)16